mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-09 06:07:05 -06:00
9.34
This commit is contained in:
committed by
Kornel Lesiński
parent
83f8ddcc5b
commit
f08f4dcc3c
109
CPP/7zip/UI/Common/CompressCall.cpp
Executable file → Normal file
109
CPP/7zip/UI/Common/CompressCall.cpp
Executable file → Normal file
@@ -2,17 +2,17 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Common/IntToString.h"
|
||||
#include "Common/MyCom.h"
|
||||
#include "Common/Random.h"
|
||||
#include "Common/StringConvert.h"
|
||||
#include "../../../Common/IntToString.h"
|
||||
#include "../../../Common/MyCom.h"
|
||||
#include "../../../Common/Random.h"
|
||||
#include "../../../Common/StringConvert.h"
|
||||
|
||||
#include "Windows/DLL.h"
|
||||
#include "Windows/Error.h"
|
||||
#include "Windows/FileDir.h"
|
||||
#include "Windows/FileMapping.h"
|
||||
#include "Windows/Process.h"
|
||||
#include "Windows/Synchronization.h"
|
||||
#include "../../../Windows/DLL.h"
|
||||
#include "../../../Windows/ErrorMsg.h"
|
||||
#include "../../../Windows/FileDir.h"
|
||||
#include "../../../Windows/FileMapping.h"
|
||||
#include "../../../Windows/ProcessUtils.h"
|
||||
#include "../../../Windows/Synchronization.h"
|
||||
|
||||
#include "../FileManager/RegistryUtils.h"
|
||||
|
||||
@@ -23,12 +23,15 @@ 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-";
|
||||
|
||||
@@ -46,7 +49,7 @@ static void ErrorMessage(LPCWSTR message)
|
||||
|
||||
static void ErrorMessageHRESULT(HRESULT res, LPCWSTR s = NULL)
|
||||
{
|
||||
UString s2 = NError::MyFormatMessageW(res);
|
||||
UString s2 = NError::MyFormatMessage(res);
|
||||
if (s)
|
||||
{
|
||||
s2 += L'\n';
|
||||
@@ -56,11 +59,12 @@ static void ErrorMessageHRESULT(HRESULT res, LPCWSTR s = NULL)
|
||||
}
|
||||
|
||||
static HRESULT MyCreateProcess(LPCWSTR imageName, const UString ¶ms,
|
||||
LPCWSTR curDir, bool waitFinish,
|
||||
// LPCWSTR curDir,
|
||||
bool waitFinish,
|
||||
NSynchronization::CBaseEvent *event)
|
||||
{
|
||||
CProcess process;
|
||||
WRes res = process.Create(imageName, params, curDir);
|
||||
WRes res = process.Create(imageName, params, NULL); // curDir);
|
||||
if (res != 0)
|
||||
{
|
||||
ErrorMessageHRESULT(res, imageName);
|
||||
@@ -71,7 +75,7 @@ static HRESULT MyCreateProcess(LPCWSTR imageName, const UString ¶ms,
|
||||
else if (event != NULL)
|
||||
{
|
||||
HANDLE handles[] = { process, *event };
|
||||
::WaitForMultipleObjects(sizeof(handles) / sizeof(handles[0]), handles, FALSE, INFINITE);
|
||||
::WaitForMultipleObjects(ARRAY_SIZE(handles), handles, FALSE, INFINITE);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
@@ -105,8 +109,8 @@ static HRESULT CreateMap(const UStringVector &names,
|
||||
UString ¶ms)
|
||||
{
|
||||
UInt32 totalSize = 1;
|
||||
for (int i = 0; i < names.Size(); i++)
|
||||
totalSize += (names[i].Length() + 1);
|
||||
FOR_VECTOR (i, names)
|
||||
totalSize += (names[i].Len() + 1);
|
||||
totalSize *= sizeof(wchar_t);
|
||||
|
||||
CRandNameGenerator random;
|
||||
@@ -153,10 +157,10 @@ static HRESULT CreateMap(const UStringVector &names,
|
||||
{
|
||||
wchar_t *cur = (wchar_t *)data;
|
||||
*cur++ = 0;
|
||||
for (int i = 0; i < names.Size(); i++)
|
||||
FOR_VECTOR (i, names)
|
||||
{
|
||||
const UString &s = names[i];
|
||||
int len = s.Length() + 1;
|
||||
int len = s.Len() + 1;
|
||||
memcpy(cur, (const wchar_t *)s, len * sizeof(wchar_t));
|
||||
cur += len;
|
||||
}
|
||||
@@ -168,6 +172,7 @@ HRESULT CompressFiles(
|
||||
const UString &arcPathPrefix,
|
||||
const UString &arcName,
|
||||
const UString &arcType,
|
||||
bool addExtension,
|
||||
const UStringVector &names,
|
||||
bool email, bool showDialog, bool waitFinish)
|
||||
{
|
||||
@@ -193,31 +198,46 @@ HRESULT CompressFiles(
|
||||
|
||||
AddLagePagesSwitch(params);
|
||||
|
||||
if (arcName.IsEmpty())
|
||||
params += L" -an";
|
||||
|
||||
if (addExtension)
|
||||
params += L" -saa";
|
||||
else
|
||||
params += L" -sae";
|
||||
|
||||
params += kStopSwitchParsing;
|
||||
params += L' ';
|
||||
|
||||
params += GetQuotedString(
|
||||
#ifdef UNDER_CE
|
||||
arcPathPrefix +
|
||||
#endif
|
||||
if (!arcName.IsEmpty())
|
||||
{
|
||||
params += GetQuotedString(
|
||||
// #ifdef UNDER_CE
|
||||
arcPathPrefix +
|
||||
// #endif
|
||||
arcName);
|
||||
}
|
||||
|
||||
return MyCreateProcess(Get7zGuiPath(), params,
|
||||
(arcPathPrefix.IsEmpty()? 0: (LPCWSTR)arcPathPrefix), waitFinish, &event);
|
||||
// (arcPathPrefix.IsEmpty()? 0: (LPCWSTR)arcPathPrefix),
|
||||
waitFinish, &event);
|
||||
MY_TRY_FINISH
|
||||
}
|
||||
|
||||
static HRESULT ExtractGroupCommand(const UStringVector &arcPaths, UString ¶ms)
|
||||
static void ExtractGroupCommand(const UStringVector &arcPaths, UString ¶ms, bool isHash)
|
||||
{
|
||||
AddLagePagesSwitch(params);
|
||||
params += kArcIncludeSwitches;
|
||||
params += isHash ? kHashIncludeSwitches : kArcIncludeSwitches;
|
||||
CFileMapping fileMapping;
|
||||
NSynchronization::CManualResetEvent event;
|
||||
RINOK(CreateMap(arcPaths, fileMapping, event, params));
|
||||
return MyCreateProcess(Get7zGuiPath(), params, 0, false, &event);
|
||||
HRESULT result = CreateMap(arcPaths, fileMapping, event, params);
|
||||
if (result == S_OK)
|
||||
result = MyCreateProcess(Get7zGuiPath(), params, false, &event);
|
||||
if (result != S_OK)
|
||||
ErrorMessageHRESULT(result);
|
||||
}
|
||||
|
||||
HRESULT ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog)
|
||||
void ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog, bool elimDup)
|
||||
{
|
||||
MY_TRY_BEGIN
|
||||
UString params = L'x';
|
||||
@@ -226,23 +246,40 @@ HRESULT ExtractArchives(const UStringVector &arcPaths, const UString &outFolder,
|
||||
params += L" -o";
|
||||
params += GetQuotedString(outFolder);
|
||||
}
|
||||
if (elimDup)
|
||||
params += L" -spe";
|
||||
if (showDialog)
|
||||
params += kShowDialogSwitch;
|
||||
return ExtractGroupCommand(arcPaths, params);
|
||||
MY_TRY_FINISH
|
||||
ExtractGroupCommand(arcPaths, params, false);
|
||||
MY_TRY_FINISH_VOID
|
||||
}
|
||||
|
||||
HRESULT TestArchives(const UStringVector &arcPaths)
|
||||
void TestArchives(const UStringVector &arcPaths)
|
||||
{
|
||||
MY_TRY_BEGIN
|
||||
UString params = L't';
|
||||
return ExtractGroupCommand(arcPaths, params);
|
||||
MY_TRY_FINISH
|
||||
ExtractGroupCommand(arcPaths, params, false);
|
||||
MY_TRY_FINISH_VOID
|
||||
}
|
||||
|
||||
HRESULT Benchmark(bool totalMode)
|
||||
void CalcChecksum(const UStringVector &paths, const UString &methodName)
|
||||
{
|
||||
MY_TRY_BEGIN
|
||||
return MyCreateProcess(Get7zGuiPath(), totalMode ? L"b -mm=*" : L"b", 0, false, NULL);
|
||||
MY_TRY_FINISH
|
||||
UString params = L'h';
|
||||
if (!methodName.IsEmpty())
|
||||
{
|
||||
params += L" -scrc";
|
||||
params += methodName;
|
||||
}
|
||||
ExtractGroupCommand(paths, params, true);
|
||||
MY_TRY_FINISH_VOID
|
||||
}
|
||||
|
||||
void Benchmark(bool totalMode)
|
||||
{
|
||||
MY_TRY_BEGIN
|
||||
HRESULT result = MyCreateProcess(Get7zGuiPath(), 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