mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-06 13:14:59 -06:00
9.34
This commit is contained in:
committed by
Kornel Lesiński
parent
83f8ddcc5b
commit
f08f4dcc3c
229
CPP/7zip/UI/GUI/GUI.cpp
Executable file → Normal file
229
CPP/7zip/UI/GUI/GUI.cpp
Executable file → Normal file
@@ -2,18 +2,19 @@
|
||||
|
||||
#include "StdAfx.h"
|
||||
|
||||
#include "Common/MyInitGuid.h"
|
||||
|
||||
#include "../../../../C/Alloc.h"
|
||||
|
||||
#include "Common/CommandLineParser.h"
|
||||
#include "Common/MyException.h"
|
||||
#include "Common/StringConvert.h"
|
||||
#include "../../../Common/MyInitGuid.h"
|
||||
|
||||
#include "Windows/Error.h"
|
||||
#include "Windows/NtCheck.h"
|
||||
#include "../../../Common/CommandLineParser.h"
|
||||
#include "../../../Common/IntToString.h"
|
||||
#include "../../../Common/MyException.h"
|
||||
#include "../../../Common/StringConvert.h"
|
||||
|
||||
#include "../../../Windows/FileDir.h"
|
||||
#include "../../../Windows/NtCheck.h"
|
||||
#ifdef _WIN32
|
||||
#include "Windows/MemoryLock.h"
|
||||
#include "../../../Windows/MemoryLock.h"
|
||||
#endif
|
||||
|
||||
#include "../Common/ArchiveCommandLine.h"
|
||||
@@ -24,6 +25,7 @@
|
||||
|
||||
#include "BenchmarkDialog.h"
|
||||
#include "ExtractGUI.h"
|
||||
#include "HashGUI.h"
|
||||
#include "UpdateGUI.h"
|
||||
|
||||
#include "ExtractRes.h"
|
||||
@@ -34,25 +36,50 @@ HINSTANCE g_hInstance;
|
||||
#ifndef _UNICODE
|
||||
#endif
|
||||
|
||||
#ifdef UNDER_CE
|
||||
bool g_LVN_ITEMACTIVATE_Support = true;
|
||||
#ifndef UNDER_CE
|
||||
|
||||
DWORD g_ComCtl32Version;
|
||||
|
||||
static DWORD GetDllVersion(LPCTSTR dllName)
|
||||
{
|
||||
DWORD dwVersion = 0;
|
||||
HINSTANCE hinstDll = LoadLibrary(dllName);
|
||||
if (hinstDll)
|
||||
{
|
||||
DLLGETVERSIONPROC pDllGetVersion = (DLLGETVERSIONPROC)GetProcAddress(hinstDll, "DllGetVersion");
|
||||
if (pDllGetVersion)
|
||||
{
|
||||
DLLVERSIONINFO dvi;
|
||||
ZeroMemory(&dvi, sizeof(dvi));
|
||||
dvi.cbSize = sizeof(dvi);
|
||||
HRESULT hr = (*pDllGetVersion)(&dvi);
|
||||
if (SUCCEEDED(hr))
|
||||
dwVersion = MAKELONG(dvi.dwMinorVersion, dvi.dwMajorVersion);
|
||||
}
|
||||
FreeLibrary(hinstDll);
|
||||
}
|
||||
return dwVersion;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
bool g_LVN_ITEMACTIVATE_Support = true;
|
||||
|
||||
static void ErrorMessage(LPCWSTR message)
|
||||
{
|
||||
MessageBoxW(NULL, message, L"7-Zip", MB_ICONERROR | MB_OK);
|
||||
}
|
||||
|
||||
static void ErrorLangMessage(UINT resourceID, UInt32 langID)
|
||||
static void ErrorLangMessage(UINT resourceID)
|
||||
{
|
||||
ErrorMessage(LangString(resourceID, langID));
|
||||
ErrorMessage(LangString(resourceID));
|
||||
}
|
||||
|
||||
static const char *kNoFormats = "7-Zip cannot find the code that works with archives.";
|
||||
|
||||
static int ShowMemErrorMessage()
|
||||
{
|
||||
ErrorLangMessage(IDS_MEM_ERROR, 0x0200060B);
|
||||
ErrorLangMessage(IDS_MEM_ERROR);
|
||||
return NExitCode::kMemoryError;
|
||||
}
|
||||
|
||||
@@ -64,6 +91,12 @@ static int ShowSysErrorMessage(DWORD errorCode)
|
||||
return NExitCode::kFatalError;
|
||||
}
|
||||
|
||||
static void ThrowException_if_Error(HRESULT res)
|
||||
{
|
||||
if (res != S_OK)
|
||||
throw CSystemException(res);
|
||||
}
|
||||
|
||||
static int Main2()
|
||||
{
|
||||
UStringVector commandStrings;
|
||||
@@ -79,52 +112,79 @@ static int Main2()
|
||||
return 0;
|
||||
}
|
||||
|
||||
CArchiveCommandLineOptions options;
|
||||
CArchiveCommandLineParser parser;
|
||||
CArcCmdLineOptions options;
|
||||
CArcCmdLineParser parser;
|
||||
|
||||
parser.Parse1(commandStrings, options);
|
||||
parser.Parse2(options);
|
||||
|
||||
#if defined(_WIN32) && defined(_7ZIP_LARGE_PAGES)
|
||||
#if defined(_WIN32) && !defined(UNDER_CE)
|
||||
NSecurity::EnablePrivilege_SymLink();
|
||||
#ifdef _7ZIP_LARGE_PAGES
|
||||
if (options.LargePages)
|
||||
NSecurity::EnableLockMemoryPrivilege();
|
||||
NSecurity::EnablePrivilege_LockMemory();
|
||||
#endif
|
||||
#endif
|
||||
|
||||
CCodecs *codecs = new CCodecs;
|
||||
#ifdef EXTERNAL_CODECS
|
||||
CExternalCodecs __externalCodecs;
|
||||
__externalCodecs.GetCodecs = codecs;
|
||||
__externalCodecs.GetHashers = codecs;
|
||||
#else
|
||||
CMyComPtr<IUnknown> compressCodecsInfo = codecs;
|
||||
HRESULT result = codecs->Load();
|
||||
if (result != S_OK)
|
||||
throw CSystemException(result);
|
||||
#endif
|
||||
codecs->CaseSensitiveChange = options.CaseSensitiveChange;
|
||||
codecs->CaseSensitive = options.CaseSensitive;
|
||||
ThrowException_if_Error(codecs->Load());
|
||||
|
||||
bool isExtractGroupCommand = options.Command.IsFromExtractGroup();
|
||||
|
||||
if (codecs->Formats.Size() == 0 &&
|
||||
(isExtractGroupCommand ||
|
||||
options.Command.IsFromUpdateGroup()))
|
||||
(isExtractGroupCommand
|
||||
|
||||
|| options.Command.IsFromUpdateGroup()))
|
||||
throw kNoFormats;
|
||||
|
||||
CIntVector formatIndices;
|
||||
if (!codecs->FindFormatForArchiveType(options.ArcType, formatIndices))
|
||||
CObjectVector<COpenType> formatIndices;
|
||||
if (!ParseOpenTypes(*codecs, options.ArcType, formatIndices))
|
||||
{
|
||||
ErrorLangMessage(IDS_UNSUPPORTED_ARCHIVE_TYPE, 0x0200060D);
|
||||
ErrorLangMessage(IDS_UNSUPPORTED_ARCHIVE_TYPE);
|
||||
return NExitCode::kFatalError;
|
||||
}
|
||||
|
||||
|
||||
CIntVector excludedFormatIndices;
|
||||
FOR_VECTOR (k, options.ExcludedArcTypes)
|
||||
{
|
||||
CIntVector tempIndices;
|
||||
if (!codecs->FindFormatForArchiveType(options.ExcludedArcTypes[k], tempIndices)
|
||||
|| tempIndices.Size() != 1)
|
||||
{
|
||||
ErrorLangMessage(IDS_UNSUPPORTED_ARCHIVE_TYPE);
|
||||
return NExitCode::kFatalError;
|
||||
}
|
||||
excludedFormatIndices.AddToUniqueSorted(tempIndices[0]);
|
||||
// excludedFormatIndices.Sort();
|
||||
}
|
||||
|
||||
#ifdef EXTERNAL_CODECS
|
||||
if (isExtractGroupCommand
|
||||
|| options.Command.CommandType == NCommandType::kHash
|
||||
|| options.Command.CommandType == NCommandType::kBenchmark)
|
||||
ThrowException_if_Error(__externalCodecs.LoadCodecs());
|
||||
#endif
|
||||
|
||||
if (options.Command.CommandType == NCommandType::kBenchmark)
|
||||
{
|
||||
HRESULT res;
|
||||
#ifdef EXTERNAL_CODECS
|
||||
CObjectVector<CCodecInfoEx> externalCodecs;
|
||||
res = LoadExternalCodecs(codecs, externalCodecs);
|
||||
if (res != S_OK)
|
||||
throw CSystemException(res);
|
||||
#endif
|
||||
res = Benchmark(
|
||||
#ifdef EXTERNAL_CODECS
|
||||
codecs, &externalCodecs,
|
||||
#endif
|
||||
options.Properties);
|
||||
if (res != S_OK)
|
||||
throw CSystemException(res);
|
||||
HRESULT res = Benchmark(EXTERNAL_CODECS_VARS options.Properties);
|
||||
/*
|
||||
if (res == S_FALSE)
|
||||
{
|
||||
stdStream << "\nDecoding Error\n";
|
||||
return NExitCode::kFatalError;
|
||||
}
|
||||
*/
|
||||
ThrowException_if_Error(res);
|
||||
}
|
||||
else if (isExtractGroupCommand)
|
||||
{
|
||||
@@ -139,23 +199,39 @@ static int Main2()
|
||||
ecs->Init();
|
||||
|
||||
CExtractOptions eo;
|
||||
(CExtractOptionsBase &)eo = options.ExtractOptions;
|
||||
eo.StdInMode = options.StdInMode;
|
||||
eo.StdOutMode = options.StdOutMode;
|
||||
eo.OutputDir = options.OutputDir;
|
||||
eo.YesToAll = options.YesToAll;
|
||||
eo.OverwriteMode = options.OverwriteMode;
|
||||
eo.PathMode = options.Command.GetPathMode();
|
||||
eo.TestMode = options.Command.IsTestMode();
|
||||
eo.CalcCrc = options.CalcCrc;
|
||||
#if !defined(_7ZIP_ST) && !defined(_SFX)
|
||||
eo.TestMode = options.Command.IsTestCommand();
|
||||
|
||||
#ifndef _SFX
|
||||
eo.Properties = options.Properties;
|
||||
#endif
|
||||
|
||||
bool messageWasDisplayed = false;
|
||||
HRESULT result = ExtractGUI(codecs, formatIndices,
|
||||
|
||||
#ifndef _SFX
|
||||
CHashBundle hb;
|
||||
CHashBundle *hb_ptr = NULL;
|
||||
|
||||
if (!options.HashMethods.IsEmpty())
|
||||
{
|
||||
hb_ptr = &hb;
|
||||
ThrowException_if_Error(hb.SetMethods(EXTERNAL_CODECS_VARS options.HashMethods));
|
||||
}
|
||||
#endif
|
||||
|
||||
HRESULT result = ExtractGUI(codecs,
|
||||
formatIndices, excludedFormatIndices,
|
||||
options.ArchivePathsSorted,
|
||||
options.ArchivePathsFullSorted,
|
||||
options.WildcardCensor.Pairs.Front().Head,
|
||||
eo, options.ShowDialog, messageWasDisplayed, ecs);
|
||||
options.Censor.Pairs.Front().Head,
|
||||
eo,
|
||||
#ifndef _SFX
|
||||
hb_ptr,
|
||||
#endif
|
||||
options.ShowDialog, messageWasDisplayed, ecs);
|
||||
if (result != S_OK)
|
||||
{
|
||||
if (result != E_ABORT && messageWasDisplayed)
|
||||
@@ -183,17 +259,21 @@ static int Main2()
|
||||
// callback.StdOutMode = options.UpdateOptions.StdOutMode;
|
||||
callback.Init();
|
||||
|
||||
if (!options.UpdateOptions.Init(codecs, formatIndices, options.ArchiveName))
|
||||
if (!options.UpdateOptions.InitFormatIndex(codecs, formatIndices, options.ArchiveName) ||
|
||||
!options.UpdateOptions.SetArcPath(codecs, options.ArchiveName))
|
||||
{
|
||||
ErrorLangMessage(IDS_UPDATE_NOT_SUPPORTED, 0x02000601);
|
||||
ErrorLangMessage(IDS_UPDATE_NOT_SUPPORTED);
|
||||
return NExitCode::kFatalError;
|
||||
}
|
||||
bool messageWasDisplayed = false;
|
||||
HRESULT result = UpdateGUI(
|
||||
codecs,
|
||||
options.WildcardCensor, options.UpdateOptions,
|
||||
codecs, formatIndices,
|
||||
options.ArchiveName,
|
||||
options.Censor,
|
||||
options.UpdateOptions,
|
||||
options.ShowDialog,
|
||||
messageWasDisplayed, &callback);
|
||||
messageWasDisplayed,
|
||||
&callback);
|
||||
|
||||
if (result != S_OK)
|
||||
{
|
||||
@@ -208,6 +288,27 @@ static int Main2()
|
||||
return NExitCode::kWarning;
|
||||
}
|
||||
}
|
||||
else if (options.Command.CommandType == NCommandType::kHash)
|
||||
{
|
||||
bool messageWasDisplayed = false;
|
||||
HRESULT result = HashCalcGUI(EXTERNAL_CODECS_VARS
|
||||
options.Censor, options.HashOptions, messageWasDisplayed);
|
||||
|
||||
if (result != S_OK)
|
||||
{
|
||||
if (result != E_ABORT && messageWasDisplayed)
|
||||
return NExitCode::kFatalError;
|
||||
throw CSystemException(result);
|
||||
}
|
||||
/*
|
||||
if (callback.FailedFiles.Size() > 0)
|
||||
{
|
||||
if (!messageWasDisplayed)
|
||||
throw CSystemException(E_FAIL);
|
||||
return NExitCode::kWarning;
|
||||
}
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Unsupported command";
|
||||
@@ -233,12 +334,17 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
|
||||
|
||||
InitCommonControls();
|
||||
|
||||
#ifndef UNDER_CE
|
||||
g_ComCtl32Version = ::GetDllVersion(TEXT("comctl32.dll"));
|
||||
g_LVN_ITEMACTIVATE_Support = (g_ComCtl32Version >= MAKELONG(71, 4));
|
||||
#endif
|
||||
|
||||
// OleInitialize is required for ProgressBar in TaskBar.
|
||||
#ifndef UNDER_CE
|
||||
OleInitialize(NULL);
|
||||
#endif
|
||||
|
||||
ReloadLang();
|
||||
LoadLangOneTime();
|
||||
|
||||
// setlocale(LC_COLLATE, ".ACP");
|
||||
try
|
||||
@@ -249,9 +355,9 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
|
||||
{
|
||||
return ShowMemErrorMessage();
|
||||
}
|
||||
catch(const CArchiveCommandLineException &e)
|
||||
catch(const CArcCmdLineException &e)
|
||||
{
|
||||
ErrorMessage(GetUnicodeString(e));
|
||||
ErrorMessage(e);
|
||||
return NExitCode::kUserError;
|
||||
}
|
||||
catch(const CSystemException &systemError)
|
||||
@@ -280,9 +386,16 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
|
||||
ErrorMessage(GetUnicodeString(s));
|
||||
return NExitCode::kFatalError;
|
||||
}
|
||||
catch(int v)
|
||||
{
|
||||
wchar_t s[32];
|
||||
ConvertUInt32ToString(v, s);
|
||||
ErrorMessage(UString(L"Error: ") + s);
|
||||
return NExitCode::kFatalError;
|
||||
}
|
||||
catch(...)
|
||||
{
|
||||
ErrorLangMessage(IDS_UNKNOWN_ERROR, 0x0200060C);
|
||||
ErrorMessage(L"Unknown error");
|
||||
return NExitCode::kFatalError;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user