diff options
Diffstat (limited to '3rdparty/lzma/C/Util/SfxSetup/SfxSetup.c')
-rw-r--r-- | 3rdparty/lzma/C/Util/SfxSetup/SfxSetup.c | 109 |
1 files changed, 73 insertions, 36 deletions
diff --git a/3rdparty/lzma/C/Util/SfxSetup/SfxSetup.c b/3rdparty/lzma/C/Util/SfxSetup/SfxSetup.c index c3c56b1e7f2..0e5152e5907 100644 --- a/3rdparty/lzma/C/Util/SfxSetup/SfxSetup.c +++ b/3rdparty/lzma/C/Util/SfxSetup/SfxSetup.c @@ -1,5 +1,7 @@ /* SfxSetup.c - 7z SFX Setup -2010-12-13 : Igor Pavlov : Public domain */ +2015-11-08 : Igor Pavlov : Public domain */ + +#include "Precomp.h" #ifndef UNICODE #define UNICODE @@ -19,28 +21,28 @@ #include "../../7zFile.h" #include "../../CpuArch.h" -#define k_EXE_ExtIndex 1 +#define k_EXE_ExtIndex 2 -static const char *kExts[] = +static const char * const kExts[] = { - "bat", - "cmd", - "exe", - "inf", - "msi", + "bat" + , "cmd" + , "exe" + , "inf" + , "msi" #ifdef UNDER_CE - "cab", + , "cab" #endif - "html", - "htm" + , "html" + , "htm" }; -static const char *kNames[] = +static const char * const kNames[] = { - "setup", - "install", - "run", - "start" + "setup" + , "install" + , "run" + , "start" }; static unsigned FindExt(const wchar_t *s, unsigned *extLen) @@ -61,7 +63,7 @@ static unsigned FindExt(const wchar_t *s, unsigned *extLen) #define MAKE_CHAR_UPPER(c) ((((c) >= 'a' && (c) <= 'z') ? (c) -= 0x20 : (c))) -static unsigned FindItem(const char **items, unsigned num, const wchar_t *s, unsigned len) +static unsigned FindItem(const char * const *items, unsigned num, const wchar_t *s, unsigned len) { unsigned i; for (i = 0; i < num; i++) @@ -73,7 +75,7 @@ static unsigned FindItem(const char **items, unsigned num, const wchar_t *s, uns continue; for (j = 0; j < len; j++) { - unsigned c = item[j]; + unsigned c = (Byte)item[j]; if (c != s[j] && MAKE_CHAR_UPPER(c) != s[j]) break; } @@ -86,7 +88,7 @@ static unsigned FindItem(const char **items, unsigned num, const wchar_t *s, uns #ifdef _CONSOLE static BOOL WINAPI HandlerRoutine(DWORD ctrlType) { - ctrlType = ctrlType; + UNUSED_VAR(ctrlType); return TRUE; } #endif @@ -142,7 +144,7 @@ static Bool FindSignature(CSzFile *stream, UInt64 *resPos) processed -= k7zStartHeaderSize; for (pos = 0; pos <= processed; pos++) { - for (; buf[pos] != '7' && pos <= processed; pos++); + for (; pos <= processed && buf[pos] != '7'; pos++); if (pos > processed) break; if (memcmp(buf + pos, k7zSignature, k7zSignatureSize) == 0) @@ -180,6 +182,7 @@ static WRes RemoveDirWithSubItems(WCHAR *path) path[len] = L'\0'; if (handle == INVALID_HANDLE_VALUE) return GetLastError(); + for (;;) { if (wcscmp(fd.cFileName, L".") != 0 && @@ -188,7 +191,7 @@ static WRes RemoveDirWithSubItems(WCHAR *path) wcscpy(path + len, fd.cFileName); if ((fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) != 0) { - wcscat(path, L"\\"); + wcscat(path, WSTRING_PATH_SEPARATOR); res = RemoveDirWithSubItems(path); } else @@ -197,9 +200,11 @@ static WRes RemoveDirWithSubItems(WCHAR *path) if (DeleteFileW(path) == 0) res = GetLastError(); } + if (res != 0) break; } + if (!FindNextFileW(handle, &fd)) { res = GetLastError(); @@ -208,6 +213,7 @@ static WRes RemoveDirWithSubItems(WCHAR *path) break; } } + path[len] = L'\0'; FindClose(handle); if (res == 0) @@ -238,19 +244,23 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, ISzAlloc allocTempImp; WCHAR sfxPath[MAX_PATH + 2]; WCHAR path[MAX_PATH * 3 + 2]; + #ifndef UNDER_CE + WCHAR workCurDir[MAX_PATH + 32]; + #endif size_t pathLen; DWORD winRes; const wchar_t *cmdLineParams; const char *errorMessage = NULL; Bool useShellExecute = True; + DWORD exitCode = 0; #ifdef _CONSOLE SetConsoleCtrlHandler(HandlerRoutine, TRUE); #else - hInstance = hInstance; - hPrevInstance = hPrevInstance; - lpCmdLine = lpCmdLine; - nCmdShow = nCmdShow; + UNUSED_VAR(hInstance); + UNUSED_VAR(hPrevInstance); + UNUSED_VAR(lpCmdLine); + UNUSED_VAR(nCmdShow); #endif CrcGenerateTable(); @@ -292,6 +302,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, return 1; pathLen = wcslen(path); d = (GetTickCount() << 12) ^ (GetCurrentThreadId() << 14) ^ GetCurrentProcessId(); + for (i = 0;; i++, d += GetTickCount()) { if (i >= 100) @@ -309,7 +320,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, { unsigned t = value & 0xF; value >>= 4; - s[7 - k] = (char)((t < 10) ? ('0' + t) : ('A' + (t - 10))); + s[7 - k] = (wchar_t)((t < 10) ? ('0' + t) : ('A' + (t - 10))); } s[k] = '\0'; } @@ -318,7 +329,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, continue; if (CreateDirectoryW(path, NULL)) { - wcscat(path, L"\\"); + wcscat(path, WSTRING_PATH_SEPARATOR); pathLen = wcslen(path); break; } @@ -328,6 +339,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, break; } } + + #ifndef UNDER_CE + wcscpy(workCurDir, path); + #endif if (res != SZ_OK) errorMessage = "Can't create temp folder"; } @@ -367,6 +382,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, { res = SzArEx_Open(&db, &lookStream.s, &allocImp, &allocTempImp); } + if (res == SZ_OK) { UInt32 executeFileIndex = (UInt32)(Int32)-1; @@ -376,11 +392,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, Byte *outBuffer = 0; /* it must be 0 before first call for each new archive. */ size_t outBufferSize = 0; /* it can have any value before first call (if outBuffer = 0) */ - for (i = 0; i < db.db.NumFiles; i++) + for (i = 0; i < db.NumFiles; i++) { size_t offset = 0; size_t outSizeProcessed = 0; - const CSzFileItem *f = db.db.Files + i; size_t len; WCHAR *temp; len = SzArEx_GetFileNameUtf16(&db, i, NULL); @@ -418,7 +433,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, } } - if (f->IsDir) + if (SzArEx_IsDir(&db, i)) { MyCreateDir(path); continue; @@ -453,6 +468,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, break; } } + processedSize = outSizeProcessed; if (File_Write(&outFile, outBuffer + offset, &processedSize) != 0 || processedSize != outSizeProcessed) { @@ -461,11 +477,12 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, } #ifdef USE_WINDOWS_FILE - if (f->MTimeDefined) + if (SzBitWithVals_Check(&db.MTime, i)) { + const CNtfsFileTime *t = db.MTime.Vals + i; FILETIME mTime; - mTime.dwLowDateTime = f->MTime.Low; - mTime.dwHighDateTime = f->MTime.High; + mTime.dwLowDateTime = t->Low; + mTime.dwHighDateTime = t->High; SetFileTime(outFile.handle, NULL, NULL, &mTime); } #endif @@ -481,8 +498,8 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, } } #ifdef USE_WINDOWS_FILE - if (f->AttribDefined) - SetFileAttributesW(path, f->Attrib); + if (SzBitWithVals_Check(&db.Attribs, i)) + SetFileAttributesW(path, db.Attribs.Vals[i]); #endif } } @@ -513,6 +530,18 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, if (res == SZ_OK) { HANDLE hProcess = 0; + + #ifndef UNDER_CE + WCHAR oldCurDir[MAX_PATH + 2]; + oldCurDir[0] = 0; + { + DWORD needLen = GetCurrentDirectory(MAX_PATH + 1, oldCurDir); + if (needLen == 0 || needLen > MAX_PATH) + oldCurDir[0] = 0; + SetCurrentDirectory(workCurDir); + } + #endif + if (useShellExecute) { SHELLEXECUTEINFO ei; @@ -556,18 +585,25 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, hProcess = pi.hProcess; } } + if (hProcess != 0) { WaitForSingleObject(hProcess, INFINITE); + if (!GetExitCodeProcess(hProcess, &exitCode)) + exitCode = 1; CloseHandle(hProcess); } + + #ifndef UNDER_CE + SetCurrentDirectory(oldCurDir); + #endif } path[pathLen] = L'\0'; RemoveDirWithSubItems(path); if (res == SZ_OK) - return 0; + return (int)exitCode; { if (res == SZ_ERROR_UNSUPPORTED) @@ -581,6 +617,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, if (!errorMessage) errorMessage = "ERROR"; } + if (errorMessage) PrintErrorMessage(errorMessage); } |