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

📄 intrface.cpp

📁 压缩解压,是unzip540的升级,这个外国网站摘来的源码,是evb编写.
💻 CPP
📖 第 1 页 / 共 4 页
字号:
   // Fill in all our callback functions.   pG->message      = UzpMessagePrnt2;   pG->input        = UzpInput2;   pG->mpause       = UzpMorePause;   pG->statreportcb = CheckForAbort2;   pG->lpUserFunctions->replace                = UzpReplace;   pG->lpUserFunctions->sound                  = UzpSound;   pG->lpUserFunctions->SendApplicationMessage = SendAppMsg;#if CRYPT   pG->decr_passwd = UzpPassword;#endif   // Match filenames case-sensitively.  We can do this since we can guarantee   // exact case because the user can only select files via our UI.   pG->UzO.C_flag = FALSE;   // Allocate and store the ZIP file name in pG->zipfn   if (!(pG->zipfnPtr = new char[FILNAMSIZ])) {      FreeGlobals(pG);      return NULL;   }   pG->zipfn = pG->zipfnPtr;   strcpy(pG->zipfn, szZipFile);   // Allocate and store the ZIP file name in pG->zipfn.  This needs to done   // so that do_wild() does not wind up clearing out the zip file name when   // it returns in process.c   if (!(pG->wildzipfnPtr = new char[FILNAMSIZ])) {      FreeGlobals(pG);      return NULL;   }   pG->wildzipfn = pG->wildzipfnPtr;   strcpy(pG->wildzipfn, szZipFile);   return pG;}//******************************************************************************static void FreeGlobals(Uz_Globs *pG){   // Free our ZIP file name   if (pG->zipfnPtr) {      delete[] pG->zipfnPtr;      pG->zipfnPtr = pG->zipfn = NULL;   }   // Free our wild name buffer   if (pG->wildzipfnPtr) {      delete[] pG->wildzipfnPtr;      pG->wildzipfnPtr = pG->wildzipfn = NULL;   }   // Free everything else.   DESTROYGLOBALS();}//******************************************************************************#ifdef _WIN32_WCE// On WinCE, we declare our thread function the way CreateThread() likes it.static DWORD WINAPI ExtractOrTestFilesThread(LPVOID lpv)#else// On WinNT, we declare our thread function the way _beginthreadex likes it.static unsigned __stdcall ExtractOrTestFilesThread(void *lpv)#endif{   Uz_Globs *pG = (Uz_Globs*)lpv;   if (g_pExtractInfo->fExtract) {      pG->extract_flag = TRUE;      switch (g_pExtractInfo->overwriteMode) {         case OM_NEWER:         // Update (extract only newer/brand-new files)            pG->UzO.uflag = TRUE;            break;         case OM_ALWAYS:        // OK to overwrite files without prompting            pG->UzO.overwrite_all = TRUE;            break;         case OM_NEVER:         // Never overwrite files (no prompting)            pG->UzO.overwrite_none = TRUE;            break;         default:               // Force a prompt            pG->UzO.overwrite_all = FALSE;            pG->UzO.overwrite_none = FALSE;            pG->UzO.uflag = FALSE;            break;      }      // Throw away paths if requested.      pG->UzO.jflag = !g_pExtractInfo->fRestorePaths;   } else {      pG->UzO.tflag = TRUE;   }   if (g_pExtractInfo->szFileList) {      pG->filespecs = g_pExtractInfo->dwFileCount;      pG->pfnames = g_pExtractInfo->szFileList;   } else {      // Improves performance if all files are being extracted.      pG->process_all_files = TRUE;   }   // Invalidate our file offset to show that we are starting a new operation.   g_pExtractInfo->dwFileOffset = 0xFFFFFFFF;   // 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 {      // Put a jump marker on our stack so the user can abort.      int error = setjmp(dll_error_return);      // If setjmp() returns 0, then we just set our jump marker and we can      // continue with the operation.  If setjmp() returned something else,      // then we reached this point because the operation was aborted and      // set our instruction pointer back here.      if (error > 0) {         // We already called process_zipfiles() and were thrown back here.         g_pExtractInfo->result = (error == 1) ? PK_BADERR : error;      } else {         // Entering Info-ZIP... close your eyes.         g_pExtractInfo->result = process_zipfiles(pG);      }   } __except(EXCEPTION_EXECUTE_HANDLER) {      // Catch any exception here.      DebugOut(TEXT("Exception 0x%08X occurred in ExtractOrTestFilesThread()"),               GetExceptionCode());      g_pExtractInfo->result = PK_EXCEPTION;   }   // Free our globals.   FreeGlobals(pG);   // Tell the progress dialog that we are done.   SendMessage(g_hDlgProgress, WM_PRIVATE, MSG_OPERATION_COMPLETE,               (LPARAM)g_pExtractInfo);   // Clear our global pointer as we are done with it.   g_pExtractInfo = NULL;#ifndef _WIN32_WCE   // On NT, we need to free any CRT allocated memory.   _endthreadex(0);#endif   return 0;}//******************************************************************************static void SetCurrentFile(__GPRO){   // Reset all our counters as we about to process a new file.   g_pExtractInfo->dwFileOffset = (DWORD)G.pInfo->offset;   g_pExtractInfo->dwFile++;   g_pExtractInfo->dwBytesWrittenThisFile = 0;   g_pExtractInfo->dwBytesWrittenPreviousFiles += g_pExtractInfo->dwBytesTotalThisFile;   g_pExtractInfo->dwBytesTotalThisFile = G.lrec.ucsize;   g_pExtractInfo->szFile = G.filename;   g_pExtractInfo->fNewLineOfText = TRUE;   // Pass control to our GUI thread to do a full update our progress dialog.   SendMessage(g_hWndMain, WM_PRIVATE, MSG_UPDATE_PROGRESS_COMPLETE,               (LPARAM)g_pExtractInfo);   // Check our abort flag.}#endif // POCKET_UNZIP//******************************************************************************static int IsFileOrDirectory(LPCTSTR szPath){   // Geth the attributes of the item.   DWORD dwAttribs = GetFileAttributes(szPath);   // Bail out now if we could not find the path at all.   if (dwAttribs == 0xFFFFFFFF) {      return 0;   }   // Return 1 for file and 2 for directory.   return ((dwAttribs & FILE_ATTRIBUTE_DIRECTORY) ? 2 : 1);}//******************************************************************************static BOOL SmartCreateDirectory(__GPRO__ LPCSTR szDirectory, BOOL *pNewDir){   // Copy path to a UNICODE buffer.   TCHAR szBuffer[_MAX_PATH];   MBSTOTSTR(szBuffer, szDirectory, countof(szBuffer));   switch (IsFileOrDirectory(szBuffer)) {      case 0:         // Create the directory if it does not exist.         if (!CreateDirectory(szBuffer, NULL)) {            Info(slide, 1, ((char *)slide, "error creating directory: %s\n",              FnFilter1( szDirectory)));            return FALSE;         }         if (pNewDir != NULL) *pNewDir = TRUE;         break;      case 1:         // If there is a file with the same name, then display an error.         Info(slide, 1, ((char *)slide,              "cannot create %s as a file with same name already exists.\n",              FnFilter1(szDirectory)));         return FALSE;   }   // If the directory already exists or was created, then return success.   return TRUE;}#ifdef POCKET_UNZIP//******************************************************************************//***** Callbacks from Info-ZIP code.//******************************************************************************int UZ_EXP UzpMessagePrnt2(zvoid *pG, uch *buffer, ulg size, int flag){   // Some ZIP files cause us to get called during DoListFiles(). We only handle   // messages while processing DoExtractFiles().   if (!g_pExtractInfo) {      if (g_hWndEdit) {         SendMessage(g_hWndMain, WM_PRIVATE, MSG_ADD_TEXT_TO_EDIT,                     (LPARAM)buffer);      } else {#ifdef UNICODE         DebugOut(TEXT("Unhandled call to UzpMessagePrnt2(\"%S\")"), buffer);#else         DebugOut(TEXT("Unhandled call to UzpMessagePrnt2(\"%s\")"), buffer);#endif      }      return 0;   }   // When extracting, mapname() will get called for every file which in turn   // will call SetCurrentFile().  For testing though, mapname() never gets   // called so we need to be on the lookout for a new file.   if (g_pExtractInfo->dwFileOffset != (DWORD)((Uz_Globs*)pG)->pInfo->offset) {      SetCurrentFile((Uz_Globs*)pG);   }   // Make sure this message was intended for us to display.   if (!MSG_NO_WGUI(flag) && !MSG_NO_WDLL(flag)) {      // Insert a leading newline if requested to do so.      if (MSG_LNEWLN(flag) && !g_pExtractInfo->fNewLineOfText) {         SendMessage(g_hWndMain, WM_PRIVATE, MSG_ADD_TEXT_TO_EDIT, (LPARAM)"\n");         g_pExtractInfo->fNewLineOfText = TRUE;      }      // Since we use a proportional font, we need to do a little cleanup of the      // text we are passed since it assumes a fixed font and adds padding to try      // to line things up.  We remove leading whitespace on any new line of text.      if (g_pExtractInfo->fNewLineOfText) {         while (*buffer == ' ') {            buffer++;         }      }      // We always remove trailing whitespace.      LPSTR psz = (LPSTR)buffer;      LPSTR pszn;      while ((pszn = MBSCHR(psz, ' ')) != NULL) {         for (psz = pszn+1; *psz == ' '; psz++);         if (*psz == '\0') {            *pszn = '\0';            break;         }      }      // Determine if the next line of text will be a new line of text.      g_pExtractInfo->fNewLineOfText = ((*psz == '\r') || (*psz == '\n'));      // Change all forward slashes to back slashes in the buffer      ForwardSlashesToBackSlashesA((LPSTR)buffer);      // Add the cleaned-up text to our extraction log edit control.      SendMessage(g_hWndMain, WM_PRIVATE, MSG_ADD_TEXT_TO_EDIT, (LPARAM)buffer);      // Append a trailing newline if requested to do so.      if (MSG_TNEWLN(flag) || MSG_MNEWLN(flag) && !g_pExtractInfo->fNewLineOfText) {         SendMessage(g_hWndMain, WM_PRIVATE, MSG_ADD_TEXT_TO_EDIT, (LPARAM)"\n");         g_pExtractInfo->fNewLineOfText = TRUE;      }   }   return 0;}//******************************************************************************int UZ_EXP UzpInput2(zvoid *pG, uch *buffer, int *size, int flag){   DebugOut(TEXT("WARNING: UzpInput2(...) called"));   return 0;}//******************************************************************************void UZ_EXP UzpMorePause(zvoid *pG, const char *szPrompt, int flag){   DebugOut(TEXT("WARNING: UzpMorePause(...) called"));}//******************************************************************************int UZ_EXP UzpPassword(zvoid *pG, int *pcRetry, char *szPassword, int nSize,                       const char *szZipFile, const char *szFile){   // Return Values:   //    IZ_PW_ENTERED    got some PWD string, use/try it   //    IZ_PW_CANCEL     no password available (for this entry)   //    IZ_PW_CANCELALL  no password, skip any further PWD request   //    IZ_PW_ERROR      failure (no mem, no tty, ...)#if CRYPT   // Build the data structure for our dialog.   DECRYPT_INFO di;   di.retry      = *pcRetry;   di.szPassword = szPassword;   di.nSize      = nSize;   di.szFile     = szFile;   // Clear the password to be safe.   *di.szPassword = '\0';   // On our first call for a file, *pcRetry == 0.  If we would like to allow   // for retries, then we set the value of *pcRetry to the number of retries we   // are willing to allow.  We will be recalled as neccessary, each time with   // *pcRetry being decremented once.  1 is the last retry we will get.   *pcRetry = (*pcRetry == 0) ? MAX_PASSWORD_RETRIES : (*pcRetry - 1);   // Pass control to our GUI thread which will prompt the user for a password.   return SendMessage(g_hWndMain, WM_PRIVATE, MSG_PROMPT_FOR_PASSWORD, (LPARAM)&di);#else   return -2;#endif}//******************************************************************************int UZ_EXP CheckForAbort2(zvoid *pG, int fnflag, ZCONST char *zfn,                    ZCONST char *efn, ZCONST zvoid *details){   int rval = UZ_ST_CONTINUE;   if (g_pExtractInfo->fAbort) {      // Add a newline to our log if we are in the middle of a line of text.      if (!g_pExtractInfo->fNewLineOfText) {         SendMessage(g_hWndMain, WM_PRIVATE, MSG_ADD_TEXT_TO_EDIT, (LPARAM)"\n");      }      // Make sure whatever file we are currently processing gets closed.      if (((int)((Uz_Globs *)pG)->outfile != 0) &&          ((int)((Uz_Globs *)pG)->outfile != -1)) {         if (g_pExtractInfo->fExtract && *efn) {            // Make sure the user is aware that this file is screwed.            SendMessage(g_hWndMain, WM_PRIVATE, MSG_ADD_TEXT_TO_EDIT,                        (LPARAM)"warning: ");            SendMessage(g_hWndMain, WM_PRIVATE, MSG_ADD_TEXT_TO_EDIT,                        (LPARAM)efn);            SendMessage(g_hWndMain, WM_PRIVATE, MSG_ADD_TEXT_TO_EDIT,                        (LPARAM)" is probably truncated.\n");         }      }      // Display an aborted message in the log      SendMessage(g_hWndMain, WM_PRIVATE, MSG_ADD_TEXT_TO_EDIT,                  (LPARAM)"Operation aborted by user.\n");      // Signal "Immediate Cancel" back to the UnZip engine.      rval = UZ_ST_BREAK;   }   return rval;}//******************************************************************************int WINAPI UzpReplace(LPSTR szFile) {   // Pass control to our GUI thread which will prompt the user to overwrite.   return SendMessage(g_hWndMain, WM_PRIVATE, MSG_PROMPT_TO_REPLACE, (LPARAM)szFile);}//******************************************************************************void WINAPI UzpSound(void) {   // Do nothing.}//******************************************************************************// Called from LIST.Cvoid 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){   // If we are out of memory, then just bail since we will only make things worse.   if (g_fOutOfMemory) {      return;   }   // We get our Globals structure.   GETGLOBALS();   // Allocate a FILE_NODE large enough to hold this file.   int length = strlen(szPath) + strlen(szMethod);   g_pFileLast = (FILE_NODE*)new BYTE[sizeof(FILE_NODE) + (sizeof(CHAR) * length)];   // Bail out if we failed to allocate the node.   if (!g_pFileLast) {#ifdef UNICODE      DebugOut(TEXT("Failed to create a FILE_NODE for \"%S\"."), szPath);#else      DebugOut(TEXT("Failed to create a FILE_NODE for \"%s\"."), szPath);#endif      g_fOutOfMemory = TRUE;      return;   }   // Fill in our node.   g_pFileLast->dwSize           = dwSize;

⌨️ 快捷键说明

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