home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 9 Archive / 09-Archive.zip / unzip540.zip / windll / guisfx / sfxwiz.c < prev    next >
C/C++ Source or Header  |  1998-11-15  |  17KB  |  541 lines

  1. #include <windows.h>
  2. #include <stdio.h>
  3. #ifdef WIN32
  4.    #include <shlobj.h>
  5. #else
  6.    #include <mem.h>
  7.    #include <stdlib.h>
  8.    #include <dir.h>
  9.    #include <dlgs.h>
  10.    #include <ctype.h>
  11.    #include <commdlg.h>
  12.    #include <string.h>
  13. #endif
  14. #include "dialog.h"
  15. #ifndef UzpMatch
  16. #define UzpMatch match
  17. #endif
  18. #include "../structs.h"
  19. #include "../decs.h"
  20.  
  21. LPUSERFUNCTIONS lpUserFunctions;
  22. HANDLE hUF       = (HANDLE)NULL;
  23. LPDCL lpDCL      = NULL;
  24. HANDLE hZUF      = (HANDLE)NULL;
  25. HANDLE hDCL      = (HANDLE)NULL;
  26.  
  27. BOOL fDoAll = FALSE;
  28.  
  29. char ** argv;
  30.  
  31. HINSTANCE hInst;
  32. HWND hWnd;
  33.  
  34. #ifndef TCHAR
  35. #define TCHAR char
  36. #endif
  37.  
  38. #ifndef _MAX_PATH
  39. #define _MAX_PATH PATH_MAX
  40. #endif
  41.  
  42. int WINAPI password(LPSTR p, int n, LPCSTR m, LPCSTR name);
  43. int WINAPI DisplayBuf(TCHAR far *buf, unsigned long size);
  44. int WINAPI GetReplaceDlgRetVal(TCHAR *filename);
  45. void WINAPI ReceiveDllMessage(unsigned long ucsize, unsigned long csiz,
  46.    unsigned cfactor, unsigned mo, unsigned dy, unsigned yr, unsigned hh,
  47.    unsigned mm, TCHAR c, LPSTR filename, LPSTR methbuf, unsigned long crc,
  48.    TCHAR fCrypt);
  49.  
  50. char szAppName[_MAX_PATH];
  51. char szTarget[_MAX_PATH];
  52. char szThisApp[_MAX_PATH];
  53. int iReturn;
  54.  
  55. DLGPROC fpProc;
  56.  
  57. #ifndef MAX_PATH
  58.    #define MAX_PATH    _MAX_PATH            // maximum path =length
  59. #endif
  60. #define TRUE        1                       // true value
  61. #define FALSE       0                       // false value
  62.  
  63. TCHAR   zfn[MAX_PATH],                      // zip filename and path
  64.         szHomeDir[MAX_PATH];                // Original directory
  65.  
  66. /****************************************************************************
  67.  
  68.     FUNCTION: Replace(HWND, WORD, WPARAM, LPARAM)
  69.  
  70.     PURPOSE:  Processes messages for "Replace" dialog box
  71.  
  72.     MESSAGES:
  73.  
  74.     WM_INITDIALOG - initialize dialog box
  75.     WM_COMMAND    - Input received
  76.  
  77. ****************************************************************************/
  78.  
  79. BOOL WINAPI ReplaceProc(HWND hReplaceDlg, WORD wMessage,
  80.                         WPARAM wParam, LPARAM lParam)
  81. {
  82.     static char __far *lpsz;
  83.     TCHAR szTemp[MAX_PATH];
  84.  
  85.     switch (wMessage)
  86.     {
  87.     case WM_INITDIALOG:
  88.         lpsz = (char __far *)lParam;
  89.         wsprintf(szTemp, "Replace %s ?", (LPSTR)lpsz);
  90.         SetDlgItemText(hReplaceDlg, IDM_REPLACE_TEXT, szTemp);
  91.         return TRUE;
  92.  
  93.     case WM_COMMAND:
  94.         switch (LOWORD(wParam))
  95.         {
  96.         case IDCANCEL:              /* ESC key      */
  97.         case IDOK:                  /* Enter key    */
  98.             EndDialog(hReplaceDlg, IDM_REPLACE_NO);
  99.             break;
  100.         case IDM_REPLACE_ALL:
  101.             fDoAll = TRUE;
  102.         case IDM_REPLACE_NONE:
  103.         case IDM_REPLACE_YES:
  104.         case IDM_REPLACE_NO:
  105.             EndDialog(hReplaceDlg, wParam);
  106.             break;
  107.         }
  108.         return TRUE;
  109.     }
  110.     return FALSE;
  111. }
  112.  
  113. /****************************************************************************
  114.  
  115.     FUNCTION: GetDirProc(HWND, unsigned, WPARAM, LPARAM)
  116.  
  117.     PURPOSE:  Processes messages for "Set Reference Dir Procedure for
  118.               Update Archive" dialog box
  119.  
  120.     MESSAGES:
  121.  
  122.     WM_INITDIALOG - initialize dialog box
  123.     WM_COMMAND    - Input received
  124.  
  125. ****************************************************************************/
  126. #ifdef WIN32
  127. BOOL WINAPI
  128. GetDirProc(HWND hDlg, WORD wMessage, WPARAM wParam, LPARAM lParam)
  129. {
  130.    switch (wMessage) {
  131.    case WM_INITDIALOG:
  132. /*
  133. Common control identifiers for GetOpenFileName and GetSaveFileName
  134. Control identifier   Control Description
  135. cmb2                 Drop-down combo box that displays the current drive
  136.                      or folder, and that allows the user to select a
  137.                      drive or folder to open
  138. stc4                 Label for the cmb2 combo box
  139. lst1                 List box that displays the contents of the current drive or folder
  140. stc1                 Label for the lst1 list box
  141. edt1                 Edit control that displays the name of the current file, or in which the user can type the name of the file to open
  142. stc3                 Label for the edt1 edit control
  143. cmb1                 Drop-down combo box that displays the list of file type filters
  144. stc2                 Label for the cmb1 combo box
  145. chx1                 The read-only check box
  146. IDOK                 The OK command button (push button)
  147. IDCANCEL             The Cancel command button (push button)
  148. pshHelp              The Help command button (push button)
  149.  
  150. */
  151.       CommDlg_OpenSave_HideControl(GetParent(hDlg), cmb1);
  152.       CommDlg_OpenSave_HideControl(GetParent(hDlg), stc2);
  153.       CommDlg_OpenSave_HideControl(GetParent(hDlg), edt1);
  154.       CommDlg_OpenSave_HideControl(GetParent(hDlg), stc3);
  155.       CommDlg_OpenSave_SetControlText(GetParent(hDlg),
  156.             IDOK, "Set");
  157.       break;
  158.    default:
  159.          break;
  160.    }
  161. return DefWindowProc(hDlg, wMessage, wParam, lParam);
  162. }
  163. #else
  164.  
  165. #ifdef __BORLANDC__
  166. #pragma argsused
  167. #endif
  168.  
  169. BOOL WINAPI
  170. GetDirProc(HWND hwndDlg, WORD wMessage, WPARAM wParam, LPARAM lParam)
  171. {
  172. HWND hTemp;
  173.  
  174.    switch (wMessage) {
  175.    case WM_INITDIALOG:
  176.       hTemp = GetDlgItem(hwndDlg, lst1);
  177.       EnableWindow(hTemp, FALSE);
  178.       ShowWindow(hTemp, SW_HIDE);
  179.       hTemp = GetDlgItem(hwndDlg, edt1);
  180.       EnableWindow(hTemp, FALSE);
  181.       ShowWindow(hTemp, SW_HIDE);
  182.       hTemp = GetDlgItem(hwndDlg, stc2);
  183.       EnableWindow(hTemp, FALSE);
  184.       ShowWindow(hTemp, SW_HIDE);
  185.       hTemp = GetDlgItem(hwndDlg, stc3);
  186.       EnableWindow(hTemp, FALSE);
  187.       ShowWindow(hTemp, SW_HIDE);
  188.       hTemp = GetDlgItem(hwndDlg, cmb1);
  189.       EnableWindow(hTemp, FALSE);
  190.       ShowWindow(hTemp, SW_HIDE);
  191.  
  192.       break;
  193.    case WM_COMMAND:
  194.       switch (LOWORD(wParam)) {
  195.          case IDCANCEL:
  196.             EndDialog(hwndDlg, FALSE);
  197.             break;
  198.          case IDOK:
  199.             getcwd(szTarget, PATH_MAX);
  200.             EndDialog(hwndDlg, TRUE);
  201.             break;
  202.          }
  203.       default:
  204.          break;
  205.    }
  206.    return FALSE;
  207. }
  208. #endif /* !WIN32 */
  209.  
  210. #ifdef __BORLANDC__
  211. #pragma argsused
  212. #endif
  213.  
  214. BOOL FAR PASCAL InitDialogProc (HWND hDlg, WORD wMsg, WORD wParam, LONG lParam) {
  215.    BOOL fProcessed = TRUE;
  216.    TCHAR szMessage[256];
  217.  
  218.    RECT rc;
  219.  
  220.    switch (wMsg) {
  221.       case WM_INITDIALOG:
  222.  
  223.          hWnd = hDlg;
  224.          SetWindowText(hDlg,(LPSTR) szAppName);
  225.          SetDlgItemText(hDlg,ID_TARGET,(LPSTR)szTarget);
  226.  
  227. #ifdef WIN32
  228.          GetCurrentDirectory(PATH_MAX, szHomeDir);
  229.          SetCurrentDirectory(szTarget);
  230. #else
  231.          getcwd(szHomeDir, PATH_MAX);
  232.          chdir(szTarget);
  233.          setdisk(toupper(szTarget[0]) - 'A');
  234. #endif
  235.          GetWindowRect(hDlg, &rc);
  236.          SetWindowPos(hDlg, NULL,
  237.             (GetSystemMetrics(SM_CXSCREEN) - (rc.right - rc.left)) / 2,
  238.             (GetSystemMetrics(SM_CYSCREEN) - (rc.bottom - rc.top)) / 3,
  239.             0, 0, SWP_NOSIZE | SWP_NOZORDER);
  240.  
  241.          break;
  242.  
  243.       case WM_COMMAND:
  244.          switch (wParam) {
  245.  
  246.             case ID_BROWSE :
  247.                 {
  248. #ifndef WIN32
  249.                 FARPROC lpGetDirProc;
  250. #endif
  251.                 char szTemp[MAX_PATH]="mike_~@~*";
  252.                 OPENFILENAME ofn;
  253.  
  254.                 memset(&ofn, '\0', sizeof(OPENFILENAME)); /* init struct */
  255.                 ofn.lStructSize = sizeof(OPENFILENAME);
  256.                 ofn.hwndOwner = hWnd;
  257.                 ofn.hInstance = hInst;
  258.                 ofn.lpstrFilter = NULL;
  259.                 ofn.nFilterIndex = 1;
  260.  
  261.                 ofn.lpstrFile = szTemp;
  262.                 ofn.nMaxFile = PATH_MAX;
  263.                 ofn.lpstrFileTitle = NULL;
  264.                 ofn.nMaxFileTitle = PATH_MAX; /* ignored ! */
  265.                 ofn.lpstrTitle = (LPSTR)"Set Extraction Directory";
  266.                 ofn.lpstrInitialDir = NULL;
  267.                 ofn.Flags = OFN_ENABLEHOOK |
  268. #ifdef WIN32
  269.                             OFN_EXPLORER|
  270. #endif
  271.                             OFN_HIDEREADONLY|OFN_NOVALIDATE;
  272. #ifndef WIN32
  273.                 lpGetDirProc = MakeProcInstance((FARPROC)GetDirProc, hInst);
  274.    #ifndef MSC
  275.                 (UINT CALLBACK *)ofn.lpfnHook = (UINT CALLBACK *)lpGetDirProc;
  276.    #else
  277.                 ofn.lpfnHook = lpGetDirProc;
  278.    #endif
  279. #else
  280.                 ofn.lpfnHook = (LPOFNHOOKPROC)GetDirProc;
  281. #endif
  282.                 ofn.lpTemplateName = "GETDIR";   /* see getfiles.dlg   */
  283.                 if (!GetOpenFileName(&ofn))
  284.                    {
  285.                    break;
  286.                    }
  287.  
  288.                 ofn.lpstrFile[ofn.nFileOffset-1] = '\0';
  289. #ifdef WIN32
  290.                 SetCurrentDirectory(ofn.lpstrFile);
  291. #else
  292.                 getcwd(szTemp, MAX_PATH);
  293.                 chdir(ofn.lpstrFile);
  294.                 setdisk(toupper(ofn.lpstrFile[0]) - 'A');
  295. #endif
  296.                 lstrcpy(szTarget,ofn.lpstrFile);
  297.                 SetDlgItemText(hDlg,ID_TARGET,(LPSTR)szTarget);
  298.                 }
  299.                break;
  300.  
  301.             case IDOK:
  302. #ifdef WIN32
  303.                GetCurrentDirectory(_MAX_PATH,szTarget);
  304. #else
  305.                getcwd(szTarget, _MAX_PATH);
  306. #endif
  307.  
  308.                lpDCL->ncflag = 0;
  309.                lpDCL->fQuiet = 0; // If not zero, no status messages will come through
  310.                lpDCL->ntflag = 0;
  311.                lpDCL->nvflag = 0;
  312.                lpDCL->nUflag = 0;
  313.                lpDCL->nzflag = 0;
  314.                lpDCL->ndflag = 1;
  315.                lpDCL->noflag = 0;
  316.                lpDCL->naflag = 0;
  317.                lpDCL->PromptToOverwrite = 1;
  318.                lpDCL->lpszZipFN = zfn;
  319.                lpDCL->lpszExtractDir = NULL;
  320.                iReturn = Wiz_SingleEntryUnzip(0, NULL, 0, NULL, lpDCL, lpUserFunctions);
  321.  
  322. /* external return codes for unzip library */
  323. //#define PK_OK              0   /* no error */
  324. //#define PK_COOL            0   /* no error */
  325. //#define PK_GNARLY          0   /* no error */
  326. //#define PK_WARN            1   /* warning error */
  327. //#define PK_ERR             2   /* error in zipfile */
  328. //#define PK_BADERR          3   /* severe error in zipfile */
  329. //#define PK_MEM             4   /* insufficient memory (during initialization) */
  330. //#define PK_MEM2            5   /* insufficient memory (password failure) */
  331. //#define PK_MEM3            6   /* insufficient memory (file decompression) */
  332. //#define PK_MEM4            7   /* insufficient memory (memory decompression) */
  333. //#define PK_MEM5            8   /* insufficient memory (not yet used) */
  334. //#define PK_NOZIP           9   /* zipfile not found */
  335. //#define PK_PARAM          10   /* bad or illegal parameters specified */
  336. //#define PK_FIND           11   /* no files found */
  337. //#define PK_DISK           50   /* disk full */
  338. //#define PK_EOF            51   /* unexpected EOF */
  339.  
  340. //#define IZ_CTRLC          80   /* user hit ^C to terminate */
  341. //#define IZ_UNSUP          81   /* no files found: all unsup. compr/encrypt. */
  342. //#define IZ_BADPWD         82   /* no files found: all had bad password */
  343.  
  344. /* internal and DLL-only return codes */
  345. //#define IZ_DIR            76   /* potential zipfile is a directory */
  346. //#define IZ_CREATED_DIR    77   /* directory created: set time and permissions */
  347. //#define IZ_VOL_LABEL      78   /* volume label, but can't set on hard disk */
  348. //#define IZ_EF_TRUNC       79   /* local extra field truncated (PKZIP'd) */
  349.  
  350. /* return codes of password fetches (negative = user abort; positive = error) */
  351. //#define IZ_PW_ENTERED      0   /* got some password string; use/try it */
  352. //#define IZ_PW_CANCEL      -1   /* no password available (for this entry) */
  353. //#define IZ_PW_CANCELALL   -2   /* no password, skip any further pwd. request */
  354. //#define IZ_PW_ERROR        5   /* = PK_MEM2 : failure (no mem, no tty, ...) */
  355.                switch (iReturn) {
  356.                 case PK_OK:
  357.                      wsprintf(szMessage, "%s", "All files extracted OK");
  358.                      break;
  359.                 case PK_ERR:
  360.                      wsprintf(szMessage, "%s", "Warning occurred on one or more files");
  361.                      break;
  362.                 case PK_BADERR:
  363.                      wsprintf(szMessage, "%s", "Error in archive");
  364.                      break;
  365.                 case PK_MEM:
  366.                 case PK_MEM2:
  367.                 case PK_MEM3:
  368.                 case PK_MEM4:
  369.                 case PK_MEM5:
  370.                      wsprintf(szMessage, "%s", "Insufficient memory");
  371.                      break;
  372.                 case PK_NOZIP:
  373.                      wsprintf(szMessage, "%s", "Archive not found");
  374.                      break;
  375.                 case PK_FIND:
  376.                      wsprintf(szMessage, "%s", "No files found");
  377.                      break;
  378.                 case PK_DISK:
  379.                      wsprintf(szMessage, "%s", "Disk full");
  380.                      break;
  381.                 case PK_EOF:
  382.                      wsprintf(szMessage, "%s", "Unexpected end of file");
  383.                      break;
  384.                 case IZ_UNSUP:
  385.                      wsprintf(szMessage, "%s", "No files found: All unsupported");
  386.                      break;
  387.                 case IZ_BADPWD:
  388.                      wsprintf(szMessage, "%s", "No files found: Bad password");
  389.                      break;
  390.                 default:
  391.                      wsprintf(szMessage, "%s", "Unknown error");
  392.                      break;
  393.                 }
  394.                MessageBox(hDlg, szMessage, szAppName, MB_OK);
  395. /* Uncomment line below to have SFXWix terminate automatically
  396.    when done.
  397.  */
  398. //              EndDialog(hDlg, wParam);
  399.  
  400.                break;
  401.                case IDCANCEL:
  402.                     EndDialog(hDlg, wParam);
  403.                     PostQuitMessage(0);
  404.                     exit(0); // ..and then quit
  405.                     break;
  406.          }
  407.          break;
  408.  
  409.       default:
  410.          fProcessed = FALSE;
  411.          break;
  412.    }
  413.    return(fProcessed);
  414. }
  415.  
  416.  
  417. #define WasCancelled(hDlg) (!IsWindowEnabled(GetDlgItem(hDlg,IDCANCEL)))
  418.  
  419. #ifdef __BORLANDC__
  420. #pragma argsused
  421. #endif
  422. int WINAPI password(LPSTR p, int n, LPCSTR m, LPCSTR name)
  423. {
  424. TCHAR sz[MAX_PATH];
  425. sprintf(sz, "%s is encrypted", name);
  426. MessageBox(hWnd, sz, "Encryption not supported", MB_OK);
  427. return IZ_PW_CANCELALL;
  428. }
  429.  
  430. int WINAPI DisplayBuf(TCHAR far *buf, unsigned long size)
  431. {
  432. if ((buf[0] != '\n') && (buf[0] != '\r'))
  433.    SetDlgItemText(hWnd, ID_STATUS, buf);
  434. return (unsigned int) size;
  435. }
  436.  
  437. int WINAPI GetReplaceDlgRetVal(TCHAR *filename)
  438. {
  439. #ifndef WIN32
  440. FARPROC lpfnprocReplace;
  441. #endif
  442. int ReplaceDlgRetVal;   /* replace dialog return value */
  443.  
  444. #ifdef WIN32
  445. ReplaceDlgRetVal = DialogBoxParam(hInst, "Replace",
  446.    hWnd, (DLGPROC)ReplaceProc, (DWORD)(LPSTR)filename);
  447. #else
  448. lpfnprocReplace = MakeProcInstance(ReplaceProc, hInst);
  449. ReplaceDlgRetVal = DialogBoxParam(hInst, "Replace",
  450.    hWnd, lpfnprocReplace, (DWORD)(LPSTR)filename);
  451. FreeProcInstance(lpfnprocReplace);
  452. #endif
  453. return ReplaceDlgRetVal;
  454. }
  455.  
  456. #ifdef __BORLANDC__
  457. #pragma argsused
  458. #endif
  459. void WINAPI ReceiveDllMessage(unsigned long ucsize, unsigned long csiz,
  460.    unsigned cfactor, unsigned mo, unsigned dy, unsigned yr, unsigned hh,
  461.    unsigned mm, TCHAR c, LPSTR filename, LPSTR methbuf, unsigned long crc,
  462.    TCHAR fCrypt)
  463. {
  464. }
  465.  
  466. #ifdef __BORLANDC__
  467. #pragma argsused
  468. #endif
  469.  
  470. int PASCAL WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  471.                     LPSTR lpszCmdLine, int nCmdShow)
  472. {
  473. TCHAR *ptr = NULL;
  474. hInst = hInstance;
  475.  
  476. hDCL = GlobalAlloc( GPTR, (DWORD)sizeof(DCL));
  477. if (!hDCL)
  478.    {
  479.    return 0;
  480.    }
  481. lpDCL = (LPDCL)GlobalLock(hDCL);
  482. if (!lpDCL)
  483.    {
  484.    return 0;
  485.    }
  486.  
  487. hUF = GlobalAlloc( GPTR, (DWORD)sizeof(USERFUNCTIONS));
  488. if (!hUF)
  489.    {
  490.    return 0;
  491.    }
  492. lpUserFunctions = (LPUSERFUNCTIONS)GlobalLock(hUF);
  493.  
  494. if (!lpUserFunctions)
  495.    {
  496.    return 0;
  497.    }
  498.  
  499. lpUserFunctions->password = password;
  500. lpUserFunctions->print = DisplayBuf;
  501. lpUserFunctions->sound = NULL;
  502. lpUserFunctions->replace = GetReplaceDlgRetVal;
  503. lpUserFunctions->SendApplicationMessage = ReceiveDllMessage;
  504. lpUserFunctions->ServCallBk = NULL;
  505.  
  506.  
  507.  
  508. GetModuleFileName(hInstance,(LPSTR)szThisApp,sizeof(szThisApp));
  509. lstrcpy(zfn, szThisApp);
  510.  
  511. ptr = strrchr(szThisApp, '\\');
  512. //if (SearchPath(
  513. //    NULL,               /* address of search path               */
  514. //    szThisApp,          /* address of filename                  */
  515. //    NULL,               /* address of extension                 */
  516. //    PATH_MAX,           /* size, in characters, of buffer       */
  517. //    szThisApp,          /* address of buffer for found filename */
  518. //    &ptr                /* address of pointer to file component */
  519. //   ) != 0)
  520. if (ptr != NULL)
  521.    {
  522.    lstrcpy(szAppName, ptr);
  523.    ptr[0] = '\0';
  524.    lstrcpy(szTarget, szThisApp);
  525.  
  526.    iReturn = DialogBox(hInstance, MAKEINTRESOURCE(INITDIALOG),
  527.          (HWND)NULL, (DLGPROC)InitDialogProc);
  528.    DestroyWindow((HWND) INITDIALOG);
  529.  
  530. #ifdef WIN32
  531.    SetCurrentDirectory(szHomeDir);
  532. #else
  533.    getcwd(szTarget, MAX_PATH);
  534.    chdir(szHomeDir);
  535.    setdisk(toupper(szHomeDir[0]) - 'A');
  536. #endif
  537.    }
  538. PostQuitMessage(0);
  539. return (0);
  540. }
  541.