home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 March / CMCD0304.ISO / Software / Freeware / Programare / nullsoft / nsis20.exe / Contrib / zip2exe / main.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-02-06  |  20.8 KB  |  721 lines

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #include <commctrl.h>
  4.  
  5. /*
  6.  
  7. version 0.31 (by Joost Verburg)
  8. * LZMA compression support
  9. * Fixed compression setting
  10.  
  11. version 0.31 (by Joost Verburg)
  12. * Based on header files
  13. * Improved interface
  14. * Modern UI support
  15. * New script code
  16. * Immproved folder detection
  17.  
  18. portions Copyright ⌐ 1999-2001 Miguel Garrido (mgarrido01@hotmail.com)
  19.  
  20. */
  21.  
  22. extern "C"
  23. {
  24. #include "zlib/unzip.h"
  25. };
  26. #include "resource.h"
  27.  
  28. const char *g_errcaption="Zip2Exe Error";
  29.  
  30. HINSTANCE g_hInstance;
  31. HWND g_hwnd;
  32. HANDLE g_hThread;
  33. char g_cmdline[1024];
  34. int g_extracting;
  35. int g_compressor;
  36. int g_mui;
  37. int g_zipfile_size;
  38.  
  39. char *g_options="";//"/V3";
  40.  
  41. static BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam);
  42.  
  43.  
  44. int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInst,
  45.                    LPSTR lpszCmdParam, int nCmdShow)
  46. {
  47.   g_hInstance=hInstance;
  48.  
  49.   InitCommonControls();
  50.   return DialogBox(hInstance,MAKEINTRESOURCE(IDD_DIALOG1),GetDesktopWindow(),DlgProc);
  51. }
  52. char tempzip_path[1024];
  53.  
  54.  
  55. int made;
  56.  
  57. static void doRMDir(char *buf)
  58. {
  59.   HANDLE h;
  60.   WIN32_FIND_DATA fd;
  61.   char *p=buf;
  62.   while (*p) p++;
  63.   lstrcpy(p,"\\*.*");
  64.   h = FindFirstFile(buf,&fd);
  65.   if (h != INVALID_HANDLE_VALUE)
  66.   {
  67.     do
  68.     {
  69.       if (fd.cFileName[0] != '.' ||
  70.           (fd.cFileName[1] != '.' && fd.cFileName[1]))
  71.       {
  72.         lstrcpy(p+1,fd.cFileName);
  73.         if (fd.dwFileAttributes & FILE_ATTRIBUTE_READONLY)
  74.           SetFileAttributes(buf,fd.dwFileAttributes^FILE_ATTRIBUTE_READONLY);
  75.         if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) doRMDir(buf);
  76.         else
  77.         {
  78.           DeleteFile(buf);
  79.         }
  80.       }
  81.     } while (FindNextFile(h,&fd));
  82.     FindClose(h);
  83.   }
  84.   p[0]=0; // fix buffer
  85.   RemoveDirectory(buf);
  86. }
  87.  
  88. static void doMKDir(char *directory)
  89. {
  90.   char *p, *p2;
  91.   char buf[MAX_PATH];
  92.   if (!*directory) return;
  93.   lstrcpy(buf,directory);
  94.   p=buf; while (*p) p++;
  95.   while (p >= buf && *p != '\\') p--;
  96.   p2 = buf;
  97.   if (p2[1] == ':') p2+=4;
  98.   else if (p2[0] == '\\' && p2[1] == '\\')
  99.   {
  100.     p2+=2;
  101.     while (*p2 && *p2 != '\\') p2++;
  102.     if (*p2) p2++;
  103.     while (*p2 && *p2 != '\\') p2++;
  104.     if (*p2) p2++;
  105.   }
  106.   if (p >= p2)
  107.   {
  108.     *p=0;
  109.     doMKDir(buf);
  110.   }
  111.   CreateDirectory(directory,NULL);
  112. }
  113.  
  114.  
  115.  
  116. void tempzip_cleanup(HWND hwndDlg, int err)
  117. {
  118.   if (tempzip_path[0]) doRMDir(tempzip_path);
  119.   tempzip_path[0]=0;
  120.   if (err)
  121.   {
  122.     SendDlgItemMessage(hwndDlg,IDC_ZIPINFO_FILES,LB_RESETCONTENT,0,0);
  123.     EnableWindow(GetDlgItem(hwndDlg,IDOK),0);
  124.     SetDlgItemText(hwndDlg,IDC_ZIPINFO_SUMMARY,"");
  125.     SetDlgItemText(hwndDlg,IDC_ZIPFILE,"");
  126.     SetDlgItemText(hwndDlg,IDC_OUTFILE,"");
  127.   }
  128. }
  129.  
  130. int tempzip_make(HWND hwndDlg, char *fn)
  131. {
  132.   char buf[MAX_PATH];
  133.   GetTempPath(MAX_PATH,buf);
  134.   GetTempFileName(buf,"z2e",GetTickCount(),tempzip_path);
  135.   if (!CreateDirectory(tempzip_path,NULL))
  136.   {
  137.     GetTempPath(MAX_PATH,tempzip_path);
  138.     strcat(tempzip_path,"\\nsi");
  139.     if (!CreateDirectory(tempzip_path,NULL))
  140.     {
  141.       tempzip_path[0]=0;
  142.       MessageBox(hwndDlg,"Error creating temporary directory",g_errcaption,MB_OK|MB_ICONSTOP);
  143.       return 1;
  144.     }
  145.   }
  146.   FILE *fp=fopen(fn,"rb");
  147.   if (fp)
  148.   {
  149.     fseek(fp,0,SEEK_END);
  150.     g_zipfile_size=ftell(fp);
  151.     fclose(fp);
  152.   }
  153.   else g_zipfile_size=0;
  154.   unzFile f;
  155.   f = unzOpen(fn);
  156.   if (!f || unzGoToFirstFile(f) != UNZ_OK)
  157.   {
  158.     if (f) unzClose(f);
  159.     MessageBox(hwndDlg,"Error opening ZIP file",g_errcaption,MB_OK|MB_ICONSTOP);
  160.     return 1;
  161.   }
  162.  
  163.   int nf=0, nkb=0;
  164.   g_extracting=1;
  165.   do {
  166.     char filename[MAX_PATH];
  167.     unzGetCurrentFileInfo(f,NULL,filename,sizeof(filename),NULL,0,NULL,0);
  168.     if (filename[0] &&
  169.         filename[strlen(filename)-1] != '\\' &&
  170.         filename[strlen(filename)-1] != '/')
  171.     {
  172.       char *pfn=filename;
  173.       while (*pfn)
  174.       {
  175.         if (*pfn == '/') *pfn='\\';
  176.         pfn++;
  177.       }
  178.       pfn=filename;
  179.       if (pfn[1] == ':' && pfn[2] == '\\') pfn+=3;
  180.       while (*pfn == '\\') pfn++;
  181.  
  182.       char out_filename[1024];
  183.       lstrcpy(out_filename,tempzip_path);
  184.       lstrcat(out_filename,"\\");
  185.       lstrcat(out_filename,pfn);
  186.       if (strstr(pfn,"\\"))
  187.       {
  188.         char buf[1024];
  189.         lstrcpy(buf,out_filename);
  190.         char *p=buf+strlen(buf);
  191.         while (p > buf && *p != '\\') p--;
  192.         *p=0;
  193.         if (buf[0]) doMKDir(buf);
  194.       }
  195.  
  196.       if (unzOpenCurrentFile(f) == UNZ_OK)
  197.       {
  198.         SendDlgItemMessage(hwndDlg,IDC_ZIPINFO_FILES,LB_ADDSTRING,0,(LPARAM)pfn);
  199.         FILE *fp;
  200.         int l;
  201.         fp = fopen(out_filename,"wb");
  202.         if (fp)
  203.         {
  204.           do
  205.           {
  206.             char buf[1024];
  207.             l=unzReadCurrentFile(f,buf,sizeof(buf));
  208.             if (l > 0)
  209.             {
  210.               if (fwrite(buf,1,l,fp) != (unsigned int)l)
  211.               {
  212.                 unzClose(f);
  213.                 fclose(fp);
  214.                 MessageBox(hwndDlg,"Error writing output file(s)",g_errcaption,MB_OK|MB_ICONSTOP);
  215.                 g_extracting=0;
  216.                 return 1;
  217.               }
  218.               nkb++;
  219.             }
  220.           } while (l > 0);
  221.  
  222.           fclose(fp);
  223.         }
  224.         else
  225.         {
  226.           unzClose(f);
  227.           MessageBox(hwndDlg,"Error opening output file(s)",g_errcaption,MB_OK|MB_ICONSTOP);
  228.           g_extracting=0;
  229.           return 1;
  230.         }
  231.         nf++;
  232.         wsprintf(buf,"Extracting: %d files, %dKB",nf,nkb);
  233.         SetDlgItemText(hwndDlg,IDC_ZIPINFO_SUMMARY,buf);
  234.         MSG msg;
  235.         int quit=0;
  236.         while (PeekMessage(&msg,NULL,0,0,PM_REMOVE))
  237.         {
  238.           if (msg.message == WM_DESTROY && msg.hwnd == g_hwnd)
  239.           {
  240.             quit++;
  241.             break;
  242.           }
  243.           TranslateMessage(&msg);
  244.           DispatchMessage(&msg);
  245.         }
  246.         unzCloseCurrentFile(f);
  247.         if (quit) break;
  248.       }
  249.       else
  250.       {
  251.         unzClose(f);
  252.         MessageBox(hwndDlg,"Error extracting from ZIP file",g_errcaption,MB_OK|MB_ICONSTOP);
  253.         g_extracting=0;
  254.         return 1;
  255.       }
  256.     }
  257.   } while (unzGoToNextFile(f) == UNZ_OK);
  258.  
  259.   g_extracting=0;
  260.   wsprintf(buf,"Extracted: %d files, %dKB",nf,nkb);
  261.   SetDlgItemText(hwndDlg,IDC_ZIPINFO_SUMMARY,buf);
  262.   unzClose(f);
  263.   return 0;
  264. }
  265.  
  266. char *gp_winamp = "(WINAMP DIRECTORY)";
  267. char *gp_winamp_plugins = "(WINAMP PLUG-INS DIRECTORY)";
  268. char *gp_winamp_vis = "(WINAMP VIS PLUG-INS DIRECTORY)";
  269. char *gp_winamp_dsp = "(WINAMP DSP PLUG-INS DIRECTORY)";
  270. char *gp_winamp_skins = "(WINAMP SKINS DIRECTORY)";
  271. char *gp_poi = "(PATH OF INSTALLER)";
  272.  
  273.  
  274. void wnd_printf(const char *str)
  275. {
  276.   if (!*str) return;
  277.   char existing_text[32000];
  278.   existing_text[0]=0;
  279.   UINT l=GetDlgItemText(g_hwnd, IDC_OUTPUTTEXT, existing_text, 32000);
  280.   l+=strlen(str);
  281.  
  282.   char *p=existing_text;
  283.   existing_text[31000]=0;
  284.   while (l > 31000 && *p)
  285.   {
  286.     while (*p != '\r' && *p != '\n' && *p)
  287.     {
  288.       p++;
  289.       l--;
  290.     }
  291.     while (*p == '\r' || *p == '\n')
  292.     {
  293.       p++;
  294.       l--;
  295.     }
  296.   }
  297.  
  298.   char buf[31000];
  299.   lstrcpy(buf,p);
  300.   lstrcpy(existing_text,buf);
  301.   lstrcat(existing_text,str);
  302.  
  303.   SetDlgItemText(g_hwnd, IDC_OUTPUTTEXT, existing_text);
  304.   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
  305.  
  306. }
  307.  
  308. void ErrorMessage(char *str)  //display detailed error info
  309. {
  310.   LPVOID msg;
  311.   FormatMessage(
  312.     FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
  313.     NULL,
  314.     GetLastError(),
  315.     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
  316.     (LPTSTR) &msg,
  317.     0,
  318.     NULL
  319.     );
  320.   wnd_printf(str);
  321.   wnd_printf(": ");
  322.   wnd_printf((char*)msg);
  323.   LocalFree(msg);
  324. }
  325.  
  326. DWORD WINAPI ThreadProc(LPVOID p) // thread that will start & monitor wwwinamp
  327. {
  328.   char buf[1024];           //i/o buffer
  329.   STARTUPINFO si={sizeof(si),};
  330.   SECURITY_ATTRIBUTES sa={sizeof(sa),};
  331.   SECURITY_DESCRIPTOR sd={0,};               //security information for pipes
  332.   PROCESS_INFORMATION pi={0,};
  333.   HANDLE newstdout=0,read_stdout=0;         //pipe handles
  334.  
  335.   OSVERSIONINFO osv={sizeof(osv)};
  336.   GetVersionEx(&osv);
  337.   if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT)        //initialize security descriptor (Windows NT)
  338.   {
  339.     InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
  340.     SetSecurityDescriptorDacl(&sd, true, NULL, false);
  341.     sa.lpSecurityDescriptor = &sd;
  342.   }
  343.   else sa.lpSecurityDescriptor = NULL;
  344.   sa.bInheritHandle = true;         //allow inheritable handles
  345.  
  346.   if (!CreatePipe(&read_stdout,&newstdout,&sa,0))  //create stdout pipe
  347.   {
  348.     ErrorMessage("CreatePipe");
  349.     PostMessage(g_hwnd,WM_USER+1203,0,1);
  350.     return 1;
  351.   }
  352.  
  353.   GetStartupInfo(&si);      //set startupinfo for the spawned process
  354.   /*
  355.     The dwFlags member tells CreateProcess how to make the process.
  356.     STARTF_USESTDHANDLES validates the hStd* members. STARTF_USESHOWWINDOW
  357.     validates the wShowWindow member.
  358.   */
  359.   si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
  360.   si.wShowWindow = SW_HIDE;
  361.   si.hStdOutput = newstdout;
  362.   si.hStdError = newstdout;     //set the new handles for the child process
  363.  
  364.   // *******************************************************************
  365.   // If there is a command line in the config file, use it for create process
  366.  
  367.   //spawn the child process
  368.   if (!CreateProcess(NULL,g_cmdline,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,
  369.       NULL,tempzip_path,&si,&pi))
  370.   {
  371.     ErrorMessage("CreateProcess");
  372.     wnd_printf("\r\nPlease make sure the path to makensis.exe is correct.");
  373.     CloseHandle(newstdout);
  374.     CloseHandle(read_stdout);
  375.     PostMessage(g_hwnd,WM_USER+1203,0,1);
  376.     return 1;
  377.   }
  378.  
  379.   unsigned long exit=0;  //process exit code
  380.   unsigned long bread;   //bytes read
  381.   unsigned long avail;   //bytes available
  382.  
  383.   memset(buf,0,sizeof(buf));
  384.   while (1)      //main program loop
  385.   {
  386.     PeekNamedPipe(read_stdout,buf,1023,&bread,&avail,NULL);
  387.     //check to see if there is any data to read from stdout
  388.     if (bread != 0)
  389.     {
  390.       memset(buf,0,sizeof(buf));
  391.       if (avail > 1023)
  392.       {
  393.         while (bread >= 1023)
  394.         {
  395.           ReadFile(read_stdout,buf,1023,&bread,NULL);  //read the stdout pipe
  396.           wnd_printf(buf);
  397.           memset(buf,0,sizeof(buf));
  398.         }
  399.       }
  400.       else
  401.       {
  402.         ReadFile(read_stdout,buf,1023,&bread,NULL);
  403.         wnd_printf(buf);
  404.       }
  405.     }
  406.  
  407.     GetExitCodeProcess(pi.hProcess,&exit);      //while the process is running
  408.     if (exit != STILL_ACTIVE)
  409.       break;
  410.  
  411.     Sleep(100);
  412.   }
  413.   CloseHandle(pi.hThread);
  414.   CloseHandle(pi.hProcess);
  415.   CloseHandle(newstdout);
  416.   CloseHandle(read_stdout);
  417.  
  418.  
  419.   wsprintf(buf,"(source ZIP size was %d bytes)\r\n",g_zipfile_size);
  420.   wnd_printf(buf);
  421.  
  422.   PostMessage(g_hwnd,WM_USER+1203,0,0);
  423.   return 0;
  424. }
  425.  
  426.  
  427. char nsifilename[MAX_PATH];
  428.  
  429.  
  430.  
  431. void makeEXE(HWND hwndDlg)
  432. {
  433.   char buf[2048];
  434.   GetTempPath(MAX_PATH,buf);
  435.   GetTempFileName(buf,"zne",0,nsifilename);
  436.   FILE *fp=fopen(nsifilename,"w");
  437.   if (!fp)
  438.   {
  439.     MessageBox(hwndDlg,"Error writing .NSI file",g_errcaption,MB_OK|MB_ICONSTOP);
  440.     PostMessage(g_hwnd,WM_USER+1203,0,0);
  441.     return;
  442.   }
  443.   GetDlgItemText(hwndDlg,IDC_INSTNAME,buf,sizeof(buf));
  444.   fprintf(fp,"!define ZIP2EXE_NAME `%s`\n",buf);
  445.   GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,sizeof(buf));
  446.   fprintf(fp,"!define ZIP2EXE_OUTFILE `%s`\n",buf);
  447.   if (g_compressor == 1)
  448.     fprintf(fp,"!define ZIP2EXE_COMPRESSOR_ZLIB\n");
  449.   if (g_compressor == 2)
  450.     fprintf(fp,"!define ZIP2EXE_COMPRESSOR_BZIP2\n");
  451.   if (g_compressor == 3)
  452.     fprintf(fp,"!define ZIP2EXE_COMPRESSOR_LZMA\n");
  453.   GetDlgItemText(hwndDlg,IDC_INSTPATH,buf,sizeof(buf));
  454.   char *outpath = "$INSTDIR";
  455.   int iswinamp=0;
  456.   char *iswinampmode=NULL;
  457.   if (!strcmp(buf,gp_poi)) lstrcpy(buf,"$EXEDIR");
  458.  
  459.   if (!strcmp(buf,gp_winamp))
  460.   {
  461.     iswinamp=1;
  462.   }
  463.   if (!strcmp(buf,gp_winamp_plugins))
  464.   {
  465.     iswinamp=1;
  466.     fprintf(fp,"!define ZIP2EXE_INSTALLDIR_PLUGINS\n");
  467.   }
  468.   if (!strcmp(buf,gp_winamp_vis))
  469.   {
  470.     iswinamp=1;
  471.     iswinampmode="VisDir";
  472.   }
  473.   if (!strcmp(buf,gp_winamp_dsp))
  474.   {
  475.     iswinamp=1;
  476.     iswinampmode="DSPDir";
  477.   }
  478.   if (!strcmp(buf,gp_winamp_skins))
  479.   {
  480.     iswinamp=1;
  481.     iswinampmode="SkinDir";
  482.     fprintf(fp,"!define ZIP2EXE_INSTALLDIR_SKINS\n");
  483.   }
  484.  
  485.   if (iswinamp)
  486.   {
  487.     fprintf(fp,"!define ZIP2EXE_INSTALLDIR_WINAMP\n");
  488.  
  489.     if (iswinampmode)
  490.     {
  491.       fprintf(fp,"!define ZIP2EXE_INSTALLDIR_WINAMPMODE `%s`\n",iswinampmode);
  492.     }
  493.   }
  494.   else  // set out path to $INSTDIR
  495.   {
  496.     fprintf(fp,"!define ZIP2EXE_INSTALLDIR `%s`\n",buf);
  497.   }
  498.  
  499.   fprintf(fp,"!include `${NSISDIR}\\Contrib\\zip2exe\\Base.nsh`\n");
  500.   fprintf(fp,"!include `${NSISDIR}\\Contrib\\zip2exe\\%s.nsh`\n",g_mui?"Modern":"Classic");
  501.  
  502.   fprintf(fp,"!insertmacro SECTION_BEGIN\n");
  503.   fprintf(fp,"File /r `%s\\*.*`\n",tempzip_path);
  504.   fprintf(fp,"!insertmacro SECTION_END\n");
  505.  
  506.   fclose(fp);
  507.  
  508.   char g_makensis_path[MAX_PATH];
  509.   char *p=g_makensis_path;
  510.   GetModuleFileName(g_hInstance,g_makensis_path,sizeof(g_makensis_path));
  511.   while (*p) p++;
  512.   while (p >= g_makensis_path && *p != '\\') p--;
  513.   strcpy(p+1,"makensis.exe");
  514.  
  515.   WIN32_FIND_DATA fd;
  516.   HANDLE h=FindFirstFile(g_makensis_path,&fd);
  517.   if (h==INVALID_HANDLE_VALUE)
  518.   {
  519.     if ((p-g_makensis_path>4)&&(tolower(*(p-1))=='n')&&(tolower(*(p-2))=='i')&&(tolower(*(p-3))=='b')&&(*(p-4)=='\\'))
  520.     {
  521.       p -= 4;
  522.       strcpy(p+1,"makensis.exe");
  523.       h=FindFirstFile(g_makensis_path,&fd);
  524.       if (h==INVALID_HANDLE_VALUE)
  525.       {
  526.         MessageBox(hwndDlg,"Error finding makensis.exe.",g_errcaption,MB_OK|MB_ICONSTOP);
  527.         PostMessage(g_hwnd,WM_USER+1203,0,0);
  528.         return;
  529.       }
  530.     }
  531.   }
  532.   if (h!=INVALID_HANDLE_VALUE) FindClose(h);
  533.  
  534.  
  535.  
  536.   wsprintf(g_cmdline,"\"%s\" %s \"%s\"",g_makensis_path,g_options,nsifilename);
  537.  
  538.   DWORD id;
  539.   g_hThread=CreateThread(NULL,0,ThreadProc,0,0,&id);
  540.  
  541. }
  542.  
  543.  
  544. BOOL CALLBACK DlgProc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
  545. {
  546.   static int ids[]={IDC_INFO,IDC_NSISICON,IDC_SZIPFRAME,IDC_BROWSE,IDC_ZIPFILE,IDC_ZIPINFO_SUMMARY,IDC_ZIPINFO_FILES,IDC_OFRAME,IDC_INAMEST,
  547.                         IDC_INSTNAME,IDC_INSTPATH,IDC_OEFST,IDC_OUTFILE,IDC_BROWSE2,IDC_COMPRESSOR,IDC_ZLIB,IDC_BZIP2,IDC_LZMA,IDC_INTERFACE,IDC_MODERNUI,IDC_CLASSICUI};
  548.   static HICON hIcon;
  549.   static HFONT hFont;
  550.   if (uMsg == WM_DESTROY) { if (hIcon) DeleteObject(hIcon); hIcon=0; if (hFont) DeleteObject(hFont); hFont=0; }
  551.   switch (uMsg)
  552.   {
  553.     case WM_INITDIALOG:
  554.       g_hwnd=hwndDlg;
  555.       CheckDlgButton(hwndDlg,IDC_LZMA,BST_CHECKED);
  556.       CheckDlgButton(hwndDlg,IDC_MODERNUI,BST_CHECKED);
  557.       SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_poi);
  558.       SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$TEMP");
  559.       SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$SYSDIR");
  560.       SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$WINDIR");
  561.       SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$DESKTOP");
  562.       SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$DESKTOP\\YourNameHere");
  563.       SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$PROGRAMFILES\\YourNameHere");
  564.       SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$STARTMENU");
  565.       SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)"$SMPROGRAMS");
  566.  
  567.       SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp);
  568.       SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp_plugins);
  569.       SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp_vis);
  570.       SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp_dsp);
  571.       SendDlgItemMessage(hwndDlg,IDC_INSTPATH,CB_ADDSTRING,0,(LPARAM)gp_winamp_skins);
  572.  
  573.       SetDlgItemText(hwndDlg,IDC_INSTPATH,gp_poi);
  574.  
  575.       hIcon=LoadIcon(g_hInstance,MAKEINTRESOURCE(IDI_ICON1));
  576.       SetClassLong(hwndDlg,GCL_HICON,(long)hIcon);
  577.  
  578.       hFont=CreateFont(15,0,0,0,FW_NORMAL,0,0,0,DEFAULT_CHARSET,
  579.               OUT_CHARACTER_PRECIS,
  580.               CLIP_DEFAULT_PRECIS,
  581.               DEFAULT_QUALITY,FIXED_PITCH|FF_DONTCARE,"Courier New");
  582.       SendDlgItemMessage(hwndDlg,IDC_OUTPUTTEXT,WM_SETFONT,(WPARAM)hFont,0);
  583.     return 1;
  584.     case WM_CLOSE:
  585.       if (!g_hThread)
  586.       {
  587.         tempzip_cleanup(hwndDlg,0);
  588.         EndDialog(hwndDlg,1);
  589.       }
  590.     break;
  591.     case WM_USER+1203:
  592.  
  593.       if (g_hThread)
  594.       {
  595.         if (!lParam) ShowWindow(GetDlgItem(hwndDlg,IDC_TEST),SW_SHOWNA);
  596.         CloseHandle(g_hThread);
  597.         g_hThread=0;
  598.       }
  599.       made=1;
  600.       ShowWindow(GetDlgItem(hwndDlg,IDC_BACK),SW_SHOWNA);
  601.       EnableWindow(GetDlgItem(hwndDlg,IDOK),1);
  602.       if (nsifilename[0]) DeleteFile(nsifilename);
  603.       nsifilename[0]=0;
  604.     break;
  605.     case WM_COMMAND:
  606.       switch (LOWORD(wParam))
  607.       {
  608.         case IDC_BROWSE:
  609.           if (!g_extracting) {
  610.             OPENFILENAME l={sizeof(l),};
  611.             char buf[1024];
  612.             l.hwndOwner = hwndDlg;
  613.             l.lpstrFilter = "ZIP Files\0*.zip\0All Files\0*.*\0";
  614.             l.lpstrFile = buf;
  615.             l.nMaxFile = 1023;
  616.             l.lpstrTitle = "Open ZIP File";
  617.             l.lpstrDefExt = "zip";
  618.             l.lpstrInitialDir = NULL;
  619.             l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER|OFN_PATHMUSTEXIST;
  620.             buf[0]=0;
  621.             if (GetOpenFileName(&l))
  622.             {
  623.               char buf2[1024];
  624.               lstrcpy(buf2,buf);
  625.               tempzip_cleanup(hwndDlg,1);
  626.               SetDlgItemText(hwndDlg,IDC_ZIPFILE,buf);
  627.               char *t=buf+strlen(buf);
  628.               while (t > buf && *t != '\\' && *t != '.') t--;
  629.               {
  630.                 char *p=t;
  631.                 while (p >= buf && *p != '\\') p--;
  632.                 p++;
  633.                 *t=0;
  634.                 SetDlgItemText(hwndDlg,IDC_INSTNAME,p[0]?p:"Stuff");
  635.               }
  636.               strcpy(t,".exe");
  637.               SetDlgItemText(hwndDlg,IDC_OUTFILE,buf);
  638.               if (tempzip_make(hwndDlg,buf2)) tempzip_cleanup(hwndDlg,1);
  639.               else
  640.               {
  641.                 EnableWindow(GetDlgItem(hwndDlg,IDOK),1);
  642.               }
  643.             }
  644.           }
  645.         break;
  646.         case IDC_BROWSE2:
  647.           {
  648.             OPENFILENAME l={sizeof(l),};
  649.             char buf[1024];
  650.             l.hwndOwner = hwndDlg;
  651.             l.lpstrFilter = "Executables\0*.exe\0All Files\0*.*\0";
  652.             l.lpstrFile = buf;
  653.             l.nMaxFile = 1023;
  654.             l.lpstrTitle = "Select Output EXE File";
  655.             l.lpstrDefExt = "exe";
  656.             l.lpstrInitialDir = NULL;
  657.             l.Flags = OFN_HIDEREADONLY|OFN_EXPLORER;
  658.             GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,sizeof(buf));
  659.             if (GetSaveFileName(&l))
  660.             {
  661.               SetDlgItemText(hwndDlg,IDC_OUTFILE,buf);
  662.             }
  663.           }
  664.         break;
  665.         case IDC_BACK:
  666.           if (!g_hThread)
  667.           {
  668.             made=0;
  669.             ShowWindow(GetDlgItem(hwndDlg,IDC_BACK),SW_HIDE);
  670.             ShowWindow(GetDlgItem(hwndDlg,IDC_TEST),SW_HIDE);
  671.             ShowWindow(GetDlgItem(hwndDlg,IDC_OUTPUTTEXT),SW_HIDE);
  672.             {
  673.               int x;
  674.               for (x = 0; x < sizeof(ids)/sizeof(ids[0]); x ++)
  675.                 ShowWindow(GetDlgItem(hwndDlg,ids[x]),SW_SHOWNA);
  676.               SetDlgItemText(hwndDlg,IDOK,"&Generate");
  677.               EnableWindow(GetDlgItem(hwndDlg,IDOK),1);
  678.             }
  679.           }
  680.         break;
  681.         case IDC_TEST:
  682.           if (!g_hThread) {
  683.             char buf[1024];
  684.             GetDlgItemText(hwndDlg,IDC_OUTFILE,buf,sizeof(buf));
  685.             ShellExecute(hwndDlg,"open",buf,"","",SW_SHOW);
  686.           }
  687.         break;
  688.         case IDOK:
  689.           if (!g_hThread)
  690.           {
  691.             if (!made)
  692.             {
  693.               if (IsDlgButtonChecked(hwndDlg,IDC_ZLIB))
  694.                 g_compressor = 1;
  695.               if (IsDlgButtonChecked(hwndDlg,IDC_BZIP2))
  696.                 g_compressor = 2;
  697.               if (IsDlgButtonChecked(hwndDlg,IDC_LZMA))
  698.                 g_compressor = 3;
  699.               g_mui=!IsDlgButtonChecked(hwndDlg,IDC_CLASSICUI);
  700.               SetDlgItemText(g_hwnd, IDC_OUTPUTTEXT, "");
  701.               int x;
  702.               for (x = 0; x < sizeof(ids)/sizeof(ids[0]); x ++)
  703.                 ShowWindow(GetDlgItem(hwndDlg,ids[x]),SW_HIDE);
  704.               ShowWindow(GetDlgItem(hwndDlg,IDC_OUTPUTTEXT),SW_SHOWNA);
  705.               SetDlgItemText(hwndDlg,IDOK,"&Close");
  706.               EnableWindow(GetDlgItem(hwndDlg,IDOK),0);
  707.  
  708.               makeEXE(hwndDlg);
  709.             }
  710.             else
  711.             {
  712.               tempzip_cleanup(hwndDlg,0);
  713.               EndDialog(hwndDlg,0);
  714.             }
  715.           }
  716.         break;
  717.       }
  718.     break;
  719.   }
  720.   return 0;
  721. }