?? intrface.cpp
字號:
/* Copyright (c) 1990-2002 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// IsFileOrDirectory// SmartCreateDirectory// ExtractOrTestFilesThread// CheckForAbort2// SetCurrentFile// UzpMessagePrnt2// UzpInput2// UzpMorePause// UzpPassword// UzpReplace// UzpSound// SendAppMsg// win_fprintf// mapattr// utimeToFileTime// GetFileTimes// SetFileSize// close_outfile// do_wild// mapname// test_NT// checkdir// match// iswild// IsOldFileSystem// 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////*****************************************************************************//*****************************************************************************// 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)////****************************************************************************/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 SetCurrentFile(Uz_Globs *pG);// Callbacks from Info-ZIP code.int UZ_EXP UzpMessagePrnt2(zvoid *pG, uch *buffer, ulg size, int flag);int UZ_EXP UzpInput2(zvoid *pG, uch *buffer, int *size, int flag);void UZ_EXP UzpMorePause(zvoid *pG, const char *szPrompt, int flag);int UZ_EXP UzpPassword(zvoid *pG, int *pcRetry, char *szPassword, int nSize, const char *szZipFile, const char *szFile);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);int win_fprintf(zvoid *pG, FILE *file, unsigned int dwCount, char far *buffer);void WINAPI Wiz_NoPrinting(int f);// 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, ZCONST 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; } // 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 szFile) { int result; // Create our Globals struct and fill it in whith some default values. Uz_Globs *pG = InitGlobals(szFile); 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; } }
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -