📄 windll.c
字号:
/* Copyright (C) 1996 Mike White Permission is granted to any individual or institution to use, copy, or redistribute this software so long as all of the original files are included, that it is not sold for profit, and that this copyright notice is retained.*//* Windows Info-ZIP Unzip DLL module * * Author: Mike White * * Original: 1996 * * This module has the entry points for "unzipping" a zip file. *//*--------------------------------------------------------------------------- This file is the WINDLL replacement for the generic ``main program source file'' unzip.c. See the general comments in the header part of unzip.c. Copyrights: see accompanying file "COPYING" in UnZip source distribution. (This software is free but NOT IN THE PUBLIC DOMAIN. There are some restrictions on commercial use.) ---------------------------------------------------------------------------*/#include <windows.h>#ifdef __RSXNT__# include "win32/rsxntwin.h"#endif#ifdef __BORLANDC__#include <dir.h>#endif#define UNZIP_INTERNAL#include "unzip.h"#include "crypt.h"#include "version.h"#include "windll.h"#include "structs.h"#include "consts.h"/* Added type casts to prevent potential "type mismatch" error messages. */#ifdef REENTRANT# undef __G# undef __G__# define __G (Uz_Globs *)pG# define __G__ (Uz_Globs *)pG,#endifHANDLE hwildZipFN;HANDLE hInst; /* current instance */HANDLE hDCL;int fNoPrinting = 0;extern jmp_buf dll_error_return;/* For displaying status messages and error messages */static int UZ_EXP DllMessagePrint(zvoid *pG, uch *buf, ulg size, int flag);#if 0 /* currently unused *//* For displaying files extracted to the display window */int DllDisplayPrint(zvoid *pG, uch *buf, ulg size, int flag);#endif /* never *//* Callback function for status report and/or user interception */static int UZ_EXP Wiz_StatReportCB(zvoid *pG, int fnflag, ZCONST char *zfn, ZCONST char *efn, ZCONST zvoid *details);/* Dummy sound function for those applications that don't use sound */static void WINAPI DummySound(void);#ifndef UNZIPLIB/* DLL Entry Point */#ifdef __BORLANDC__#pragma argsused/* Borland seems to want DllEntryPoint instead of DllMain like MSVC */#define DllMain DllEntryPoint#endif#ifdef WIN32BOOL WINAPI DllMain( HINSTANCE hInstance, DWORD dwReason, LPVOID plvReserved)#elseint FAR PASCAL LibMain( HINSTANCE hInstance, WORD wDataSegment, WORD wHeapSize, LPSTR lpszCmdLine )#endif{#ifndef WIN32/* The startup code for the DLL initializes the local heap(if there is one) * with a call to LocalInit which locks the data segment. */if ( wHeapSize != 0 ) { UnlockData( 0 ); }hInst = hInstance;return 1; /* Indicate that the DLL was initialized successfully. */#elseBOOL rc = TRUE;switch( dwReason ) { case DLL_PROCESS_ATTACH: // DLL is loaded. Do your initialization here. // If cannot init, set rc to FALSE. hInst = hInstance; break; case DLL_PROCESS_DETACH: // DLL is unloaded. Do your cleanup here. break; default: break; }return rc;#endif}#ifdef __BORLANDC__#pragma argsused#endifint FAR PASCAL WEP ( int bSystemExit ){return 1;}#endif /* !UNZIPLIB *//* DLL calls *//* ExtractOnlyNewer = true if you are to extract only newer SpaceToUnderscore = true if convert space to underscore PromptToOverwrite = true if prompt to overwrite is wanted fQuiet = quiet flag. 1 = few messages, 2 = no messages, 0 = all messages ncflag = write to stdout if true ntflag = test zip file nvflag = verbose listing nUflag = "update" (extract only newer/new files) nzflag = display zip file comment ndflag = all args are files/dir to be extracted noflag = overwrite all files naflag = do end-of-line translation nZIflag = get Zip Info if TRUE C_flag = be case insensitive if TRUE fPrivilege = restore ACL's if 1, use privileges if 2 lpszZipFN = zip file name lpszExtractDir = directory to extract to; NULL means: current directory*/BOOL WINAPI Wiz_SetOpts(pG, C)zvoid *pG;LPDCL C;{ uO.qflag = C->fQuiet; /* Quiet flag */ G.pfnames = (char **)&fnames[0]; /* assign default file name vector */ G.pxnames = (char **)&fnames[1]; uO.jflag = !C->ndflag; uO.cflag = C->ncflag; uO.overwrite_all = C->noflag; uO.tflag = C->ntflag ; uO.vflag = C->nvflag; uO.zflag = C->nzflag; uO.uflag = C->nUflag; uO.aflag = C->naflag; uO.C_flag = C->C_flag; uO.uflag = C->ExtractOnlyNewer; G.prompt_always = C->PromptToOverwrite;#ifdef WIN32 uO.X_flag = C->fPrivilege;#endif uO.overwrite_none = !uO.overwrite_all; uO.sflag = C->SpaceToUnderscore; /* Translate spaces to underscores? */ if (C->nZIflag) { uO.zipinfo_mode = TRUE; uO.hflag = TRUE; uO.lflag = 10; uO.qflag = 2; } else { uO.zipinfo_mode = FALSE; } G.extract_flag = (!uO.zipinfo_mode && !uO.cflag && !uO.tflag && !uO.vflag && !uO.zflag#ifdef TIMESTAMP && !uO.T_flag#endif ); if (C->lpszExtractDir != NULL && G.extract_flag) {#ifndef CRTL_CP_IS_ISO char *pExDirRoot = (char *)malloc(strlen(C->lpszExtractDir)+1); if (pExDirRoot == NULL) return FALSE; ISO_TO_INTERN(C->lpszExtractDir, pExDirRoot);#else# define pExDirRoot C->lpszExtractDir#endif uO.exdir = pExDirRoot; } else { uO.exdir = (char *)NULL; }/* G.wildzipfn needs to be initialized so that do_wild does not wind up clearing out the zip file name when it returns in process.c*/ hwildZipFN = GlobalAlloc(GPTR, FILNAMSIZ); if (hwildZipFN == (HGLOBAL) NULL) return FALSE; G.wildzipfn = GlobalLock(hwildZipFN); lstrcpy(G.wildzipfn, C->lpszZipFN); _ISO_INTERN(G.wildzipfn); return TRUE; /* set up was OK */}void FreeDllMem(__GPRO){ if (G.wildzipfn) { GlobalUnlock(hwildZipFN); G.wildzipfn = NULL; } if (hwildZipFN) hwildZipFN = GlobalFree(hwildZipFN); uO.zipinfo_mode = FALSE;}int WINAPI Wiz_SingleEntryUnzip(int ifnc, char **ifnv, int xfnc, char **xfnv, LPDCL C, LPUSERFUNCTIONS lpUserFunc){int retcode;CONSTRUCTGLOBALS();if (!Wiz_Init((zvoid *)&G, lpUserFunc)) { DESTROYGLOBALS(); return PK_BADERR; }if (C->lpszZipFN == NULL) /* Something has screwed up, we don't have a filename */ { DESTROYGLOBALS(); return PK_NOZIP; }Wiz_SetOpts((zvoid *)&G, C);#ifdef SFXG.zipfn = C->lpszZipFN;G.argv0 = C->lpszZipFN;#endif/* Here is the actual call to "unzip" the files (or whatever else you * are doing.) */retcode = Wiz_Unzip((zvoid *)&G, ifnc, ifnv, xfnc, xfnv);DESTROYGLOBALS();return retcode;}BOOL WINAPI Wiz_Init(pG, lpUserFunc)zvoid *pG;LPUSERFUNCTIONS lpUserFunc;{G.message = DllMessagePrint;G.statreportcb = Wiz_StatReportCB;if (lpUserFunc->sound == NULL) lpUserFunc->sound = DummySound;G.lpUserFunctions = lpUserFunc;if (!G.lpUserFunctions->print || !G.lpUserFunctions->sound || !G.lpUserFunctions->replace) return FALSE;return TRUE;}int WINAPI Wiz_Unzip(pG, ifnc, ifnv, xfnc, xfnv)zvoid *pG;int ifnc;char **ifnv;int xfnc;char **xfnv;{int retcode, f_cnt;#ifndef CRTL_CP_IS_ISOchar **intern_ifv = NULL, **intern_xfv = NULL;#endifif (ifnv == (char **)NULL && ifnc != 0) ifnc = 0;else for (f_cnt = 0; f_cnt < ifnc; f_cnt++) if (ifnv[f_cnt] == (char *)NULL) { ifnc = f_cnt; break; }if (xfnv == (char **)NULL && xfnc != 0) xfnc = 0;else for (f_cnt = 0; f_cnt < xfnc; f_cnt++) if (xfnv[f_cnt] == (char *)NULL) { xfnc = f_cnt; break; }G.process_all_files = (ifnc == 0 && xfnc == 0); /* for speed */G.filespecs = ifnc;G.xfilespecs = xfnc;if (ifnc > 0) {#ifdef CRTL_CP_IS_ISO G.pfnames = ifnv;#else /* !CRTL_CP_IS_ISO */ unsigned bufsize = 0; intern_ifv = (char **)malloc((ifnc+1)*sizeof(char **)); if (intern_ifv == (char **)NULL) { FreeDllMem(__G); return PK_BADERR; } for (f_cnt = ifnc; --f_cnt >= 0;) bufsize += strlen(ifnv[f_cnt]) + 1; intern_ifv[0] = (char *)malloc(bufsize); if (intern_ifv[0] == (char *)NULL) { free(intern_ifv); FreeDllMem(__G); return PK_BADERR; } for (f_cnt = 0; ; f_cnt++) { ISO_TO_INTERN(ifnv[f_cnt], intern_ifv[f_cnt]); if ((f_cnt+1) >= ifnc) break; intern_ifv[f_cnt+1] = intern_ifv[f_cnt] + (strlen(intern_ifv[f_cnt]) + 1); } intern_ifv[ifnc] = (char *)NULL; G.pfnames = intern_ifv;#endif /* ?CRTL_CP_IS_ISO */ }if (xfnc > 0) {#ifdef CRTL_CP_IS_ISO G.pxnames = xfnv;#else /* !CRTL_CP_IS_ISO */ unsigned bufsize = 0; intern_xfv = (char **)malloc((xfnc+1)*sizeof(char **)); if (intern_xfv == (char **)NULL) { if (ifnc > 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -