mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-06 17:15:00 -06:00
15.05
This commit is contained in:
committed by
Kornel Lesiński
parent
0713a3ab80
commit
54490d51d5
@@ -2,6 +2,8 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include <wchar.h>
|
||||
|
||||
#include "../../../Common/IntToString.h"
|
||||
#include "../../../Common/MyCom.h"
|
||||
#include "../../../Common/Random.h"
|
||||
@@ -21,25 +23,32 @@
|
||||
using namespace NWindows;
|
||||
|
||||
#define MY_TRY_BEGIN try {
|
||||
|
||||
#define MY_TRY_FINISH } \
|
||||
catch(...) { ErrorMessageHRESULT(E_FAIL); return E_FAIL; }
|
||||
|
||||
#define MY_TRY_FINISH_VOID } \
|
||||
catch(...) { ErrorMessageHRESULT(E_FAIL); }
|
||||
|
||||
static LPCWSTR kShowDialogSwitch = L" -ad";
|
||||
static LPCWSTR kEmailSwitch = L" -seml.";
|
||||
static LPCWSTR kIncludeSwitch = L" -i";
|
||||
static LPCWSTR kArchiveTypeSwitch = L" -t";
|
||||
static LPCWSTR kArcIncludeSwitches = L" -an -ai";
|
||||
static LPCWSTR kHashIncludeSwitches = L" -i";
|
||||
static LPCWSTR kStopSwitchParsing = L" --";
|
||||
static LPCWSTR kLargePagesDisable = L" -slp-";
|
||||
static const char *k7zGui = "7zG.exe";
|
||||
|
||||
static const char *kShowDialogSwitch = " -ad";
|
||||
static const char *kEmailSwitch = " -seml.";
|
||||
static const char *kIncludeSwitch = " -i";
|
||||
static const char *kArchiveTypeSwitch = " -t";
|
||||
static const char *kArcIncludeSwitches = " -an -ai";
|
||||
static const char *kHashIncludeSwitches = " -i";
|
||||
static const char *kStopSwitchParsing = " --";
|
||||
static const char *kLargePagesDisable = " -slp-";
|
||||
|
||||
extern HWND g_HWND;
|
||||
|
||||
UString GetQuotedString(const UString &s)
|
||||
{
|
||||
return UString(L'\"') + s + UString(L'\"');
|
||||
UString s2 = L'\"';
|
||||
s2 += s;
|
||||
s2 += L'\"';
|
||||
return s2;
|
||||
}
|
||||
|
||||
static void ErrorMessage(LPCWSTR message)
|
||||
@@ -52,17 +61,20 @@ static void ErrorMessageHRESULT(HRESULT res, LPCWSTR s = NULL)
|
||||
UString s2 = NError::MyFormatMessage(res);
|
||||
if (s)
|
||||
{
|
||||
s2 += L'\n';
|
||||
s2.Add_LF();
|
||||
s2 += s;
|
||||
}
|
||||
ErrorMessage(s2);
|
||||
}
|
||||
|
||||
static HRESULT MyCreateProcess(LPCWSTR imageName, const UString ¶ms,
|
||||
static HRESULT Call7zGui(const UString ¶ms,
|
||||
// LPCWSTR curDir,
|
||||
bool waitFinish,
|
||||
NSynchronization::CBaseEvent *event)
|
||||
{
|
||||
UString imageName = fs2us(NWindows::NDLL::GetModuleDirPrefix());
|
||||
imageName.AddAscii(k7zGui);
|
||||
|
||||
CProcess process;
|
||||
WRes res = process.Create(imageName, params, NULL); // curDir);
|
||||
if (res != 0)
|
||||
@@ -83,12 +95,7 @@ static HRESULT MyCreateProcess(LPCWSTR imageName, const UString ¶ms,
|
||||
static void AddLagePagesSwitch(UString ¶ms)
|
||||
{
|
||||
if (!ReadLockMemoryEnable())
|
||||
params += kLargePagesDisable;
|
||||
}
|
||||
|
||||
static UString Get7zGuiPath()
|
||||
{
|
||||
return fs2us(NWindows::NDLL::GetModuleDirPrefix()) + L"7zG.exe";
|
||||
params.AddAscii(kLargePagesDisable);
|
||||
}
|
||||
|
||||
class CRandNameGenerator
|
||||
@@ -96,11 +103,12 @@ class CRandNameGenerator
|
||||
CRandom _random;
|
||||
public:
|
||||
CRandNameGenerator() { _random.Init(); }
|
||||
UString GenerateName()
|
||||
void GenerateName(UString &s, const char *prefix)
|
||||
{
|
||||
wchar_t temp[16];
|
||||
ConvertUInt32ToString((UInt32)_random.Generate(), temp);
|
||||
return temp;
|
||||
s.AddAscii(prefix);
|
||||
char temp[16];
|
||||
ConvertUInt32ToString((UInt32)(unsigned)_random.Generate(), temp);
|
||||
s.AddAscii(temp);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -108,9 +116,11 @@ static HRESULT CreateMap(const UStringVector &names,
|
||||
CFileMapping &fileMapping, NSynchronization::CManualResetEvent &event,
|
||||
UString ¶ms)
|
||||
{
|
||||
UInt32 totalSize = 1;
|
||||
FOR_VECTOR (i, names)
|
||||
totalSize += (names[i].Len() + 1);
|
||||
size_t totalSize = 1;
|
||||
{
|
||||
FOR_VECTOR (i, names)
|
||||
totalSize += (names[i].Len() + 1);
|
||||
}
|
||||
totalSize *= sizeof(wchar_t);
|
||||
|
||||
CRandNameGenerator random;
|
||||
@@ -118,7 +128,7 @@ static HRESULT CreateMap(const UStringVector &names,
|
||||
UString mappingName;
|
||||
for (;;)
|
||||
{
|
||||
mappingName = L"7zMap" + random.GenerateName();
|
||||
random.GenerateName(mappingName, "7zMap");
|
||||
|
||||
WRes res = fileMapping.Create(PAGE_READWRITE, totalSize, GetSystemString(mappingName));
|
||||
if (fileMapping.IsCreated() && res == 0)
|
||||
@@ -131,7 +141,7 @@ static HRESULT CreateMap(const UStringVector &names,
|
||||
UString eventName;
|
||||
for (;;)
|
||||
{
|
||||
eventName = L"7zEvent" + random.GenerateName();
|
||||
random.GenerateName(eventName, "7zEvent");
|
||||
WRes res = event.CreateWithName(false, GetSystemString(eventName));
|
||||
if (event.IsCreated() && res == 0)
|
||||
break;
|
||||
@@ -143,25 +153,25 @@ static HRESULT CreateMap(const UStringVector &names,
|
||||
params += L'#';
|
||||
params += mappingName;
|
||||
params += L':';
|
||||
wchar_t temp[16];
|
||||
ConvertUInt32ToString(totalSize, temp);
|
||||
params += temp;
|
||||
char temp[32];
|
||||
ConvertUInt64ToString(totalSize, temp);
|
||||
params.AddAscii(temp);
|
||||
|
||||
params += L':';
|
||||
params += eventName;
|
||||
|
||||
LPVOID data = fileMapping.Map(FILE_MAP_WRITE, 0, totalSize);
|
||||
if (data == NULL)
|
||||
if (!data)
|
||||
return E_FAIL;
|
||||
CFileUnmapper unmapper(data);
|
||||
{
|
||||
wchar_t *cur = (wchar_t *)data;
|
||||
*cur++ = 0;
|
||||
*cur++ = 0; // it means wchar_t strings (UTF-16 in WIN32)
|
||||
FOR_VECTOR (i, names)
|
||||
{
|
||||
const UString &s = names[i];
|
||||
int len = s.Len() + 1;
|
||||
memcpy(cur, (const wchar_t *)s, len * sizeof(wchar_t));
|
||||
unsigned len = s.Len() + 1;
|
||||
wmemcpy(cur, (const wchar_t *)s, len);
|
||||
cur += len;
|
||||
}
|
||||
}
|
||||
@@ -181,33 +191,33 @@ HRESULT CompressFiles(
|
||||
|
||||
CFileMapping fileMapping;
|
||||
NSynchronization::CManualResetEvent event;
|
||||
params += kIncludeSwitch;
|
||||
params.AddAscii(kIncludeSwitch);
|
||||
RINOK(CreateMap(names, fileMapping, event, params));
|
||||
|
||||
if (!arcType.IsEmpty())
|
||||
{
|
||||
params += kArchiveTypeSwitch;
|
||||
params.AddAscii(kArchiveTypeSwitch);
|
||||
params += arcType;
|
||||
}
|
||||
|
||||
if (email)
|
||||
params += kEmailSwitch;
|
||||
params.AddAscii(kEmailSwitch);
|
||||
|
||||
if (showDialog)
|
||||
params += kShowDialogSwitch;
|
||||
params.AddAscii(kShowDialogSwitch);
|
||||
|
||||
AddLagePagesSwitch(params);
|
||||
|
||||
if (arcName.IsEmpty())
|
||||
params += L" -an";
|
||||
params.AddAscii(" -an");
|
||||
|
||||
if (addExtension)
|
||||
params += L" -saa";
|
||||
params.AddAscii(" -saa");
|
||||
else
|
||||
params += L" -sae";
|
||||
params.AddAscii(" -sae");
|
||||
|
||||
params += kStopSwitchParsing;
|
||||
params += L' ';
|
||||
params.AddAscii(kStopSwitchParsing);
|
||||
params.Add_Space();
|
||||
|
||||
if (!arcName.IsEmpty())
|
||||
{
|
||||
@@ -218,7 +228,7 @@ HRESULT CompressFiles(
|
||||
arcName);
|
||||
}
|
||||
|
||||
return MyCreateProcess(Get7zGuiPath(), params,
|
||||
return Call7zGui(params,
|
||||
// (arcPathPrefix.IsEmpty()? 0: (LPCWSTR)arcPathPrefix),
|
||||
waitFinish, &event);
|
||||
MY_TRY_FINISH
|
||||
@@ -227,12 +237,12 @@ HRESULT CompressFiles(
|
||||
static void ExtractGroupCommand(const UStringVector &arcPaths, UString ¶ms, bool isHash)
|
||||
{
|
||||
AddLagePagesSwitch(params);
|
||||
params += isHash ? kHashIncludeSwitches : kArcIncludeSwitches;
|
||||
params.AddAscii(isHash ? kHashIncludeSwitches : kArcIncludeSwitches);
|
||||
CFileMapping fileMapping;
|
||||
NSynchronization::CManualResetEvent event;
|
||||
HRESULT result = CreateMap(arcPaths, fileMapping, event, params);
|
||||
if (result == S_OK)
|
||||
result = MyCreateProcess(Get7zGuiPath(), params, false, &event);
|
||||
result = Call7zGui(params, false, &event);
|
||||
if (result != S_OK)
|
||||
ErrorMessageHRESULT(result);
|
||||
}
|
||||
@@ -243,13 +253,13 @@ void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bo
|
||||
UString params = L'x';
|
||||
if (!outFolder.IsEmpty())
|
||||
{
|
||||
params += L" -o";
|
||||
params.AddAscii(" -o");
|
||||
params += GetQuotedString(outFolder);
|
||||
}
|
||||
if (elimDup)
|
||||
params += L" -spe";
|
||||
params.AddAscii(" -spe");
|
||||
if (showDialog)
|
||||
params += kShowDialogSwitch;
|
||||
params.AddAscii(kShowDialogSwitch);
|
||||
ExtractGroupCommand(arcPaths, params, false);
|
||||
MY_TRY_FINISH_VOID
|
||||
}
|
||||
@@ -268,7 +278,7 @@ void CalcChecksum(const UStringVector &paths, const UString &methodName)
|
||||
UString params = L'h';
|
||||
if (!methodName.IsEmpty())
|
||||
{
|
||||
params += L" -scrc";
|
||||
params.AddAscii(" -scrc");
|
||||
params += methodName;
|
||||
}
|
||||
ExtractGroupCommand(paths, params, true);
|
||||
@@ -278,7 +288,7 @@ void CalcChecksum(const UStringVector &paths, const UString &methodName)
|
||||
void Benchmark(bool totalMode)
|
||||
{
|
||||
MY_TRY_BEGIN
|
||||
HRESULT result = MyCreateProcess(Get7zGuiPath(), totalMode ? L"b -mm=*" : L"b", false, NULL);
|
||||
HRESULT result = Call7zGui(totalMode ? L"b -mm=*" : L"b", false, NULL);
|
||||
if (result != S_OK)
|
||||
ErrorMessageHRESULT(result);
|
||||
MY_TRY_FINISH_VOID
|
||||
|
||||
Reference in New Issue
Block a user