⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 intrface.cpp

📁 完整的解压zip文件的源码。包含密码功能
💻 CPP
📖 第 1 页 / 共 4 页
字号:
//******************************************************************************//// File:        INTRFACE.CPP//// Description: This module acts as the interface between the Info-ZIP code and//              our Windows code in WINMAIN.CPP.  We expose the needed//              functions to query a file list, test file(s), extract file(s),//              and display a zip file comment.  The windows code is never//              bothered with understanding the Globals structure "Uz_Globs".////              This module also catches all the callbacks from the Info-ZIP//              code, cleans up the data provided in the callback, and then//              forwards the information to the appropriate function in the//              windows code.  These callbacks include status messages, file//              lists, comments, password prompt, and file overwrite prompts.////              Finally, this module implements the few functions that the//              Info-ZIP code expects the port to implement. These functions are//              OS dependent and are mostly related to validating file names and//              directoies, and setting file attributes and dates of saved files.//// Copyright:   All the source files for Pocket UnZip, except for components//              written by the Info-ZIP group, are copyrighted 1997 by Steve P.//              Miller.  The product "Pocket UnZip" itself is property of the//              author and cannot be altered in any way without written consent//              from Steve P. Miller.//// Disclaimer:  All project files are provided "as is" with no guarantee of//              their correctness.  The authors are not liable for any outcome//              that is the result of using this source.  The source for Pocket//              UnZip has been placed in the public domain to help provide an//              understanding of its implementation.  You are hereby granted//              full permission to use this source in any way you wish, except//              to alter Pocket UnZip itself.  For comments, suggestions, and//              bug reports, please write to stevemil@pobox.com.//// Functions:   DoListFiles//              DoExtractOrTestFiles//              DoGetComment//              SetExtractToDirectory//              InitGlobals//              FreeGlobals//              IsFileOrDirectory//              SmartCreateDirectory//              ExtractOrTestFilesThread//              CheckForAbort//              SetCurrentFile//              UzpMessagePrnt2//              UzpInput2//              UzpMorePause//              UzpPassword//              UzpReplace//              UzpSound//              SendAppMsg//              win_fprintf//              mapattr//              utimeToFileTime//              GetFileTimes//              close_outfile//              do_wild//              mapname//              test_NT//              checkdir//              match//              iswild//              IsOldFileSystem////// Date      Name          History// --------  ------------  -----------------------------------------------------// 02/01/97  Steve Miller  Created (Version 1.0 using Info-ZIP UnZip 5.30)////******************************************************************************//******************************************************************************#if 0 // The following information and structure are here just for reference//******************************************************************************//// The Windows CE version of Unzip builds with the following defines set://////    WIN32//    _WINDOWS//    UNICODE//    _UNICODE//    WIN32_LEAN_AND_MEAN//    STRICT////    POCKET_UNZIP         (Main define - Always set)////    UNZIP_INTERNAL//    WINDLL//    DLL//    REENTRANT//    USE_EF_UT_TIME//    NO_ZIPINFO//    NO_STDDEF_H//    NO_NTSD_EAS////    USE_SMITH_CODE       (optional - See COPYING document)//    USE_UNSHRINK         (optional - See COPYING document)////    DEBUG                (When building for Debug)//    _DEBUG               (When building for Debug)//    NDEBUG               (When building for Retail)//    _NDEBUG              (When building for Retail)////    _WIN32_WCE=100       (When building for Windows CE native)//// This causes our Globals structure to look like the following.  The only// things we care about is this Globals structure, the process_zipfiles()// function, and a few callback functions.  The Info-ZIP code has not been// been modified in any way.//typedef struct Globals {   zvoid         *callerglobs;          // points to pass-through global vars   UzpOpts        UzO;                  // command options structure   int            prompt_always;        // prompt to overwrite if TRUE   int            noargs;               // did true command line have *any* arguments?   unsigned       filespecs;            // number of real file specifications to be matched   unsigned       xfilespecs;           // number of excluded filespecs to be matched   int            process_all_files;   int            create_dirs;          // used by main(), mapname(), checkdir()   int            extract_flag;   int            newzip;               // reset in extract.c; used in crypt.c   LONGINT        real_ecrec_offset;   LONGINT        expect_ecrec_offset;   long           csize;                // used by decompr. (NEXTBYTE): must be signed   long           ucsize;               // used by unReduce(), explode()   long           used_csize;           // used by extract_or_test_member(), explode()   int            fValidate;            // true if only validating an archive   int            filenotfound;   int            redirect_data;        // redirect data to memory buffer   int            redirect_text;        // redirect text output to buffer   int            redirect_slide;       // redirect decompression area to mem buffer   unsigned       _wsize;   unsigned       redirect_size;   uch           *redirect_buffer;   uch           *redirect_pointer;   uch           *redirect_sldptr;      // head of decompression slide buffer   char         **pfnames;   char         **pxnames;   char           sig[4];   char           answerbuf[10];   min_info       info[DIR_BLKSIZ];   min_info      *pInfo;   union work     area;                 // see unzpriv.h for definition of work   ZCONST ulg near *crc_32_tab;   ulg            crc32val;             // CRC shift reg. (was static in funzip)   uch           *inbuf;                // input buffer (any size is OK)   uch           *inptr;                // pointer into input buffer   int            incnt;   ulg            bitbuf;   int            bits_left;            // unreduce and unshrink only   int            zipeof;   char          *argv0;                // used for NT and EXE_EXTENSION   char          *wildzipfn;   char          *zipfn;                // GRR:  MSWIN:  must nuke any malloc'd zipfn...   int            zipfd;                // zipfile file handle   LONGINT        ziplen;   LONGINT        cur_zipfile_bufstart; // extract_or_test, readbuf, ReadByte   LONGINT        extra_bytes;          // used in unzip.c, misc.c   uch           *extra_field;          // Unix, VMS, Mac, OS/2, Acorn, ...   uch           *hold;   local_file_hdr lrec;                 // used in unzip.c, extract.c   cdir_file_hdr  crec;                 // used in unzip.c, extract.c, misc.c   ecdir_rec      ecrec;                // used in unzip.c, extract.c   struct stat    statbuf;              // used by main, mapname, check_for_newer   int            mem_mode;   uch           *outbufptr;            // extract.c static   ulg            outsize;              // extract.c static   int            reported_backslash;   // extract.c static   int            disk_full;   int            newfile;   int            didCRlast;            // fileio static   ulg            numlines;             // fileio static: number of lines printed   int            sol;                  // fileio static: at start of line   int            no_ecrec;             // process static   FILE          *outfile;   uch           *outbuf;   uch           *realbuf;   uch           *outbuf2;              //  main() (never changes); else malloc'd   uch           *outptr;   ulg            outcnt;               // number of chars stored in outbuf   char           filename[FILNAMSIZ];   char          *key;                  // crypt static: decryption password or NULL   int            nopwd;                // crypt static   ulg            keys[3];              // crypt static: keys defining pseudo-random sequence   unsigned       hufts;                // track memory usage   struct huft   *fixed_tl;             // inflate static   struct huft   *fixed_td;             // inflate static   int            fixed_bl   int            fixed_bd;             // inflate static   unsigned       wp;                   // inflate static: current position in slide   ulg            bb;                   // inflate static: bit buffer   unsigned       bk;                   // inflate static: bits in bit buffer   MsgFn         *message;   InputFn       *input;   PauseFn       *mpause;   PasswdFn      *decr_passwd;   StatCBFn      *statreportcb;   LPUSERFUNCTIONS lpUserFunctions;   int            incnt_leftover;       // so improved NEXTBYTE does not waste input   uch           *inptr_leftover;   // These are defined in PUNZIP.H.   char           matchname[FILNAMSIZ]; // used by do_wild()   int            notfirstcall;         // used by do_wild()   char          *zipfnPtr;   char          *wildzipfnPtr;} Uz_Globs;#endif // #if 0 - This struct is here just for reference//******************************************************************************extern "C" {#define __INTRFACE_CPP__#define UNZIP_INTERNAL#include "unzip.h"#include "crypt.h"     // Needed to pick up CRYPT define#include <commctrl.h>#include "intrface.h"#include "winmain.h"#ifndef _WIN32_WCE#include <process.h>   // _beginthreadex() and _endthreadex()#endif}#include <tchar.h> // Must be outside of extern "C" block//******************************************************************************//***** "Local" Global Variables//******************************************************************************static USERFUNCTIONS  g_uf;static EXTRACT_INFO  *g_pExtractInfo = NULL;static FILE_NODE     *g_pFileLast    = NULL;static CHAR           g_szExtractToDirectory[_MAX_PATH];static BOOL           g_fOutOfMemory;//******************************************************************************//***** Local Function Prototypes//******************************************************************************extern "C" {// Our exposed interface functions to the Info-ZIP core.BOOL DoListFiles(LPCSTR szZipFile);BOOL DoExtractOrTestFiles(LPCSTR szZipFile, EXTRACT_INFO *pei);BOOL DoGetComment(LPCSTR szFile);BOOL SetExtractToDirectory(LPTSTR szDirectory);// Internal functions.Uz_Globs* InitGlobals(LPCSTR szZipFile);void FreeGlobals(Uz_Globs *pG);int IsFileOrDirectory(LPCTSTR szPath);BOOL SmartCreateDirectory(Uz_Globs *pG, LPCSTR szDirectory);#ifdef _WIN32_WCEDWORD WINAPI ExtractOrTestFilesThread(LPVOID lpv);#elseunsigned __stdcall ExtractOrTestFilesThread(void *lpv);#endifvoid CheckForAbort(Uz_Globs *pG);void SetCurrentFile(Uz_Globs *pG);// Callbacks from Info-ZIP code.int UzpMessagePrnt2(zvoid *pG, uch *buffer, ulg size, int flag);int UzpInput2(zvoid *pG, uch *buffer, int *size, int flag);void UzpMorePause(zvoid *pG, const char *szPrompt, int flag);int UzpPassword(zvoid *pG, int *pcRetry, char *szPassword, int nSize,                const char *szZipFile, const char *szFile);int WINAPI UzpReplace(char *szFile);void WINAPI UzpSound(void);void WINAPI SendAppMsg(ulg dwSize, ulg dwCompressedSize, int ratio, int month,                       int day, int year, int hour, int minute, int uppercase,                       char *szPath, char *szMethod, ulg dwCRC);int win_fprintf(FILE *file, unsigned int dwCount, char far *buffer);// Functions that Info-ZIP expects the port to write and export.void utimeToFileTime(time_t ut, FILETIME *pft, BOOL fOldFileSystem);int GetFileTimes(Uz_Globs *pG, FILETIME *pftCreated, FILETIME *pftAccessed,                 FILETIME *pftModified);int mapattr(Uz_Globs *pG);void close_outfile(Uz_Globs *pG);char* do_wild(Uz_Globs *pG, char *wildspec);int mapname(Uz_Globs *pG, int renamed);int test_NT(Uz_Globs *pG, uch *eb, unsigned eb_size);int checkdir(Uz_Globs *pG, char *pathcomp, int flag);// Check for FAT, VFAT, HPFS, etc.BOOL IsOldFileSystem(char *szPath);} // extern "C"//******************************************************************************//***** Our exposed interface functions to the Info-ZIP core//******************************************************************************int DoListFiles(LPCSTR szZipFile) {   int result;   // Create our Globals struct and fill it in whith some default values.   Uz_Globs *pG = InitGlobals(szZipFile);   if (!pG) {      return PK_MEM;   }   pG->UzO.vflag = 1; // verbosely: list directory (for WIN32 it is 0 or 1)   pG->process_all_files = TRUE; // improves speed   g_pFileLast = NULL;   g_fOutOfMemory = FALSE;   // We wrap some exception handling around the entire Info-ZIP engine to be   // safe.  Since we are running on a device with tight memory configurations,   // all sorts of problems can arise when we run out of memory.   __try {      // Call the unzip routine.  We will catch the file information in a      // callback to SendAppMsg().      result = process_zipfiles(pG);      // Make sure we didn't run out of memory in the process.      if (g_fOutOfMemory) {         result = PK_MEM;      }   } __except(EXCEPTION_EXECUTE_HANDLER) {      // Catch any exception here.      DebugOut(TEXT("Exception 0x%08X occurred in DoListFiles()"),               GetExceptionCode());      result = PK_EXCEPTION;   }   g_pFileLast = NULL;   // It is possible that the ZIP engine change the file name a bit (like adding   // a ".zip" if needed).  If so, we will pick up the new name.   if ((result != PK_EXCEPTION) && pG->zipfn && *pG->zipfn) {      strcpy(g_szZipFile, pG->zipfn);   }   // Free our globals.   FreeGlobals(pG);   return result;}//******************************************************************************BOOL DoExtractOrTestFiles(LPCSTR szZipFile, EXTRACT_INFO *pei) {   // WARNING!!!  This functions hands the EXTRACT_INFO structure of to a thread   // to perform the actual extraction/test.  When the thread is done, it will   // send a message to the progress dialog.  The calling function must not   // delete the EXTRAT_INFO structure until it receives the message.  Currently,   // this is not a problem for us since the structure lives on the stack of the   // calling thread.  The calling thread then displays a dialog that blocks the   // calling thread from clearing the stack until the dialog is dismissed, which   // occurs when the dialog receives the message.   // Create our globals so we can store the file name.   Uz_Globs *pG = InitGlobals(szZipFile);   if (!pG) {      pei->result = PK_MEM;      SendMessage(g_hDlgProgress, WM_PRIVATE, MSG_OPERATION_COMPLETE, (LPARAM)pei);      return FALSE;   }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -