?? intrface.cpp
字號:
// flush the file. We need to flush, because any unsaved data that is // written to the file during CloseHandle() will step on the work done // by SetFileTime(). HANDLE hFile = (HANDLE)pG->outfile; FlushFileBuffers(hFile);#else // Close the file and then re-open it using the Win32 CreateFile() call. // SetFileTime() requires a Win32 file HANDLE created with GENERIC_WRITE // access. fclose(pG->outfile); HANDLE hFile = CreateFile(szFile, GENERIC_WRITE, FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);#endif // Set the file's date and time. if (hFile != INVALID_HANDLE_VALUE) { // Make sure we retrieved some valid time stamp(s) if (timeFlags) { // Set the various date and time fields. if (!SetFileTime(hFile, (timeFlags & EB_UT_FL_CTIME) ? &ftCreated : NULL, (timeFlags & EB_UT_FL_ATIME) ? &ftAccessed : NULL, (timeFlags & EB_UT_FL_MTIME) ? &ftModified : NULL)) { DebugOut(TEXT("SetFileTime() failed [%u]"), GetLastError()); } } else { DebugOut(TEXT("GetFileTimes() failed")); } // Close out file. CloseHandle(hFile); } else { DebugOut(TEXT("CreateFile() failed [%u]"), GetLastError()); } // If the file was successfully written, then set the attributes. if (!pG->disk_full && !g_pExtractInfo->fAbort) { if (!SetFileAttributes(szFile, G.pInfo->file_attr & 0x7F)) { DebugOut(TEXT("SetFileAttributes() failed [%u]"), GetLastError()); } } // Clear outfile so we know it is closed. pG->outfile = 0; return;}//******************************************************************************// Called by PROCESS.Cchar* do_wild(Uz_Globs *pG, ZCONST char *wildspec) { // This is a very slimmed down version of do_wild() taken from WIN32.C. // Since we don't support wildcards, we basically just return the wildspec // passed in as the filename. // First call - must initialize everything. if (!pG->notfirstcall) { pG->notfirstcall = TRUE; return strcpy(pG->matchname, wildspec); } // Last time through - reset for new wildspec. pG->notfirstcall = FALSE; return (char*)NULL;}//******************************************************************************// Called from EXTRACT.C//// returns:// MPN_OK - no problem detected// MPN_INF_TRUNC - (on APPEND_NAME) truncated filename// MPN_INF_SKIP - path doesn't exist, not allowed to create// MPN_ERR_SKIP - path doesn't exist, tried to create and failed; or path// exists and is not a directory, but is supposed to be// MPN_ERR_TOOLONG - path is too long// MPN_NOMEM - can't allocate memory for filename buffers//// MPN_VOL_LABEL - Path was a volume label, skip it.// MPN_CREATED_DIR - Created a directory.//int mapname(Uz_Globs *pG, int renamed) { int error = MPN_OK; // mapname() is a great place to reset all our status counters for the next // file to be processed since it is called for every zip file member before // any work is done with that member. SetCurrentFile(pG); // If Volume Label, skip the "extraction" quietly if (pG->pInfo->vollabel) { return MPN_VOL_LABEL; } CHAR szBuffer[countof(pG->filename)] = "", *pIn, *pOut, *pLastSemi = NULL; CHAR *pPathComp; int killed_ddot = FALSE; // Initialize file path buffer with our "extract to" path. strcpy(szBuffer, g_szExtractToDirectory); pOut = szBuffer + strlen(szBuffer); pPathComp = pOut; // Point pIn to beginning of our internal pathname. // If we are junking paths, then locate the file portion of the path. pIn = (pG->UzO.jflag) ? (CHAR*)GetFileFromPath(pG->filename) : pG->filename; // Begin main loop through characters in filename. for ( ; *pIn; INCSTR(pIn)) { // Make sure we don't overflow our output buffer. if (pOut >= (szBuffer + countof(szBuffer) - 2)) { Info(slide, 1, ((char*)slide, "path too long: %s\n", FnFilter1(pG->filename))); return MPN_ERR_TOOLONG; } // Examine the next character in our input buffer. switch (*pIn) { // Check for a directory wack. case '/': case '\\': *pOut = '\0'; if (!SmartCreateDirectory(pG, szBuffer)) { Info(slide, 1, ((char*)slide, "failure extracting: %s\n", FnFilter1(pG->filename))); return MPN_ERR_SKIP; } *(pOut++) = '\\'; pPathComp = pOut; // Remember start pos of new path component pLastSemi = NULL; // Leave any directory semi-colons alone break; // Check for dir traversals and skip them unless explicitely allowed. case '.': if (pOut == pPathComp) { // nothing appended yet... if (pIn[1] == '/') { // don't bother appending "./" to ++pIn; // the path: skip behind the '/' break; } else if (!uO.ddotflag && pIn[1] == '.' && pIn[2] == '/') { /* "../" dir traversal detected */ pIn += 2; // skip over behind the '/' killed_ddot = TRUE; // set "show message" flag break; } } *(pOut++) = '.'; break; // Check for illegal characters and replace with underscore. case ':': case '*': case '?': case '"': case '<': case '>': case '|': *(pOut++) = '_'; break; // Check for start of VMS version. case ';': pLastSemi = pOut; // Make note as to where we are. *(pOut++) = *pIn; // Leave the semi-colon alone for now. break; default: // Allow European characters and spaces in filenames.#ifdef _MBCS if ((UCHAR)*pIn >= 0x20) { memcpy(pOut, pIn, CLEN(pIn)); INCSTR(pOut); } else { *(pOut++) = '_'; }#else *(pOut++) = (((UCHAR)*pIn >= 0x20) ? *pIn : '_');#endif } } // Done with output buffer, terminate it. *pOut = '\0'; // Remove any VMS version numbers if found (appended ";###"). if (pLastSemi) { // Walk over all digits following the semi-colon. for (pOut = pLastSemi + 1; (*pOut >= '0') && (*pOut <= '9'); pOut++) { } // If we reached the end, then nuke the semi-colon and digits. if (!*pOut) { *pLastSemi = '\0'; } } // Show warning when stripping insecure "parent dir" path components if (killed_ddot && QCOND2) { Info(slide, 0, ((char *)slide, "warning: skipped \"../\" path component(s) in %s\n", FnFilter1(G.filename))); if (!(error & ~MPN_MASK)) error = (error & MPN_MASK) | PK_WARN; } // Copy the mapped name back to the internal path buffer strcpy(pG->filename, szBuffer); // Fill in the mapped name buffer if the original caller requested us to. if (g_pExtractInfo->szMappedPath) { strcpy(g_pExtractInfo->szMappedPath, szBuffer); } // If it is a directory, then display the "creating" status text. if ((pOut > szBuffer) && (lastchar(szBuffer, pOut-szBuffer) == '\\')) { Info(slide, 0, ((char *)slide, "creating: %s\n", FnFilter1(pG->filename))); return (error & ~MPN_MASK) | MPN_CREATED_DIR; } return error;}//******************************************************************************// Called from EXTRACT.Cint test_NT(Uz_Globs *pG, uch *eb, unsigned eb_size) { // This function is called when an NT security descriptor is found in the // extra field. We have nothing to do, so we just return success. return PK_OK;}//******************************************************************************// Called from PROCESS.Cint checkdir(Uz_Globs *pG, char *pathcomp, int flag) { // This function is only called by free_G_buffers() from PROCESS.C with the // flag set to END. We have nothing to do, so we just return success. return MPN_OK;}//******************************************************************************// Called from EXTRACT.C and LIST.Cint match(ZCONST char *string, ZCONST char *pattern, int ignore_case) { // match() for the other ports compares a file in the Zip file with some // command line file pattern. In our case, we always pass in exact matches, // so we can simply do a string compare to see if we have a match. return (strcmp(string, pattern) == 0);}//******************************************************************************// Called from PROCESS.Cint iswild(ZCONST char *pattern) { // Our file patterns never contain wild characters. They are always exact // matches of file names in our Zip file. return FALSE;}//******************************************************************************//***** Functions to correct time stamp bugs on old file systems.//******************************************************************************//******************************************************************************// Borrowed/Modified from win32.cBOOL IsOldFileSystem(char *szPath) {#ifdef _WIN32_WCE char szRoot[10]; // Get the first nine characters of the path. strncpy(szRoot, szPath, 9); szRoot[9] = '\0'; // Convert to uppercase to help with compare. _strupr(szRoot); // PC Cards are mounted off the root in a directory called "\PC Cards". // PC Cards are FAT, no CEOS. We need to check if the file is being // extracted to the PC card. return !strcmp(szRoot, "\\PC CARD\\");#else char szRoot[_MAX_PATH] = "\0\0\0", szFS[64]; // Check to see if our path contains a drive letter. if (isalpha(szPath[0]) && (szPath[1] == ':') && (szPath[2] == '\\')) { // If so, then just copy the drive letter, colon, and wack to our root path. strncpy(szRoot, szPath, 3); } else { // Expand the path so we can get a drive letter. GetFullPathNameA(szPath, sizeof(szRoot), szRoot, NULL); // Make sure we actually got a drive letter back in our root path buffer.. if (!isalpha(szRoot[0]) || (szRoot[1] != ':') || (szRoot[2] != '\\')) { // When in doubt, return TRUE. return TRUE; } } // NULL terminate after the wack to ensure we have just the root path. szRoot[3] = '\0'; // Get the file system type string. GetVolumeInformationA(szRoot, NULL, 0, NULL, NULL, NULL, szFS, sizeof(szFS)); // Ensure that the file system type string is uppercase. _strupr(szFS); // Return true for (V)FAT and (OS/2) HPFS format. return !strncmp(szFS, "FAT", 3) || !strncmp(szFS, "VFAT", 4) || !strncmp(szFS, "HPFS", 4);#endif // _WIN32_WCE}//******************************************************************************//***** Functions to supply timezone information from the Windows registry to//***** Info-ZIP's private RTL "localtime() et al." replacements in timezone.c.//******************************************************************************//******************************************************************************// Copied from win32.c#ifdef W32_USE_IZ_TIMEZONE#include "timezone.h"#define SECSPERMIN 60#define MINSPERHOUR 60#define SECSPERHOUR (SECSPERMIN * MINSPERHOUR)static void conv_to_rule(LPSYSTEMTIME lpw32tm, struct rule * ZCONST ptrule);static void conv_to_rule(LPSYSTEMTIME lpw32tm, struct rule * ZCONST ptrule){ if (lpw32tm->wYear != 0) { ptrule->r_type = JULIAN_DAY; ptrule->r_day = ydays[lpw32tm->wMonth - 1] + lpw32tm->wDay; } else { ptrule->r_type = MONTH_NTH_DAY_OF_WEEK; ptrule->r_mon = lpw32tm->wMonth; ptrule->r_day = lpw32tm->wDayOfWeek; ptrule->r_week = lpw32tm->wDay; } ptrule->r_time = (long)lpw32tm->wHour * SECSPERHOUR + (long)(lpw32tm->wMinute * SECSPERMIN) + (long)lpw32tm->wSecond;}int GetPlatformLocalTimezone(register struct state * ZCONST sp, void (*fill_tzstate_from_rules)(struct state * ZCONST sp_res, ZCONST struct rule * ZCONST start, ZCONST struct rule * ZCONST end)){ TIME_ZONE_INFORMATION tzinfo; DWORD res; /* read current timezone settings from registry if TZ envvar missing */ res = GetTimeZoneInformation(&tzinfo); if (res != TIME_ZONE_ID_INVALID) { struct rule startrule, stoprule; conv_to_rule(&(tzinfo.StandardDate), &stoprule); conv_to_rule(&(tzinfo.DaylightDate), &startrule); sp->timecnt = 0; sp->ttis[0].tt_abbrind = 0; if ((sp->charcnt = WideCharToMultiByte(CP_ACP, 0, tzinfo.StandardName, -1, sp->chars, sizeof(sp->chars), NULL, NULL)) == 0) sp->chars[sp->charcnt++] = '\0'; sp->ttis[1].tt_abbrind = sp->charcnt; sp->charcnt += WideCharToMultiByte(CP_ACP, 0, tzinfo.DaylightName, -1, sp->chars + sp->charcnt, sizeof(sp->chars) - sp->charcnt, NULL, NULL); if ((sp->charcnt - sp->ttis[1].tt_abbrind) == 0) sp->chars[sp->charcnt++] = '\0'; sp->ttis[0].tt_gmtoff = - (tzinfo.Bias + tzinfo.StandardBias) * MINSPERHOUR; sp->ttis[1].tt_gmtoff = - (tzinfo.Bias + tzinfo.DaylightBias) * MINSPERHOUR; sp->ttis[0].tt_isdst = 0; sp->ttis[1].tt_isdst = 1; sp->typecnt = (startrule.r_mon == 0 && stoprule.r_mon == 0) ? 1 : 2; if (sp->typecnt > 1) (*fill_tzstate_from_rules)(sp, &startrule, &stoprule); return TRUE; } return FALSE;}#endif /* W32_USE_IZ_TIMEZONE */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -