mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-13 04:11:34 -06:00
4.20
This commit is contained in:
committed by
Kornel Lesiński
parent
8c1b5c7b7e
commit
3c510ba80b
@@ -11,14 +11,18 @@
|
||||
|
||||
#include "Windows/Synchronization.h"
|
||||
#include "Windows/FileMapping.h"
|
||||
#include "Windows/FileDir.h"
|
||||
|
||||
#include "../../FileManager/ProgramLocation.h"
|
||||
|
||||
using namespace NWindows;
|
||||
|
||||
static LPCWSTR kShowDialogSwitch = L" -ad";
|
||||
static LPCWSTR kEmailSwitch = L" -seml";
|
||||
static LPCWSTR kEmailSwitch = L" -seml.";
|
||||
static LPCWSTR kMapSwitch = L" -i#";
|
||||
static LPCWSTR kArchiveNoNameSwitch = L" -an";
|
||||
static LPCWSTR kArchiveMapSwitch = L" -ai#";
|
||||
static LPCWSTR kStopSwitchParsing = L" --";
|
||||
|
||||
|
||||
static bool IsItWindowsNT()
|
||||
@@ -31,6 +35,7 @@ static bool IsItWindowsNT()
|
||||
}
|
||||
|
||||
HRESULT MyCreateProcess(const UString ¶ms,
|
||||
LPCTSTR curDir,
|
||||
NWindows::NSynchronization::CEvent *event)
|
||||
{
|
||||
STARTUPINFO startupInfo;
|
||||
@@ -45,7 +50,8 @@ HRESULT MyCreateProcess(const UString ¶ms,
|
||||
PROCESS_INFORMATION processInformation;
|
||||
BOOL result = ::CreateProcess(NULL, (TCHAR *)(const TCHAR *)
|
||||
GetSystemString(params),
|
||||
NULL, NULL, FALSE, 0, NULL, NULL,
|
||||
NULL, NULL, FALSE, 0, NULL,
|
||||
curDir,
|
||||
&startupInfo, &processInformation);
|
||||
if (result == 0)
|
||||
return ::GetLastError();
|
||||
@@ -70,7 +76,7 @@ static UString GetQuotedString(const UString &s)
|
||||
|
||||
static UString Get7zGuiPath()
|
||||
{
|
||||
UString path = L"\"";
|
||||
UString path;
|
||||
UString folder;
|
||||
if (GetProgramFolderPath(folder))
|
||||
path += folder;
|
||||
@@ -78,28 +84,117 @@ static UString Get7zGuiPath()
|
||||
path += L"7zgn.exe";
|
||||
else
|
||||
path += L"7zg.exe";
|
||||
path += L"\"";
|
||||
return path;
|
||||
// path += L"7z.exe";
|
||||
return GetQuotedString(path);
|
||||
}
|
||||
|
||||
static HRESULT CreateMap(const UStringVector &names,
|
||||
const UString &id,
|
||||
CFileMapping &fileMapping, NSynchronization::CEvent &event,
|
||||
UString ¶ms)
|
||||
{
|
||||
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;
|
||||
UString eventName;
|
||||
|
||||
CRandom random;
|
||||
random.Init(GetTickCount());
|
||||
while(true)
|
||||
{
|
||||
int number = random.Generate();
|
||||
wchar_t temp[32];
|
||||
ConvertUInt64ToString(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)
|
||||
break;
|
||||
fileMapping.Close();
|
||||
}
|
||||
|
||||
while(true)
|
||||
{
|
||||
int number = random.Generate();
|
||||
wchar_t temp[32];
|
||||
ConvertUInt64ToString(UInt32(number), temp);
|
||||
eventName = id;
|
||||
eventName += L"MappingEndEvent";
|
||||
eventName += temp;
|
||||
if (!event.Create(true, false, GetSystemString(eventName)))
|
||||
return E_FAIL;
|
||||
if (::GetLastError() != ERROR_ALREADY_EXISTS)
|
||||
break;
|
||||
event.Close();
|
||||
}
|
||||
|
||||
params += mappingName;
|
||||
params += L":";
|
||||
wchar_t string[10];
|
||||
ConvertUInt64ToString(totalSize, string);
|
||||
params += string;
|
||||
|
||||
params += L":";
|
||||
params += eventName;
|
||||
|
||||
LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_WRITE, 0, totalSize);
|
||||
if (data == NULL)
|
||||
return E_FAIL;
|
||||
try
|
||||
{
|
||||
wchar_t *curData = (wchar_t *)data;
|
||||
*curData = 0;
|
||||
curData++;
|
||||
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';
|
||||
}
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
UnmapViewOfFile(data);
|
||||
throw;
|
||||
}
|
||||
// UnmapViewOfFile(data);
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT CompressFiles(
|
||||
const UString &curDir,
|
||||
const UString &archiveName,
|
||||
const UStringVector &names,
|
||||
// const UString &outFolder,
|
||||
bool email,
|
||||
bool showDialog)
|
||||
{
|
||||
/*
|
||||
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;
|
||||
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;
|
||||
UInt32 totalSize = extraSize + dataSize;
|
||||
|
||||
UString mappingName;
|
||||
UString eventName;
|
||||
@@ -111,7 +206,7 @@ HRESULT CompressFiles(
|
||||
{
|
||||
int number = random.Generate();
|
||||
wchar_t temp[32];
|
||||
ConvertUINT64ToString(UINT32(number), temp);
|
||||
ConvertUInt64ToString(UInt32(number), temp);
|
||||
mappingName = L"7zCompressMapping";
|
||||
mappingName += temp;
|
||||
if (!fileMapping.Create(INVALID_HANDLE_VALUE, NULL,
|
||||
@@ -130,7 +225,7 @@ HRESULT CompressFiles(
|
||||
{
|
||||
int number = random.Generate();
|
||||
wchar_t temp[32];
|
||||
ConvertUINT64ToString(UINT32(number), temp);
|
||||
ConvertUInt64ToString(UInt32(number), temp);
|
||||
eventName = L"7zCompressMappingEndEvent";
|
||||
eventName += temp;
|
||||
if (!event.Create(true, false, GetSystemString(eventName)))
|
||||
@@ -146,7 +241,7 @@ HRESULT CompressFiles(
|
||||
params += mappingName;
|
||||
params += L":";
|
||||
wchar_t string[10];
|
||||
ConvertUINT64ToString(totalSize, string);
|
||||
ConvertUInt64ToString(totalSize, string);
|
||||
params += string;
|
||||
|
||||
params += L":";
|
||||
@@ -158,7 +253,9 @@ HRESULT CompressFiles(
|
||||
if (showDialog)
|
||||
params += kShowDialogSwitch;
|
||||
|
||||
params += kStopSwitchParsing;
|
||||
params += L" ";
|
||||
|
||||
params += GetQuotedString(archiveName);
|
||||
|
||||
LPVOID data = fileMapping.MapViewOfFile(FILE_MAP_WRITE, 0, totalSize);
|
||||
@@ -177,11 +274,14 @@ HRESULT CompressFiles(
|
||||
const UString &unicodeString = names[i];
|
||||
memcpy(curData, (const wchar_t *)unicodeString ,
|
||||
unicodeString .Length() * sizeof(wchar_t));
|
||||
curData += unicodeString .Length();
|
||||
curData += unicodeString.Length();
|
||||
*curData++ = L'\0';
|
||||
}
|
||||
// MessageBox(0, params, 0, 0);
|
||||
RINOK(MyCreateProcess(params, &event));
|
||||
CSysString sysCurDir = GetSystemString(curDir);
|
||||
RINOK(MyCreateProcess(params,
|
||||
(sysCurDir.IsEmpty()? 0: (LPCTSTR)sysCurDir),
|
||||
&event));
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
@@ -190,8 +290,7 @@ HRESULT CompressFiles(
|
||||
}
|
||||
UnmapViewOfFile(data);
|
||||
|
||||
|
||||
|
||||
|
||||
/*
|
||||
CThreadCompressMain *compressor = new CThreadCompressMain();;
|
||||
compressor->FileNames = _fileNames;
|
||||
@@ -202,13 +301,24 @@ HRESULT CompressFiles(
|
||||
return S_OK;
|
||||
}
|
||||
|
||||
HRESULT ExtractArchive(const UString &archiveName,
|
||||
static HRESULT ExtractGroupCommand(const UStringVector &archivePaths,
|
||||
const UString ¶ms)
|
||||
{
|
||||
UString params2 = params;
|
||||
params2 += kArchiveNoNameSwitch;
|
||||
params2 += kArchiveMapSwitch;
|
||||
CFileMapping fileMapping;
|
||||
NSynchronization::CEvent event;
|
||||
RINOK(CreateMap(archivePaths, L"7zExtract", fileMapping, event, params2));
|
||||
return MyCreateProcess(params2, 0, &event);
|
||||
}
|
||||
|
||||
HRESULT ExtractArchives(const UStringVector &archivePaths,
|
||||
const UString &outFolder, bool showDialog)
|
||||
{
|
||||
UString params;
|
||||
params = Get7zGuiPath();
|
||||
params += L" x ";
|
||||
params += GetQuotedString(archiveName);
|
||||
params += L" x";
|
||||
if (!outFolder.IsEmpty())
|
||||
{
|
||||
params += L" -o";
|
||||
@@ -216,14 +326,13 @@ HRESULT ExtractArchive(const UString &archiveName,
|
||||
}
|
||||
if (showDialog)
|
||||
params += kShowDialogSwitch;
|
||||
return MyCreateProcess(params);
|
||||
return ExtractGroupCommand(archivePaths, params);
|
||||
}
|
||||
|
||||
HRESULT TestArchive(const UString &archiveName)
|
||||
HRESULT TestArchives(const UStringVector &archivePaths)
|
||||
{
|
||||
UString params;
|
||||
params = Get7zGuiPath();
|
||||
params += L" t ";
|
||||
params += GetQuotedString(archiveName);
|
||||
return MyCreateProcess(params);
|
||||
params += L" t";
|
||||
return ExtractGroupCommand(archivePaths, params);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user