mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-07 09:15:00 -06:00
9.06 beta
This commit is contained in:
committed by
Kornel Lesiński
parent
829409452d
commit
c99f3ebdd6
@@ -3,8 +3,10 @@
|
||||
#include "StdAfx.h"
|
||||
|
||||
#ifdef _WIN32
|
||||
#ifndef UNDER_CE
|
||||
#include <io.h>
|
||||
#endif
|
||||
#endif
|
||||
#include <stdio.h>
|
||||
|
||||
#include "Common/ListFileUtils.h"
|
||||
@@ -26,6 +28,12 @@
|
||||
|
||||
extern bool g_CaseSensitive;
|
||||
|
||||
#ifdef UNDER_CE
|
||||
|
||||
#define MY_IS_TERMINAL(x) false;
|
||||
|
||||
#else
|
||||
|
||||
#if _MSC_VER >= 1400
|
||||
#define MY_isatty_fileno(x) _isatty(_fileno(x))
|
||||
#else
|
||||
@@ -34,6 +42,8 @@ extern bool g_CaseSensitive;
|
||||
|
||||
#define MY_IS_TERMINAL(x) (MY_isatty_fileno(x) != 0);
|
||||
|
||||
#endif
|
||||
|
||||
using namespace NCommandLineParser;
|
||||
using namespace NWindows;
|
||||
using namespace NFile;
|
||||
@@ -250,26 +260,21 @@ static bool ParseArchiveCommand(const UString &commandString, CArchiveCommand &c
|
||||
// ------------------------------------------------------------------
|
||||
// filenames functions
|
||||
|
||||
static bool AddNameToCensor(NWildcard::CCensor &wildcardCensor,
|
||||
static void AddNameToCensor(NWildcard::CCensor &wildcardCensor,
|
||||
const UString &name, bool include, NRecursedType::EEnum type)
|
||||
{
|
||||
bool isWildCard = DoesNameContainWildCard(name);
|
||||
bool recursed = false;
|
||||
|
||||
switch (type)
|
||||
{
|
||||
case NRecursedType::kWildCardOnlyRecursed:
|
||||
recursed = isWildCard;
|
||||
recursed = DoesNameContainWildCard(name);
|
||||
break;
|
||||
case NRecursedType::kRecursed:
|
||||
recursed = true;
|
||||
break;
|
||||
case NRecursedType::kNonRecursed:
|
||||
recursed = false;
|
||||
break;
|
||||
}
|
||||
wildcardCensor.AddItem(include, name, recursed);
|
||||
return true;
|
||||
}
|
||||
|
||||
static void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor,
|
||||
@@ -279,15 +284,7 @@ static void AddToCensorFromListFile(NWildcard::CCensor &wildcardCensor,
|
||||
if (!ReadNamesFromListFile(fileName, names, codePage))
|
||||
throw kIncorrectListFile;
|
||||
for (int i = 0; i < names.Size(); i++)
|
||||
if (!AddNameToCensor(wildcardCensor, names[i], include, type))
|
||||
throw kIncorrectWildCardInListFile;
|
||||
}
|
||||
|
||||
static void AddCommandLineWildCardToCensr(NWildcard::CCensor &wildcardCensor,
|
||||
const UString &name, bool include, NRecursedType::EEnum recursedType)
|
||||
{
|
||||
if (!AddNameToCensor(wildcardCensor, name, include, recursedType))
|
||||
throw kIncorrectWildCardInCommandLine;
|
||||
AddNameToCensor(wildcardCensor, names[i], include, type);
|
||||
}
|
||||
|
||||
static void AddToCensorFromNonSwitchesStrings(
|
||||
@@ -297,14 +294,14 @@ static void AddToCensorFromNonSwitchesStrings(
|
||||
bool thereAreSwitchIncludes, UINT codePage)
|
||||
{
|
||||
if (nonSwitchStrings.Size() == startIndex && (!thereAreSwitchIncludes))
|
||||
AddCommandLineWildCardToCensr(wildcardCensor, kUniversalWildcard, true, type);
|
||||
AddNameToCensor(wildcardCensor, kUniversalWildcard, true, type);
|
||||
for (int i = startIndex; i < nonSwitchStrings.Size(); i++)
|
||||
{
|
||||
const UString &s = nonSwitchStrings[i];
|
||||
if (s[0] == kFileListID)
|
||||
AddToCensorFromListFile(wildcardCensor, s.Mid(1), true, type, codePage);
|
||||
else
|
||||
AddCommandLineWildCardToCensr(wildcardCensor, s, true, type);
|
||||
AddNameToCensor(wildcardCensor, s, true, type);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -330,9 +327,9 @@ static void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor,
|
||||
UInt32 dataSize = (UInt32)dataSize64;
|
||||
{
|
||||
CFileMapping fileMapping;
|
||||
if (!fileMapping.Open(FILE_MAP_READ, false, GetSystemString(mappingName)))
|
||||
if (fileMapping.Open(FILE_MAP_READ, GetSystemString(mappingName)) != 0)
|
||||
ThrowException("Can not open mapping");
|
||||
LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_READ, 0, dataSize);
|
||||
LPVOID data = fileMapping.Map(FILE_MAP_READ, 0, dataSize);
|
||||
if (data == NULL)
|
||||
ThrowException("MapViewOfFile error");
|
||||
try
|
||||
@@ -347,8 +344,7 @@ static void ParseMapWithPaths(NWildcard::CCensor &wildcardCensor,
|
||||
wchar_t c = curData[i];
|
||||
if (c == L'\0')
|
||||
{
|
||||
AddCommandLineWildCardToCensr(wildcardCensor,
|
||||
name, include, commonRecursedType);
|
||||
AddNameToCensor(wildcardCensor, name, include, commonRecursedType);
|
||||
name.Empty();
|
||||
}
|
||||
else
|
||||
@@ -398,7 +394,7 @@ static void AddSwitchWildCardsToCensor(NWildcard::CCensor &wildcardCensor,
|
||||
ThrowUserErrorException();
|
||||
UString tail = name.Mid(pos + 1);
|
||||
if (name[pos] == kImmediateNameID)
|
||||
AddCommandLineWildCardToCensr(wildcardCensor, tail, include, recursedType);
|
||||
AddNameToCensor(wildcardCensor, tail, include, recursedType);
|
||||
else if (name[pos] == kFileListID)
|
||||
AddToCensorFromListFile(wildcardCensor, tail, include, recursedType, codePage);
|
||||
#ifdef _WIN32
|
||||
@@ -764,6 +760,52 @@ static bool ConvertStringToUInt32(const wchar_t *s, UInt32 &v)
|
||||
return true;
|
||||
}
|
||||
|
||||
void EnumerateDirItemsAndSort(NWildcard::CCensor &wildcardCensor,
|
||||
UStringVector &sortedPaths,
|
||||
UStringVector &sortedFullPaths)
|
||||
{
|
||||
UStringVector paths;
|
||||
{
|
||||
CDirItems dirItems;
|
||||
{
|
||||
UStringVector errorPaths;
|
||||
CRecordVector<DWORD> errorCodes;
|
||||
HRESULT res = EnumerateItems(wildcardCensor, dirItems, NULL, errorPaths, errorCodes);
|
||||
if (res != S_OK || errorPaths.Size() > 0)
|
||||
throw "cannot find archive";
|
||||
}
|
||||
for (int i = 0; i < dirItems.Items.Size(); i++)
|
||||
{
|
||||
const CDirItem &dirItem = dirItems.Items[i];
|
||||
if (!dirItem.IsDir())
|
||||
paths.Add(dirItems.GetPhyPath(i));
|
||||
}
|
||||
}
|
||||
|
||||
if (paths.Size() == 0)
|
||||
throw "there is no such archive";
|
||||
|
||||
UStringVector fullPaths;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < paths.Size(); i++)
|
||||
{
|
||||
UString fullPath;
|
||||
NFile::NDirectory::MyGetFullPathName(paths[i], fullPath);
|
||||
fullPaths.Add(fullPath);
|
||||
}
|
||||
CIntVector indices;
|
||||
SortFileNames(fullPaths, indices);
|
||||
sortedPaths.Reserve(indices.Size());
|
||||
sortedFullPaths.Reserve(indices.Size());
|
||||
for (i = 0; i < indices.Size(); i++)
|
||||
{
|
||||
int index = indices[i];
|
||||
sortedPaths.Add(paths[index]);
|
||||
sortedFullPaths.Add(fullPaths[index]);
|
||||
}
|
||||
}
|
||||
|
||||
void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)
|
||||
{
|
||||
const UStringVector &nonSwitchStrings = parser.NonSwitchStrings;
|
||||
@@ -844,16 +886,14 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)
|
||||
NWildcard::CCensor archiveWildcardCensor;
|
||||
|
||||
if (parser[NKey::kArInclude].ThereIs)
|
||||
{
|
||||
AddSwitchWildCardsToCensor(archiveWildcardCensor,
|
||||
parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, codePage);
|
||||
}
|
||||
parser[NKey::kArInclude].PostStrings, true, NRecursedType::kNonRecursed, codePage);
|
||||
if (parser[NKey::kArExclude].ThereIs)
|
||||
AddSwitchWildCardsToCensor(archiveWildcardCensor,
|
||||
parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, codePage);
|
||||
parser[NKey::kArExclude].PostStrings, false, NRecursedType::kNonRecursed, codePage);
|
||||
|
||||
if (thereIsArchiveName)
|
||||
AddCommandLineWildCardToCensr(archiveWildcardCensor, options.ArchiveName, true, NRecursedType::kNonRecursed);
|
||||
AddNameToCensor(archiveWildcardCensor, options.ArchiveName, true, NRecursedType::kNonRecursed);
|
||||
|
||||
#ifdef _WIN32
|
||||
ConvertToLongNames(archiveWildcardCensor);
|
||||
@@ -869,50 +909,11 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
UStringVector archivePaths;
|
||||
|
||||
{
|
||||
CDirItems dirItems;
|
||||
{
|
||||
UStringVector errorPaths;
|
||||
CRecordVector<DWORD> errorCodes;
|
||||
HRESULT res = EnumerateItems(archiveWildcardCensor, dirItems, NULL, errorPaths, errorCodes);
|
||||
if (res != S_OK || errorPaths.Size() > 0)
|
||||
throw "cannot find archive";
|
||||
}
|
||||
for (int i = 0; i < dirItems.Items.Size(); i++)
|
||||
{
|
||||
const CDirItem &dirItem = dirItems.Items[i];
|
||||
if (!dirItem.IsDir())
|
||||
archivePaths.Add(dirItems.GetPhyPath(i));
|
||||
}
|
||||
}
|
||||
|
||||
if (archivePaths.Size() == 0)
|
||||
throw "there is no such archive";
|
||||
|
||||
UStringVector archivePathsFull;
|
||||
|
||||
int i;
|
||||
for (i = 0; i < archivePaths.Size(); i++)
|
||||
{
|
||||
UString fullPath;
|
||||
NFile::NDirectory::MyGetFullPathName(archivePaths[i], fullPath);
|
||||
archivePathsFull.Add(fullPath);
|
||||
}
|
||||
CIntVector indices;
|
||||
SortFileNames(archivePathsFull, indices);
|
||||
options.ArchivePathsSorted.Reserve(indices.Size());
|
||||
options.ArchivePathsFullSorted.Reserve(indices.Size());
|
||||
for (i = 0; i < indices.Size(); i++)
|
||||
{
|
||||
options.ArchivePathsSorted.Add(archivePaths[indices[i]]);
|
||||
options.ArchivePathsFullSorted.Add(archivePathsFull[indices[i]]);
|
||||
EnumerateDirItemsAndSort(archiveWildcardCensor,
|
||||
options.ArchivePathsSorted,
|
||||
options.ArchivePathsFullSorted);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (isExtractGroupCommand)
|
||||
{
|
||||
SetMethodOptions(parser, options.ExtractProperties);
|
||||
@@ -926,8 +927,7 @@ void CArchiveCommandLineParser::Parse2(CArchiveCommandLineOptions &options)
|
||||
|
||||
options.OverwriteMode = NExtract::NOverwriteMode::kAskBefore;
|
||||
if (parser[NKey::kOverwrite].ThereIs)
|
||||
options.OverwriteMode =
|
||||
k_OverwriteModes[parser[NKey::kOverwrite].PostCharIndex];
|
||||
options.OverwriteMode = k_OverwriteModes[parser[NKey::kOverwrite].PostCharIndex];
|
||||
else if (options.YesToAll)
|
||||
options.OverwriteMode = NExtract::NOverwriteMode::kWithoutPrompt;
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// ArchiveCommandLine.h
|
||||
|
||||
#ifndef __ARCHIVECOMMANDLINE_H
|
||||
#define __ARCHIVECOMMANDLINE_H
|
||||
#ifndef __ARCHIVE_COMMAND_LINE_H
|
||||
#define __ARCHIVE_COMMAND_LINE_H
|
||||
|
||||
#include "Common/Wildcard.h"
|
||||
#include "Common/CommandLineParser.h"
|
||||
#include "Common/Wildcard.h"
|
||||
|
||||
#include "Extract.h"
|
||||
#include "Update.h"
|
||||
@@ -104,4 +104,8 @@ public:
|
||||
void Parse2(CArchiveCommandLineOptions &options);
|
||||
};
|
||||
|
||||
void EnumerateDirItemsAndSort(NWildcard::CCensor &wildcardCensor,
|
||||
UStringVector &sortedPaths,
|
||||
UStringVector &sortedFullPaths);
|
||||
|
||||
#endif
|
||||
|
||||
@@ -75,9 +75,12 @@ struct CInFileStreamVol: public CInFileStream
|
||||
CMyComPtr<IArchiveOpenCallback> OpenCallbackRef;
|
||||
~CInFileStreamVol()
|
||||
{
|
||||
int index = OpenCallbackImp->FindName(Name);
|
||||
if (index >= 0)
|
||||
OpenCallbackImp->FileNames.Delete(index);
|
||||
if (OpenCallbackRef)
|
||||
{
|
||||
int index = OpenCallbackImp->FindName(Name);
|
||||
if (index >= 0)
|
||||
OpenCallbackImp->FileNames.Delete(index);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
|
||||
#include "Windows/FileDir.h"
|
||||
#include "Windows/FileMapping.h"
|
||||
#include "Windows/Process.h"
|
||||
#include "Windows/Synchronization.h"
|
||||
|
||||
#include "../FileManager/ProgramLocation.h"
|
||||
@@ -16,253 +17,170 @@
|
||||
|
||||
#include "CompressCall.h"
|
||||
|
||||
#ifndef _UNICODE
|
||||
extern bool g_IsNT;
|
||||
#endif _UNICODE
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
#define MY_TRY_BEGIN try {
|
||||
#define MY_TRY_FINISH } \
|
||||
catch(...) { ErrorMessageHRESULT(E_FAIL); return E_FAIL; }
|
||||
|
||||
static LPCWSTR kShowDialogSwitch = L" -ad";
|
||||
static LPCWSTR kEmailSwitch = L" -seml.";
|
||||
static LPCWSTR kMapSwitch = L" -i#";
|
||||
static LPCWSTR kArchiveNoNameSwitch = L" -an";
|
||||
static LPCWSTR kIncludeSwitch = L" -i";
|
||||
static LPCWSTR kArchiveTypeSwitch = L" -t";
|
||||
static LPCWSTR kArchiveMapSwitch = L" -ai#";
|
||||
static LPCWSTR kArcIncludeSwitches = L" -an -ai";
|
||||
static LPCWSTR kStopSwitchParsing = L" --";
|
||||
static LPCWSTR kLargePagesDisable = L" -slp-";
|
||||
|
||||
UString GetQuotedString(const UString &s)
|
||||
{
|
||||
return UString(L'\"') + s + UString(L'\"');
|
||||
}
|
||||
static void ErrorMessage(LPCWSTR message)
|
||||
{
|
||||
MessageBoxW(g_HWND, message, L"7-Zip", MB_ICONERROR | MB_OK);
|
||||
}
|
||||
|
||||
static void ErrorMessageHRESULT(HRESULT res, LPCWSTR s = NULL)
|
||||
{
|
||||
UString s2 = HResultToMessage(res);
|
||||
if (s)
|
||||
{
|
||||
s2 += L'\n';
|
||||
s2 += s;
|
||||
}
|
||||
ErrorMessage(s2);
|
||||
}
|
||||
|
||||
static HRESULT MyCreateProcess(LPCWSTR imageName, const UString ¶ms,
|
||||
LPCWSTR curDir, bool waitFinish,
|
||||
NSynchronization::CBaseEvent *event)
|
||||
{
|
||||
CProcess process;
|
||||
WRes res = process.Create(imageName, params, curDir);
|
||||
if (res != 0)
|
||||
{
|
||||
ErrorMessageHRESULT(res, imageName);
|
||||
return res;
|
||||
}
|
||||
if (waitFinish)
|
||||
process.Wait();
|
||||
else if (event != NULL)
|
||||
{
|
||||
HANDLE handles[] = { process, *event };
|
||||
::WaitForMultipleObjects(sizeof(handles) / sizeof(handles[0]), handles, FALSE, INFINITE);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static void AddLagePagesSwitch(UString ¶ms)
|
||||
{
|
||||
if (!ReadLockMemoryEnable())
|
||||
params += kLargePagesDisable;
|
||||
}
|
||||
|
||||
HRESULT MyCreateProcess(const UString ¶ms,
|
||||
LPCWSTR curDir, bool waitFinish,
|
||||
NWindows::NSynchronization::CBaseEvent *event)
|
||||
{
|
||||
const UString params2 = params;
|
||||
PROCESS_INFORMATION processInformation;
|
||||
BOOL result;
|
||||
#ifndef _UNICODE
|
||||
if (!g_IsNT)
|
||||
{
|
||||
STARTUPINFOA startupInfo;
|
||||
startupInfo.cb = sizeof(startupInfo);
|
||||
startupInfo.lpReserved = 0;
|
||||
startupInfo.lpDesktop = 0;
|
||||
startupInfo.lpTitle = 0;
|
||||
startupInfo.dwFlags = 0;
|
||||
startupInfo.cbReserved2 = 0;
|
||||
startupInfo.lpReserved2 = 0;
|
||||
|
||||
CSysString curDirA;
|
||||
if (curDir != 0)
|
||||
curDirA = GetSystemString(curDir);
|
||||
result = ::CreateProcessA(NULL, (LPSTR)(LPCSTR)GetSystemString(params),
|
||||
NULL, NULL, FALSE, 0, NULL,
|
||||
((curDir != 0) ? (LPCSTR)curDirA: 0),
|
||||
&startupInfo, &processInformation);
|
||||
}
|
||||
else
|
||||
#endif
|
||||
{
|
||||
STARTUPINFOW startupInfo;
|
||||
startupInfo.cb = sizeof(startupInfo);
|
||||
startupInfo.lpReserved = 0;
|
||||
startupInfo.lpDesktop = 0;
|
||||
startupInfo.lpTitle = 0;
|
||||
startupInfo.dwFlags = 0;
|
||||
startupInfo.cbReserved2 = 0;
|
||||
startupInfo.lpReserved2 = 0;
|
||||
|
||||
result = ::CreateProcessW(NULL, (LPWSTR)(LPCWSTR)params,
|
||||
NULL, NULL, FALSE, 0, NULL,
|
||||
curDir,
|
||||
&startupInfo, &processInformation);
|
||||
}
|
||||
if (result == 0)
|
||||
return ::GetLastError();
|
||||
else
|
||||
{
|
||||
::CloseHandle(processInformation.hThread);
|
||||
if (waitFinish)
|
||||
WaitForSingleObject(processInformation.hProcess, INFINITE);
|
||||
else if (event != NULL)
|
||||
{
|
||||
HANDLE handles[] = {processInformation.hProcess, *event };
|
||||
::WaitForMultipleObjects(sizeof(handles) / sizeof(handles[0]),
|
||||
handles, FALSE, INFINITE);
|
||||
}
|
||||
::CloseHandle(processInformation.hProcess);
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static UString GetQuotedString(const UString &s)
|
||||
{
|
||||
return UString(L"\"") + s + UString(L"\"");
|
||||
}
|
||||
|
||||
static UString Get7zGuiPath()
|
||||
{
|
||||
UString path;
|
||||
UString folder;
|
||||
if (GetProgramFolderPath(folder))
|
||||
path += folder;
|
||||
path += L"7zG.exe";
|
||||
return GetQuotedString(path);
|
||||
GetProgramFolderPath(path);
|
||||
return path + L"7zG.exe";
|
||||
}
|
||||
|
||||
static HRESULT CreateTempEvent(const wchar_t *name,
|
||||
NSynchronization::CManualResetEvent &event, UString &eventName)
|
||||
class CRandNameGenerator
|
||||
{
|
||||
CRandom random;
|
||||
random.Init(GetTickCount());
|
||||
for (;;)
|
||||
CRandom _random;
|
||||
public:
|
||||
CRandNameGenerator() { _random.Init(); }
|
||||
UString GenerateName()
|
||||
{
|
||||
int number = random.Generate();
|
||||
wchar_t temp[16];
|
||||
ConvertUInt32ToString((UInt32)number, temp);
|
||||
eventName = name;
|
||||
eventName += temp;
|
||||
RINOK(event.CreateWithName(false, GetSystemString(eventName)));
|
||||
if (::GetLastError() != ERROR_ALREADY_EXISTS)
|
||||
return S_OK;
|
||||
event.Close();
|
||||
ConvertUInt32ToString((UInt32)_random.Generate(), temp);
|
||||
return temp;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
static HRESULT CreateMap(const UStringVector &names,
|
||||
const UString &id,
|
||||
CFileMapping &fileMapping, NSynchronization::CManualResetEvent &event,
|
||||
UString ¶ms)
|
||||
{
|
||||
UInt32 extraSize = 2;
|
||||
UInt32 dataSize = 0;
|
||||
UInt32 totalSize = 1;
|
||||
for (int i = 0; i < names.Size(); i++)
|
||||
dataSize += (names[i].Length() + 1) * sizeof(wchar_t);
|
||||
UInt32 totalSize = extraSize + dataSize;
|
||||
totalSize += (names[i].Length() + 1);
|
||||
totalSize *= sizeof(wchar_t);
|
||||
|
||||
CRandNameGenerator random;
|
||||
|
||||
UString mappingName;
|
||||
|
||||
CRandom random;
|
||||
random.Init(GetTickCount());
|
||||
for (;;)
|
||||
{
|
||||
int number = random.Generate();
|
||||
wchar_t temp[16];
|
||||
ConvertUInt32ToString(UInt32(number), temp);
|
||||
mappingName = id;
|
||||
mappingName += L"Mapping";
|
||||
mappingName += temp;
|
||||
if (!fileMapping.Create(INVALID_HANDLE_VALUE, NULL,
|
||||
PAGE_READWRITE, totalSize, GetSystemString(mappingName)))
|
||||
return E_FAIL;
|
||||
if (::GetLastError() != ERROR_ALREADY_EXISTS)
|
||||
mappingName = L"7zMap" + random.GenerateName();
|
||||
|
||||
WRes res = fileMapping.Create(PAGE_READWRITE, totalSize, GetSystemString(mappingName));
|
||||
if (fileMapping.IsCreated() && res == 0)
|
||||
break;
|
||||
if (res != ERROR_ALREADY_EXISTS)
|
||||
return res;
|
||||
fileMapping.Close();
|
||||
}
|
||||
|
||||
UString eventName;
|
||||
RINOK(CreateTempEvent(id + L"MappingEndEvent", event, eventName));
|
||||
for (;;)
|
||||
{
|
||||
eventName = L"7zEvent" + random.GenerateName();
|
||||
WRes res = event.CreateWithName(false, GetSystemString(eventName));
|
||||
if (event.IsCreated() && res == 0)
|
||||
break;
|
||||
if (res != ERROR_ALREADY_EXISTS)
|
||||
return res;
|
||||
event.Close();
|
||||
}
|
||||
|
||||
params += L'#';
|
||||
params += mappingName;
|
||||
params += L":";
|
||||
wchar_t string[16];
|
||||
ConvertUInt32ToString(totalSize, string);
|
||||
params += string;
|
||||
params += L':';
|
||||
wchar_t temp[16];
|
||||
ConvertUInt32ToString(totalSize, temp);
|
||||
params += temp;
|
||||
|
||||
params += L":";
|
||||
params += L':';
|
||||
params += eventName;
|
||||
|
||||
LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_WRITE, 0, totalSize);
|
||||
LPVOID data = fileMapping.Map(FILE_MAP_WRITE, 0, totalSize);
|
||||
if (data == NULL)
|
||||
return E_FAIL;
|
||||
CFileUnmapper unmapper(data);
|
||||
{
|
||||
wchar_t *curData = (wchar_t *)data;
|
||||
*curData = 0;
|
||||
curData++;
|
||||
wchar_t *cur = (wchar_t *)data;
|
||||
*cur++ = 0;
|
||||
for (int i = 0; i < names.Size(); i++)
|
||||
{
|
||||
const UString &s = names[i];
|
||||
memcpy(curData, (const wchar_t *)s, s.Length() * sizeof(wchar_t));
|
||||
curData += s.Length();
|
||||
*curData++ = L'\0';
|
||||
int len = s.Length() + 1;
|
||||
memcpy(cur, (const wchar_t *)s, len * sizeof(wchar_t));
|
||||
cur += len;
|
||||
}
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CompressFiles(
|
||||
const UString &curDir,
|
||||
const UString &archiveName,
|
||||
const UString &archiveType,
|
||||
const UString &arcPathPrefix,
|
||||
const UString &arcName,
|
||||
const UString &arcType,
|
||||
const UStringVector &names,
|
||||
// const UString &outFolder,
|
||||
bool email,
|
||||
bool showDialog,
|
||||
bool waitFinish)
|
||||
bool email, bool showDialog, bool waitFinish)
|
||||
{
|
||||
/*
|
||||
UString curDir;
|
||||
if (names.Size() > 0)
|
||||
{
|
||||
NFile::NDirectory::GetOnlyDirPrefix(names[0], curDir);
|
||||
}
|
||||
*/
|
||||
UString params;
|
||||
params = Get7zGuiPath();
|
||||
params += L" a";
|
||||
params += kMapSwitch;
|
||||
// params += _fileNames[0];
|
||||
|
||||
UInt32 extraSize = 2;
|
||||
UInt32 dataSize = 0;
|
||||
for (int i = 0; i < names.Size(); i++)
|
||||
dataSize += (names[i].Length() + 1) * sizeof(wchar_t);
|
||||
UInt32 totalSize = extraSize + dataSize;
|
||||
|
||||
UString mappingName;
|
||||
MY_TRY_BEGIN
|
||||
UString params = L'a';
|
||||
|
||||
CFileMapping fileMapping;
|
||||
CRandom random;
|
||||
random.Init(GetTickCount());
|
||||
for (;;)
|
||||
{
|
||||
int number = random.Generate();
|
||||
wchar_t temp[16];
|
||||
ConvertUInt32ToString(UInt32(number), temp);
|
||||
mappingName = L"7zCompressMapping";
|
||||
mappingName += temp;
|
||||
if (!fileMapping.Create(INVALID_HANDLE_VALUE, NULL,
|
||||
PAGE_READWRITE, totalSize, GetSystemString(mappingName)))
|
||||
{
|
||||
// MyMessageBox(IDS_ERROR, 0x02000605);
|
||||
return E_FAIL;
|
||||
}
|
||||
if (::GetLastError() != ERROR_ALREADY_EXISTS)
|
||||
break;
|
||||
fileMapping.Close();
|
||||
}
|
||||
|
||||
NSynchronization::CManualResetEvent event;
|
||||
UString eventName;
|
||||
RINOK(CreateTempEvent(L"7zCompressMappingEndEvent", event, eventName));
|
||||
params += kIncludeSwitch;
|
||||
RINOK(CreateMap(names, fileMapping, event, params));
|
||||
|
||||
params += mappingName;
|
||||
params += L":";
|
||||
wchar_t string[16];
|
||||
ConvertUInt32ToString(totalSize, string);
|
||||
params += string;
|
||||
|
||||
params += L":";
|
||||
params += eventName;
|
||||
|
||||
if (!archiveType.IsEmpty())
|
||||
if (!arcType.IsEmpty())
|
||||
{
|
||||
params += kArchiveTypeSwitch;
|
||||
params += archiveType;
|
||||
params += arcType;
|
||||
}
|
||||
|
||||
if (email)
|
||||
@@ -274,71 +192,33 @@ HRESULT CompressFiles(
|
||||
AddLagePagesSwitch(params);
|
||||
|
||||
params += kStopSwitchParsing;
|
||||
params += L" ";
|
||||
params += L' ';
|
||||
|
||||
params += GetQuotedString(archiveName);
|
||||
params += GetQuotedString(
|
||||
#ifdef UNDER_CE
|
||||
arcPathPrefix +
|
||||
#endif
|
||||
arcName);
|
||||
|
||||
LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_WRITE, 0, totalSize);
|
||||
if (data == NULL)
|
||||
{
|
||||
// MyMessageBox(IDS_ERROR, 0x02000605);
|
||||
return E_FAIL;
|
||||
}
|
||||
try
|
||||
{
|
||||
wchar_t *curData = (wchar_t *)data;
|
||||
*curData = 0;
|
||||
curData++;
|
||||
for (int i = 0; i < names.Size(); i++)
|
||||
{
|
||||
const UString &unicodeString = names[i];
|
||||
memcpy(curData, (const wchar_t *)unicodeString ,
|
||||
unicodeString .Length() * sizeof(wchar_t));
|
||||
curData += unicodeString.Length();
|
||||
*curData++ = L'\0';
|
||||
}
|
||||
// MessageBox(0, params, 0, 0);
|
||||
RINOK(MyCreateProcess(params,
|
||||
(curDir.IsEmpty()? 0: (LPCWSTR)curDir),
|
||||
waitFinish, &event));
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
UnmapViewOfFile(data);
|
||||
throw;
|
||||
}
|
||||
UnmapViewOfFile(data);
|
||||
|
||||
|
||||
/*
|
||||
CThreadCompressMain *compressor = new CThreadCompressMain();;
|
||||
compressor->FileNames = _fileNames;
|
||||
CThread thread;
|
||||
if (!thread.Create(CThreadCompressMain::MyThreadFunction, compressor))
|
||||
throw 271824;
|
||||
*/
|
||||
return S_OK;
|
||||
return MyCreateProcess(Get7zGuiPath(), params,
|
||||
(arcPathPrefix.IsEmpty()? 0: (LPCWSTR)arcPathPrefix), waitFinish, &event);
|
||||
MY_TRY_FINISH
|
||||
}
|
||||
|
||||
static HRESULT ExtractGroupCommand(const UStringVector &archivePaths,
|
||||
const UString ¶ms)
|
||||
static HRESULT ExtractGroupCommand(const UStringVector &arcPaths, UString ¶ms)
|
||||
{
|
||||
UString params2 = params;
|
||||
AddLagePagesSwitch(params2);
|
||||
params2 += kArchiveNoNameSwitch;
|
||||
params2 += kArchiveMapSwitch;
|
||||
AddLagePagesSwitch(params);
|
||||
params += kArcIncludeSwitches;
|
||||
CFileMapping fileMapping;
|
||||
NSynchronization::CManualResetEvent event;
|
||||
RINOK(CreateMap(archivePaths, L"7zExtract", fileMapping, event, params2));
|
||||
return MyCreateProcess(params2, 0, false, &event);
|
||||
RINOK(CreateMap(arcPaths, fileMapping, event, params));
|
||||
return MyCreateProcess(Get7zGuiPath(), params, 0, false, &event);
|
||||
}
|
||||
|
||||
HRESULT ExtractArchives(const UStringVector &archivePaths,
|
||||
const UString &outFolder, bool showDialog)
|
||||
HRESULT ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog)
|
||||
{
|
||||
UString params;
|
||||
params = Get7zGuiPath();
|
||||
params += L" x";
|
||||
MY_TRY_BEGIN
|
||||
UString params = L'x';
|
||||
if (!outFolder.IsEmpty())
|
||||
{
|
||||
params += L" -o";
|
||||
@@ -346,21 +226,21 @@ HRESULT ExtractArchives(const UStringVector &archivePaths,
|
||||
}
|
||||
if (showDialog)
|
||||
params += kShowDialogSwitch;
|
||||
return ExtractGroupCommand(archivePaths, params);
|
||||
return ExtractGroupCommand(arcPaths, params);
|
||||
MY_TRY_FINISH
|
||||
}
|
||||
|
||||
HRESULT TestArchives(const UStringVector &archivePaths)
|
||||
HRESULT TestArchives(const UStringVector &arcPaths)
|
||||
{
|
||||
UString params;
|
||||
params = Get7zGuiPath();
|
||||
params += L" t";
|
||||
return ExtractGroupCommand(archivePaths, params);
|
||||
MY_TRY_BEGIN
|
||||
UString params = L't';
|
||||
return ExtractGroupCommand(arcPaths, params);
|
||||
MY_TRY_FINISH
|
||||
}
|
||||
|
||||
HRESULT Benchmark()
|
||||
{
|
||||
UString params;
|
||||
params = Get7zGuiPath();
|
||||
params += L" b";
|
||||
return MyCreateProcess(params, 0, false, NULL);
|
||||
MY_TRY_BEGIN
|
||||
return MyCreateProcess(Get7zGuiPath(), L'b', 0, false, NULL);
|
||||
MY_TRY_FINISH
|
||||
}
|
||||
|
||||
@@ -1,30 +1,24 @@
|
||||
// CompressCall.h
|
||||
|
||||
#ifndef __COMPRESSCALL_H
|
||||
#define __COMPRESSCALL_H
|
||||
#ifndef __COMPRESS_CALL_H
|
||||
#define __COMPRESS_CALL_H
|
||||
|
||||
#include "Common/MyString.h"
|
||||
#include "Windows/Synchronization.h"
|
||||
|
||||
HRESULT MyCreateProcess(const UString ¶ms,
|
||||
LPCWSTR lpCurrentDirectory, bool waitFinish,
|
||||
NWindows::NSynchronization::CBaseEvent *event);
|
||||
UString GetQuotedString(const UString &s);
|
||||
|
||||
extern HWND g_HWND;
|
||||
UString HResultToMessage(HRESULT errorCode);
|
||||
|
||||
HRESULT CompressFiles(
|
||||
const UString &curDir,
|
||||
const UString &archiveName,
|
||||
const UString &archiveType,
|
||||
const UString &arcPathPrefix,
|
||||
const UString &arcName,
|
||||
const UString &arcType,
|
||||
const UStringVector &names,
|
||||
// const UString &outFolder,
|
||||
bool email, bool showDialog, bool waitFinish);
|
||||
|
||||
HRESULT ExtractArchives(
|
||||
const UStringVector &archivePaths,
|
||||
const UString &outFolder, bool showDialog);
|
||||
|
||||
HRESULT TestArchives(const UStringVector &archivePaths);
|
||||
|
||||
HRESULT ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog);
|
||||
HRESULT TestArchives(const UStringVector &arcPaths);
|
||||
HRESULT Benchmark();
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
173
CPP/7zip/UI/Common/CompressCall2.cpp
Executable file
173
CPP/7zip/UI/Common/CompressCall2.cpp
Executable file
@@ -0,0 +1,173 @@
|
||||
// CompressCall.cpp
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Common/MyException.h"
|
||||
|
||||
#include "../../UI/common/ArchiveCommandLine.h"
|
||||
|
||||
#include "../../UI/GUI/BenchmarkDialog.h"
|
||||
#include "../../UI/GUI/ExtractGUI.h"
|
||||
#include "../../UI/GUI/UpdateGUI.h"
|
||||
|
||||
#include "../../UI/GUI/ExtractRes.h"
|
||||
|
||||
#include "CompressCall.h"
|
||||
|
||||
#define MY_TRY_BEGIN try {
|
||||
#define MY_TRY_FINISH } \
|
||||
catch(CSystemException &e) { result = e.ErrorCode; } \
|
||||
catch(...) { result = E_FAIL; } \
|
||||
if (result != S_OK && result != E_ABORT) \
|
||||
ErrorMessageHRESULT(result);
|
||||
|
||||
#define CREATE_CODECS \
|
||||
CCodecs *codecs = new CCodecs; \
|
||||
CMyComPtr<IUnknown> compressCodecsInfo = codecs; \
|
||||
result = codecs->Load(); \
|
||||
if (result != S_OK) \
|
||||
throw CSystemException(result);
|
||||
|
||||
UString GetQuotedString(const UString &s)
|
||||
{
|
||||
return UString(L'\"') + s + UString(L'\"');
|
||||
}
|
||||
|
||||
static void ErrorMessage(LPCWSTR message)
|
||||
{
|
||||
MessageBoxW(g_HWND, message, L"7-Zip", MB_ICONERROR);
|
||||
}
|
||||
|
||||
static void ErrorMessageHRESULT(HRESULT res)
|
||||
{
|
||||
ErrorMessage(HResultToMessage(res));
|
||||
}
|
||||
|
||||
static void ErrorLangMessage(UINT resourceID, UInt32 langID)
|
||||
{
|
||||
ErrorMessage(LangString(resourceID, langID));
|
||||
}
|
||||
|
||||
HRESULT CompressFiles(
|
||||
const UString &arcPathPrefix,
|
||||
const UString &arcName,
|
||||
const UString &arcType,
|
||||
const UStringVector &names,
|
||||
bool email, bool showDialog, bool /* waitFinish */)
|
||||
{
|
||||
HRESULT result;
|
||||
MY_TRY_BEGIN
|
||||
CREATE_CODECS
|
||||
|
||||
CUpdateCallbackGUI callback;
|
||||
|
||||
callback.Init();
|
||||
|
||||
CUpdateOptions uo;
|
||||
uo.EMailMode = email;
|
||||
uo.SetAddActionCommand();
|
||||
|
||||
CIntVector formatIndices;
|
||||
if (!codecs->FindFormatForArchiveType(arcType, formatIndices))
|
||||
{
|
||||
ErrorLangMessage(IDS_UNSUPPORTED_ARCHIVE_TYPE, 0x0200060D);
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!uo.Init(codecs, formatIndices, arcPathPrefix + arcName))
|
||||
{
|
||||
ErrorLangMessage(IDS_UPDATE_NOT_SUPPORTED, 0x02000601);
|
||||
return E_FAIL;
|
||||
}
|
||||
|
||||
NWildcard::CCensor censor;
|
||||
for (int i = 0; i < names.Size(); i++)
|
||||
censor.AddItem(true, names[i], false);
|
||||
|
||||
bool messageWasDisplayed = false;
|
||||
result = UpdateGUI(codecs, censor, uo, showDialog, messageWasDisplayed, &callback, g_HWND);
|
||||
|
||||
if (result != S_OK)
|
||||
{
|
||||
if (result != E_ABORT && messageWasDisplayed)
|
||||
return E_FAIL;
|
||||
throw CSystemException(result);
|
||||
}
|
||||
if (callback.FailedFiles.Size() > 0)
|
||||
{
|
||||
if (!messageWasDisplayed)
|
||||
throw CSystemException(E_FAIL);
|
||||
return E_FAIL;
|
||||
}
|
||||
MY_TRY_FINISH
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
static HRESULT ExtractGroupCommand(const UStringVector &arcPaths,
|
||||
bool showDialog, const UString &outFolder, bool testMode)
|
||||
{
|
||||
HRESULT result;
|
||||
MY_TRY_BEGIN
|
||||
CREATE_CODECS
|
||||
|
||||
CExtractOptions eo;
|
||||
eo.OutputDir = outFolder;
|
||||
eo.TestMode = testMode;
|
||||
|
||||
CExtractCallbackImp *ecs = new CExtractCallbackImp;
|
||||
CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;
|
||||
|
||||
ecs->Init();
|
||||
|
||||
// eo.CalcCrc = options.CalcCrc;
|
||||
|
||||
UStringVector arcPathsSorted;
|
||||
UStringVector arcFullPathsSorted;
|
||||
{
|
||||
NWildcard::CCensor acrCensor;
|
||||
for (int i = 0; i < arcPaths.Size(); i++)
|
||||
acrCensor.AddItem(true, arcPaths[i], false);
|
||||
EnumerateDirItemsAndSort(acrCensor, arcPathsSorted, arcFullPathsSorted);
|
||||
}
|
||||
|
||||
CIntVector formatIndices;
|
||||
|
||||
NWildcard::CCensor censor;
|
||||
censor.AddItem(true, L"*", false);
|
||||
|
||||
bool messageWasDisplayed = false;
|
||||
result = ExtractGUI(codecs, formatIndices, arcPathsSorted, arcFullPathsSorted,
|
||||
censor.Pairs.Front().Head, eo, showDialog, messageWasDisplayed, ecs, g_HWND);
|
||||
if (result != S_OK)
|
||||
{
|
||||
if (result != E_ABORT && messageWasDisplayed)
|
||||
return E_FAIL;
|
||||
throw CSystemException(result);
|
||||
}
|
||||
return ecs->IsOK() ? S_OK : E_FAIL;
|
||||
MY_TRY_FINISH
|
||||
return result;
|
||||
}
|
||||
|
||||
HRESULT ExtractArchives(const UStringVector &arcPaths, const UString &outFolder, bool showDialog)
|
||||
{
|
||||
return ExtractGroupCommand(arcPaths, showDialog, outFolder, false);
|
||||
}
|
||||
|
||||
HRESULT TestArchives(const UStringVector &arcPaths)
|
||||
{
|
||||
return ExtractGroupCommand(arcPaths, true, UString(), true);
|
||||
}
|
||||
|
||||
HRESULT Benchmark()
|
||||
{
|
||||
HRESULT result;
|
||||
MY_TRY_BEGIN
|
||||
CREATE_CODECS
|
||||
result = Benchmark(
|
||||
#ifdef EXTERNAL_LZMA
|
||||
codecs,
|
||||
#endif
|
||||
(UInt32)-1, (UInt32)-1, g_HWND);
|
||||
MY_TRY_FINISH
|
||||
return result;
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
// HandlerLoader.h
|
||||
|
||||
#ifndef __HANDLERLOADER_H
|
||||
#define __HANDLERLOADER_H
|
||||
|
||||
#include "../../ICoder.h"
|
||||
#include "Windows/DLL.h"
|
||||
|
||||
typedef UInt32 (WINAPI * CreateObjectFunc)(
|
||||
const GUID *clsID,
|
||||
const GUID *interfaceID,
|
||||
void **outObject);
|
||||
|
||||
class CHandlerLoader: public NWindows::NDLL::CLibrary
|
||||
{
|
||||
public:
|
||||
HRESULT CreateHandler(LPCWSTR filepath, REFGUID clsID,
|
||||
void **archive, bool outHandler)
|
||||
{
|
||||
if (!Load(filepath))
|
||||
return GetLastError();
|
||||
CreateObjectFunc createObject = (CreateObjectFunc)
|
||||
GetProcAddress("CreateObject");
|
||||
if (createObject == NULL)
|
||||
{
|
||||
HRESULT res = ::GetLastError();
|
||||
Free();
|
||||
return res;
|
||||
}
|
||||
HRESULT res = createObject(&clsID,
|
||||
outHandler ? &IID_IOutArchive : &IID_IInArchive, (void **)archive);
|
||||
if (res != 0)
|
||||
Free();
|
||||
return res;
|
||||
}
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -111,12 +111,12 @@ static HRESULT GetCoderClass(GetMethodPropertyFunc getMethodProperty, UInt32 ind
|
||||
HRESULT CCodecs::LoadCodecs()
|
||||
{
|
||||
CCodecLib &lib = Libs.Back();
|
||||
lib.GetMethodProperty = (GetMethodPropertyFunc)lib.Lib.GetProcAddress("GetMethodProperty");
|
||||
lib.GetMethodProperty = (GetMethodPropertyFunc)lib.Lib.GetProc("GetMethodProperty");
|
||||
if (lib.GetMethodProperty == NULL)
|
||||
return S_OK;
|
||||
|
||||
UInt32 numMethods = 1;
|
||||
GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)lib.Lib.GetProcAddress("GetNumberOfMethods");
|
||||
GetNumberOfMethodsFunc getNumberOfMethodsFunc = (GetNumberOfMethodsFunc)lib.Lib.GetProc("GetNumberOfMethods");
|
||||
if (getNumberOfMethodsFunc != NULL)
|
||||
{
|
||||
RINOK(getNumberOfMethodsFunc(&numMethods));
|
||||
@@ -210,10 +210,11 @@ static void SplitString(const UString &srcString, UStringVector &destStrings)
|
||||
destStrings.Add(s);
|
||||
}
|
||||
|
||||
void CArcInfoEx::AddExts(const wchar_t* ext, const wchar_t* addExt)
|
||||
void CArcInfoEx::AddExts(const wchar_t *ext, const wchar_t *addExt)
|
||||
{
|
||||
UStringVector exts, addExts;
|
||||
SplitString(ext, exts);
|
||||
if (ext != 0)
|
||||
SplitString(ext, exts);
|
||||
if (addExt != 0)
|
||||
SplitString(addExt, addExts);
|
||||
for (int i = 0; i < exts.Size(); i++)
|
||||
@@ -236,19 +237,16 @@ HRESULT CCodecs::LoadFormats()
|
||||
{
|
||||
const NDLL::CLibrary &lib = Libs.Back().Lib;
|
||||
GetHandlerPropertyFunc getProp = 0;
|
||||
GetHandlerPropertyFunc2 getProp2 = (GetHandlerPropertyFunc2)
|
||||
lib.GetProcAddress("GetHandlerProperty2");
|
||||
GetHandlerPropertyFunc2 getProp2 = (GetHandlerPropertyFunc2)lib.GetProc("GetHandlerProperty2");
|
||||
if (getProp2 == NULL)
|
||||
{
|
||||
getProp = (GetHandlerPropertyFunc)
|
||||
lib.GetProcAddress("GetHandlerProperty");
|
||||
getProp = (GetHandlerPropertyFunc)lib.GetProc("GetHandlerProperty");
|
||||
if (getProp == NULL)
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
UInt32 numFormats = 1;
|
||||
GetNumberOfFormatsFunc getNumberOfFormats = (GetNumberOfFormatsFunc)
|
||||
lib.GetProcAddress("GetNumberOfFormats");
|
||||
GetNumberOfFormatsFunc getNumberOfFormats = (GetNumberOfFormatsFunc)lib.GetProc("GetNumberOfFormats");
|
||||
if (getNumberOfFormats != NULL)
|
||||
{
|
||||
RINOK(getNumberOfFormats(&numFormats));
|
||||
@@ -294,37 +292,48 @@ HRESULT CCodecs::LoadFormats()
|
||||
}
|
||||
|
||||
#ifdef NEW_FOLDER_INTERFACE
|
||||
void CCodecLib::LoadIcons()
|
||||
void CCodecIcons::LoadIcons(HMODULE m)
|
||||
{
|
||||
UString iconTypes = MyLoadStringW((HMODULE)Lib, kIconTypesResId);
|
||||
UString iconTypes = MyLoadStringW(m, kIconTypesResId);
|
||||
UStringVector pairs;
|
||||
SplitString(iconTypes, pairs);
|
||||
for (int i = 0; i < pairs.Size(); i++)
|
||||
{
|
||||
const UString &s = pairs[i];
|
||||
int pos = s.Find(L':');
|
||||
if (pos < 0)
|
||||
continue;
|
||||
CIconPair iconPair;
|
||||
const wchar_t *end;
|
||||
UString num = s.Mid(pos + 1);
|
||||
iconPair.IconIndex = (UInt32)ConvertStringToUInt64(num, &end);
|
||||
if (*end != L'\0')
|
||||
continue;
|
||||
iconPair.IconIndex = -1;
|
||||
if (pos < 0)
|
||||
pos = s.Length();
|
||||
else
|
||||
{
|
||||
UString num = s.Mid(pos + 1);
|
||||
if (!num.IsEmpty())
|
||||
{
|
||||
const wchar_t *end;
|
||||
iconPair.IconIndex = (UInt32)ConvertStringToUInt64(num, &end);
|
||||
if (*end != L'\0')
|
||||
continue;
|
||||
}
|
||||
}
|
||||
iconPair.Ext = s.Left(pos);
|
||||
IconPairs.Add(iconPair);
|
||||
}
|
||||
}
|
||||
|
||||
int CCodecLib::FindIconIndex(const UString &ext) const
|
||||
bool CCodecIcons::FindIconIndex(const UString &ext, int &iconIndex) const
|
||||
{
|
||||
iconIndex = -1;
|
||||
for (int i = 0; i < IconPairs.Size(); i++)
|
||||
{
|
||||
const CIconPair &pair = IconPairs[i];
|
||||
if (ext.CompareNoCase(pair.Ext) == 0)
|
||||
return pair.IconIndex;
|
||||
{
|
||||
iconIndex = pair.IconIndex;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -335,8 +344,9 @@ extern "C"
|
||||
}
|
||||
#endif
|
||||
|
||||
HRESULT CCodecs::LoadDll(const CSysString &dllPath)
|
||||
HRESULT CCodecs::LoadDll(const CSysString &dllPath, bool needCheckDll)
|
||||
{
|
||||
if (needCheckDll)
|
||||
{
|
||||
NDLL::CLibrary library;
|
||||
if (!library.LoadEx(dllPath, LOAD_LIBRARY_AS_DATAFILE))
|
||||
@@ -358,13 +368,13 @@ HRESULT CCodecs::LoadDll(const CSysString &dllPath)
|
||||
#ifdef _7ZIP_LARGE_PAGES
|
||||
if (g_LargePageSize != 0)
|
||||
{
|
||||
SetLargePageModeFunc setLargePageMode = (SetLargePageModeFunc)lib.Lib.GetProcAddress("SetLargePageMode");
|
||||
SetLargePageModeFunc setLargePageMode = (SetLargePageModeFunc)lib.Lib.GetProc("SetLargePageMode");
|
||||
if (setLargePageMode != 0)
|
||||
setLargePageMode();
|
||||
}
|
||||
#endif
|
||||
|
||||
lib.CreateObject = (CreateObjectFunc)lib.Lib.GetProcAddress("CreateObject");
|
||||
lib.CreateObject = (CreateObjectFunc)lib.Lib.GetProc("CreateObject");
|
||||
if (lib.CreateObject != 0)
|
||||
{
|
||||
int startSize = Codecs.Size();
|
||||
@@ -391,7 +401,7 @@ HRESULT CCodecs::LoadDllsFromFolder(const CSysString &folderPrefix)
|
||||
{
|
||||
if (fi.IsDir())
|
||||
continue;
|
||||
RINOK(LoadDll(folderPrefix + fi.Name));
|
||||
RINOK(LoadDll(folderPrefix + fi.Name, true));
|
||||
}
|
||||
return S_OK;
|
||||
}
|
||||
@@ -408,6 +418,10 @@ static inline void SetBuffer(CByteBuffer &bb, const Byte *data, int size)
|
||||
|
||||
HRESULT CCodecs::Load()
|
||||
{
|
||||
#ifdef NEW_FOLDER_INTERFACE
|
||||
InternalIcons.LoadIcons(g_hInstance);
|
||||
#endif
|
||||
|
||||
Formats.Clear();
|
||||
#ifdef EXTERNAL_CODECS
|
||||
Codecs.Clear();
|
||||
@@ -430,7 +444,7 @@ HRESULT CCodecs::Load()
|
||||
}
|
||||
#ifdef EXTERNAL_CODECS
|
||||
const CSysString baseFolder = GetBaseFolderPrefixFromRegistry();
|
||||
RINOK(LoadDll(baseFolder + kMainDll));
|
||||
RINOK(LoadDll(baseFolder + kMainDll, false));
|
||||
RINOK(LoadDllsFromFolder(baseFolder + kCodecsFolderName TEXT(STRING_PATH_SEPARATOR)));
|
||||
RINOK(LoadDllsFromFolder(baseFolder + kFormatsFolderName TEXT(STRING_PATH_SEPARATOR)));
|
||||
#endif
|
||||
|
||||
@@ -102,21 +102,31 @@ typedef UInt32 (WINAPI *GetMethodPropertyFunc)(UInt32 index, PROPID propID, PROP
|
||||
typedef UInt32 (WINAPI *CreateObjectFunc)(const GUID *clsID, const GUID *interfaceID, void **outObject);
|
||||
|
||||
|
||||
#ifdef NEW_FOLDER_INTERFACE
|
||||
struct CCodecIcons
|
||||
{
|
||||
struct CIconPair
|
||||
{
|
||||
UString Ext;
|
||||
int IconIndex;
|
||||
};
|
||||
CObjectVector<CIconPair> IconPairs;
|
||||
void LoadIcons(HMODULE m);
|
||||
bool FindIconIndex(const UString &ext, int &iconIndex) const;
|
||||
};
|
||||
#endif
|
||||
|
||||
struct CCodecLib
|
||||
#ifdef NEW_FOLDER_INTERFACE
|
||||
: public CCodecIcons
|
||||
#endif
|
||||
{
|
||||
NWindows::NDLL::CLibrary Lib;
|
||||
GetMethodPropertyFunc GetMethodProperty;
|
||||
CreateObjectFunc CreateObject;
|
||||
#ifdef NEW_FOLDER_INTERFACE
|
||||
struct CIconPair
|
||||
{
|
||||
UString Ext;
|
||||
UInt32 IconIndex;
|
||||
};
|
||||
CSysString Path;
|
||||
CObjectVector<CIconPair> IconPairs;
|
||||
void LoadIcons();
|
||||
int FindIconIndex(const UString &ext) const;
|
||||
void LoadIcons() { CCodecIcons::LoadIcons((HMODULE)Lib); }
|
||||
#endif
|
||||
CCodecLib(): GetMethodProperty(0) {}
|
||||
};
|
||||
@@ -134,9 +144,14 @@ public:
|
||||
#ifdef EXTERNAL_CODECS
|
||||
CObjectVector<CCodecLib> Libs;
|
||||
CObjectVector<CDllCodecInfo> Codecs;
|
||||
|
||||
#ifdef NEW_FOLDER_INTERFACE
|
||||
CCodecIcons InternalIcons;
|
||||
#endif
|
||||
|
||||
HRESULT LoadCodecs();
|
||||
HRESULT LoadFormats();
|
||||
HRESULT LoadDll(const CSysString &path);
|
||||
HRESULT LoadDll(const CSysString &path, bool needCheckDll);
|
||||
HRESULT LoadDllsFromFolder(const CSysString &folderPrefix);
|
||||
|
||||
HRESULT CreateArchiveHandler(const CArcInfoEx &ai, void **archive, bool outHandler) const
|
||||
|
||||
@@ -94,6 +94,15 @@ static inline bool TestSignature(const Byte *p1, const Byte *p2, size_t size)
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef UNDER_CE
|
||||
static const int kNumHashBytes = 1;
|
||||
#define HASH_VAL(buf, pos) ((buf)[pos])
|
||||
#else
|
||||
static const int kNumHashBytes = 2;
|
||||
#define HASH_VAL(buf, pos) ((buf)[pos] | ((UInt32)(buf)[pos + 1] << 8))
|
||||
#endif
|
||||
|
||||
|
||||
HRESULT CArc::OpenStream(
|
||||
CCodecs *codecs,
|
||||
int formatIndex,
|
||||
@@ -144,30 +153,33 @@ HRESULT CArc::OpenStream(
|
||||
return S_FALSE;
|
||||
|
||||
const Byte *buf = byteBuffer;
|
||||
Byte hash[1 << 16];
|
||||
memset(hash, 0xFF, 1 << 16);
|
||||
CByteBuffer hashBuffer;
|
||||
const UInt32 kNumVals = 1 << (kNumHashBytes * 8);
|
||||
hashBuffer.SetCapacity(kNumVals);
|
||||
Byte *hash = hashBuffer;
|
||||
memset(hash, 0xFF, kNumVals);
|
||||
Byte prevs[256];
|
||||
if (orderIndices.Size() > 255)
|
||||
if (orderIndices.Size() >= 256)
|
||||
return S_FALSE;
|
||||
int i;
|
||||
for (i = 0; i < orderIndices.Size(); i++)
|
||||
{
|
||||
const CArcInfoEx &ai = codecs->Formats[orderIndices[i]];
|
||||
const CByteBuffer &sig = ai.StartSignature;
|
||||
if (sig.GetCapacity() < 2)
|
||||
if (sig.GetCapacity() < kNumHashBytes)
|
||||
continue;
|
||||
UInt32 v = sig[0] | ((UInt32)sig[1] << 8);
|
||||
UInt32 v = HASH_VAL(sig, 0);
|
||||
prevs[i] = hash[v];
|
||||
hash[v] = (Byte)i;
|
||||
}
|
||||
|
||||
processedSize--;
|
||||
processedSize -= (kNumHashBytes - 1);
|
||||
for (UInt32 pos = 0; pos < processedSize; pos++)
|
||||
{
|
||||
for (; pos < processedSize && hash[buf[pos] | ((UInt32)buf[pos + 1] << 8)] == 0xFF; pos++);
|
||||
for (; pos < processedSize && hash[HASH_VAL(buf, pos)] == 0xFF; pos++);
|
||||
if (pos == processedSize)
|
||||
break;
|
||||
UInt32 v = buf[pos] | ((UInt32)buf[pos + 1] << 8);
|
||||
UInt32 v = HASH_VAL(buf, pos);
|
||||
Byte *ptr = &hash[v];
|
||||
int i = *ptr;
|
||||
do
|
||||
@@ -175,14 +187,15 @@ HRESULT CArc::OpenStream(
|
||||
int index = orderIndices[i];
|
||||
const CArcInfoEx &ai = codecs->Formats[index];
|
||||
const CByteBuffer &sig = ai.StartSignature;
|
||||
if (sig.GetCapacity() != 0 && pos + sig.GetCapacity() <= processedSize + 1)
|
||||
if (TestSignature(buf + pos, sig, sig.GetCapacity()))
|
||||
{
|
||||
orderIndices2.Add(index);
|
||||
orderIndices[i] = 0xFF;
|
||||
*ptr = prevs[i];
|
||||
}
|
||||
ptr = &prevs[i];
|
||||
if (sig.GetCapacity() != 0 && pos + sig.GetCapacity() <= processedSize + (kNumHashBytes - 1) &&
|
||||
TestSignature(buf + pos, sig, sig.GetCapacity()))
|
||||
{
|
||||
orderIndices2.Add(index);
|
||||
orderIndices[i] = 0xFF;
|
||||
*ptr = prevs[i];
|
||||
}
|
||||
else
|
||||
ptr = &prevs[i];
|
||||
i = *ptr;
|
||||
}
|
||||
while (i != 0xFF);
|
||||
@@ -323,6 +336,15 @@ HRESULT CArc::OpenStreamOrFile(
|
||||
stream = fileStream;
|
||||
}
|
||||
|
||||
/*
|
||||
if (callback)
|
||||
{
|
||||
UInt64 fileSize;
|
||||
RINOK(stream->Seek(0, STREAM_SEEK_END, &fileSize));
|
||||
RINOK(callback->SetTotal(NULL, &fileSize))
|
||||
}
|
||||
*/
|
||||
|
||||
return OpenStream(codecs, formatIndex, stream, seqStream, callback);
|
||||
}
|
||||
|
||||
|
||||
@@ -439,7 +439,7 @@ static HRESULT Compress(
|
||||
{
|
||||
errorInfo.SystemError = ::GetLastError();
|
||||
errorInfo.FileName = realPath;
|
||||
errorInfo.Message = L"Can not open file";
|
||||
errorInfo.Message = L"7-Zip cannot open file";
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
@@ -472,7 +472,7 @@ static HRESULT Compress(
|
||||
if (!sfxStreamSpec->Open(sfxModule))
|
||||
{
|
||||
errorInfo.SystemError = ::GetLastError();
|
||||
errorInfo.Message = L"Can't open sfx module";
|
||||
errorInfo.Message = L"7-Zip cannot open SFX module";
|
||||
errorInfo.FileName = sfxModule;
|
||||
return E_FAIL;
|
||||
}
|
||||
@@ -490,7 +490,7 @@ static HRESULT Compress(
|
||||
{
|
||||
errorInfo.SystemError = ::GetLastError();
|
||||
errorInfo.FileName = realPath;
|
||||
errorInfo.Message = L"Can not open file";
|
||||
errorInfo.Message = L"7-Zip cannot open file";
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
@@ -606,17 +606,14 @@ static HRESULT UpdateWithItemLists(
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#if defined(_WIN32) && !defined(UNDER_CE)
|
||||
class CCurrentDirRestorer
|
||||
{
|
||||
UString m_CurrentDirectory;
|
||||
UString _path;
|
||||
public:
|
||||
CCurrentDirRestorer()
|
||||
{ NFile::NDirectory::MyGetCurrentDirectory(m_CurrentDirectory); }
|
||||
~CCurrentDirRestorer()
|
||||
{ RestoreDirectory();}
|
||||
bool RestoreDirectory()
|
||||
{ return BOOLToBool(NFile::NDirectory::MySetCurrentDirectory(m_CurrentDirectory)); }
|
||||
CCurrentDirRestorer() { NFile::NDirectory::MyGetCurrentDirectory(_path); }
|
||||
~CCurrentDirRestorer() { RestoreDirectory();}
|
||||
bool RestoreDirectory() { return BOOLToBool(NFile::NDirectory::MySetCurrentDirectory(_path)); }
|
||||
};
|
||||
#endif
|
||||
|
||||
@@ -662,13 +659,19 @@ HRESULT UpdateArchive(
|
||||
options.MethodMode.Properties.Add(property);
|
||||
if (options.SfxModule.IsEmpty())
|
||||
{
|
||||
errorInfo.Message = L"sfx file is not specified";
|
||||
errorInfo.Message = L"SFX file is not specified";
|
||||
return E_FAIL;
|
||||
}
|
||||
UString name = options.SfxModule;
|
||||
#ifdef UNDER_CE
|
||||
if (!NFind::DoesFileExist(name))
|
||||
#else
|
||||
if (!NDirectory::MySearchPath(NULL, name, NULL, options.SfxModule))
|
||||
#endif
|
||||
{
|
||||
errorInfo.Message = L"can't find specified sfx module";
|
||||
errorInfo.SystemError = ::GetLastError();
|
||||
errorInfo.Message = L"7-Zip cannot find specified SFX module";
|
||||
errorInfo.FileName = name;
|
||||
return E_FAIL;
|
||||
}
|
||||
}
|
||||
@@ -744,7 +747,6 @@ HRESULT UpdateArchive(
|
||||
{
|
||||
if (res != E_ABORT)
|
||||
errorInfo.Message = L"Scanning error";
|
||||
// errorInfo.FileName = errorPath;
|
||||
return res;
|
||||
}
|
||||
RINOK(callback->FinishScanning());
|
||||
@@ -804,7 +806,7 @@ HRESULT UpdateArchive(
|
||||
if (NFind::DoesFileOrDirExist(path))
|
||||
{
|
||||
errorInfo.SystemError = 0;
|
||||
errorInfo.Message = L"File already exists";
|
||||
errorInfo.Message = L"The file already exists";
|
||||
errorInfo.FileName = path;
|
||||
return E_FAIL;
|
||||
}
|
||||
@@ -839,14 +841,14 @@ HRESULT UpdateArchive(
|
||||
if (!NDirectory::DeleteFileAlways(archiveName))
|
||||
{
|
||||
errorInfo.SystemError = ::GetLastError();
|
||||
errorInfo.Message = L"delete file error";
|
||||
errorInfo.Message = L"7-Zip cannot delete the file";
|
||||
errorInfo.FileName = archiveName;
|
||||
return E_FAIL;
|
||||
}
|
||||
if (!NDirectory::MyMoveFile(tempPath, archiveName))
|
||||
{
|
||||
errorInfo.SystemError = ::GetLastError();
|
||||
errorInfo.Message = L"move file error";
|
||||
errorInfo.Message = L"7-Zip cannot move the file";
|
||||
errorInfo.FileName = tempPath;
|
||||
errorInfo.FileName2 = archiveName;
|
||||
return E_FAIL;
|
||||
@@ -858,22 +860,21 @@ HRESULT UpdateArchive(
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
#if defined(_WIN32) && !defined(UNDER_CE)
|
||||
if (options.EMailMode)
|
||||
{
|
||||
NDLL::CLibrary mapiLib;
|
||||
if (!mapiLib.Load(TEXT("Mapi32.dll")))
|
||||
{
|
||||
errorInfo.SystemError = ::GetLastError();
|
||||
errorInfo.Message = L"can not load Mapi32.dll";
|
||||
errorInfo.Message = L"7-Zip cannot load Mapi32.dll";
|
||||
return E_FAIL;
|
||||
}
|
||||
MY_LPMAPISENDDOCUMENTS fnSend = (MY_LPMAPISENDDOCUMENTS)
|
||||
mapiLib.GetProcAddress("MAPISendDocuments");
|
||||
MY_LPMAPISENDDOCUMENTS fnSend = (MY_LPMAPISENDDOCUMENTS)mapiLib.GetProc("MAPISendDocuments");
|
||||
if (fnSend == 0)
|
||||
{
|
||||
errorInfo.SystemError = ::GetLastError();
|
||||
errorInfo.Message = L"can not find MAPISendDocuments function";
|
||||
errorInfo.Message = L"7-Zip cannot find MAPISendDocuments function";
|
||||
return E_FAIL;
|
||||
}
|
||||
UStringVector fullPaths;
|
||||
@@ -885,6 +886,7 @@ HRESULT UpdateArchive(
|
||||
if (!NFile::NDirectory::MyGetFullPathName(ap.GetFinalPath(), arcPath))
|
||||
{
|
||||
errorInfo.SystemError = ::GetLastError();
|
||||
errorInfo.Message = L"GetFullPathName error";
|
||||
return E_FAIL;
|
||||
}
|
||||
fullPaths.Add(arcPath);
|
||||
|
||||
@@ -122,6 +122,15 @@ struct CUpdateOptions
|
||||
EMailRemoveAfter(false),
|
||||
OpenShareForWrite(false)
|
||||
{};
|
||||
|
||||
void SetAddActionCommand()
|
||||
{
|
||||
Commands.Clear();
|
||||
CUpdateArchiveCommand c;
|
||||
c.ActionSet = NUpdateArchive::kAddActionSet;
|
||||
Commands.Add(c);
|
||||
}
|
||||
|
||||
CRecordVector<UInt64> VolumesSizes;
|
||||
};
|
||||
|
||||
|
||||
@@ -2,31 +2,28 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "WorkDir.h"
|
||||
|
||||
#include "Common/StringConvert.h"
|
||||
#include "Common/Wildcard.h"
|
||||
|
||||
#include "Windows/FileName.h"
|
||||
#include "Windows/FileDir.h"
|
||||
#include "Windows/FileName.h"
|
||||
|
||||
static inline UINT GetCurrentCodePage()
|
||||
{ return ::AreFileApisANSI() ? CP_ACP : CP_OEMCP; }
|
||||
#include "WorkDir.h"
|
||||
|
||||
using namespace NWindows;
|
||||
using namespace NFile;
|
||||
using namespace NName;
|
||||
|
||||
UString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path)
|
||||
{
|
||||
NWorkDir::NMode::EEnum mode = workDirInfo.Mode;
|
||||
#ifndef UNDER_CE
|
||||
if (workDirInfo.ForRemovableOnly)
|
||||
{
|
||||
mode = NWorkDir::NMode::kCurrent;
|
||||
UString prefix = path.Left(3);
|
||||
if (prefix[1] == L':' && prefix[2] == L'\\')
|
||||
{
|
||||
UINT driveType = GetDriveType(GetSystemString(prefix, GetCurrentCodePage()));
|
||||
UINT driveType = GetDriveType(GetSystemString(prefix, ::AreFileApisANSI() ? CP_ACP : CP_OEMCP));
|
||||
if (driveType == DRIVE_CDROM || driveType == DRIVE_REMOVABLE)
|
||||
mode = workDirInfo.Mode;
|
||||
}
|
||||
@@ -38,6 +35,7 @@ UString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path)
|
||||
mode = NZipSettings::NWorkDir::NMode::kCurrent;
|
||||
*/
|
||||
}
|
||||
#endif
|
||||
switch(mode)
|
||||
{
|
||||
case NWorkDir::NMode::kCurrent:
|
||||
@@ -47,18 +45,15 @@ UString GetWorkDir(const NWorkDir::CInfo &workDirInfo, const UString &path)
|
||||
case NWorkDir::NMode::kSpecified:
|
||||
{
|
||||
UString tempDir = workDirInfo.Path;
|
||||
NormalizeDirPathPrefix(tempDir);
|
||||
NName::NormalizeDirPathPrefix(tempDir);
|
||||
return tempDir;
|
||||
}
|
||||
default:
|
||||
{
|
||||
UString tempDir;
|
||||
if(!NFile::NDirectory::MyGetTempPath(tempDir))
|
||||
if (!NDirectory::MyGetTempPath(tempDir))
|
||||
throw 141717;
|
||||
return tempDir;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -2,142 +2,101 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "ZipRegistry.h"
|
||||
|
||||
#include "Common/IntToString.h"
|
||||
#include "Common/StringConvert.h"
|
||||
|
||||
#include "Windows/Synchronization.h"
|
||||
#include "Windows/Registry.h"
|
||||
|
||||
#include "Windows/FileDir.h"
|
||||
#include "Windows/Registry.h"
|
||||
#include "Windows/Synchronization.h"
|
||||
|
||||
#include "ZipRegistry.h"
|
||||
|
||||
using namespace NWindows;
|
||||
using namespace NRegistry;
|
||||
|
||||
static const TCHAR *kCUBasePath = TEXT("Software") TEXT(STRING_PATH_SEPARATOR) TEXT("7-ZIP");
|
||||
static NSynchronization::CCriticalSection g_CS;
|
||||
#define CS_LOCK NSynchronization::CCriticalSectionLock lock(g_CS);
|
||||
|
||||
static NSynchronization::CCriticalSection g_RegistryOperationsCriticalSection;
|
||||
static const TCHAR *kCuPrefix = TEXT("Software") TEXT(STRING_PATH_SEPARATOR) TEXT("7-Zip") TEXT(STRING_PATH_SEPARATOR);
|
||||
|
||||
//////////////////////
|
||||
// ExtractionInfo
|
||||
static CSysString GetKeyPath(const CSysString &path) { return kCuPrefix + path; }
|
||||
|
||||
static const TCHAR *kExtractionKeyName = TEXT("Extraction");
|
||||
|
||||
static const TCHAR *kExtractionPathHistoryKeyName = TEXT("PathHistory");
|
||||
static const TCHAR *kExtractionExtractModeValueName = TEXT("ExtarctMode");
|
||||
static const TCHAR *kExtractionOverwriteModeValueName = TEXT("OverwriteMode");
|
||||
static const TCHAR *kExtractionShowPasswordValueName = TEXT("ShowPassword");
|
||||
|
||||
static CSysString GetKeyPath(const CSysString &path)
|
||||
static LONG OpenMainKey(CKey &key, LPCTSTR keyName)
|
||||
{
|
||||
return CSysString(kCUBasePath) + CSysString(CHAR_PATH_SEPARATOR) + path;
|
||||
return key.Open(HKEY_CURRENT_USER, GetKeyPath(keyName), KEY_READ);
|
||||
}
|
||||
|
||||
void SaveExtractionInfo(const NExtract::CInfo &info)
|
||||
static LONG CreateMainKey(CKey &key, LPCTSTR keyName)
|
||||
{
|
||||
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
|
||||
CKey extractionKey;
|
||||
extractionKey.Create(HKEY_CURRENT_USER, GetKeyPath(kExtractionKeyName));
|
||||
extractionKey.RecurseDeleteKey(kExtractionPathHistoryKeyName);
|
||||
{
|
||||
CKey pathHistoryKey;
|
||||
pathHistoryKey.Create(extractionKey, kExtractionPathHistoryKeyName);
|
||||
for(int i = 0; i < info.Paths.Size(); i++)
|
||||
{
|
||||
wchar_t numberString[16];
|
||||
ConvertUInt32ToString(i, numberString);
|
||||
pathHistoryKey.SetValue(numberString, info.Paths[i]);
|
||||
}
|
||||
}
|
||||
extractionKey.SetValue(kExtractionExtractModeValueName, UInt32(info.PathMode));
|
||||
extractionKey.SetValue(kExtractionOverwriteModeValueName, UInt32(info.OverwriteMode));
|
||||
extractionKey.SetValue(kExtractionShowPasswordValueName, info.ShowPassword);
|
||||
return key.Create(HKEY_CURRENT_USER, GetKeyPath(keyName));
|
||||
}
|
||||
|
||||
void ReadExtractionInfo(NExtract::CInfo &info)
|
||||
namespace NExtract
|
||||
{
|
||||
info.Paths.Clear();
|
||||
info.PathMode = NExtract::NPathMode::kCurrentPathnames;
|
||||
info.OverwriteMode = NExtract::NOverwriteMode::kAskBefore;
|
||||
info.ShowPassword = false;
|
||||
|
||||
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
|
||||
CKey extractionKey;
|
||||
if(extractionKey.Open(HKEY_CURRENT_USER, GetKeyPath(kExtractionKeyName), KEY_READ) != ERROR_SUCCESS)
|
||||
static const TCHAR *kKeyName = TEXT("Extraction");
|
||||
|
||||
static const TCHAR *kExtractMode = TEXT("ExtractMode");
|
||||
static const TCHAR *kOverwriteMode = TEXT("OverwriteMode");
|
||||
static const TCHAR *kShowPassword = TEXT("ShowPassword");
|
||||
static const TCHAR *kPathHistory = TEXT("PathHistory");
|
||||
|
||||
void CInfo::Save() const
|
||||
{
|
||||
CS_LOCK
|
||||
CKey key;
|
||||
CreateMainKey(key, kKeyName);
|
||||
key.SetValue(kExtractMode, (UInt32)PathMode);
|
||||
key.SetValue(kOverwriteMode, (UInt32)OverwriteMode);
|
||||
key.SetValue(kShowPassword, ShowPassword);
|
||||
key.RecurseDeleteKey(kPathHistory);
|
||||
key.SetValue_Strings(kPathHistory, Paths);
|
||||
}
|
||||
|
||||
|
||||
void CInfo::Load()
|
||||
{
|
||||
PathMode = NPathMode::kCurrentPathnames;
|
||||
OverwriteMode = NOverwriteMode::kAskBefore;
|
||||
ShowPassword = false;
|
||||
Paths.Clear();
|
||||
|
||||
CS_LOCK
|
||||
CKey key;
|
||||
if (OpenMainKey(key, kKeyName) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
{
|
||||
CKey pathHistoryKey;
|
||||
if(pathHistoryKey.Open(extractionKey, kExtractionPathHistoryKeyName, KEY_READ) ==
|
||||
ERROR_SUCCESS)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
wchar_t numberString[16];
|
||||
ConvertUInt32ToString(info.Paths.Size(), numberString);
|
||||
UString path;
|
||||
if (pathHistoryKey.QueryValue(numberString, path) != ERROR_SUCCESS)
|
||||
break;
|
||||
info.Paths.Add(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
UInt32 extractModeIndex;
|
||||
if (extractionKey.QueryValue(kExtractionExtractModeValueName, extractModeIndex) == ERROR_SUCCESS)
|
||||
{
|
||||
switch (extractModeIndex)
|
||||
{
|
||||
case NExtract::NPathMode::kFullPathnames:
|
||||
case NExtract::NPathMode::kCurrentPathnames:
|
||||
case NExtract::NPathMode::kNoPathnames:
|
||||
info.PathMode = NExtract::NPathMode::EEnum(extractModeIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
UInt32 overwriteModeIndex;
|
||||
if (extractionKey.QueryValue(kExtractionOverwriteModeValueName, overwriteModeIndex) == ERROR_SUCCESS)
|
||||
{
|
||||
switch (overwriteModeIndex)
|
||||
{
|
||||
case NExtract::NOverwriteMode::kAskBefore:
|
||||
case NExtract::NOverwriteMode::kWithoutPrompt:
|
||||
case NExtract::NOverwriteMode::kSkipExisting:
|
||||
case NExtract::NOverwriteMode::kAutoRename:
|
||||
case NExtract::NOverwriteMode::kAutoRenameExisting:
|
||||
info.OverwriteMode = NExtract::NOverwriteMode::EEnum(overwriteModeIndex);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (extractionKey.QueryValue(kExtractionShowPasswordValueName,
|
||||
info.ShowPassword) != ERROR_SUCCESS)
|
||||
info.ShowPassword = false;
|
||||
key.GetValue_Strings(kPathHistory, Paths);
|
||||
UInt32 v;
|
||||
if (key.QueryValue(kExtractMode, v) == ERROR_SUCCESS && v <= NPathMode::kNoPathnames)
|
||||
PathMode = (NPathMode::EEnum)v;
|
||||
if (key.QueryValue(kOverwriteMode, v) == ERROR_SUCCESS && v <= NOverwriteMode::kAutoRenameExisting)
|
||||
OverwriteMode = (NOverwriteMode::EEnum)v;
|
||||
key.GetValue_IfOk(kShowPassword, ShowPassword);
|
||||
}
|
||||
|
||||
///////////////////////////////////
|
||||
// CompressionInfo
|
||||
}
|
||||
|
||||
static const TCHAR *kCompressionKeyName = TEXT("Compression");
|
||||
namespace NCompression
|
||||
{
|
||||
|
||||
static const TCHAR *kCompressionHistoryArchivesKeyName = TEXT("ArcHistory");
|
||||
static const TCHAR *kCompressionLevelValueName = TEXT("Level");
|
||||
static const TCHAR *kCompressionLastFormatValueName = TEXT("Archiver");
|
||||
static const TCHAR *kCompressionShowPasswordValueName = TEXT("ShowPassword");
|
||||
static const TCHAR *kCompressionEncryptHeadersValueName = TEXT("EncryptHeaders");
|
||||
static const TCHAR *kKeyName = TEXT("Compression");
|
||||
|
||||
static const TCHAR *kCompressionOptionsKeyName = TEXT("Options");
|
||||
// static const TCHAR *kSolid = TEXT("Solid");
|
||||
// static const TCHAR *kMultiThread = TEXT("Multithread");
|
||||
static const TCHAR *kArcHistory = TEXT("ArcHistory");
|
||||
static const WCHAR *kArchiver = L"Archiver";
|
||||
static const TCHAR *kShowPassword = TEXT("ShowPassword");
|
||||
static const TCHAR *kEncryptHeaders = TEXT("EncryptHeaders");
|
||||
|
||||
static const WCHAR *kCompressionOptions = L"Options";
|
||||
static const TCHAR *kCompressionLevel = TEXT("Level");
|
||||
static const WCHAR *kCompressionMethod = L"Method";
|
||||
static const TCHAR *kOptionsKeyName = TEXT("Options");
|
||||
|
||||
static const TCHAR *kLevel = TEXT("Level");
|
||||
static const TCHAR *kDictionary = TEXT("Dictionary");
|
||||
static const TCHAR *kOrder = TEXT("Order");
|
||||
static const TCHAR *kBlockSize = TEXT("BlockSize");
|
||||
static const TCHAR *kNumThreads = TEXT("NumThreads");
|
||||
static const WCHAR *kMethod = L"Method";
|
||||
static const WCHAR *kOptions = L"Options";
|
||||
static const WCHAR *kEncryptionMethod = L"EncryptionMethod";
|
||||
static const TCHAR *kCompressionDictionary = TEXT("Dictionary");
|
||||
static const TCHAR *kCompressionOrder = TEXT("Order");
|
||||
static const TCHAR *kCompressionNumThreads = TEXT("NumThreads");
|
||||
static const TCHAR *kCompressionBlockSize = TEXT("BlockSize");
|
||||
|
||||
|
||||
static void SetRegString(CKey &key, const WCHAR *name, const UString &value)
|
||||
{
|
||||
@@ -164,254 +123,171 @@ static void GetRegString(CKey &key, const WCHAR *name, UString &value)
|
||||
static void GetRegUInt32(CKey &key, const TCHAR *name, UInt32 &value)
|
||||
{
|
||||
if (key.QueryValue(name, value) != ERROR_SUCCESS)
|
||||
value = UInt32(-1);
|
||||
value = (UInt32)-1;
|
||||
}
|
||||
|
||||
void SaveCompressionInfo(const NCompression::CInfo &info)
|
||||
void CInfo::Save() const
|
||||
{
|
||||
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
|
||||
CS_LOCK
|
||||
|
||||
CKey compressionKey;
|
||||
compressionKey.Create(HKEY_CURRENT_USER, GetKeyPath(kCompressionKeyName));
|
||||
compressionKey.RecurseDeleteKey(kCompressionHistoryArchivesKeyName);
|
||||
{
|
||||
CKey historyArchivesKey;
|
||||
historyArchivesKey.Create(compressionKey, kCompressionHistoryArchivesKeyName);
|
||||
for(int i = 0; i < info.HistoryArchives.Size(); i++)
|
||||
{
|
||||
wchar_t numberString[16];
|
||||
ConvertUInt32ToString(i, numberString);
|
||||
historyArchivesKey.SetValue(numberString, info.HistoryArchives[i]);
|
||||
}
|
||||
}
|
||||
CKey key;
|
||||
CreateMainKey(key, kKeyName);
|
||||
key.SetValue(kLevel, (UInt32)Level);
|
||||
key.SetValue(kArchiver, ArcType);
|
||||
key.SetValue(kShowPassword, ShowPassword);
|
||||
key.SetValue(kEncryptHeaders, EncryptHeaders);
|
||||
key.RecurseDeleteKey(kArcHistory);
|
||||
key.SetValue_Strings(kArcHistory, ArcPaths);
|
||||
|
||||
// compressionKey.SetValue(kSolid, info.Solid);
|
||||
// compressionKey.SetValue(kMultiThread, info.MultiThread);
|
||||
compressionKey.RecurseDeleteKey(kCompressionOptionsKeyName);
|
||||
key.RecurseDeleteKey(kOptionsKeyName);
|
||||
{
|
||||
CKey optionsKey;
|
||||
optionsKey.Create(compressionKey, kCompressionOptionsKeyName);
|
||||
for(int i = 0; i < info.FormatOptionsVector.Size(); i++)
|
||||
optionsKey.Create(key, kOptionsKeyName);
|
||||
for (int i = 0; i < Formats.Size(); i++)
|
||||
{
|
||||
const NCompression::CFormatOptions &fo = info.FormatOptionsVector[i];
|
||||
CKey formatKey;
|
||||
formatKey.Create(optionsKey, fo.FormatID);
|
||||
const CFormatOptions &fo = Formats[i];
|
||||
CKey fk;
|
||||
fk.Create(optionsKey, fo.FormatID);
|
||||
|
||||
SetRegString(formatKey, kCompressionOptions, fo.Options);
|
||||
SetRegString(formatKey, kCompressionMethod, fo.Method);
|
||||
SetRegString(formatKey, kEncryptionMethod, fo.EncryptionMethod);
|
||||
SetRegUInt32(fk, kLevel, fo.Level);
|
||||
SetRegUInt32(fk, kDictionary, fo.Dictionary);
|
||||
SetRegUInt32(fk, kOrder, fo.Order);
|
||||
SetRegUInt32(fk, kBlockSize, fo.BlockLogSize);
|
||||
SetRegUInt32(fk, kNumThreads, fo.NumThreads);
|
||||
|
||||
SetRegUInt32(formatKey, kCompressionLevel, fo.Level);
|
||||
SetRegUInt32(formatKey, kCompressionDictionary, fo.Dictionary);
|
||||
SetRegUInt32(formatKey, kCompressionOrder, fo.Order);
|
||||
SetRegUInt32(formatKey, kCompressionBlockSize, fo.BlockLogSize);
|
||||
SetRegUInt32(formatKey, kCompressionNumThreads, fo.NumThreads);
|
||||
SetRegString(fk, kMethod, fo.Method);
|
||||
SetRegString(fk, kOptions, fo.Options);
|
||||
SetRegString(fk, kEncryptionMethod, fo.EncryptionMethod);
|
||||
}
|
||||
}
|
||||
|
||||
compressionKey.SetValue(kCompressionLevelValueName, UInt32(info.Level));
|
||||
compressionKey.SetValue(kCompressionLastFormatValueName, GetSystemString(info.ArchiveType));
|
||||
|
||||
compressionKey.SetValue(kCompressionShowPasswordValueName, info.ShowPassword);
|
||||
compressionKey.SetValue(kCompressionEncryptHeadersValueName, info.EncryptHeaders);
|
||||
// compressionKey.SetValue(kCompressionMaximizeValueName, info.Maximize);
|
||||
}
|
||||
|
||||
void ReadCompressionInfo(NCompression::CInfo &info)
|
||||
void CInfo::Load()
|
||||
{
|
||||
info.HistoryArchives.Clear();
|
||||
ArcPaths.Clear();
|
||||
Formats.Clear();
|
||||
|
||||
// info.Solid = true;
|
||||
// info.MultiThread = IsMultiProcessor();
|
||||
info.FormatOptionsVector.Clear();
|
||||
Level = 5;
|
||||
ArcType = L"7z";
|
||||
ShowPassword = false;
|
||||
EncryptHeaders = false;
|
||||
|
||||
info.Level = 5;
|
||||
info.ArchiveType = L"7z";
|
||||
// definedStatus.Maximize = false;
|
||||
info.ShowPassword = false;
|
||||
info.EncryptHeaders = false;
|
||||
CS_LOCK
|
||||
CKey key;
|
||||
|
||||
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
|
||||
CKey compressionKey;
|
||||
|
||||
if(compressionKey.Open(HKEY_CURRENT_USER,
|
||||
GetKeyPath(kCompressionKeyName), KEY_READ) != ERROR_SUCCESS)
|
||||
if (OpenMainKey(key, kKeyName) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
{
|
||||
CKey historyArchivesKey;
|
||||
if(historyArchivesKey.Open(compressionKey, kCompressionHistoryArchivesKeyName, KEY_READ) ==
|
||||
ERROR_SUCCESS)
|
||||
{
|
||||
for (;;)
|
||||
{
|
||||
wchar_t numberString[16];
|
||||
ConvertUInt32ToString(info.HistoryArchives.Size(), numberString);
|
||||
UString path;
|
||||
if (historyArchivesKey.QueryValue(numberString, path) != ERROR_SUCCESS)
|
||||
break;
|
||||
info.HistoryArchives.Add(path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
key.GetValue_Strings(kArcHistory, ArcPaths);
|
||||
|
||||
/*
|
||||
bool solid = false;
|
||||
if (compressionKey.QueryValue(kSolid, solid) == ERROR_SUCCESS)
|
||||
info.Solid = solid;
|
||||
bool multiThread = false;
|
||||
if (compressionKey.QueryValue(kMultiThread, multiThread) == ERROR_SUCCESS)
|
||||
info.MultiThread = multiThread;
|
||||
*/
|
||||
|
||||
{
|
||||
CKey optionsKey;
|
||||
if(optionsKey.Open(compressionKey, kCompressionOptionsKeyName, KEY_READ) ==
|
||||
ERROR_SUCCESS)
|
||||
if (optionsKey.Open(key, kOptionsKeyName, KEY_READ) == ERROR_SUCCESS)
|
||||
{
|
||||
CSysStringVector formatIDs;
|
||||
optionsKey.EnumKeys(formatIDs);
|
||||
for(int i = 0; i < formatIDs.Size(); i++)
|
||||
for (int i = 0; i < formatIDs.Size(); i++)
|
||||
{
|
||||
CKey formatKey;
|
||||
NCompression::CFormatOptions fo;
|
||||
CKey fk;
|
||||
CFormatOptions fo;
|
||||
fo.FormatID = formatIDs[i];
|
||||
if(formatKey.Open(optionsKey, fo.FormatID, KEY_READ) == ERROR_SUCCESS)
|
||||
if (fk.Open(optionsKey, fo.FormatID, KEY_READ) == ERROR_SUCCESS)
|
||||
{
|
||||
GetRegString(formatKey, kCompressionOptions, fo.Options);
|
||||
GetRegString(formatKey, kCompressionMethod, fo.Method);
|
||||
GetRegString(formatKey, kEncryptionMethod, fo.EncryptionMethod);
|
||||
GetRegString(fk, kOptions, fo.Options);
|
||||
GetRegString(fk, kMethod, fo.Method);
|
||||
GetRegString(fk, kEncryptionMethod, fo.EncryptionMethod);
|
||||
|
||||
GetRegUInt32(formatKey, kCompressionLevel, fo.Level);
|
||||
GetRegUInt32(formatKey, kCompressionDictionary, fo.Dictionary);
|
||||
GetRegUInt32(formatKey, kCompressionOrder, fo.Order);
|
||||
GetRegUInt32(formatKey, kCompressionBlockSize, fo.BlockLogSize);
|
||||
GetRegUInt32(formatKey, kCompressionNumThreads, fo.NumThreads);
|
||||
GetRegUInt32(fk, kLevel, fo.Level);
|
||||
GetRegUInt32(fk, kDictionary, fo.Dictionary);
|
||||
GetRegUInt32(fk, kOrder, fo.Order);
|
||||
GetRegUInt32(fk, kBlockSize, fo.BlockLogSize);
|
||||
GetRegUInt32(fk, kNumThreads, fo.NumThreads);
|
||||
|
||||
info.FormatOptionsVector.Add(fo);
|
||||
Formats.Add(fo);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
UInt32 level;
|
||||
if (compressionKey.QueryValue(kCompressionLevelValueName, level) == ERROR_SUCCESS)
|
||||
info.Level = level;
|
||||
CSysString archiveType;
|
||||
if (compressionKey.QueryValue(kCompressionLastFormatValueName, archiveType) == ERROR_SUCCESS)
|
||||
info.ArchiveType = GetUnicodeString(archiveType);
|
||||
if (compressionKey.QueryValue(kCompressionShowPasswordValueName,
|
||||
info.ShowPassword) != ERROR_SUCCESS)
|
||||
info.ShowPassword = false;
|
||||
if (compressionKey.QueryValue(kCompressionEncryptHeadersValueName,
|
||||
info.EncryptHeaders) != ERROR_SUCCESS)
|
||||
info.EncryptHeaders = false;
|
||||
/*
|
||||
if (compressionKey.QueryValue(kCompressionLevelValueName, info.Maximize) == ERROR_SUCCESS)
|
||||
definedStatus.Maximize = true;
|
||||
*/
|
||||
UString a;
|
||||
if (key.QueryValue(kArchiver, a) == ERROR_SUCCESS)
|
||||
ArcType = a;
|
||||
key.GetValue_IfOk(kLevel, Level);
|
||||
key.GetValue_IfOk(kShowPassword, ShowPassword);
|
||||
key.GetValue_IfOk(kEncryptHeaders, EncryptHeaders);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////////////
|
||||
// WorkDirInfo
|
||||
}
|
||||
|
||||
static const TCHAR *kOptionsInfoKeyName = TEXT("Options");
|
||||
|
||||
static const TCHAR *kWorkDirTypeValueName = TEXT("WorkDirType");
|
||||
static const WCHAR *kWorkDirPathValueName = L"WorkDirPath";
|
||||
static const TCHAR *kTempRemovableOnlyValueName = TEXT("TempRemovableOnly");
|
||||
static const TCHAR *kCascadedMenuValueName = TEXT("CascadedMenu");
|
||||
static const TCHAR *kContextMenuValueName = TEXT("ContextMenu");
|
||||
|
||||
void SaveWorkDirInfo(const NWorkDir::CInfo &info)
|
||||
namespace NWorkDir
|
||||
{
|
||||
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
|
||||
CKey optionsKey;
|
||||
optionsKey.Create(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName));
|
||||
optionsKey.SetValue(kWorkDirTypeValueName, UInt32(info.Mode));
|
||||
optionsKey.SetValue(kWorkDirPathValueName, info.Path);
|
||||
optionsKey.SetValue(kTempRemovableOnlyValueName, info.ForRemovableOnly);
|
||||
static const TCHAR *kWorkDirType = TEXT("WorkDirType");
|
||||
static const WCHAR *kWorkDirPath = L"WorkDirPath";
|
||||
static const TCHAR *kTempRemovableOnly = TEXT("TempRemovableOnly");
|
||||
|
||||
|
||||
void CInfo::Save()const
|
||||
{
|
||||
CS_LOCK
|
||||
CKey key;
|
||||
CreateMainKey(key, kOptionsInfoKeyName);
|
||||
key.SetValue(kWorkDirType, (UInt32)Mode);
|
||||
key.SetValue(kWorkDirPath, Path);
|
||||
key.SetValue(kTempRemovableOnly, ForRemovableOnly);
|
||||
}
|
||||
|
||||
void ReadWorkDirInfo(NWorkDir::CInfo &info)
|
||||
void CInfo::Load()
|
||||
{
|
||||
info.SetDefault();
|
||||
SetDefault();
|
||||
|
||||
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
|
||||
CKey optionsKey;
|
||||
if(optionsKey.Open(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName), KEY_READ) != ERROR_SUCCESS)
|
||||
CS_LOCK
|
||||
CKey key;
|
||||
if (OpenMainKey(key, kOptionsInfoKeyName) != ERROR_SUCCESS)
|
||||
return;
|
||||
|
||||
UInt32 dirType;
|
||||
if (optionsKey.QueryValue(kWorkDirTypeValueName, dirType) != ERROR_SUCCESS)
|
||||
if (key.QueryValue(kWorkDirType, dirType) != ERROR_SUCCESS)
|
||||
return;
|
||||
switch (dirType)
|
||||
{
|
||||
case NWorkDir::NMode::kSystem:
|
||||
case NWorkDir::NMode::kCurrent:
|
||||
case NWorkDir::NMode::kSpecified:
|
||||
info.Mode = NWorkDir::NMode::EEnum(dirType);
|
||||
case NMode::kSystem:
|
||||
case NMode::kCurrent:
|
||||
case NMode::kSpecified:
|
||||
Mode = (NMode::EEnum)dirType;
|
||||
}
|
||||
UString sysWorkDir;
|
||||
if (optionsKey.QueryValue(kWorkDirPathValueName, sysWorkDir) != ERROR_SUCCESS)
|
||||
if (key.QueryValue(kWorkDirPath, Path) != ERROR_SUCCESS)
|
||||
{
|
||||
info.Path.Empty();
|
||||
if (info.Mode == NWorkDir::NMode::kSpecified)
|
||||
info.Mode = NWorkDir::NMode::kSystem;
|
||||
Path.Empty();
|
||||
if (Mode == NMode::kSpecified)
|
||||
Mode = NMode::kSystem;
|
||||
}
|
||||
info.Path = GetUnicodeString(sysWorkDir);
|
||||
if (optionsKey.QueryValue(kTempRemovableOnlyValueName, info.ForRemovableOnly) != ERROR_SUCCESS)
|
||||
info.SetForRemovableOnlyDefault();
|
||||
key.GetValue_IfOk(kTempRemovableOnly, ForRemovableOnly);
|
||||
}
|
||||
|
||||
static void SaveOption(const TCHAR *value, bool enabled)
|
||||
}
|
||||
|
||||
static const TCHAR *kCascadedMenu = TEXT("CascadedMenu");
|
||||
static const TCHAR *kContextMenu = TEXT("ContextMenu");
|
||||
|
||||
void CContextMenuInfo::Save() const
|
||||
{
|
||||
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
|
||||
CKey optionsKey;
|
||||
optionsKey.Create(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName));
|
||||
optionsKey.SetValue(value, enabled);
|
||||
CS_LOCK
|
||||
CKey key;
|
||||
CreateMainKey(key, kOptionsInfoKeyName);
|
||||
key.SetValue(kCascadedMenu, Cascaded);
|
||||
key.SetValue(kContextMenu, Flags);
|
||||
}
|
||||
|
||||
static bool ReadOption(const TCHAR *value, bool defaultValue)
|
||||
void CContextMenuInfo::Load()
|
||||
{
|
||||
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
|
||||
CKey optionsKey;
|
||||
if(optionsKey.Open(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName), KEY_READ) != ERROR_SUCCESS)
|
||||
return defaultValue;
|
||||
bool enabled;
|
||||
if (optionsKey.QueryValue(value, enabled) != ERROR_SUCCESS)
|
||||
return defaultValue;
|
||||
return enabled;
|
||||
Cascaded = true;
|
||||
Flags = (UInt32)-1;
|
||||
CS_LOCK
|
||||
CKey key;
|
||||
if (OpenMainKey(key, kOptionsInfoKeyName) != ERROR_SUCCESS)
|
||||
return;
|
||||
key.GetValue_IfOk(kCascadedMenu, Cascaded);
|
||||
key.GetValue_IfOk(kContextMenu, Flags);
|
||||
}
|
||||
|
||||
void SaveCascadedMenu(bool show)
|
||||
{ SaveOption(kCascadedMenuValueName, show); }
|
||||
bool ReadCascadedMenu()
|
||||
{ return ReadOption(kCascadedMenuValueName, true); }
|
||||
|
||||
|
||||
static void SaveValue(const TCHAR *value, UInt32 valueToWrite)
|
||||
{
|
||||
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
|
||||
CKey optionsKey;
|
||||
optionsKey.Create(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName));
|
||||
optionsKey.SetValue(value, valueToWrite);
|
||||
}
|
||||
|
||||
static bool ReadValue(const TCHAR *value, UInt32 &result)
|
||||
{
|
||||
NSynchronization::CCriticalSectionLock lock(g_RegistryOperationsCriticalSection);
|
||||
CKey optionsKey;
|
||||
if(optionsKey.Open(HKEY_CURRENT_USER, GetKeyPath(kOptionsInfoKeyName), KEY_READ) != ERROR_SUCCESS)
|
||||
return false;
|
||||
return (optionsKey.QueryValue(value, result) == ERROR_SUCCESS);
|
||||
}
|
||||
|
||||
void SaveContextMenuStatus(UInt32 value)
|
||||
{ SaveValue(kContextMenuValueName, value); }
|
||||
|
||||
bool ReadContextMenuStatus(UInt32 &value)
|
||||
{ return ReadValue(kContextMenuValueName, value); }
|
||||
|
||||
@@ -1,10 +1,11 @@
|
||||
// ZipRegistry.h
|
||||
|
||||
#ifndef __ZIPREGISTRY_H
|
||||
#define __ZIPREGISTRY_H
|
||||
#ifndef __ZIP_REGISTRY_H
|
||||
#define __ZIP_REGISTRY_H
|
||||
|
||||
#include "Common/MyString.h"
|
||||
#include "Common/Types.h"
|
||||
|
||||
#include "ExtractMode.h"
|
||||
|
||||
namespace NExtract
|
||||
@@ -13,49 +14,56 @@ namespace NExtract
|
||||
{
|
||||
NPathMode::EEnum PathMode;
|
||||
NOverwriteMode::EEnum OverwriteMode;
|
||||
UStringVector Paths;
|
||||
bool ShowPassword;
|
||||
UStringVector Paths;
|
||||
|
||||
void Save() const;
|
||||
void Load();
|
||||
};
|
||||
}
|
||||
|
||||
namespace NCompression {
|
||||
|
||||
namespace NCompression
|
||||
{
|
||||
struct CFormatOptions
|
||||
{
|
||||
CSysString FormatID;
|
||||
UString Options;
|
||||
UString Method;
|
||||
UString EncryptionMethod;
|
||||
UInt32 Level;
|
||||
UInt32 Dictionary;
|
||||
UInt32 Order;
|
||||
UInt32 BlockLogSize;
|
||||
UInt32 NumThreads;
|
||||
|
||||
CSysString FormatID;
|
||||
UString Method;
|
||||
UString Options;
|
||||
UString EncryptionMethod;
|
||||
|
||||
void ResetForLevelChange()
|
||||
{
|
||||
BlockLogSize = NumThreads = Level = Dictionary = Order = UInt32(-1);
|
||||
Method.Empty();
|
||||
// EncryptionMethod.Empty();
|
||||
// Options.Empty();
|
||||
// EncryptionMethod.Empty();
|
||||
}
|
||||
CFormatOptions() { ResetForLevelChange(); }
|
||||
};
|
||||
|
||||
struct CInfo
|
||||
{
|
||||
UStringVector HistoryArchives;
|
||||
UInt32 Level;
|
||||
UString ArchiveType;
|
||||
|
||||
CObjectVector<CFormatOptions> FormatOptionsVector;
|
||||
|
||||
bool ShowPassword;
|
||||
bool EncryptHeaders;
|
||||
UString ArcType;
|
||||
UStringVector ArcPaths;
|
||||
|
||||
CObjectVector<CFormatOptions> Formats;
|
||||
|
||||
void Save() const;
|
||||
void Load();
|
||||
};
|
||||
}
|
||||
|
||||
namespace NWorkDir{
|
||||
|
||||
namespace NWorkDir
|
||||
{
|
||||
namespace NMode
|
||||
{
|
||||
enum EEnum
|
||||
@@ -70,6 +78,7 @@ namespace NWorkDir{
|
||||
NMode::EEnum Mode;
|
||||
UString Path;
|
||||
bool ForRemovableOnly;
|
||||
|
||||
void SetForRemovableOnlyDefault() { ForRemovableOnly = true; }
|
||||
void SetDefault()
|
||||
{
|
||||
@@ -77,22 +86,20 @@ namespace NWorkDir{
|
||||
Path.Empty();
|
||||
SetForRemovableOnlyDefault();
|
||||
}
|
||||
|
||||
void Save() const;
|
||||
void Load();
|
||||
};
|
||||
}
|
||||
|
||||
void SaveExtractionInfo(const NExtract::CInfo &info);
|
||||
void ReadExtractionInfo(NExtract::CInfo &info);
|
||||
|
||||
void SaveCompressionInfo(const NCompression::CInfo &info);
|
||||
void ReadCompressionInfo(NCompression::CInfo &info);
|
||||
struct CContextMenuInfo
|
||||
{
|
||||
bool Cascaded;
|
||||
UInt32 Flags;
|
||||
|
||||
void SaveWorkDirInfo(const NWorkDir::CInfo &info);
|
||||
void ReadWorkDirInfo(NWorkDir::CInfo &info);
|
||||
|
||||
void SaveCascadedMenu(bool enabled);
|
||||
bool ReadCascadedMenu();
|
||||
|
||||
void SaveContextMenuStatus(UInt32 value);
|
||||
bool ReadContextMenuStatus(UInt32 &value);
|
||||
void Save() const;
|
||||
void Load();
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user