?? wince.cpp
字號:
/* Copyright (c) 1990-2001 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: WINCE.CPP//// Description: This file implements all the Win32 APIs and C runtime functions// that the Info-ZIP code calls, but are not implemented natively// on Windows CE.//// Copyright: All the source files for Pocket UnZip, except for components// written by the Info-ZIP group, are copyrighted 1997 by Steve P.// Miller. The product "Pocket UnZip" itself is property of the// author and cannot be altered in any way without written consent// from Steve P. Miller.//// 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.//// Functions: DebugOut// chmod// close// isatty// lseek// open// read// setmode// unlink// fflush// fgets// fileno// fopen// fprintf// fclose// putc// sprintf// _stricmp// _strupr// strrchr (non-_MBCS only)// localtime// isupper// stat// localtime// SafeGetTimeZoneInformation// GetTransitionTimeT// IsDST////// Date Name History// -------- ------------ -----------------------------------------------------// 02/01/97 Steve Miller Created (Version 1.0 using Info-ZIP UnZip 5.30)////******************************************************************************extern "C" {#include "punzip.h"}#include <tchar.h> // Must be outside of extern "C" block//******************************************************************************//***** For all platforms - Our debug output function//******************************************************************************#ifdef DEBUG // RETAIL version is __inline and does not generate any code.void DebugOut(LPCTSTR szFormat, ...) { TCHAR szBuffer[512] = TEXT("PUNZIP: "); va_list pArgs; va_start(pArgs, szFormat); _vsntprintf(szBuffer + 8, countof(szBuffer) - 10, szFormat, pArgs); va_end(pArgs); TCHAR *psz = szBuffer; while (psz = _tcschr(psz, TEXT('\n'))) { *psz = TEXT('|'); } psz = szBuffer; while (psz = _tcschr(psz, TEXT('\r'))) { *psz = TEXT('|'); } _tcscat(szBuffer, TEXT("\r\n")); OutputDebugString(szBuffer);}#endif // DEBUG//******************************************************************************//***** Windows CE Native//******************************************************************************#if defined(_WIN32_WCE)//******************************************************************************//***** Local Function Prototyopes//******************************************************************************void SafeGetTimeZoneInformation(TIME_ZONE_INFORMATION *ptzi);time_t GetTransitionTimeT(TIME_ZONE_INFORMATION *ptzi, int year, BOOL fStartDST);BOOL IsDST(TIME_ZONE_INFORMATION *ptzi, time_t localTime);//******************************************************************************//***** IO.H functions//******************************************************************************//-- Called from fileio.cint __cdecl chmod(const char *filename, int pmode) { // Called before unlink() to delete read-only files. DWORD dwAttribs = (pmode & _S_IWRITE) ? FILE_ATTRIBUTE_NORMAL : FILE_ATTRIBUTE_READONLY; TCHAR szPath[_MAX_PATH]; MBSTOTSTR(szPath, filename, countof(szPath)); return (SetFileAttributes(szPath, dwAttribs) ? 0 : -1);}//******************************************************************************//-- Called from process.cint __cdecl close(int handle) { return (CloseHandle((HANDLE)handle) ? 0 : -1);}//******************************************************************************//-- Called from fileio.cint __cdecl isatty(int handle) { // returns TRUE if handle is a terminal, console, printer, or serial port // called with 1 (stdout) and 2 (stderr) return 0;}//******************************************************************************//-- Called from extract.c, fileio.c, process.clong __cdecl lseek(int handle, long offset, int origin) { // SEEK_SET, SEEK_CUR, SEEK_END are equal to FILE_BEGIN, FILE_CURRENT, FILE_END return SetFilePointer((HANDLE)handle, offset, NULL, origin);}//******************************************************************************//-- Called from fileio.cint __cdecl open(const char *filename, int oflag, ...) { // The Info-Zip code currently only opens existing ZIP files for read using open(). TCHAR szPath[_MAX_PATH]; MBSTOTSTR(szPath, filename, countof(szPath)); HANDLE hFile = CreateFile(szPath, GENERIC_READ, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); return ((hFile == INVALID_HANDLE_VALUE) ? -1 : (int)hFile);}//******************************************************************************//-- Called from extract.c, fileio.c, process.cint __cdecl read(int handle, void *buffer, unsigned int count) { DWORD dwRead = 0; return (ReadFile((HANDLE)handle, buffer, count, &dwRead, NULL) ? dwRead : -1);}//******************************************************************************//-- Called from extract.cint __cdecl setmode(int handle, int mode) { //TEXT/BINARY translation - currently always called with O_BINARY. return O_BINARY;}//******************************************************************************//-- Called from fileio.cint __cdecl unlink(const char *filename) { // Called to delete files before an extract overwrite. TCHAR szPath[_MAX_PATH]; MBSTOTSTR(szPath, filename, countof(szPath)); return (DeleteFile(szPath) ? 0: -1);}//******************************************************************************//***** STDIO.H functions//******************************************************************************//-- Called from fileio.cint __cdecl fflush(FILE *stream) { return (FlushFileBuffers((HANDLE)stream) ? 0 : EOF);}//******************************************************************************//-- Called from extract.cchar * __cdecl fgets(char *string, int n, FILE *stream) { // stream always equals "stdin" and fgets() should never be called. DebugOut(TEXT("WARNING: fgets(0x%08X, %d, %08X) called."), string, n, stream); return NULL;}//******************************************************************************//-- Called from extract.cint __cdecl fileno(FILE *stream) { return (int)stream;}//******************************************************************************//-- Called from fileio.cFILE * __cdecl fopen(const char *filename, const char *mode) { // fopen() is used to create all extracted files. DWORD dwAccess = 0; DWORD dwCreate = 0; BOOL fAppend = FALSE; if (strstr(mode, "r+")) { dwAccess = GENERIC_READ | GENERIC_WRITE; dwCreate = OPEN_EXISTING; } else if (strstr(mode, "w+")) { dwAccess = GENERIC_READ | GENERIC_WRITE; dwCreate = CREATE_ALWAYS; } else if (strstr(mode, "a+")) { dwAccess = GENERIC_READ | GENERIC_WRITE; dwCreate = OPEN_ALWAYS; fAppend = TRUE; } else if (strstr(mode, "r")) { dwAccess = GENERIC_READ; dwCreate = OPEN_EXISTING; } else if (strstr(mode, "w")) { dwAccess = GENERIC_WRITE; dwCreate = CREATE_ALWAYS; } else if (strstr(mode, "a")) { dwAccess = GENERIC_WRITE; dwCreate = OPEN_ALWAYS; fAppend = TRUE; } TCHAR szPath[_MAX_PATH]; MBSTOTSTR(szPath, filename, countof(szPath)); HANDLE hFile = CreateFile(szPath, dwAccess, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, dwCreate, FILE_ATTRIBUTE_NORMAL, NULL); if (hFile == INVALID_HANDLE_VALUE) { return NULL; } if (fAppend) { SetFilePointer(hFile, 0, NULL, FILE_END); } return (FILE*)hFile;}//******************************************************************************//-- Called from unshrink.cint __cdecl fprintf(FILE *stream, const char *format, ...) { // All standard output/error in Info-ZIP is handled through fprintf() if ((stream == stdout) || (stream == stderr)) { return 1; } // "stream" always equals "stderr" or "stdout" - log error if we see otherwise.#ifdef UNICODE DebugOut(TEXT("WARNING: fprintf(0x%08X, \"%S\", ...) called."), stream, format);#else DebugOut(TEXT("WARNING: fprintf(0x%08X, \"%s\", ...) called."), stream, format);#endif return 0;}//******************************************************************************//-- Called from fileio.cint __cdecl fclose(FILE *stream) { return (CloseHandle((HANDLE)stream) ? 0 : EOF);}//******************************************************************************//-- Called from fileio.cint __cdecl putc(int c, FILE *stream) { DebugOut(TEXT("WARNING: putc(%d, 0x%08X) called."), c, stream); return 0;}//******************************************************************************//-- Called from intrface.cpp, extract.c, fileio.c, list.c, process.cint __cdecl sprintf(char *buffer, const char *format, ...) { WCHAR wszBuffer[512], wszFormat[512]; MBSTOTSTR(wszFormat, format, countof(wszFormat)); BOOL fPercent = FALSE; for (WCHAR *pwsz = wszFormat; *pwsz; pwsz++) { if (*pwsz == L'%') { fPercent = !fPercent; } else if (fPercent && (((*pwsz >= L'a') && (*pwsz <= L'z')) || ((*pwsz >= L'A') && (*pwsz <= L'Z')))) { if (*pwsz == L's') { *pwsz = L'S'; } else if (*pwsz == L'S') { *pwsz = L's'; } fPercent = FALSE; } } va_list pArgs; va_start(pArgs, format); _vsntprintf(wszBuffer, countof(wszBuffer), wszFormat, pArgs); va_end(pArgs); TSTRTOMBS(buffer, wszBuffer, countof(wszBuffer)); return 0;}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -