mirror of
https://github.com/Xevion/easy7zip.git
synced 2025-12-06 15:14:59 -06:00
185 lines
4.3 KiB
C++
Executable File
185 lines
4.3 KiB
C++
Executable File
// Main.cpp
|
|
|
|
#include "StdAfx.h"
|
|
|
|
#include "Common/MyInitGuid.h"
|
|
|
|
#include "Common/CommandLineParser.h"
|
|
#include "Common/StringConvert.h"
|
|
|
|
#include "Windows/DLL.h"
|
|
#include "Windows/Error.h"
|
|
#include "Windows/FileDir.h"
|
|
#include "Windows/FileName.h"
|
|
#include "Windows/NtCheck.h"
|
|
#include "Windows/ResourceString.h"
|
|
|
|
#include "../../ICoder.h"
|
|
#include "../../IPassword.h"
|
|
#include "../../Archive/IArchive.h"
|
|
#include "../../UI/Common/Extract.h"
|
|
#include "../../UI/Common/ExitCode.h"
|
|
#include "../../UI/Explorer/MyMessages.h"
|
|
#include "../../UI/FileManager/MyWindowsNew.h"
|
|
#include "../../UI/GUI/ExtractGUI.h"
|
|
#include "../../UI/GUI/ExtractRes.h"
|
|
|
|
HINSTANCE g_hInstance;
|
|
|
|
#ifdef UNDER_CE
|
|
bool g_LVN_ITEMACTIVATE_Support = true;
|
|
#endif
|
|
|
|
static const wchar_t *kUnknownExceptionMessage = L"ERROR: Unknown Error!";
|
|
|
|
void ErrorMessageForHRESULT(HRESULT res)
|
|
{
|
|
ShowErrorMessage(HResultToMessage(res));
|
|
}
|
|
|
|
int APIENTRY WinMain2()
|
|
{
|
|
// OleInitialize is required for ProgressBar in TaskBar.
|
|
#ifndef UNDER_CE
|
|
OleInitialize(NULL);
|
|
#endif
|
|
|
|
UString password;
|
|
bool assumeYes = false;
|
|
bool outputFolderDefined = false;
|
|
FString outputFolder;
|
|
UStringVector commandStrings;
|
|
NCommandLineParser::SplitCommandLine(GetCommandLineW(), commandStrings);
|
|
|
|
#ifndef UNDER_CE
|
|
if (commandStrings.Size() > 0)
|
|
commandStrings.Delete(0);
|
|
#endif
|
|
|
|
for (int i = 0; i < commandStrings.Size(); i++)
|
|
{
|
|
const UString &s = commandStrings[i];
|
|
if (s.CompareNoCase(L"-y") == 0)
|
|
assumeYes = true;
|
|
else if (s.Left(2).CompareNoCase(L"-o") == 0)
|
|
{
|
|
outputFolder = us2fs(s.Mid(2));
|
|
NWindows::NFile::NName::NormalizeDirPathPrefix(outputFolder);
|
|
outputFolderDefined = !outputFolder.IsEmpty();
|
|
}
|
|
else if (s.Left(2).CompareNoCase(L"-p") == 0)
|
|
{
|
|
password = s.Mid(2);
|
|
}
|
|
}
|
|
|
|
FString path;
|
|
NWindows::NDLL::MyGetModuleFileName(path);
|
|
|
|
FString fullPath;
|
|
if (!NWindows::NFile::NDirectory::MyGetFullPathName(path, fullPath))
|
|
{
|
|
ShowErrorMessage(L"Error 1329484");
|
|
return 1;
|
|
}
|
|
|
|
CCodecs *codecs = new CCodecs;
|
|
CMyComPtr<IUnknown> compressCodecsInfo = codecs;
|
|
HRESULT result = codecs->Load();
|
|
if (result != S_OK)
|
|
{
|
|
ErrorMessageForHRESULT(result);
|
|
return 1;
|
|
}
|
|
|
|
// COpenCallbackGUI openCallback;
|
|
|
|
// openCallback.PasswordIsDefined = !password.IsEmpty();
|
|
// openCallback.Password = password;
|
|
|
|
CExtractCallbackImp *ecs = new CExtractCallbackImp;
|
|
CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;
|
|
ecs->Init();
|
|
|
|
#ifndef _NO_CRYPTO
|
|
ecs->PasswordIsDefined = !password.IsEmpty();
|
|
ecs->Password = password;
|
|
#endif
|
|
|
|
CExtractOptions eo;
|
|
|
|
FString dirPrefix;
|
|
if (!NWindows::NFile::NDirectory::GetOnlyDirPrefix(path, dirPrefix))
|
|
{
|
|
ShowErrorMessage(L"Error 1329485");
|
|
return 1;
|
|
}
|
|
|
|
eo.OutputDir = outputFolderDefined ? outputFolder : dirPrefix;
|
|
eo.YesToAll = assumeYes;
|
|
eo.OverwriteMode = assumeYes ?
|
|
NExtract::NOverwriteMode::kWithoutPrompt :
|
|
NExtract::NOverwriteMode::kAskBefore;
|
|
eo.PathMode = NExtract::NPathMode::kFullPathnames;
|
|
eo.TestMode = false;
|
|
|
|
UStringVector v1, v2;
|
|
v1.Add(fs2us(fullPath));
|
|
v2.Add(fs2us(fullPath));
|
|
NWildcard::CCensorNode wildcardCensor;
|
|
wildcardCensor.AddItem(true, L"*", true, true, true);
|
|
|
|
bool messageWasDisplayed = false;
|
|
result = ExtractGUI(codecs, CIntVector(), v1, v2,
|
|
wildcardCensor, eo, (assumeYes ? false: true), messageWasDisplayed, ecs);
|
|
|
|
if (result == S_OK)
|
|
{
|
|
if (!ecs->IsOK())
|
|
return NExitCode::kFatalError;
|
|
return 0;
|
|
}
|
|
if (result == E_ABORT)
|
|
return NExitCode::kUserBreak;
|
|
if (!messageWasDisplayed)
|
|
{
|
|
if (result == S_FALSE)
|
|
ShowErrorMessage(L"Error in archive");
|
|
else
|
|
ErrorMessageForHRESULT(result);
|
|
}
|
|
if (result == E_OUTOFMEMORY)
|
|
return NExitCode::kMemoryError;
|
|
return NExitCode::kFatalError;
|
|
}
|
|
|
|
#define NT_CHECK_FAIL_ACTION ShowErrorMessage(L"Unsupported Windows version"); return NExitCode::kFatalError;
|
|
|
|
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */,
|
|
#ifdef UNDER_CE
|
|
LPWSTR
|
|
#else
|
|
LPSTR
|
|
#endif
|
|
/* lpCmdLine */, int /* nCmdShow */)
|
|
{
|
|
g_hInstance = (HINSTANCE)hInstance;
|
|
|
|
NT_CHECK
|
|
|
|
try
|
|
{
|
|
return WinMain2();
|
|
}
|
|
catch(const CNewException &)
|
|
{
|
|
ErrorMessageForHRESULT(E_OUTOFMEMORY);
|
|
return NExitCode::kMemoryError;
|
|
}
|
|
catch(...)
|
|
{
|
|
ShowErrorMessage(kUnknownExceptionMessage);
|
|
return NExitCode::kFatalError;
|
|
}
|
|
}
|