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

📄 intrface.cpp

📁 zip压缩
💻 CPP
📖 第 1 页 / 共 4 页
字号:
         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 and then retrieve the real file name.   GETGLOBALS();   szPath = pG->filename;   // 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(TCHAR) * 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;   g_pFileLast->dwCompressedSize = dwCompressedSize;   g_pFileLast->dwCRC            = dwCRC;   g_pFileLast->szComment        = NULL;   g_pFileLast->szType           = NULL;   // Fix the year value to contain the real year.   year += 1900;   // Year:   0 - 4095 (12) 1111 1111 1111 0000 0000 0000 0000 0000 (0xFFF00000)   // Month:  1 -   12 ( 4) 0000 0000 0000 1111 0000 0000 0000 0000 (0x000F0000)   // Day:    1 -   31 ( 5) 0000 0000 0000 0000 1111 1000 0000 0000 (0x0000F800)   // Hour:   0 -   23 ( 5) 0000 0000 0000 0000 0000 0111 1100 0000 (0x000007C0)   // Minute: 0 -   59 ( 6) 0000 0000 0000 0000 0000 0000 0011 1111 (0x0000003F)   // Do some bit shifting to make the date and time fit in a DWORD.   g_pFileLast->dwModified = (((DWORD)(year   & 0x0FFF) << 20) |                              ((DWORD)(month  & 0x000F) << 16) |                              ((DWORD)(day    & 0x001F) << 11) |                              ((DWORD)(hour   & 0x001F) <<  6) |                              ((DWORD)(minute & 0x003F)));   // We need to get our globals structure to determine our attributes and   // encryption information.   g_pFileLast->dwAttributes = (pG->crec.external_file_attributes & 0xFF);   if (chCrypt == 'E') {      g_pFileLast->dwAttributes |= ZFILE_ATTRIBUTE_ENCRYPTED;   }   // Store the path and method in our string buffer.   strcpy(g_pFileLast->szPathAndMethod, szPath);   strcpy(g_pFileLast->szPathAndMethod + strlen(szPath) + 1, szMethod);   // Pass the file object to our windows code to have it added to our list.   AddFileToListView(g_pFileLast);}//******************************************************************************int win_fprintf(zvoid *pG, FILE *file, unsigned int dwCount, char far *buffer){   // win_fprintf() is used within Info-ZIP to write to a file as well as log   // information.  If the "file" is a real file handle (not stdout or stderr),   // then we write the data to the file and return.   if ((file != stdout) && (file != stderr)) {      DWORD dwBytesWriten = 0;#ifdef _WIN32_WCE      // On WinCE all FILEs are really HANDLEs.  See WINCE.CPP for more info.      WriteFile((HANDLE)file, buffer, dwCount, &dwBytesWriten, NULL);#else      dwBytesWriten = fwrite(buffer, 1, dwCount, file);#endif      // Update our bytes written count.      g_pExtractInfo->dwBytesWrittenThisFile += dwBytesWriten;      // Pass control to our GUI thread to do a partial update our progress dialog.      SendMessage(g_hWndMain, WM_PRIVATE, MSG_UPDATE_PROGRESS_PARTIAL,                  (LPARAM)g_pExtractInfo);      return dwBytesWriten;   }   // Check to see if we are expecting a extraction progress string   if (g_pExtractInfo) {      // Most of our progress strings come to our UzpMessagePrnt2() callback,      // but we occasionally get one here.  We will just forward it to      // UzpMessagePrnt2() as if it never came here.      UzpMessagePrnt2(pG, (uch*)buffer, dwCount, 0);      return dwCount;   }   // Check to see if we are expecting a zip file comment string.   if (g_hWndEdit) {      // Change all forward slashes to back slashes in the buffer      ForwardSlashesToBackSlashesA((LPSTR)buffer);      SendMessage(g_hWndMain, WM_PRIVATE, MSG_ADD_TEXT_TO_EDIT, (LPARAM)buffer);      return dwCount;   }   // Check to see if we are expecting a compressed file comment string.   if (g_pFileLast) {      // Calcalute the size of the buffer we will need to store this comment.      // We are going to convert all ASC values 0 - 31 (except tab, new line,      // and CR) to ^char.      int size = 1;      for (char *p2, *p1 = buffer; *p1; INCSTR(p1)) {         size += ((*p1 >= 32) || (*p1 == '\t') ||                  (*p1 == '\r') || (*p1 == '\n')) ? CLEN(p1) : 2;      }      // Allocate a comment buffer and assign it to the last file node we saw.      if (g_pFileLast->szComment = new CHAR[size]) {         // Copy while formatting.         for (p1 = buffer, p2 = (char*)g_pFileLast->szComment; *p1; INCSTR(p1)) {            if ((*p1 >= 32) || (*p1 == '\t') ||                (*p1 == '\r') || (*p1 == '\n')) {               memcpy(p2, p1, CLEN(p1));               p2 += CLEN(p1);            } else {               *(p2++) = '^';               *(p2++) = 64 + *p1;            }         }         *p2 = '\0';      }      // Update the attributes of the file node to include the comment attribute.      g_pFileLast->dwAttributes |= ZFILE_ATTRIBUTE_COMMENT;      // Clear the file node so we don't try to add another bogus comment to it.      g_pFileLast = NULL;      return dwCount;   }   if (dwCount >= _MAX_PATH) {      buffer[_MAX_PATH] = '\0';   }#ifdef UNICODE   DebugOut(TEXT("Unhandled call to win_fprintf(\"%S\")"), buffer);#else   DebugOut(TEXT("Unhandled call to win_fprintf(\"%S\")"), buffer);#endif   return dwCount;}//******************************************************************************void WINAPI Wiz_NoPrinting(int f) {   // Do nothing.}//******************************************************************************//***** Functions that Info-ZIP expects the port to write and export.//***** Some of this code was stolen from the WIN32 port and highly modified.//******************************************************************************int mapattr(Uz_Globs *pG) {   // Check to see if we are extracting this file for viewing.  Currently, we do   // this by checking the szMappedPath member of our extract info stucture   // since we know OnActionView() is the only one who sets this member.   if (g_pExtractInfo && g_pExtractInfo->szMappedPath) {      // If we are extracting for view only, then we ignore the file's real      // attributes and force the file to create as read-only.  We make the file      // read-only to help prevent the user from making changes to the temporary      // file and then trying to save the changes back to a file that we will      // eventually delete.      pG->pInfo->file_attr = FILE_ATTRIBUTE_READONLY;   } else {      // Store the attribute exactly as it appears for normal extraction/test.      pG->pInfo->file_attr = (unsigned)pG->crec.external_file_attributes & 0xff;   }   return PK_OK;}//******************************************************************************void utimeToFileTime(time_t ut, FILETIME *pft, BOOL fOldFileSystem) {   // time_t    is a 32-bit value for the seconds since January 1, 1970   // FILETIME  is a 64-bit value for the number of 100-nanosecond intervals since   //           January 1, 1601   // DWORDLONG is a 64-bit int that we can use to perform large math operations.   // time_t has minimum of 1/1/1970.  Many file systems, such as FAT, have a   // minimum date of 1/1/1980.  If extracting to one of those file systems and   // out time_t is less than 1980, then we make it 1/1/1980.   // (365 days/yr * 10 yrs + 3 leap yr days) * (60 secs * 60 mins * 24 hrs).   if (fOldFileSystem && (ut < 0x12CFF780)) {      ut = 0x12CFF780;   }   // Compute the FILETIME for the given time_t.   DWORDLONG dwl = ((DWORDLONG)116444736000000000 +                   ((DWORDLONG)ut * (DWORDLONG)10000000));   // Store the return value.   *pft = *(FILETIME*)&dwl;   // Now for the next fix for old file systems.  If we are in Daylight Savings   // Time (DST) and the file is not in DST, then we need subtract off the DST   // bias from the filetime.  This is due to a bug in Windows (NT, CE, and 95)   // that causes the DST bias to be added to all file times when the system   // is in DST, even if the file is not in DST.  This only effects old file   // systems since they store local times instead of UTC times.  Newer file   // systems like NTFS and CEFS store UTC times.   if (fOldFileSystem) {      // We use the CRT's localtime() and Win32's FileTimeToLocalTime()      // functions to compute the DST bias.  This works because localtime()      // correctly adds the DST bias only if the file time is in DST.      // FileTimeToLocalTime() always adds the DST bias to the time.      // Therefore, if the functions return different results, we know we      // are dealing with a non-DST file during a system DST.      FILETIME ftCRT, ftWin32;      // Get the CRT result - result is a "tm" struct.      struct tm *ptmCRT = localtime(&ut);      // Convert the "tm" struct to a FILETIME.      SYSTEMTIME stCRT;      ZeroMemory(&stCRT, sizeof(stCRT));      stCRT.wYear   = ptmCRT->tm_year + 1900;      stCRT.wMonth  = ptmCRT->tm_mon + 1;      stCRT.wDay    = ptmCRT->tm_mday;      stCRT.wHour   = ptmCRT->tm_hour;      stCRT.wMinute = ptmCRT->tm_min;      stCRT.wSecond = ptmCRT->tm_sec;      SystemTimeToFileTime(&stCRT, &ftCRT);      // Get the Win32 result - result is a FILETIME.      if (FileTimeToLocalFileTime(pft, &ftWin32)) {         // Subtract the difference from our current filetime.         *(DWORDLONG*)pft -= *(DWORDLONG*)&ftWin32 - *(DWORDLONG*)&ftCRT;      }   }}//******************************************************************************int GetFileTimes(Uz_Globs *pG, FILETIME *pftCreated, FILETIME *pftAccessed,                 FILETIME *pftModified){   // We need to check to see if this file system is limited.  This includes   // FAT, VFAT, and HPFS.  It does not include NTFS and CEFS.  The limited   // file systems can not support dates < 1980 and they store file local times   // for files as opposed to UTC times.   BOOL fOldFileSystem = IsOldFileSystem(pG->filename);#ifdef USE_EF_UT_TIME  // Always true for WinCE build#ifdef IZ_CHECK_TZ   if (pG->extra_field && pG->tz_is_valid) {#else   if (pG->extra_field) {#endif      // Structure for Unix style actime, modtime, creatime      iztimes z_utime;      // Get any date/time we can.  This can return 0 to 3 unix time fields.      unsigned eb_izux_flg = ef_scan_for_izux(pG->extra_field,                                              pG->lrec.extra_field_length, 0,                                              pG->lrec.last_mod_dos_datetime,                                              &z_utime, NULL);      // We require at least a modified time.      if (eb_izux_flg & EB_UT_FL_MTIME) {         // We know we have a modified time, so get it first.         utimeToFileTime(z_utime.mtime, pftModified, fOldFileSystem);         // Get the accessed time if we have one.         if (eb_izux_flg & EB_UT_FL_ATIME) {            utimeToFileTime(z_utime.atime, pftAccessed, fOldFileSystem);         }         // Get the created time if we have one.         if (eb_izux_flg & EB_UT_FL_CTIME) {            utimeToFileTime(z_utime.ctime, pftCreated, fOldFileSystem);         }         // Return our flags.         return (int)eb_izux_flg;      }   }#endif // USE_EF_UT_TIME   // If all else fails, we can resort to using the DOS date and time data.   time_t ux_modtime = dos_to_unix_time(G.lrec.last_mod_dos_datetime);   utimeToFileTime(ux_modtime, pftModified, fOldFileSystem);   *pftAccessed = *pftModified;   return (EB_UT_FL_MTIME | EB_UT_FL_ATIME);}//******************************************************************************int SetFileSize(FILE *file, ulg filesize){#if (defined(_WIN32_WCE) || defined(__RSXNT__))    // For native Windows CE, it is not known whether the API supports    // presetting a file's size.    // RSXNT environment lacks a translation function from C file pointer    // to Win32-API file handle.    // So, simply do nothing.    return 0;#else /* !(_WIN32_WCE || __RSXNT__) */    /* not yet verified, if that really creates an unfragmented file      rommel@ars.de     */    HANDLE os_fh;    /* Win9x supports FAT file system, only; presetting file size does       not help to prevent fragmentation. */    if ((long)GetVersion() < 0) return 0;    /* Win32-API calls require access to the Win32 file handle.       The interface function used to retrieve the Win32 handle for       a file opened by the C rtl is non-standard and may not be       available for every Win32 compiler environment.       (see also win32/win32.c of the Zip distribution)     */    os_fh = (HANDLE)_get_osfhandle(fileno(file));    /* move file pointer behind the last byte of the expected file size */    if (SetFilePointer(os_fh, filesize, 0, FILE_BEGIN) == 0xFFFFFFFF)        return -1;    /* extend/truncate file to the current position */    if (SetEndOfFile(os_fh) == 0)        return -1;    /* move file position pointer back to the start of the file! */    return (SetFilePointer(os_fh, 0, 0, FILE_BEGIN) == 0xFFFFFFFF) ? -1 : 0;#endif /* ?(_WIN32_WCE || __RSXNT__) */} /* end function SetFileSize() *///******************************************************************************void close_outfile(Uz_Globs *pG) {   // Get the 3 time stamps for the file.   FILETIME ftCreated, ftAccessed, ftModified;   int timeFlags = GetFileTimes(pG, &ftCreated, &ftAccessed, &ftModified);   TCHAR szFile[_MAX_PATH];   MBSTOTSTR(szFile, pG->filename, countof(szFile));#ifdef _WIN32_WCE   // Cast the outfile to a HANDLE (since that is really what it is), and

⌨️ 快捷键说明

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