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

📄 intrface.cpp

📁 完整的解压zip文件的源码。包含密码功能
💻 CPP
📖 第 1 页 / 共 4 页
字号:
   // 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;      }   }   // Store the directory for when we do an extract.   wcstombs(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//******************************************************************************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;   }   // Store a global pointer to our USERFUNCTIONS structure so that LIST.C,   // PROCESS.C, and WINMAIN can access it.   pG->lpUserFunctions = &g_uf;   // Clear our USERFUNCTIONS structure and assign our SendAppMsg() function.   ZeroMemory(&g_uf, sizeof(g_uf));   g_uf.SendApplicationMessage = SendAppMsg;   // Fill in all our callback functions.   pG->message     = UzpMessagePrnt2;   pG->input       = UzpInput2;   pG->mpause      = UzpMorePause;   pG->lpUserFunctions->replace     = UzpReplace;   pG->lpUserFunctions->sound       = UzpSound;#if CRYPT   pG->decr_passwd = UzpPassword;#endif   // Match filenames case-sensitively.  We can do this since we can guarentee   // 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;}//******************************************************************************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()}//******************************************************************************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);}//******************************************************************************BOOL SmartCreateDirectory(Uz_Globs *pG, LPCSTR szDirectory) {   // Copy path to a UNICODE buffer.   TCHAR szBuffer[_MAX_PATH];   mbstowcs(szBuffer, szDirectory, countof(szBuffer));   int x = IsFileOrDirectory(szBuffer);   // Create the directory if it does not exist.   if (x == 0) {      if (!CreateDirectory(szBuffer, NULL)) {         Info(slide, 1, ((char *)slide, "error creating directory: %s\n", szDirectory));         return FALSE;      }   // If there is a file with the same name, then display an error.   } else if (x == 1) {      Info(slide, 1, ((char *)slide,           "cannot create %s as a file with same name already exists.\n",           szDirectory));      return FALSE;   }   // If the directory already exists or was created, then return success.   return TRUE;}//******************************************************************************#ifdef _WIN32_WCE// On WinCE, we declare our thread function the way CreateThread() likes it.DWORD WINAPI ExtractOrTestFilesThread(LPVOID lpv) {#else// On WinNT, we declare our thread function the way _beginthreadex likes it.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->prompt_always = TRUE;            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;}//******************************************************************************void CheckForAbort(Uz_Globs *pG) {   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)pG->outfile != 0) && ((int)pG->outfile != -1)) {         if (g_pExtractInfo->fExtract && *pG->filename) {            // 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)pG->filename);            SendMessage(g_hWndMain, WM_PRIVATE, MSG_ADD_TEXT_TO_EDIT,                        (LPARAM)" is probably truncated.\n");         }         // Close the file.         close_outfile(pG);      }      // Display an aborted message in the log      SendMessage(g_hWndMain, WM_PRIVATE, MSG_ADD_TEXT_TO_EDIT,                  (LPARAM)"Operation aborted by user.\n");

⌨️ 快捷键说明

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