2002-08-02 10:01:35 +00:00
# include <windows.h>
# include <stdio.h>
2005-04-16 17:07:16 +00:00
# include <ctype.h>
2002-09-10 03:44:53 +00:00
# include <commctrl.h>
2003-09-28 12:42:03 +00:00
2003-11-25 18:11:23 +00:00
/*
2005-11-12 17:19:46 +00:00
version 0.35
* drag & drop support
2005-11-08 21:49:07 +00:00
version 0.34
* preserve zip timestamps
2005-10-21 13:55:15 +00:00
version 0.33
* Added solid compression checkbox
2004-06-25 10:48:31 +00:00
version 0.32
* Fixed codepage problems
2003-11-25 18:11:23 +00:00
version 0.31 ( by Joost Verburg )
* LZMA compression support
* Fixed compression setting
version 0.31 ( by Joost Verburg )
* Based on header files
* Improved interface
* Modern UI support
* New script code
* Immproved folder detection
portions Copyright <EFBFBD> 1999 - 2001 Miguel Garrido ( mgarrido01 @ hotmail . com )
*/
2002-08-02 10:01:35 +00:00
extern " C "
{
# include "zlib/unzip.h"
} ;
# include "resource.h"
2003-09-28 12:42:03 +00:00
const char * g_errcaption = " Zip2Exe Error " ;
2002-08-02 10:01:35 +00:00
HINSTANCE g_hInstance ;
HWND g_hwnd ;
HANDLE g_hThread ;
char g_cmdline [ 1024 ] ;
int g_extracting ;
2003-11-25 18:11:23 +00:00
int g_compressor ;
2005-10-21 13:53:27 +00:00
int g_compressor_solid ;
2003-09-28 12:42:03 +00:00
int g_mui ;
2002-08-02 10:01:35 +00:00
int g_zipfile_size ;
char * g_options = " " ; //"/V3";
2004-02-06 17:36:48 +00:00
static BOOL CALLBACK DlgProc ( HWND hwndDlg , UINT uMsg , WPARAM wParam , LPARAM lParam ) ;
2002-08-02 10:01:35 +00:00
int WINAPI WinMain ( HINSTANCE hInstance , HINSTANCE hPrevInst ,
LPSTR lpszCmdParam , int nCmdShow )
{
g_hInstance = hInstance ;
2002-09-10 03:44:53 +00:00
InitCommonControls ( ) ;
2002-08-02 10:01:35 +00:00
return DialogBox ( hInstance , MAKEINTRESOURCE ( IDD_DIALOG1 ) , GetDesktopWindow ( ) , DlgProc ) ;
}
char tempzip_path [ 1024 ] ;
int made ;
static void doRMDir ( char * buf )
{
HANDLE h ;
WIN32_FIND_DATA fd ;
char * p = buf ;
while ( * p ) p + + ;
lstrcpy ( p , " \\ *.* " ) ;
h = FindFirstFile ( buf , & fd ) ;
2004-02-06 17:36:48 +00:00
if ( h ! = INVALID_HANDLE_VALUE )
2002-08-02 10:01:35 +00:00
{
do
{
if ( fd . cFileName [ 0 ] ! = ' . ' | |
( fd . cFileName [ 1 ] ! = ' . ' & & fd . cFileName [ 1 ] ) )
{
lstrcpy ( p + 1 , fd . cFileName ) ;
2004-02-06 17:36:48 +00:00
if ( fd . dwFileAttributes & FILE_ATTRIBUTE_READONLY )
2002-08-02 10:01:35 +00:00
SetFileAttributes ( buf , fd . dwFileAttributes ^ FILE_ATTRIBUTE_READONLY ) ;
if ( fd . dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY ) doRMDir ( buf ) ;
2004-02-06 17:36:48 +00:00
else
2002-08-02 10:01:35 +00:00
{
DeleteFile ( buf ) ;
}
}
} while ( FindNextFile ( h , & fd ) ) ;
FindClose ( h ) ;
}
p [ 0 ] = 0 ; // fix buffer
RemoveDirectory ( buf ) ;
}
static void doMKDir ( char * directory )
{
2004-02-06 17:36:48 +00:00
char * p , * p2 ;
char buf [ MAX_PATH ] ;
2002-08-02 10:01:35 +00:00
if ( ! * directory ) return ;
2004-02-06 17:36:48 +00:00
lstrcpy ( buf , directory ) ;
2002-08-02 10:01:35 +00:00
p = buf ; while ( * p ) p + + ;
2004-02-06 17:36:48 +00:00
while ( p > = buf & & * p ! = ' \\ ' ) p - - ;
p2 = buf ;
if ( p2 [ 1 ] = = ' : ' ) p2 + = 4 ;
else if ( p2 [ 0 ] = = ' \\ ' & & p2 [ 1 ] = = ' \\ ' )
{
p2 + = 2 ;
while ( * p2 & & * p2 ! = ' \\ ' ) p2 + + ;
if ( * p2 ) p2 + + ;
while ( * p2 & & * p2 ! = ' \\ ' ) p2 + + ;
if ( * p2 ) p2 + + ;
}
if ( p > = p2 )
{
* p = 0 ;
doMKDir ( buf ) ;
}
CreateDirectory ( directory , NULL ) ;
2002-08-02 10:01:35 +00:00
}
void tempzip_cleanup ( HWND hwndDlg , int err )
{
if ( tempzip_path [ 0 ] ) doRMDir ( tempzip_path ) ;
tempzip_path [ 0 ] = 0 ;
if ( err )
{
SendDlgItemMessage ( hwndDlg , IDC_ZIPINFO_FILES , LB_RESETCONTENT , 0 , 0 ) ;
EnableWindow ( GetDlgItem ( hwndDlg , IDOK ) , 0 ) ;
SetDlgItemText ( hwndDlg , IDC_ZIPINFO_SUMMARY , " " ) ;
SetDlgItemText ( hwndDlg , IDC_ZIPFILE , " " ) ;
SetDlgItemText ( hwndDlg , IDC_OUTFILE , " " ) ;
}
}
int tempzip_make ( HWND hwndDlg , char * fn )
{
char buf [ MAX_PATH ] ;
GetTempPath ( MAX_PATH , buf ) ;
GetTempFileName ( buf , " z2e " , GetTickCount ( ) , tempzip_path ) ;
if ( ! CreateDirectory ( tempzip_path , NULL ) )
{
GetTempPath ( MAX_PATH , tempzip_path ) ;
strcat ( tempzip_path , " \\ nsi " ) ;
if ( ! CreateDirectory ( tempzip_path , NULL ) )
{
tempzip_path [ 0 ] = 0 ;
MessageBox ( hwndDlg , " Error creating temporary directory " , g_errcaption , MB_OK | MB_ICONSTOP ) ;
return 1 ;
}
}
FILE * fp = fopen ( fn , " rb " ) ;
if ( fp )
{
fseek ( fp , 0 , SEEK_END ) ;
g_zipfile_size = ftell ( fp ) ;
fclose ( fp ) ;
}
else g_zipfile_size = 0 ;
unzFile f ;
f = unzOpen ( fn ) ;
if ( ! f | | unzGoToFirstFile ( f ) ! = UNZ_OK )
{
if ( f ) unzClose ( f ) ;
MessageBox ( hwndDlg , " Error opening ZIP file " , g_errcaption , MB_OK | MB_ICONSTOP ) ;
return 1 ;
}
2004-02-06 17:36:48 +00:00
2002-08-02 10:01:35 +00:00
int nf = 0 , nkb = 0 ;
g_extracting = 1 ;
2004-02-06 17:36:48 +00:00
do {
char filename [ MAX_PATH ] ;
2004-06-18 18:58:56 +00:00
unz_file_info info ;
unzGetCurrentFileInfo ( f , & info , filename , sizeof ( filename ) , NULL , 0 , NULL , 0 ) ;
// was zip created on MS-DOS/Windows?
if ( ( info . version & 0xFF00 ) = = 0 )
{
2005-04-23 19:22:01 +00:00
OemToCharBuff ( filename , filename , strlen ( filename ) ) ;
2004-06-18 18:58:56 +00:00
}
2004-02-06 17:36:48 +00:00
if ( filename [ 0 ] & &
filename [ strlen ( filename ) - 1 ] ! = ' \\ ' & &
2002-08-02 10:01:35 +00:00
filename [ strlen ( filename ) - 1 ] ! = ' / ' )
{
char * pfn = filename ;
while ( * pfn )
{
if ( * pfn = = ' / ' ) * pfn = ' \\ ' ;
pfn + + ;
}
pfn = filename ;
if ( pfn [ 1 ] = = ' : ' & & pfn [ 2 ] = = ' \\ ' ) pfn + = 3 ;
while ( * pfn = = ' \\ ' ) pfn + + ;
char out_filename [ 1024 ] ;
lstrcpy ( out_filename , tempzip_path ) ;
lstrcat ( out_filename , " \\ " ) ;
lstrcat ( out_filename , pfn ) ;
if ( strstr ( pfn , " \\ " ) )
{
char buf [ 1024 ] ;
lstrcpy ( buf , out_filename ) ;
char * p = buf + strlen ( buf ) ;
while ( p > buf & & * p ! = ' \\ ' ) p - - ;
* p = 0 ;
if ( buf [ 0 ] ) doMKDir ( buf ) ;
}
2004-02-06 17:36:48 +00:00
if ( unzOpenCurrentFile ( f ) = = UNZ_OK )
{
2002-08-02 10:01:35 +00:00
SendDlgItemMessage ( hwndDlg , IDC_ZIPINFO_FILES , LB_ADDSTRING , 0 , ( LPARAM ) pfn ) ;
2004-02-06 17:36:48 +00:00
FILE * fp ;
int l ;
fp = fopen ( out_filename , " wb " ) ;
if ( fp )
{
do
{
char buf [ 1024 ] ;
l = unzReadCurrentFile ( f , buf , sizeof ( buf ) ) ;
if ( l > 0 )
2002-08-02 10:01:35 +00:00
{
if ( fwrite ( buf , 1 , l , fp ) ! = ( unsigned int ) l )
{
unzClose ( f ) ;
fclose ( fp ) ;
MessageBox ( hwndDlg , " Error writing output file(s) " , g_errcaption , MB_OK | MB_ICONSTOP ) ;
g_extracting = 0 ;
return 1 ;
}
nkb + + ;
}
2004-02-06 17:36:48 +00:00
} while ( l > 0 ) ;
2002-08-02 10:01:35 +00:00
2004-02-06 17:36:48 +00:00
fclose ( fp ) ;
2005-11-08 21:49:07 +00:00
{
// set file time
HANDLE hf = CreateFile ( out_filename , GENERIC_WRITE , 0 , 0 , OPEN_ALWAYS , 0 , 0 ) ;
if ( hf ! = INVALID_HANDLE_VALUE )
{
FILETIME ft , lft ;
DosDateTimeToFileTime ( HIWORD ( info . dosDate ) , LOWORD ( info . dosDate ) , & ft ) ;
LocalFileTimeToFileTime ( & ft , & lft ) ;
SetFileTime ( hf , 0 , 0 , & lft ) ;
CloseHandle ( hf ) ;
}
}
2004-02-06 17:36:48 +00:00
}
2002-08-02 10:01:35 +00:00
else
{
unzClose ( f ) ;
MessageBox ( hwndDlg , " Error opening output file(s) " , g_errcaption , MB_OK | MB_ICONSTOP ) ;
g_extracting = 0 ;
return 1 ;
}
nf + + ;
wsprintf ( buf , " Extracting: %d files, %dKB " , nf , nkb ) ;
SetDlgItemText ( hwndDlg , IDC_ZIPINFO_SUMMARY , buf ) ;
MSG msg ;
int quit = 0 ;
while ( PeekMessage ( & msg , NULL , 0 , 0 , PM_REMOVE ) )
{
2004-02-06 17:36:48 +00:00
if ( msg . message = = WM_DESTROY & & msg . hwnd = = g_hwnd )
2002-08-02 10:01:35 +00:00
{
quit + + ;
break ;
}
TranslateMessage ( & msg ) ;
DispatchMessage ( & msg ) ;
}
2004-02-06 17:36:48 +00:00
unzCloseCurrentFile ( f ) ;
2002-08-02 10:01:35 +00:00
if ( quit ) break ;
2004-02-06 17:36:48 +00:00
}
2002-08-02 10:01:35 +00:00
else
{
unzClose ( f ) ;
MessageBox ( hwndDlg , " Error extracting from ZIP file " , g_errcaption , MB_OK | MB_ICONSTOP ) ;
g_extracting = 0 ;
return 1 ;
}
}
} while ( unzGoToNextFile ( f ) = = UNZ_OK ) ;
2004-02-06 17:36:48 +00:00
2002-08-02 10:01:35 +00:00
g_extracting = 0 ;
wsprintf ( buf , " Extracted: %d files, %dKB " , nf , nkb ) ;
SetDlgItemText ( hwndDlg , IDC_ZIPINFO_SUMMARY , buf ) ;
unzClose ( f ) ;
return 0 ;
}
char * gp_winamp = " (WINAMP DIRECTORY) " ;
char * gp_winamp_plugins = " (WINAMP PLUG-INS DIRECTORY) " ;
char * gp_winamp_vis = " (WINAMP VIS PLUG-INS DIRECTORY) " ;
char * gp_winamp_dsp = " (WINAMP DSP PLUG-INS DIRECTORY) " ;
char * gp_winamp_skins = " (WINAMP SKINS DIRECTORY) " ;
char * gp_poi = " (PATH OF INSTALLER) " ;
void wnd_printf ( const char * str )
{
if ( ! * str ) return ;
2004-02-06 17:36:48 +00:00
char existing_text [ 32000 ] ;
2002-08-02 10:01:35 +00:00
existing_text [ 0 ] = 0 ;
2004-02-06 17:36:48 +00:00
UINT l = GetDlgItemText ( g_hwnd , IDC_OUTPUTTEXT , existing_text , 32000 ) ;
2002-08-02 10:01:35 +00:00
l + = strlen ( str ) ;
char * p = existing_text ;
existing_text [ 31000 ] = 0 ;
while ( l > 31000 & & * p )
{
while ( * p ! = ' \r ' & & * p ! = ' \n ' & & * p )
{
p + + ;
l - - ;
}
while ( * p = = ' \r ' | | * p = = ' \n ' )
{
p + + ;
l - - ;
}
}
char buf [ 31000 ] ;
lstrcpy ( buf , p ) ;
lstrcpy ( existing_text , buf ) ;
lstrcat ( existing_text , str ) ;
2004-02-06 17:36:48 +00:00
SetDlgItemText ( g_hwnd , IDC_OUTPUTTEXT , existing_text ) ;
SendDlgItemMessage ( g_hwnd , IDC_OUTPUTTEXT , EM_LINESCROLL , 0 , SendDlgItemMessage ( g_hwnd , IDC_OUTPUTTEXT , EM_GETLINECOUNT , 0 , 0 ) ) ; // scroll to the last line of the textbox
2002-08-02 10:01:35 +00:00
}
void ErrorMessage ( char * str ) //display detailed error info
{
2004-02-06 17:36:48 +00:00
LPVOID msg ;
FormatMessage (
FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM ,
NULL ,
GetLastError ( ) ,
MAKELANGID ( LANG_NEUTRAL , SUBLANG_DEFAULT ) , // Default language
( LPTSTR ) & msg ,
0 ,
NULL
) ;
2002-08-02 10:01:35 +00:00
wnd_printf ( str ) ;
wnd_printf ( " : " ) ;
wnd_printf ( ( char * ) msg ) ;
2004-02-06 17:36:48 +00:00
LocalFree ( msg ) ;
2002-08-02 10:01:35 +00:00
}
DWORD WINAPI ThreadProc ( LPVOID p ) // thread that will start & monitor wwwinamp
{
2004-02-06 17:36:48 +00:00
char buf [ 1024 ] ; //i/o buffer
2002-08-02 10:01:35 +00:00
STARTUPINFO si = { sizeof ( si ) , } ;
SECURITY_ATTRIBUTES sa = { sizeof ( sa ) , } ;
SECURITY_DESCRIPTOR sd = { 0 , } ; //security information for pipes
PROCESS_INFORMATION pi = { 0 , } ;
HANDLE newstdout = 0 , read_stdout = 0 ; //pipe handles
OSVERSIONINFO osv = { sizeof ( osv ) } ;
2004-02-06 17:36:48 +00:00
GetVersionEx ( & osv ) ;
if ( osv . dwPlatformId = = VER_PLATFORM_WIN32_NT ) //initialize security descriptor (Windows NT)
{
InitializeSecurityDescriptor ( & sd , SECURITY_DESCRIPTOR_REVISION ) ;
SetSecurityDescriptorDacl ( & sd , true , NULL , false ) ;
sa . lpSecurityDescriptor = & sd ;
}
else sa . lpSecurityDescriptor = NULL ;
sa . bInheritHandle = true ; //allow inheritable handles
if ( ! CreatePipe ( & read_stdout , & newstdout , & sa , 0 ) ) //create stdout pipe
{
ErrorMessage ( " CreatePipe " ) ;
2002-08-02 10:01:35 +00:00
PostMessage ( g_hwnd , WM_USER + 1203 , 0 , 1 ) ;
2004-02-06 17:36:48 +00:00
return 1 ;
}
GetStartupInfo ( & si ) ; //set startupinfo for the spawned process
/*
The dwFlags member tells CreateProcess how to make the process .
STARTF_USESTDHANDLES validates the hStd * members . STARTF_USESHOWWINDOW
validates the wShowWindow member .
*/
si . dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW ;
si . wShowWindow = SW_HIDE ;
si . hStdOutput = newstdout ;
si . hStdError = newstdout ; //set the new handles for the child process
// *******************************************************************
// If there is a command line in the config file, use it for create process
//spawn the child process
if ( ! CreateProcess ( NULL , g_cmdline , NULL , NULL , TRUE , CREATE_NEW_CONSOLE ,
NULL , tempzip_path , & si , & pi ) )
{
ErrorMessage ( " CreateProcess " ) ;
wnd_printf ( " \r \n Please make sure the path to makensis.exe is correct. " ) ;
CloseHandle ( newstdout ) ;
CloseHandle ( read_stdout ) ;
2002-08-02 10:01:35 +00:00
PostMessage ( g_hwnd , WM_USER + 1203 , 0 , 1 ) ;
2004-02-06 17:36:48 +00:00
return 1 ;
}
unsigned long exit = 0 ; //process exit code
unsigned long bread ; //bytes read
unsigned long avail ; //bytes available
2002-08-02 10:01:35 +00:00
memset ( buf , 0 , sizeof ( buf ) ) ;
2004-02-06 17:36:48 +00:00
while ( 1 ) //main program loop
{
PeekNamedPipe ( read_stdout , buf , 1023 , & bread , & avail , NULL ) ;
//check to see if there is any data to read from stdout
if ( bread ! = 0 )
{
2002-08-02 10:01:35 +00:00
memset ( buf , 0 , sizeof ( buf ) ) ;
2004-02-06 17:36:48 +00:00
if ( avail > 1023 )
{
while ( bread > = 1023 )
{
ReadFile ( read_stdout , buf , 1023 , & bread , NULL ) ; //read the stdout pipe
wnd_printf ( buf ) ;
2002-08-02 10:01:35 +00:00
memset ( buf , 0 , sizeof ( buf ) ) ;
2004-02-06 17:36:48 +00:00
}
}
else
{
ReadFile ( read_stdout , buf , 1023 , & bread , NULL ) ;
wnd_printf ( buf ) ;
}
}
GetExitCodeProcess ( pi . hProcess , & exit ) ; //while the process is running
if ( exit ! = STILL_ACTIVE )
break ;
Sleep ( 100 ) ;
}
CloseHandle ( pi . hThread ) ;
CloseHandle ( pi . hProcess ) ;
CloseHandle ( newstdout ) ;
CloseHandle ( read_stdout ) ;
2002-08-02 10:01:35 +00:00
wsprintf ( buf , " (source ZIP size was %d bytes) \r \n " , g_zipfile_size ) ;
wnd_printf ( buf ) ;
2004-02-06 17:36:48 +00:00
2002-08-02 10:01:35 +00:00
PostMessage ( g_hwnd , WM_USER + 1203 , 0 , 0 ) ;
return 0 ;
}
char nsifilename [ MAX_PATH ] ;
void makeEXE ( HWND hwndDlg )
{
char buf [ 2048 ] ;
GetTempPath ( MAX_PATH , buf ) ;
GetTempFileName ( buf , " zne " , 0 , nsifilename ) ;
FILE * fp = fopen ( nsifilename , " w " ) ;
if ( ! fp )
{
MessageBox ( hwndDlg , " Error writing .NSI file " , g_errcaption , MB_OK | MB_ICONSTOP ) ;
2002-10-03 07:27:02 +00:00
PostMessage ( g_hwnd , WM_USER + 1203 , 0 , 0 ) ;
2002-08-02 10:01:35 +00:00
return ;
}
GetDlgItemText ( hwndDlg , IDC_INSTNAME , buf , sizeof ( buf ) ) ;
2003-09-28 12:42:03 +00:00
fprintf ( fp , " !define ZIP2EXE_NAME `%s` \n " , buf ) ;
2002-08-02 10:01:35 +00:00
GetDlgItemText ( hwndDlg , IDC_OUTFILE , buf , sizeof ( buf ) ) ;
2003-09-28 12:42:03 +00:00
fprintf ( fp , " !define ZIP2EXE_OUTFILE `%s` \n " , buf ) ;
2003-11-25 18:11:23 +00:00
if ( g_compressor = = 1 )
fprintf ( fp , " !define ZIP2EXE_COMPRESSOR_ZLIB \n " ) ;
if ( g_compressor = = 2 )
fprintf ( fp , " !define ZIP2EXE_COMPRESSOR_BZIP2 \n " ) ;
if ( g_compressor = = 3 )
fprintf ( fp , " !define ZIP2EXE_COMPRESSOR_LZMA \n " ) ;
2005-10-21 13:53:27 +00:00
if ( g_compressor_solid = = 1 )
fprintf ( fp , " !define ZIP2EXE_COMPRESSOR_SOLID \n " ) ;
2002-08-02 10:01:35 +00:00
GetDlgItemText ( hwndDlg , IDC_INSTPATH , buf , sizeof ( buf ) ) ;
char * outpath = " $INSTDIR " ;
int iswinamp = 0 ;
char * iswinampmode = NULL ;
if ( ! strcmp ( buf , gp_poi ) ) lstrcpy ( buf , " $EXEDIR " ) ;
2004-02-06 17:36:48 +00:00
2002-08-02 10:01:35 +00:00
if ( ! strcmp ( buf , gp_winamp ) )
{
iswinamp = 1 ;
}
if ( ! strcmp ( buf , gp_winamp_plugins ) )
{
iswinamp = 1 ;
2004-02-06 17:36:48 +00:00
fprintf ( fp , " !define ZIP2EXE_INSTALLDIR_PLUGINS \n " ) ;
2002-08-02 10:01:35 +00:00
}
if ( ! strcmp ( buf , gp_winamp_vis ) )
{
iswinamp = 1 ;
iswinampmode = " VisDir " ;
}
if ( ! strcmp ( buf , gp_winamp_dsp ) )
{
iswinamp = 1 ;
iswinampmode = " DSPDir " ;
}
if ( ! strcmp ( buf , gp_winamp_skins ) )
{
iswinamp = 1 ;
iswinampmode = " SkinDir " ;
2004-02-06 17:36:48 +00:00
fprintf ( fp , " !define ZIP2EXE_INSTALLDIR_SKINS \n " ) ;
2002-08-02 10:01:35 +00:00
}
if ( iswinamp )
{
2003-09-28 12:42:03 +00:00
fprintf ( fp , " !define ZIP2EXE_INSTALLDIR_WINAMP \n " ) ;
2002-08-02 10:01:35 +00:00
if ( iswinampmode )
{
2003-09-28 12:42:03 +00:00
fprintf ( fp , " !define ZIP2EXE_INSTALLDIR_WINAMPMODE `%s` \n " , iswinampmode ) ;
2002-08-02 10:01:35 +00:00
}
}
else // set out path to $INSTDIR
{
2004-02-06 17:36:48 +00:00
fprintf ( fp , " !define ZIP2EXE_INSTALLDIR `%s` \n " , buf ) ;
2002-08-02 10:01:35 +00:00
}
2003-09-28 12:42:03 +00:00
fprintf ( fp , " !include `${NSISDIR} \\ Contrib \\ zip2exe \\ Base.nsh` \n " ) ;
fprintf ( fp , " !include `${NSISDIR} \\ Contrib \\ zip2exe \\ %s.nsh` \n " , g_mui ? " Modern " : " Classic " ) ;
2002-08-02 10:01:35 +00:00
2003-09-28 12:42:03 +00:00
fprintf ( fp , " !insertmacro SECTION_BEGIN \n " ) ;
2002-08-02 10:01:35 +00:00
fprintf ( fp , " File /r `%s \\ *.*` \n " , tempzip_path ) ;
2003-09-28 12:42:03 +00:00
fprintf ( fp , " !insertmacro SECTION_END \n " ) ;
2002-08-02 10:01:35 +00:00
2003-09-28 12:42:03 +00:00
fclose ( fp ) ;
2002-08-02 10:01:35 +00:00
2002-10-03 07:27:02 +00:00
char g_makensis_path [ MAX_PATH ] ;
char * p = g_makensis_path ;
GetModuleFileName ( g_hInstance , g_makensis_path , sizeof ( g_makensis_path ) ) ;
while ( * p ) p + + ;
while ( p > = g_makensis_path & & * p ! = ' \\ ' ) p - - ;
strcpy ( p + 1 , " makensis.exe " ) ;
WIN32_FIND_DATA fd ;
HANDLE h = FindFirstFile ( g_makensis_path , & fd ) ;
if ( h = = INVALID_HANDLE_VALUE )
{
2004-02-06 17:36:48 +00:00
if ( ( p - g_makensis_path > 4 ) & & ( tolower ( * ( p - 1 ) ) = = ' n ' ) & & ( tolower ( * ( p - 2 ) ) = = ' i ' ) & & ( tolower ( * ( p - 3 ) ) = = ' b ' ) & & ( * ( p - 4 ) = = ' \\ ' ) )
2002-10-03 07:27:02 +00:00
{
p - = 4 ;
strcpy ( p + 1 , " makensis.exe " ) ;
h = FindFirstFile ( g_makensis_path , & fd ) ;
if ( h = = INVALID_HANDLE_VALUE )
{
MessageBox ( hwndDlg , " Error finding makensis.exe. " , g_errcaption , MB_OK | MB_ICONSTOP ) ;
PostMessage ( g_hwnd , WM_USER + 1203 , 0 , 0 ) ;
return ;
}
}
}
if ( h ! = INVALID_HANDLE_VALUE ) FindClose ( h ) ;
wsprintf ( g_cmdline , " \" %s \" %s \" %s \" " , g_makensis_path , g_options , nsifilename ) ;
2002-08-02 10:01:35 +00:00
DWORD id ;
g_hThread = CreateThread ( NULL , 0 , ThreadProc , 0 , 0 , & id ) ;
}
2005-11-12 17:19:46 +00:00
void SetZip ( HWND hwndDlg , char * path )
{
char buf2 [ 1024 ] ;
lstrcpy ( buf2 , path ) ;
tempzip_cleanup ( hwndDlg , 1 ) ;
SetDlgItemText ( hwndDlg , IDC_ZIPFILE , path ) ;
char * t = path + lstrlen ( path ) ;
while ( t > path & & * t ! = ' \\ ' & & * t ! = ' . ' ) t - - ;
{
char * p = t ;
while ( p > = path & & * p ! = ' \\ ' ) p - - ;
p + + ;
* t = 0 ;
SetDlgItemText ( hwndDlg , IDC_INSTNAME , p [ 0 ] ? p : " Stuff " ) ;
}
strcpy ( t , " .exe " ) ;
SetDlgItemText ( hwndDlg , IDC_OUTFILE , path ) ;
if ( tempzip_make ( hwndDlg , buf2 ) ) tempzip_cleanup ( hwndDlg , 1 ) ;
else
{
EnableWindow ( GetDlgItem ( hwndDlg , IDOK ) , 1 ) ;
}
}
2002-08-02 10:01:35 +00:00
BOOL CALLBACK DlgProc ( HWND hwndDlg , UINT uMsg , WPARAM wParam , LPARAM lParam )
{
2003-09-28 12:42:03 +00:00
static int ids [ ] = { IDC_INFO , IDC_NSISICON , IDC_SZIPFRAME , IDC_BROWSE , IDC_ZIPFILE , IDC_ZIPINFO_SUMMARY , IDC_ZIPINFO_FILES , IDC_OFRAME , IDC_INAMEST ,
2005-10-21 13:53:27 +00:00
IDC_INSTNAME , IDC_INSTPATH , IDC_OEFST , IDC_OUTFILE , IDC_BROWSE2 , IDC_COMPRESSOR , IDC_ZLIB , IDC_BZIP2 , IDC_LZMA , IDC_SOLID , IDC_INTERFACE , IDC_MODERNUI , IDC_CLASSICUI } ;
2002-08-02 10:01:35 +00:00
static HICON hIcon ;
static HFONT hFont ;
if ( uMsg = = WM_DESTROY ) { if ( hIcon ) DeleteObject ( hIcon ) ; hIcon = 0 ; if ( hFont ) DeleteObject ( hFont ) ; hFont = 0 ; }
switch ( uMsg )
{
case WM_INITDIALOG :
g_hwnd = hwndDlg ;
2003-11-25 18:11:23 +00:00
CheckDlgButton ( hwndDlg , IDC_LZMA , BST_CHECKED ) ;
2004-02-06 17:36:48 +00:00
CheckDlgButton ( hwndDlg , IDC_MODERNUI , BST_CHECKED ) ;
2002-08-02 10:01:35 +00:00
SendDlgItemMessage ( hwndDlg , IDC_INSTPATH , CB_ADDSTRING , 0 , ( LPARAM ) gp_poi ) ;
SendDlgItemMessage ( hwndDlg , IDC_INSTPATH , CB_ADDSTRING , 0 , ( LPARAM ) " $TEMP " ) ;
SendDlgItemMessage ( hwndDlg , IDC_INSTPATH , CB_ADDSTRING , 0 , ( LPARAM ) " $SYSDIR " ) ;
SendDlgItemMessage ( hwndDlg , IDC_INSTPATH , CB_ADDSTRING , 0 , ( LPARAM ) " $WINDIR " ) ;
SendDlgItemMessage ( hwndDlg , IDC_INSTPATH , CB_ADDSTRING , 0 , ( LPARAM ) " $DESKTOP " ) ;
2003-09-28 12:42:03 +00:00
SendDlgItemMessage ( hwndDlg , IDC_INSTPATH , CB_ADDSTRING , 0 , ( LPARAM ) " $DESKTOP \\ YourNameHere " ) ;
SendDlgItemMessage ( hwndDlg , IDC_INSTPATH , CB_ADDSTRING , 0 , ( LPARAM ) " $PROGRAMFILES \\ YourNameHere " ) ;
2002-08-02 10:01:35 +00:00
SendDlgItemMessage ( hwndDlg , IDC_INSTPATH , CB_ADDSTRING , 0 , ( LPARAM ) " $STARTMENU " ) ;
SendDlgItemMessage ( hwndDlg , IDC_INSTPATH , CB_ADDSTRING , 0 , ( LPARAM ) " $SMPROGRAMS " ) ;
SendDlgItemMessage ( hwndDlg , IDC_INSTPATH , CB_ADDSTRING , 0 , ( LPARAM ) gp_winamp ) ;
SendDlgItemMessage ( hwndDlg , IDC_INSTPATH , CB_ADDSTRING , 0 , ( LPARAM ) gp_winamp_plugins ) ;
SendDlgItemMessage ( hwndDlg , IDC_INSTPATH , CB_ADDSTRING , 0 , ( LPARAM ) gp_winamp_vis ) ;
SendDlgItemMessage ( hwndDlg , IDC_INSTPATH , CB_ADDSTRING , 0 , ( LPARAM ) gp_winamp_dsp ) ;
SendDlgItemMessage ( hwndDlg , IDC_INSTPATH , CB_ADDSTRING , 0 , ( LPARAM ) gp_winamp_skins ) ;
2004-02-06 17:36:48 +00:00
SetDlgItemText ( hwndDlg , IDC_INSTPATH , gp_poi ) ;
hIcon = LoadIcon ( g_hInstance , MAKEINTRESOURCE ( IDI_ICON1 ) ) ;
SetClassLong ( hwndDlg , GCL_HICON , ( long ) hIcon ) ;
2002-08-02 10:01:35 +00:00
hFont = CreateFont ( 15 , 0 , 0 , 0 , FW_NORMAL , 0 , 0 , 0 , DEFAULT_CHARSET ,
OUT_CHARACTER_PRECIS ,
CLIP_DEFAULT_PRECIS ,
DEFAULT_QUALITY , FIXED_PITCH | FF_DONTCARE , " Courier New " ) ;
SendDlgItemMessage ( hwndDlg , IDC_OUTPUTTEXT , WM_SETFONT , ( WPARAM ) hFont , 0 ) ;
2005-11-12 17:19:46 +00:00
DragAcceptFiles ( hwndDlg , TRUE ) ;
2002-08-02 10:01:35 +00:00
return 1 ;
case WM_CLOSE :
if ( ! g_hThread )
{
tempzip_cleanup ( hwndDlg , 0 ) ;
EndDialog ( hwndDlg , 1 ) ;
}
break ;
case WM_USER + 1203 :
if ( g_hThread )
{
2004-02-06 17:36:48 +00:00
if ( ! lParam ) ShowWindow ( GetDlgItem ( hwndDlg , IDC_TEST ) , SW_SHOWNA ) ;
2002-08-02 10:01:35 +00:00
CloseHandle ( g_hThread ) ;
g_hThread = 0 ;
}
2002-10-03 07:27:02 +00:00
made = 1 ;
ShowWindow ( GetDlgItem ( hwndDlg , IDC_BACK ) , SW_SHOWNA ) ;
EnableWindow ( GetDlgItem ( hwndDlg , IDOK ) , 1 ) ;
if ( nsifilename [ 0 ] ) DeleteFile ( nsifilename ) ;
nsifilename [ 0 ] = 0 ;
2002-08-02 10:01:35 +00:00
break ;
2005-11-12 17:19:46 +00:00
case WM_DROPFILES :
{
char dropped_file [ MAX_PATH ] = " " ;
2007-03-11 15:58:46 +00:00
if ( DragQueryFile ( ( HDROP ) wParam , ( UINT ) - 1 , NULL , 0 ) = = 1 )
2005-11-12 17:19:46 +00:00
{
DragQueryFile ( ( HDROP ) wParam , 0 , dropped_file , MAX_PATH ) ;
if ( lstrlen ( dropped_file ) > 0 )
{
SetZip ( hwndDlg , dropped_file ) ;
}
}
else
{
MessageBox ( hwndDlg , " Dropping more than one zip file at a time is not supported " , g_errcaption , MB_OK | MB_ICONSTOP ) ;
}
2005-11-12 17:29:04 +00:00
DragFinish ( ( HDROP ) wParam ) ;
2005-11-12 17:19:46 +00:00
return TRUE ;
}
2002-08-02 10:01:35 +00:00
case WM_COMMAND :
switch ( LOWORD ( wParam ) )
{
case IDC_BROWSE :
if ( ! g_extracting ) {
OPENFILENAME l = { sizeof ( l ) , } ;
char buf [ 1024 ] ;
l . hwndOwner = hwndDlg ;
2003-09-28 12:42:03 +00:00
l . lpstrFilter = " ZIP Files \0 *.zip \0 All Files \0 *.* \0 " ;
2002-08-02 10:01:35 +00:00
l . lpstrFile = buf ;
l . nMaxFile = 1023 ;
2003-09-28 12:42:03 +00:00
l . lpstrTitle = " Open ZIP File " ;
2002-08-02 10:01:35 +00:00
l . lpstrDefExt = " zip " ;
l . lpstrInitialDir = NULL ;
2004-02-06 17:36:48 +00:00
l . Flags = OFN_HIDEREADONLY | OFN_EXPLORER | OFN_PATHMUSTEXIST ;
2002-08-02 10:01:35 +00:00
buf [ 0 ] = 0 ;
2004-02-06 17:36:48 +00:00
if ( GetOpenFileName ( & l ) )
2002-08-02 10:01:35 +00:00
{
2005-11-12 17:19:46 +00:00
SetZip ( hwndDlg , buf ) ;
2002-08-02 10:01:35 +00:00
}
2004-02-06 17:36:48 +00:00
}
2002-08-02 10:01:35 +00:00
break ;
case IDC_BROWSE2 :
{
OPENFILENAME l = { sizeof ( l ) , } ;
char buf [ 1024 ] ;
l . hwndOwner = hwndDlg ;
2003-09-28 12:42:03 +00:00
l . lpstrFilter = " Executables \0 *.exe \0 All Files \0 *.* \0 " ;
2002-08-02 10:01:35 +00:00
l . lpstrFile = buf ;
l . nMaxFile = 1023 ;
2003-09-28 12:42:03 +00:00
l . lpstrTitle = " Select Output EXE File " ;
2002-08-02 10:01:35 +00:00
l . lpstrDefExt = " exe " ;
l . lpstrInitialDir = NULL ;
2004-02-06 17:36:48 +00:00
l . Flags = OFN_HIDEREADONLY | OFN_EXPLORER ;
2002-08-02 10:01:35 +00:00
GetDlgItemText ( hwndDlg , IDC_OUTFILE , buf , sizeof ( buf ) ) ;
2004-02-06 17:36:48 +00:00
if ( GetSaveFileName ( & l ) )
2002-08-02 10:01:35 +00:00
{
SetDlgItemText ( hwndDlg , IDC_OUTFILE , buf ) ;
}
2004-02-06 17:36:48 +00:00
}
2002-08-02 10:01:35 +00:00
break ;
case IDC_BACK :
if ( ! g_hThread )
{
made = 0 ;
ShowWindow ( GetDlgItem ( hwndDlg , IDC_BACK ) , SW_HIDE ) ;
2004-02-06 17:36:48 +00:00
ShowWindow ( GetDlgItem ( hwndDlg , IDC_TEST ) , SW_HIDE ) ;
2002-08-02 10:01:35 +00:00
ShowWindow ( GetDlgItem ( hwndDlg , IDC_OUTPUTTEXT ) , SW_HIDE ) ;
{
int x ;
for ( x = 0 ; x < sizeof ( ids ) / sizeof ( ids [ 0 ] ) ; x + + )
2004-02-06 17:36:48 +00:00
ShowWindow ( GetDlgItem ( hwndDlg , ids [ x ] ) , SW_SHOWNA ) ;
2003-09-28 12:42:03 +00:00
SetDlgItemText ( hwndDlg , IDOK , " &Generate " ) ;
2002-08-02 10:01:35 +00:00
EnableWindow ( GetDlgItem ( hwndDlg , IDOK ) , 1 ) ;
}
}
break ;
case IDC_TEST :
if ( ! g_hThread ) {
char buf [ 1024 ] ;
GetDlgItemText ( hwndDlg , IDC_OUTFILE , buf , sizeof ( buf ) ) ;
ShellExecute ( hwndDlg , " open " , buf , " " , " " , SW_SHOW ) ;
}
break ;
case IDOK :
if ( ! g_hThread )
{
if ( ! made )
{
2004-02-06 17:36:48 +00:00
if ( IsDlgButtonChecked ( hwndDlg , IDC_ZLIB ) )
2003-11-25 18:11:23 +00:00
g_compressor = 1 ;
2004-02-06 17:36:48 +00:00
if ( IsDlgButtonChecked ( hwndDlg , IDC_BZIP2 ) )
2003-11-25 18:11:23 +00:00
g_compressor = 2 ;
2004-02-06 17:36:48 +00:00
if ( IsDlgButtonChecked ( hwndDlg , IDC_LZMA ) )
2003-11-25 18:11:23 +00:00
g_compressor = 3 ;
2005-10-21 13:53:27 +00:00
if ( IsDlgButtonChecked ( hwndDlg , IDC_SOLID ) )
g_compressor_solid = 1 ;
else
g_compressor_solid = 0 ;
2004-02-06 17:36:48 +00:00
g_mui = ! IsDlgButtonChecked ( hwndDlg , IDC_CLASSICUI ) ;
2002-08-02 10:01:35 +00:00
SetDlgItemText ( g_hwnd , IDC_OUTPUTTEXT , " " ) ;
int x ;
for ( x = 0 ; x < sizeof ( ids ) / sizeof ( ids [ 0 ] ) ; x + + )
2004-02-06 17:36:48 +00:00
ShowWindow ( GetDlgItem ( hwndDlg , ids [ x ] ) , SW_HIDE ) ;
2002-08-02 10:01:35 +00:00
ShowWindow ( GetDlgItem ( hwndDlg , IDC_OUTPUTTEXT ) , SW_SHOWNA ) ;
2003-09-28 12:42:03 +00:00
SetDlgItemText ( hwndDlg , IDOK , " &Close " ) ;
2002-08-02 10:01:35 +00:00
EnableWindow ( GetDlgItem ( hwndDlg , IDOK ) , 0 ) ;
makeEXE ( hwndDlg ) ;
}
2004-02-06 17:36:48 +00:00
else
2002-08-02 10:01:35 +00:00
{
tempzip_cleanup ( hwndDlg , 0 ) ;
EndDialog ( hwndDlg , 0 ) ;
}
}
break ;
}
break ;
}
return 0 ;
2007-03-11 15:58:46 +00:00
}