Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/kornelski/7z.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'CPP/7zip/UI/Common/CompressCall.cpp')
-rw-r--r--[-rwxr-xr-x]CPP/7zip/UI/Common/CompressCall.cpp111
1 files changed, 74 insertions, 37 deletions
diff --git a/CPP/7zip/UI/Common/CompressCall.cpp b/CPP/7zip/UI/Common/CompressCall.cpp
index eb20d5cc..f5407b03 100755..100644
--- a/CPP/7zip/UI/Common/CompressCall.cpp
+++ b/CPP/7zip/UI/Common/CompressCall.cpp
@@ -2,17 +2,17 @@
#include "StdAfx.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 "../../../Common/IntToString.h"
+#include "../../../Common/MyCom.h"
+#include "../../../Common/Random.h"
+#include "../../../Common/StringConvert.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 &params,
- 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 &params,
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 &params)
{
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 &params)
+static void ExtractGroupCommand(const UStringVector &arcPaths, UString &params, 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
}