📄 action.c
字号:
/* Action.c module of WizUnZip. * Author: Robert A. Heath, 1993 * I, Robert Heath, place this source code module in the public domain. * * Modifications: Mike White 1995, 1996 * Now modified for WiZ - WizUnZip no longer exists */#include <stdio.h>#include <string.h>#include <stdlib.h>#ifndef WIN32# include <dos.h># include <ctype.h>#endif#include "wiz.h"#include "unzip\windll\decs.h"#include "helpids.h"#ifdef ZE_MEM#undef ZE_MEM#define ZE_MEM 4#endif#include "ziperr.h"int argc;char **argv;extern BOOL fUpdateEntries;extern BOOL fSpool;extern char szRefDir[PATH_MAX];extern LPSTR szFileList;extern HANDLE hFileList;unsigned long dSpaceToUse;char __based(__segname("STRINGS_TEXT")) szNoMemory[] = "Insufficient memory for this operation!";char __based(__segname("STRINGS_TEXT")) szCantChDir[] = "Can't change directory to %s!";BOOL IsValidArchive(LPSTR archive){int retcode, AllCodes = FALSE;hSaveCursor = SetCursor(hHourGlass);ShowCursor(TRUE);retcode = (*Unz_Validate)((char *)archive, AllCodes);ShowCursor(FALSE);SetCursor(hSaveCursor);return retcode;}/* Get Selection Count returns a count of the selected * list box items. If the count is greater than zero, it also returns * a pointer to a locked list in local memory of the item nos. * and their local memory handle. * * A value of -1 indicates an error. * * Note the WIN32 version does not use the parameter hListBox */#ifdef __BORLANDC__#pragma argsused#endifint CLBItemsGet(HWND hListBox, int __far * __far *ppnSelItems, HANDLE *phnd){#ifndef WIN32int cSelLBItems = (int)SendMessage(hListBox, LB_GETSELCOUNT, 0, 0L);#elseint i, j, k = 0;LV_ITEM lvi;int cSelLBItems = ListView_GetSelectedCount(hWndList);#endifif ( !phnd ) return -1;*phnd = 0;if (cSelLBItems) { *phnd = GlobalAlloc(GMEM_FIXED, cSelLBItems * sizeof(int)); if ( !*phnd ) return -1; *ppnSelItems = (int __far *)GlobalLock( *phnd ); if ( !*ppnSelItems ) { GlobalFree( *phnd ); *phnd = 0; return -1; } /* Get list of selected items. Return value is number of selected items */#ifndef WIN32 if (SendMessage(hWndList, LB_GETSELITEMS, cSelLBItems, (LONG)*ppnSelItems) != cSelLBItems) { GlobalUnlock(*phnd); GlobalFree(*phnd); *phnd = 0; return -1; }#else j = ListView_GetItemCount(hWndList); for (i = 0; i < j; i++) { lvi.mask = LVIF_STATE; lvi.stateMask = LVIS_SELECTED; lvi.iItem = i; lvi.iSubItem = 0; ListView_GetItem(hWndList, &lvi); if (lvi.state) { (*ppnSelItems)[k++] = i; } }#endif } return cSelLBItems;}#ifndef WIN32/* Re-select listbox contents from given list. The pnSelItems is a * list containing the indices of those items selected in the listbox. * This list was probably created by GetLBSelCount() above. * * This routine is only called from wndproc.c when switching between * the long and short format. As the short format is not supported * by the Win32 version, this routine is not necessary. * */void ReselectLB(HWND hListBox, int cSelLBItems, int __far *pnSelItems){int i;for (i = 0; i < cSelLBItems; ++i) { SendMessage(hListBox, LB_SETSEL, TRUE, MAKELPARAM(pnSelItems[i],0)); }}#endif/* Action is called on double-clicking, or selecting one of the * main action buttons. The action code is the action * relative to the listbox or the button ID. */void Action(HWND hWnd, WPARAM wActionCode){HANDLE hMem;int i;int iSelection;int cch;unsigned long dFreeSpace, dStrlen = 0;int cSelLBItems;int __far *pnSelItems; /* pointer to list of selected items */#ifndef WIN32struct diskfree_t df;#elseDWORD SectorsPerCluster, BytesPerSector, FreeClusters, Clusters;#endifHANDLE hnd = 0;char **pszIndex;char *sz;LPSTR lpszT;#ifndef WIN32WORD wIndex = (WORD)(!uf.fFormatLong ? SHORT_FORM_FNAME_INX : LONG_FORM_FNAME_INX);#endifcSelLBItems = CLBItemsGet(hWndList, &pnSelItems, &hnd);/* if no items were selected */if (cSelLBItems < 1) return; /* Note: this global value can be overriden in replace.c */uf.fDoAll = (lpDCL->noflag) ? 1 : 0;SetCapture(hWnd);hSaveCursor = SetCursor(hHourGlass);ShowCursor(TRUE); /* If all the files are selected pass in no filenames */ /* since unzipping all files is the default */hMem = GlobalAlloc( GPTR, (PATH_MAX * 2));if ( !hMem ) goto done;lpszT = (LPSTR)GlobalLock( hMem );if ( !lpszT ) { GlobalFree( hMem ); goto done; }hFileList = GlobalAlloc( GPTR, FILENAME_BUF_SIZE);szFileList = (LPSTR)GlobalLock(hFileList);if (!szFileList) { GlobalFree(hFileList); goto done; }argc = ((WORD)cSelLBItems == cZippedFiles) ? 0 : 1;iSelection = 0;do { if ((argc) || (fUpdateEntries)) { dSpaceToUse = 0; pszIndex = (char **)szFileList; cch = (sizeof(char *) * ((cSelLBItems > cchFilesMax-1 ) ? cchFilesMax : cSelLBItems+1)); sz = szFileList + cch; for (i=0; ((i+iSelection) < cSelLBItems) && (i < cchFilesMax-1); ++i) {#ifndef WIN32 cch = (int)SendMessage(hWndList, LB_GETTEXTLEN, pnSelItems[i+iSelection], 0L); if (cch != LB_ERR) { cch = (int)SendMessage(hWndList, LB_GETTEXT, pnSelItems[i+iSelection], (LONG)lpszT); if ((cch != LB_ERR) && (cch > (int)wIndex)) { /* Get uncompressed totals to pre-flight the extraction process * The pre-flight portion of this needs to be modified to occur * only during actual extraction to disk. */ strncpy(sz, lpszT, 9); sz[9] = '\0'; dSpaceToUse += atol(sz); lstrcpy(sz, lpszT+wIndex); dStrlen += lstrlen(sz) + 1; if (dStrlen > FILENAME_BUF_SIZE ) { MessageBox(hWndMain, "Try selecting fewer files at a time", "Insufficient Memory", MB_OK |MB_SYSTEMMODAL| MB_ICONEXCLAMATION); goto done; } pszIndex[i] = sz; sz += (cch + 1 - wIndex); } else { break; } } else { MessageBeep(1); goto done; }#else /* Get uncompressed totals to pre-flight the extraction process * The pre-flight portion of this needs to be modified to occur * only during actual extraction to disk. */ ListView_GetItemText(hWndList, pnSelItems[i+iSelection], 1, lpszT, (PATH_MAX * 2)); lstrcpy(sz, lpszT); dSpaceToUse += atol(sz); /* Now we get the actual name */ ListView_GetItemText(hWndList, pnSelItems[i+iSelection], 0, lpszT, (PATH_MAX * 2)); lstrcpy(sz, lpszT+1); dStrlen += lstrlen(sz) + 1; if (dStrlen > FILENAME_BUF_SIZE ) { MessageBox(hWndMain, "Try selecting fewer files at a time", "Insufficient Memory", MB_OK |MB_SYSTEMMODAL| MB_ICONEXCLAMATION); goto done; } pszIndex[i] = sz; sz += (strlen(lpszT) + 1);#endif } /* end of for loop */ if (i == 0) { goto done; } argc = i; pszIndex[i] = 0; iSelection += i; } else { iSelection = cSelLBItems; }switch (wActionCode) {#ifdef WIN32 char tempChar;#endif int Ok; case 0: /* extract button */ /* Get amount of free space on target drive */#ifndef WIN32 _dos_getdiskfree((toupper(szUnzipToDirName[0]) - 'A'+1), &df); dFreeSpace = (long)df.avail_clusters * ((long)df.sectors_per_cluster * (long)df.bytes_per_sector);#else tempChar = szUnzipToDirName[3]; szUnzipToDirName[3] = '\0'; GetDiskFreeSpace(szUnzipToDirName, &SectorsPerCluster, &BytesPerSector, &FreeClusters, &Clusters); szUnzipToDirName[3] = tempChar; dFreeSpace = (long)SectorsPerCluster * (long)BytesPerSector * (long)FreeClusters;#endif if (dFreeSpace < dSpaceToUse) { sprintf(sz, "Free Disk Space = %lu bytes\nUncompressed Files Total %lu bytes\nContinue?\n", dFreeSpace, dSpaceToUse); Ok = MessageBox(hWndMain, sz, "Insufficient Disk Space?", MB_OKCANCEL | MB_ICONEXCLAMATION); } else Ok = IDOK; if (Ok != IDOK) break; lpDCL->ncflag = 0; lpDCL->fQuiet = 0; lpDCL->ntflag = 0; lpDCL->nvflag = 0; lpDCL->nUflag = lpDCL->ExtractOnlyNewer; lpDCL->nzflag = 0; lpDCL->ndflag = (int)(uf.fRecreateDirs ? 1 : 0); lpDCL->noflag = uf.fDoAll; lpDCL->naflag = (int)(uf.fTranslate ? 1 : 0); lpDCL->lpszZipFN = lpumb->szFileName; argv = (char **)szFileList; if (!uf.fUnzipToZipDir && szUnzipToDirName[0]) { lstrcpy(lpumb->szBuffer, szUnzipToDirName); /* OK to clobber szBuffer! */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -