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

📄 intrface.cpp

📁 压缩解压,是unzip540的升级,这个外国网站摘来的源码,是evb编写.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
/*  Copyright (c) 1990-2005 Info-ZIP.  All rights reserved.  See the accompanying file LICENSE, version 2000-Apr-09 or later  (the contents of which are also included in unzip.h) for terms of use.  If, for some reason, all these files are missing, the Info-ZIP license  also may be found at:  ftp://ftp.info-zip.org/pub/infozip/license.html*///******************************************************************************//// 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//              directories, 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.  As of June 1999, Steve P. Miller has agreed to apply//              the Info-ZIP License (see citation on top of this module)//              to his work.  See the contents of this License for terms//              and conditon of using the product "Pocket UnZip".//// 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 or the Info-ZIP//              mailing list Zip-Bugs@lists.wku.edu.//// Functions:   DoListFiles//              DoExtractOrTestFiles//              DoGetComment//              SetExtractToDirectory//              InitGlobals//              FreeGlobals//              ExtractOrTestFilesThread//              IsFileOrDirectory//              SmartCreateDirectory//              CheckForAbort2//              SetCurrentFile//              UzpMessagePrnt2//              UzpInput2//              UzpMorePause//              UzpPassword//              UzpReplace//              UzpSound//              SendAppMsg//              win_fprintf//              test_NT//              utimeToFileTime//              GetFileTimes//              IsOldFileSystem//              SetFileSize//              close_outfile//              do_wild//              mapattr//              mapname//              checkdir//              match//              iswild//              conv_to_rule//              GetPlatformLocalTimezone////// Date      Name          History// --------  ------------  -----------------------------------------------------// 02/01/97  Steve Miller  Created (Version 1.0 using Info-ZIP UnZip 5.30)// 08/01/99  Johnny Lee, Christian Spieler, Steve Miller, and others//                         Adapted to UnZip 5.41 (Version 1.1)// 12/01/02  Chr. Spieler  Updated interface for UnZip 5.50// 02/23/05  Chr. Spieler  Modified and optimized utimeToFileTime() to support//                         the NO_W32TIMES_IZFIX compilation option////*****************************************************************************//*****************************************************************************// 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 INSTALL document)//    LZW_CLEAN            (optional - See INSTALL document)//    NO_W32TIMES_IZFIX    (optional - See INSTALL 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)////****************************************************************************/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#ifdef POCKET_UNZIP//******************************************************************************//***** "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//******************************************************************************// Internal functions of the GUI interface.static Uz_Globs* InitGlobals(LPCSTR szZipFile);static void FreeGlobals(Uz_Globs *pG);#ifdef _WIN32_WCEstatic DWORD WINAPI ExtractOrTestFilesThread(LPVOID lpv);#elsestatic unsigned __stdcall ExtractOrTestFilesThread(void *lpv);#endifstatic void SetCurrentFile(__GPRO);#endif // POCKET_UNZIP// Internal helper functions for the UnZip core.static int IsFileOrDirectory(LPCTSTR szPath);static BOOL SmartCreateDirectory(__GPRO__ LPCSTR szDirectory, BOOL *pNewDir);static void utimeToFileTime(time_t ut, FILETIME *pft, BOOL fOldFileSystem);static int GetFileTimes(Uz_Globs *pG, FILETIME *pftCreated,                        FILETIME *pftAccessed, FILETIME *pftModified);// Check for FAT, VFAT, HPFS, etc.static BOOL IsOldFileSystem(char *szPath);#ifdef POCKET_UNZIPextern "C" {// Local variants of callbacks from Info-ZIP code.// (These functions are not referenced by name outside this source module.)int UZ_EXP UzpMessagePrnt2(zvoid *pG, uch *buffer, ulg size, int flag);int UZ_EXP UzpInput2(zvoid *pG, uch *buffer, int *size, int flag);int UZ_EXP CheckForAbort2(zvoid *pG, int fnflag, ZCONST char *zfn,                          ZCONST char *efn, ZCONST zvoid *details);int WINAPI UzpReplace(LPSTR szFile);void WINAPI UzpSound(void);void WINAPI SendAppMsg(ulg dwSize, ulg dwCompressedSize, unsigned ratio,                       unsigned month, unsigned day, unsigned year,                       unsigned hour, unsigned minute, char uppercase,                       LPSTR szPath, LPSTR szMethod, ulg dwCRC, char chCrypt);} // 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 EXTRACT_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;   }   // Store a global pointer to the Extract structure so it can be reached from   // our thread and callback functions.   g_pExtractInfo = pei;   // Spawn our thread   DWORD dwThreadId;   HANDLE hThread;#ifdef _WIN32_WCE   // On CE, we use good old CreateThread() since the WinCE CRT does not   // allocate per-thread storage.   hThread = CreateThread(NULL, 0, ExtractOrTestFilesThread, pG, 0,                          &dwThreadId);#else   // On NT, we need use the CRT's thread function so that we don't leak any   // CRT allocated memory when the thread exits.   hThread = (HANDLE)_beginthreadex(NULL, 0, ExtractOrTestFilesThread, pG, 0,                                    (unsigned*)&dwThreadId);#endif   // Bail out if our thread failed to create.   if (!hThread) {      DebugOut(TEXT("CreateThread() failed [%u]"), GetLastError());      // Set our error as a memory error.      g_pExtractInfo->result = PK_MEM;      // Free our globals.      FreeGlobals(pG);      // Tell the progress dialog that we are done.      SendMessage(g_hDlgProgress, WM_PRIVATE, MSG_OPERATION_COMPLETE, (LPARAM)pei);      g_pExtractInfo = NULL;      return FALSE;   }   // Close our thread handle since we have no use for it.   CloseHandle(hThread);   return TRUE;}//******************************************************************************int DoGetComment(LPCSTR szZipFile) {   int result;   // Create our Globals struct and fill it in with some default values.   Uz_Globs *pG = InitGlobals(szZipFile);   if (!pG) {      return PK_MEM;   }   pG->UzO.zflag = TRUE; // display the zipfile comment   // 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 comment string in a callback      // to win_fprintf().      result = process_zipfiles(pG);   } __except(EXCEPTION_EXECUTE_HANDLER) {      // Catch any exception here.      DebugOut(TEXT("Exception 0x%08X occurred in DoGetComment()"),               GetExceptionCode());      result = PK_EXCEPTION;   }   // Free our globals.   FreeGlobals(pG);   return result;}//******************************************************************************BOOL SetExtractToDirectory(LPTSTR szDirectory) {   BOOL fNeedToAddWack = FALSE;   // Remove any trailing wack from the path.   int length = _tcslen(szDirectory);   if ((length > 0) && (szDirectory[length - 1] == TEXT('\\'))) {      szDirectory[--length] = TEXT('\0');      fNeedToAddWack = TRUE;   }#ifndef _WIN32_WCE   // Check to see if a root directory was specified.   if ((length == 2) && isalpha(szDirectory[0]) && (szDirectory[1] == ':')) {      // If just a root is specified, we need to only verify the drive letter.      if (!(GetLogicalDrives() & (1 << (tolower(szDirectory[0]) - (int)'a')))) {         // This drive does not exist.  Bail out with a failure.         return FALSE;      }   } else#endif   // We only verify path if length is >0 since we know "\" is valid.   if (length > 0) {      // Verify the the path exists and that it is a directory.      if (IsFileOrDirectory(szDirectory) != 2) {         return FALSE;      }   }   // Store the directory for when we do an extract.   TSTRTOMBS(g_szExtractToDirectory, szDirectory, countof(g_szExtractToDirectory));   // We always want a wack at the end of our path.   strcat(g_szExtractToDirectory, "\\");   // Add the wack back to the end of the path.   if (fNeedToAddWack) {      _tcscat(szDirectory, TEXT("\\"));   }   return TRUE;}//******************************************************************************//***** Internal functions//******************************************************************************static Uz_Globs* InitGlobals(LPCSTR szZipFile){   // Create our global structure - pG   CONSTRUCTGLOBALS();   // Bail out if we failed to allocate our Globals structure.   if (!pG) {      return NULL;   }   // Clear our USERFUNCTIONS structure   ZeroMemory(&g_uf, sizeof(g_uf));   // Initialize a global pointer to our USERFUNCTIONS structure that is   // used by WINMAIN.CPP to access it (without using the pG construction).   lpUserFunctions = &g_uf;   // Store a global pointer to our USERFUNCTIONS structure in pG so that   // the generic Info-ZIP code LIST.C and PROCESS.C can access it.   pG->lpUserFunctions = &g_uf;

⌨️ 快捷键说明

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