home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Macmaailma Vuosikerta 1994 to 1996
/
TK1996_3CD.ISO
/
pc
/
k_portti
/
tk0395
/
fmexpand.c
next >
Wrap
C/C++ Source or Header
|
1995-04-18
|
4KB
|
167 lines
#include <windows.h>
#include <wfext.h>
#include <lzexpand.h>
#include <dir.h>
#include "fmexpand.h"
BOOL CALLBACK _export ExpandDlgProc(HWND, UINT, WPARAM, LPARAM);
BOOL ExpandFile(LPSTR, LPSTR);
LPSTR lstrrchr(LPSTR, char);
HINSTANCE ghInst;
HMENU ghMenu;
WORD gwMenuDelta;
FMS_GETFILESEL gFileSel;
char gszSrcName[256];
char gszDestName[256];
#pragma argsused
int CALLBACK LibMain(HINSTANCE hInstance, WORD wDataSeg, WORD wHeapSize, LPSTR lpszCmdLine)
{
ghInst = hInstance;
return 1;
}
HMENU CALLBACK _export FMExtensionProc(HWND hwnd, UINT msg, LPARAM lParam)
{
LPFMS_LOAD lpload;
short nFiles;
switch (msg)
{
case FMEVENT_LOAD:
lpload = (LPFMS_LOAD) lParam;
ghMenu = LoadMenu( ghInst, "FMExpand" );
lpload->hMenu = ghMenu;
gwMenuDelta = lpload->wMenuDelta;
lpload->dwSize = sizeof (FMS_LOAD);
lstrcpy( lpload->szMenuName, "L&aajenna" );
return ghMenu;
case FMEVENT_INITMENU:
gwMenuDelta = LOWORD(lParam);
ghMenu = (HMENU) HIWORD(lParam);
nFiles = (short) SendMessage( hwnd, FM_GETSELCOUNT, FMFOCUS_DIR, 0L );
EnableMenuItem(ghMenu, gwMenuDelta + IDM_EXPAND, nFiles ? MF_ENABLED : MF_GRAYED);
break;
case IDM_EXPAND:
SendMessage( hwnd, FM_GETFILESEL, 0, (LPARAM)(LPFMS_GETFILESEL)&gFileSel );
lstrcpy( gszSrcName, gFileSel.szName );
if ( DialogBox( ghInst, "DlgExpand", hwnd, ExpandDlgProc ) == 0 )
if ( !ExpandFile( gszSrcName, gszDestName ) )
MessageBox( hwnd, "Virhe laajennettaessa tiedostoa",
"Laajenna", MB_ICONSTOP | MB_OK );
break;
default:
break;
}
return NULL;
}
BOOL CALLBACK _export ExpandDlgProc(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam)
{
BOOL fResult = FALSE;
LPSTR lp;
char szDir[128];
char szName[14];
switch (msg)
{
case WM_INITDIALOG:
EnableWindow( GetDlgItem(hDlg, IDOK), FALSE );
lstrcpy( szDir, gszSrcName );
lp = lstrrchr(szDir, '\\');
lstrcpy( szName, AnsiNext(lp) );
*lp = '\0';
if ( lstrlen(szDir) == 2 ) /* esim. A: */
lstrcat( szDir, "\\" );
OemToAnsi( szDir, szDir );
SetWindowText( GetDlgItem(hDlg, IDD_CURRENT), (LPSTR)szDir );
OemToAnsi( szName, szName );
SetWindowText( GetDlgItem(hDlg, IDD_FROM), (LPSTR)szName );
SendDlgItemMessage( hDlg, IDD_TO, EM_LIMITTEXT, 256, 0L );
SetFocus( GetDlgItem(hDlg, IDD_TO) );
break;
case WM_COMMAND:
switch (wParam)
{
case IDD_TO:
if ( HIWORD(lParam) == EN_CHANGE )
EnableWindow( GetDlgItem(hDlg, IDOK),
(BOOL) SendMessage( (HWND) LOWORD(lParam),
WM_GETTEXTLENGTH, 0, 0L) );
fResult = TRUE;
break;
case IDOK:
GetWindowText( GetDlgItem(hDlg, IDD_TO), gszDestName, 256 );
if ( gszDestName[0] != '\0' )
{
AnsiToOem( gszDestName, gszDestName );
EndDialog( hDlg, 0 ); /* 0 = kaikki OK */
}
else
{
MessageBeep( MB_ICONASTERISK );
SetFocus( GetDlgItem(hDlg, IDD_TO) );
SendDlgItemMessage( hDlg, IDD_TO, EM_SETSEL, TRUE, MAKELONG(0,-1) );
}
fResult = TRUE;
break;
case IDCANCEL:
EndDialog( hDlg, 1 ); /* 1 = peruutettu */
fResult = TRUE;
break;
} /* switch (wParam) */
break;
} /* switch (msg) */
return fResult;
}
BOOL ExpandFile(LPSTR lpszSrc, LPSTR lpszDest)
{
OFSTRUCT ofSrc, ofDest;
HFILE hfSrc, hfDest;
BOOL fSuccess = TRUE;
hfSrc = LZOpenFile( lpszSrc, &ofSrc, OF_READ );
if ( hfSrc == HFILE_ERROR )
return FALSE;
hfDest = LZOpenFile( lpszDest, &ofDest, OF_CREATE );
if ( hfDest == HFILE_ERROR )
{
LZClose( hfSrc );
return FALSE;
}
if ( LZCopy( hfSrc, hfDest ) < 0 )
fSuccess = FALSE;
LZClose( hfSrc );
LZClose( hfDest );
return fSuccess;
}
LPSTR lstrrchr( LPSTR str, char ch )
{
LPSTR strl = str + lstrlen(str);
do
{
if ( ch == *strl ) return strl;
strl = AnsiPrev( str, strl );
}
while (strl > str);
return NULL;
}