1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
|
// Main.cpp
#include "StdAfx.h"
#include <initguid.h>
#include "Common/StringConvert.h"
#include "Common/CommandLineParser.h"
#include "Windows/FileDir.h"
#include "Windows/FileName.h"
#include "Windows/DLL.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/GUI/ExtractGUI.h"
HINSTANCE g_hInstance;
#ifndef _UNICODE
bool g_IsNT = false;
static inline bool IsItWindowsNT()
{
OSVERSIONINFO versionInfo;
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
if (!::GetVersionEx(&versionInfo))
return false;
return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
}
#endif
static const wchar_t *kMemoryExceptionMessage = L"ERROR: Can't allocate required memory!";
static const wchar_t *kUnknownExceptionMessage = L"ERROR: Unknown Error!";
int APIENTRY WinMain2()
{
UString password;
bool assumeYes = false;
bool outputFolderDefined = false;
UString outputFolder;
UStringVector subStrings;
NCommandLineParser::SplitCommandLine(GetCommandLineW(), subStrings);
for (int i = 1; i < subStrings.Size(); i++)
{
const UString &s = subStrings[i];
if (s.CompareNoCase(L"-y") == 0)
assumeYes = true;
else if (s.Left(2).CompareNoCase(L"-o") == 0)
{
outputFolder = s.Mid(2);
NWindows::NFile::NName::NormalizeDirPathPrefix(outputFolder);
outputFolderDefined = !outputFolder.IsEmpty();
}
else if (s.Left(2).CompareNoCase(L"-p") == 0)
{
password = s.Mid(2);
}
}
UString path;
NWindows::NDLL::MyGetModuleFileName(g_hInstance, path);
UString fullPath;
int fileNamePartStartIndex;
if (!NWindows::NFile::NDirectory::MyGetFullPathName(path, fullPath, fileNamePartStartIndex))
{
MyMessageBox(L"Error 1329484");
return 1;
}
CCodecs *codecs = new CCodecs;
CMyComPtr<IUnknown> compressCodecsInfo = codecs;
HRESULT result = codecs->Load();
if (result != S_OK)
{
ShowErrorMessage(0, result);
return S_OK;
}
COpenCallbackGUI openCallback;
openCallback.PasswordIsDefined = !password.IsEmpty();
openCallback.Password = password;
CExtractCallbackImp *ecs = new CExtractCallbackImp;
CMyComPtr<IFolderArchiveExtractCallback> extractCallback = ecs;
ecs->Init();
ecs->PasswordIsDefined = !password.IsEmpty();
ecs->Password = password;
CExtractOptions eo;
eo.OutputDir = outputFolderDefined ? outputFolder :
fullPath.Left(fileNamePartStartIndex);
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(fullPath);
v2.Add(fullPath);
NWildcard::CCensorNode wildcardCensor;
wildcardCensor.AddItem(true, L"*", true, true, true);
result = ExtractGUI(codecs, v1, v2,
wildcardCensor, eo, (assumeYes ? false: true), &openCallback, ecs);
/*
HRESULT result = ExtractArchive(NULL, path, assumeYes, !assumeYes,
outputFolderDefined ? outputFolder :
fullPath.Left(fileNamePartStartIndex));
*/
if (result == S_OK)
{
if (ecs->Messages.Size() > 0 || ecs->NumArchiveErrors != 0)
return NExitCode::kFatalError;
return 0;
}
if (result == E_ABORT)
return NExitCode::kUserBreak;
if (result == S_FALSE)
MyMessageBox(L"Error in archive");
else
ShowErrorMessage(0, result);
return NExitCode::kFatalError;
}
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE /* hPrevInstance */, LPSTR /* lpCmdLine */, int /* nCmdShow */)
{
g_hInstance = (HINSTANCE)hInstance;
#ifndef _UNICODE
g_IsNT = IsItWindowsNT();
#endif
try
{
return WinMain2();
}
catch(const CNewException &)
{
MyMessageBox(kMemoryExceptionMessage);
return (NExitCode::kMemoryError);
}
catch(...)
{
MyMessageBox(kUnknownExceptionMessage);
return NExitCode::kFatalError;
}
}
|