summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/lzma/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
diff options
context:
space:
mode:
Diffstat (limited to '3rdparty/lzma/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp')
-rw-r--r--3rdparty/lzma/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp114
1 files changed, 59 insertions, 55 deletions
diff --git a/3rdparty/lzma/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp b/3rdparty/lzma/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
index aef2e1969c9..47d7966d771 100644
--- a/3rdparty/lzma/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
+++ b/3rdparty/lzma/CPP/7zip/Bundles/SFXSetup/SfxSetup.cpp
@@ -2,8 +2,9 @@
#include "StdAfx.h"
-#include "../../../Common/MyWindows.h"
+#include "../../../../C/DllSecur.h"
+#include "../../../Common/MyWindows.h"
#include "../../../Common/MyInitGuid.h"
#include "../../../Common/CommandLineParser.h"
@@ -23,19 +24,19 @@
#include "ExtractEngine.h"
-#include "../../../../C/DllSecur.h"
-
#include "resource.h"
using namespace NWindows;
using namespace NFile;
using namespace NDir;
+extern
+HINSTANCE g_hInstance;
HINSTANCE g_hInstance;
-static CFSTR kTempDirPrefix = FTEXT("7zS");
+static CFSTR const kTempDirPrefix = FTEXT("7zS");
-#define _SHELL_EXECUTE
+#define MY_SHELL_EXECUTE
static bool ReadDataString(CFSTR fileName, LPCSTR startID,
LPCSTR endID, AString &stringResult)
@@ -44,44 +45,44 @@ static bool ReadDataString(CFSTR fileName, LPCSTR startID,
NIO::CInFile inFile;
if (!inFile.Open(fileName))
return false;
- const int kBufferSize = (1 << 12);
+ const size_t kBufferSize = (1 << 12);
Byte buffer[kBufferSize];
- int signatureStartSize = MyStringLen(startID);
- int signatureEndSize = MyStringLen(endID);
+ const unsigned signatureStartSize = MyStringLen(startID);
+ const unsigned signatureEndSize = MyStringLen(endID);
- UInt32 numBytesPrev = 0;
+ size_t numBytesPrev = 0;
bool writeMode = false;
UInt64 posTotal = 0;
for (;;)
{
if (posTotal > (1 << 20))
return (stringResult.IsEmpty());
- UInt32 numReadBytes = kBufferSize - numBytesPrev;
- UInt32 processedSize;
- if (!inFile.Read(buffer + numBytesPrev, numReadBytes, processedSize))
+ const size_t numReadBytes = kBufferSize - numBytesPrev;
+ size_t processedSize;
+ if (!inFile.ReadFull(buffer + numBytesPrev, numReadBytes, processedSize))
return false;
if (processedSize == 0)
return true;
- UInt32 numBytesInBuffer = numBytesPrev + processedSize;
+ const size_t numBytesInBuffer = numBytesPrev + processedSize;
UInt32 pos = 0;
for (;;)
{
if (writeMode)
{
- if (pos > numBytesInBuffer - signatureEndSize)
+ if (pos + signatureEndSize > numBytesInBuffer)
break;
if (memcmp(buffer + pos, endID, signatureEndSize) == 0)
return true;
- char b = buffer[pos];
+ const Byte b = buffer[pos];
if (b == 0)
return false;
- stringResult += b;
+ stringResult += (char)b;
pos++;
}
else
{
- if (pos > numBytesInBuffer - signatureStartSize)
+ if (pos + signatureStartSize > numBytesInBuffer)
break;
if (memcmp(buffer + pos, startID, signatureStartSize) == 0)
{
@@ -101,26 +102,28 @@ static bool ReadDataString(CFSTR fileName, LPCSTR startID,
static char kStartID[] = { ',','!','@','I','n','s','t','a','l','l','@','!','U','T','F','-','8','!', 0 };
static char kEndID[] = { ',','!','@','I','n','s','t','a','l','l','E','n','d','@','!', 0 };
-struct CInstallIDInit
+static struct CInstallIDInit
{
CInstallIDInit()
{
kStartID[0] = ';';
kEndID[0] = ';';
- };
+ }
} g_CInstallIDInit;
+#if defined(_WIN32) && defined(_UNICODE) && !defined(_WIN64) && !defined(UNDER_CE)
#define NT_CHECK_FAIL_ACTION ShowErrorMessage(L"Unsupported Windows version"); return 1;
+#endif
static void ShowErrorMessageSpec(const UString &name)
{
UString message = NError::MyFormatMessage(::GetLastError());
- int pos = message.Find(L"%1");
+ const int pos = message.Find(L"%1");
if (pos >= 0)
{
- message.Delete(pos, 2);
- message.Insert(pos, name);
+ message.Delete((unsigned)pos, 2);
+ message.Insert((unsigned)pos, name);
}
ShowErrorMessage(NULL, message);
}
@@ -144,7 +147,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
// InitCommonControls();
UString archiveName, switches;
- #ifdef _SHELL_EXECUTE
+ #ifdef MY_SHELL_EXECUTE
UString executeFile, executeParameters;
#endif
NCommandLineParser::SplitCommandLine(GetCommandLineW(), archiveName, switches);
@@ -169,7 +172,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
return 1;
}
- UString dirPrefix = L"." WSTRING_PATH_SEPARATOR;
+ UString dirPrefix ("." STRING_PATH_SEPARATOR);
UString appLaunched;
bool showProgress = true;
if (!config.IsEmpty())
@@ -181,25 +184,25 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
ShowErrorMessage(L"Config failed");
return 1;
}
- UString friendlyName = GetTextConfigValue(pairs, L"Title");
- UString installPrompt = GetTextConfigValue(pairs, L"BeginPrompt");
- UString progress = GetTextConfigValue(pairs, L"Progress");
+ const UString friendlyName = GetTextConfigValue(pairs, "Title");
+ const UString installPrompt = GetTextConfigValue(pairs, "BeginPrompt");
+ const UString progress = GetTextConfigValue(pairs, "Progress");
if (progress.IsEqualTo_Ascii_NoCase("no"))
showProgress = false;
- int index = FindTextConfigItem(pairs, L"Directory");
+ const int index = FindTextConfigItem(pairs, "Directory");
if (index >= 0)
dirPrefix = pairs[index].String;
if (!installPrompt.IsEmpty() && !assumeYes)
{
- if (MessageBoxW(0, installPrompt, friendlyName, MB_YESNO |
+ if (MessageBoxW(NULL, installPrompt, friendlyName, MB_YESNO |
MB_ICONQUESTION) != IDYES)
return 0;
}
- appLaunched = GetTextConfigValue(pairs, L"RunProgram");
+ appLaunched = GetTextConfigValue(pairs, "RunProgram");
- #ifdef _SHELL_EXECUTE
- executeFile = GetTextConfigValue(pairs, L"ExecuteFile");
- executeParameters = GetTextConfigValue(pairs, L"ExecuteParameters");
+ #ifdef MY_SHELL_EXECUTE
+ executeFile = GetTextConfigValue(pairs, "ExecuteFile");
+ executeParameters = GetTextConfigValue(pairs, "ExecuteParameters");
#endif
}
@@ -207,17 +210,17 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
if (!tempDir.Create(kTempDirPrefix))
{
if (!assumeYes)
- ShowErrorMessage(L"Can not create temp folder archive");
+ ShowErrorMessage(L"Cannot create temp folder archive");
return 1;
}
CCodecs *codecs = new CCodecs;
CMyComPtr<IUnknown> compressCodecsInfo = codecs;
{
- HRESULT result = codecs->Load();
+ const HRESULT result = codecs->Load();
if (result != S_OK)
{
- ShowErrorMessage(L"Can not load codecs");
+ ShowErrorMessage(L"Cannot load codecs");
return 1;
}
}
@@ -243,7 +246,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
{
if (errorMessage.IsEmpty())
errorMessage = NError::MyFormatMessage(result);
- ::MessageBoxW(0, errorMessage, NWindows::MyLoadString(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR);
+ ::MessageBoxW(NULL, errorMessage, NWindows::MyLoadString(IDS_EXTRACTION_ERROR_TITLE), MB_ICONERROR);
}
}
return 1;
@@ -256,11 +259,11 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
return 1;
#endif
- HANDLE hProcess = 0;
-#ifdef _SHELL_EXECUTE
+ HANDLE hProcess = NULL;
+#ifdef MY_SHELL_EXECUTE
if (!executeFile.IsEmpty())
{
- CSysString filePath = GetSystemString(executeFile);
+ CSysString filePath (GetSystemString(executeFile));
SHELLEXECUTEINFO execInfo;
execInfo.cbSize = sizeof(execInfo);
execInfo.fMask = SEE_MASK_NOCLOSEPROCESS
@@ -278,7 +281,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
executeParameters += switches;
}
- CSysString parametersSys = GetSystemString(executeParameters);
+ const CSysString parametersSys (GetSystemString(executeParameters));
if (parametersSys.IsEmpty())
execInfo.lpParameters = NULL;
else
@@ -286,13 +289,13 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
execInfo.lpDirectory = NULL;
execInfo.nShow = SW_SHOWNORMAL;
- execInfo.hProcess = 0;
+ execInfo.hProcess = NULL;
/* BOOL success = */ ::ShellExecuteEx(&execInfo);
UINT32 result = (UINT32)(UINT_PTR)execInfo.hInstApp;
if (result <= 32)
{
if (!assumeYes)
- ShowErrorMessage(L"Can not open file");
+ ShowErrorMessage(L"Cannot open file");
return 1;
}
hProcess = execInfo.hProcess;
@@ -303,10 +306,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
if (appLaunched.IsEmpty())
{
appLaunched = L"setup.exe";
- if (!NFind::DoesFileExist(us2fs(appLaunched)))
+ if (!NFind::DoesFileExist_FollowLink(us2fs(appLaunched)))
{
if (!assumeYes)
- ShowErrorMessage(L"Can not find setup.exe");
+ ShowErrorMessage(L"Cannot find setup.exe");
return 1;
}
}
@@ -317,7 +320,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
appLaunched.Replace(L"%%T" WSTRING_PATH_SEPARATOR, fs2us(s2));
}
- UString appNameForError = appLaunched; // actually we need to rtemove parameters also
+ const UString appNameForError = appLaunched; // actually we need to rtemove parameters also
appLaunched.Replace(L"%%T", fs2us(tempDirPath));
@@ -328,20 +331,21 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
}
STARTUPINFO startupInfo;
startupInfo.cb = sizeof(startupInfo);
- startupInfo.lpReserved = 0;
- startupInfo.lpDesktop = 0;
- startupInfo.lpTitle = 0;
+ startupInfo.lpReserved = NULL;
+ startupInfo.lpDesktop = NULL;
+ startupInfo.lpTitle = NULL;
startupInfo.dwFlags = 0;
startupInfo.cbReserved2 = 0;
- startupInfo.lpReserved2 = 0;
+ startupInfo.lpReserved2 = NULL;
PROCESS_INFORMATION processInformation;
- CSysString appLaunchedSys = GetSystemString(dirPrefix + appLaunched);
+ const CSysString appLaunchedSys (GetSystemString(dirPrefix + appLaunched));
- BOOL createResult = CreateProcess(NULL, (LPTSTR)(LPCTSTR)appLaunchedSys,
- NULL, NULL, FALSE, 0, NULL, NULL /*tempDir.GetPath() */,
- &startupInfo, &processInformation);
+ const BOOL createResult = CreateProcess(NULL,
+ appLaunchedSys.Ptr_non_const(),
+ NULL, NULL, FALSE, 0, NULL, NULL /*tempDir.GetPath() */,
+ &startupInfo, &processInformation);
if (createResult == 0)
{
if (!assumeYes)
@@ -355,7 +359,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
::CloseHandle(processInformation.hThread);
hProcess = processInformation.hProcess;
}
- if (hProcess != 0)
+ if (hProcess)
{
WaitForSingleObject(hProcess, INFINITE);
::CloseHandle(hProcess);