getfiles.c
上传用户:jlteech
上传日期:2007-01-06
资源大小:349k
文件大小:13k
源码类别:

压缩解压

开发平台:

Visual C++

  1. /*
  2.  Copyright (C) 1996 Mike White
  3.  Permission is granted to any individual or institution to use, copy, or
  4.  redistribute this software so long as all of the original files are included,
  5.  that it is not sold for profit, and that this copyright notice is retained.
  6. */
  7. #include <windows.h>
  8. #include "wiz.h"
  9. #include <string.h>
  10. #include <stdio.h>
  11. #ifdef __BORLANDC__
  12. #include <dir.h>
  13. #else
  14. #include <direct.h>
  15. #endif
  16. #include "helpids.h"
  17. // This is the length of a string that is required before a horizontal
  18. // scroll bar shows up, and the basis for computing the horizontal extent
  19. // required for the scroll bar.
  20. #define SCROLLWIDTH 15
  21. unsigned int cSelLBItems;
  22. unsigned int numFiles;
  23. char **pszIndex;
  24. char *sz;
  25. char baseDir[PATH_MAX], tempName[PATH_MAX];
  26. LPSTR szFileList;
  27. HANDLE hFileList;
  28. char szPattern[PATH_MAX], szLastPat[PATH_MAX];
  29. /****************************************************************************
  30.     FUNCTION: GetFilesProc(HWND, unsigned, WPARAM, LPARAM)
  31.     PURPOSE:  Processes messages for "Get Files For Archive" dialog box
  32.     MESSAGES:
  33.     WM_INITDIALOG - initialize dialog box
  34.     WM_COMMAND    - Input received
  35. ****************************************************************************/
  36. #ifdef __BORLANDC__
  37. #pragma warn -par
  38. #pragma warn -aus
  39. #endif
  40. BOOL WINAPI
  41. GetFilesProc(HWND hwndDlg, WORD wMessage, WPARAM wParam, LPARAM lParam)
  42. {
  43. char szFName[PATH_MAX];
  44. int __far * __far *ppnSelItems;
  45. int i, far *pnSelItems;
  46. DWORD iScrollWidth=0;
  47. HGLOBAL pHND;
  48. HWND hTemp;
  49.    switch (wMessage) {
  50.    case WM_INITDIALOG:
  51.       /* This hides the actual OK button associated with the file open
  52.          dialog. We basically want to disable this button, as pressing
  53.          enter will otherwise cause the OK button to be pressed, and the
  54.          dialog to terminate.
  55.        */
  56.       hTemp = GetDlgItem(hwndDlg, IDOK);
  57.       WinAssert(hTemp);
  58.       EnableWindow(hTemp, FALSE);
  59.       ShowWindow(hTemp, SW_HIDE);
  60.       ZpOpt.szRootDir[0] = '';
  61.       lstrcpy(szLastPat, "*.*");
  62.       numFiles = 0;
  63.       ZpZCL.argc = 0;
  64.       SetWindowText(GetDlgItem(hwndDlg, IDC_RECURSE_EDITBOX), "*.*");
  65.       CenterDialog(GetParent(hwndDlg), hwndDlg); /* center on parent */
  66.       break;
  67.    case WM_COMMAND:
  68.       switch (LOWORD(wParam)) {
  69.          case IDC_TEMP_PREFERENCES:
  70.             {
  71. #ifndef WIN32
  72.             FARPROC lpfnPrefs;
  73.             lpfnPrefs = MakeProcInstance((FARPROC)ZipPreferencesProc, hInst);
  74.             DialogBox(hInst, "ZIP_PREFS", hwndDlg, lpfnPrefs);
  75.             FreeProcInstance(lpfnPrefs);
  76. #else
  77.             DialogBox(hInst, "ZIP_PREFS", hwndDlg, (DLGPROC)ZipPreferencesProc);
  78. #endif
  79.             }
  80.             break;
  81.          case IDOK:
  82.             if ((HWND)lParam != NULL)
  83.                {
  84.                GetWindowText(GetDlgItem(hwndDlg, edt1), szLastPat, PATH_MAX);
  85.                break;
  86.                }
  87.          case IDC_ADD:
  88.             {
  89.             cSelLBItems = (unsigned int)SendMessage(GetDlgItem(hwndDlg, lst1),
  90.                LB_GETSELCOUNT, 0, 0L);
  91.             if (cSelLBItems == (unsigned int)SendMessage(GetDlgItem(hwndDlg, lst1),
  92.                LB_GETCOUNT, 0, 0L))
  93.                {
  94.                getcwd(baseDir, PATH_MAX);
  95.                if (baseDir[lstrlen(baseDir)-1] != '\')
  96.                   lstrcat(baseDir, "\");
  97.                lstrcat(baseDir, szLastPat);
  98.                SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  99.                   LB_INSERTSTRING, 0, (LONG) ((LPSTR) baseDir));
  100.                if (lstrlen(baseDir) > (int)iScrollWidth)
  101.                   {
  102.                   iScrollWidth = lstrlen(baseDir);
  103.                   if (iScrollWidth > SCROLLWIDTH)
  104.                      SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  105.                                  LB_SETHORIZONTALEXTENT,
  106.                                  (WPARAM)(dxChar*iScrollWidth),
  107.                                  0);
  108.                   }
  109.                return TRUE;
  110.                }
  111.             if (cSelLBItems)
  112.                {
  113.                pHND = GlobalAlloc(GMEM_FIXED, cSelLBItems * sizeof(int));
  114.                WinAssert(pHND);
  115.                pnSelItems = (int __far *)GlobalLock(pHND);
  116.                ppnSelItems = &pnSelItems;
  117.                if ( !*ppnSelItems )
  118.                   {
  119.                   GlobalFree(pHND);
  120.                   return -1;
  121.                   }
  122.                /* Get list of selected items. Return value is number of
  123.                   selected items */
  124.                if (SendMessage(GetDlgItem(hwndDlg, lst1), LB_GETSELITEMS,
  125.                   cSelLBItems, (LONG)*ppnSelItems) != cSelLBItems)
  126.                   {
  127.                   GlobalUnlock(pHND);
  128.                   GlobalFree(pHND);
  129.                   return -1;
  130.                   }
  131.                getcwd(baseDir, PATH_MAX);
  132.                lstrcat(baseDir, "\");
  133.                for (i = cSelLBItems - 1; i >= 0; i--)
  134.                   {
  135.                   SendMessage(GetDlgItem(hwndDlg, lst1), LB_GETTEXT,
  136.                      pnSelItems[i],(LPARAM) (LPCSTR) szFName);
  137.                   lstrcpy(tempName, baseDir);
  138.                   lstrcat(tempName, szFName);
  139.                   SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  140.                      LB_INSERTSTRING, 0, (LONG)(LPSTR) tempName);
  141.                   if (lstrlen(tempName) > (int)iScrollWidth)
  142.                      {
  143.                      iScrollWidth = lstrlen(tempName);
  144.                      if (iScrollWidth > SCROLLWIDTH)
  145.                         SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  146.                                     LB_SETHORIZONTALEXTENT,
  147.                                     (WPARAM)(dxChar*iScrollWidth),
  148.                                     0);
  149.                      }
  150.                   numFiles++;
  151.                   }
  152.                GlobalUnlock(pHND);
  153.                GlobalFree(pHND);
  154.                }
  155.             SendMessage(GetDlgItem(hwndDlg, lst1) , LB_SELITEMRANGE,
  156.                (WPARAM)FALSE,
  157.                 MAKELONG(0,-1));
  158.             SetWindowText(GetDlgItem(hwndDlg, edt1), szLastPat);
  159.             }
  160.             return TRUE;
  161.          case IDC_DELETE:
  162.             {
  163.             DWORD iNumEntries;
  164.             cSelLBItems = (unsigned int)SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  165.                LB_GETSELCOUNT, 0, 0L);
  166.             if (cSelLBItems)
  167.                {
  168.                pHND = GlobalAlloc(GMEM_FIXED, cSelLBItems * sizeof(int));
  169.                WinAssert(pHND);
  170.                pnSelItems = (int __far *)GlobalLock(pHND);
  171.                ppnSelItems = &pnSelItems;
  172.                if ( !*ppnSelItems )
  173.                   {
  174.                   GlobalFree(pHND);
  175.                   return -1;
  176.                   }
  177.                /* Get list of selected items. */
  178.                if (SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST), LB_GETSELITEMS,
  179.                   cSelLBItems, (LONG)*ppnSelItems) != cSelLBItems)
  180.                   {
  181.                   GlobalUnlock(pHND);
  182.                   GlobalFree(pHND);
  183.                   return -1;
  184.                   }
  185.                for (i = cSelLBItems - 1; i >= 0; i--)
  186.                   {
  187.                   SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST), LB_DELETESTRING,
  188.                      pnSelItems[i],0);
  189.                   numFiles--;
  190.                   }
  191.                GlobalUnlock(pHND);
  192.                GlobalFree(pHND);
  193.                }
  194.             iNumEntries = SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  195.                                       LB_GETCOUNT, 0, 0);
  196.             iScrollWidth = 0;
  197.             if (iNumEntries > 0)
  198.                {
  199.                DWORD i, j;
  200.                for (i = 0; i < iNumEntries; i++)
  201.                    {
  202.                    j = SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  203.                                LB_GETTEXTLEN, (WPARAM)i, 0);
  204.                    if (j > iScrollWidth)
  205.                       {
  206.                       iScrollWidth = j;
  207.                       if (iScrollWidth > SCROLLWIDTH)
  208.                          SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  209.                                      LB_SETHORIZONTALEXTENT,
  210.                                     (WPARAM)(dxChar*iScrollWidth),
  211.                                     0);
  212.                       }
  213.                    }
  214.                }
  215.             else
  216.                {
  217.                 SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  218.                             LB_SETHORIZONTALEXTENT,
  219.                             (WPARAM) 0,
  220.                             0);
  221.                }
  222.             }
  223.             break;
  224.          case IDC_SET_ROOT:
  225.             getcwd(ZpOpt.szRootDir, PATH_MAX);
  226.             SetWindowText(GetDlgItem(hwndDlg, IDC_ROOT_DIR), ZpOpt.szRootDir);
  227.             break;
  228.          case IDC_FREE_ROOT:
  229.             ZpOpt.szRootDir[0] = '';
  230.             SetWindowText(GetDlgItem(hwndDlg, IDC_ROOT_DIR), ZpOpt.szRootDir);
  231.             break;
  232.          case IDC_INCLUDE:
  233.             {
  234.             getcwd(baseDir, PATH_MAX);
  235.             lstrcat(baseDir, "\");
  236.             GetWindowText(GetDlgItem(hwndDlg, IDC_RECURSE_EDITBOX), tempName, PATH_MAX);
  237.             lstrcat(baseDir, tempName);
  238.             SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  239.                LB_INSERTSTRING, 0, (LONG) ((LPSTR) baseDir));
  240.             if (lstrlen(baseDir) > (int)iScrollWidth)
  241.                {
  242.                iScrollWidth = lstrlen(baseDir);
  243.                if (iScrollWidth > SCROLLWIDTH)
  244.                    SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  245.                                LB_SETHORIZONTALEXTENT,
  246.                                (WPARAM)(dxChar*iScrollWidth),
  247.                                0);
  248.                }
  249.             }
  250.             break;
  251.          case IDC_RECURSE:
  252.             {
  253.             char *p, drive[2];
  254.             DWORD iNumEntries;
  255.             getcwd(baseDir, PATH_MAX);
  256.             lstrcat(baseDir, "\");
  257.             GetWindowText(GetDlgItem(hwndDlg, IDC_RECURSE_EDITBOX), tempName, PATH_MAX);
  258.             lstrcat(baseDir, tempName);
  259.             drive[0] = baseDir[0];
  260.             drive[1] = '';
  261.             p = &baseDir[2];
  262.             FindFile(drive, p, hwndDlg);
  263.             iNumEntries = SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  264.                                       LB_GETCOUNT, 0, 0);
  265.             if (iNumEntries > 0)
  266.                {
  267.                DWORD i, j;
  268.                for (i = 0; i < iNumEntries; i++)
  269.                    {
  270.                    j = SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  271.                                LB_GETTEXTLEN, (WPARAM)i, 0);
  272.                    if (j > iScrollWidth)
  273.                       {
  274.                       iScrollWidth = j;
  275.                       if (iScrollWidth > SCROLLWIDTH)
  276.                          SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  277.                                      LB_SETHORIZONTALEXTENT,
  278.                                     (WPARAM)(dxChar*iScrollWidth),
  279.                                     0);
  280.                       }
  281.                    }
  282.                }
  283.             }
  284.             break;
  285.          case IDC_SELECT_ALL:
  286.          case IDC_DESELECT_ALL:
  287.             {
  288.             WORD cZippedFiles;
  289.             cZippedFiles = (WORD)SendMessage(GetDlgItem(hwndDlg, lst1),
  290.                LB_GETCOUNT, 0, 0L);
  291.             SendMessage(GetDlgItem(hwndDlg, lst1) , LB_SELITEMRANGE,
  292.                (WPARAM)(LOWORD(wParam) == IDC_DESELECT_ALL ? FALSE : TRUE),
  293.                MAKELONG(0, (cZippedFiles-1)));
  294.             }
  295.             SetWindowText(GetDlgItem(hwndDlg, edt1), szLastPat);
  296.             break;
  297.          case IDCANCEL:
  298.             ZpZCL.lpszZipFN[0] = '';
  299.             lpumb->szZipFileName[0] = '';
  300.             break;
  301.          case IDC_DONE:
  302. {
  303. int cc;
  304. char **index;
  305. SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST) , LB_SETSEL,
  306. (WPARAM)TRUE, -1);
  307. cSelLBItems = (unsigned int)SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  308. LB_GETSELCOUNT, 0, 0L);
  309. if (cSelLBItems < 1)
  310. {
  311. if (!ZpOpt.fRepair)
  312. {
  313. ZpZCL.lpszZipFN[0] = '';
  314. lpumb->szZipFileName[0] = '';
  315. }
  316. ZpZCL.argc = 0;
  317. goto pau;
  318. }
  319. ZpZCL.argc = cSelLBItems; /* keep count to transfer to dll */
  320. hFileList = GlobalAlloc( GPTR, FILENAME_BUF_SIZE);
  321. if ( hFileList )
  322. {
  323. szFileList = (char far *)GlobalLock(hFileList);
  324. }
  325.             else
  326.                {
  327.                MessageBox(hWndMain, "Try archiving fewer files at a time",
  328. "Insufficient Memory", MB_OK |MB_SYSTEMMODAL|
  329.                   MB_ICONEXCLAMATION);
  330.                ZpZCL.lpszZipFN[0] = '';
  331.                lpumb->szZipFileName[0] = '';
  332.                goto pau;
  333.                }
  334. if (cSelLBItems)
  335.                {
  336.                index = (char **)szFileList;
  337.                cc = (sizeof(char *) * ZpZCL.argc);
  338.                sz = szFileList + cc;
  339.                for (i = 0; i < ZpZCL.argc; i++)
  340. {
  341.                   cc = (int)SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST),
  342.                      LB_GETTEXT, i,(LPARAM) (LPCSTR) szFName);
  343.                   lstrcpy(sz, szFName);
  344.                   index[i] = sz;
  345.                   sz += (cc + 1);
  346.                   }
  347.                }
  348.             }
  349.             SendMessage(GetDlgItem(hwndDlg, IDC_FILE_LIST) , LB_SELITEMRANGE,
  350.                (WPARAM)FALSE,
  351.                 MAKELONG(0,-1));
  352.             SendMessage(GetDlgItem(hwndDlg, lst1) , LB_SELITEMRANGE,
  353.                (WPARAM)FALSE,
  354.  MAKELONG(0,-1));
  355. pau:
  356.             EndDialog(hwndDlg, TRUE);
  357.             break;
  358.          }
  359.       default:
  360.          break;
  361.    }
  362.    return FALSE;
  363. }
  364. #ifdef __BORLANDC__
  365. #pragma warn .aus
  366. #pragma warn .par
  367. #endif