blob: 4bdf813a9a9e084e3a1b745021cfb15f4fe7ef44 (
plain)
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
|
// MainAr.cpp
#include "StdAfx.h"
// #include <locale.h>
#include "Windows/Error.h"
#include "Common/StdOutStream.h"
#include "Common/NewHandler.h"
#include "Common/Exception.h"
#include "Common/StringConvert.h"
#ifdef _WIN32
#include "Common/Alloc.h"
#endif
#include "../Common/ExitCode.h"
#include "../Common/ArchiveCommandLine.h"
#include "ConsoleClose.h"
#ifdef CRC_GENERATE_TABLE
extern "C"
{
#include "../../../../C/7zCrc.h"
}
#endif
using namespace NWindows;
CStdOutStream *g_StdStream = 0;
#ifndef _UNICODE
bool g_IsNT = false;
#endif
extern int Main2(
#ifndef _WIN32
int numArguments, const char *arguments[]
#endif
);
static const char *kExceptionErrorMessage = "\n\nError:\n";
static const char *kUserBreak = "\nBreak signaled\n";
static const char *kMemoryExceptionMessage = "\n\nERROR: Can't allocate required memory!\n";
static const char *kUnknownExceptionMessage = "\n\nUnknown Error\n";
static const char *kInternalExceptionMessage = "\n\nInternal Error #";
static inline bool IsItWindowsNT()
{
OSVERSIONINFO versionInfo;
versionInfo.dwOSVersionInfoSize = sizeof(versionInfo);
if (!::GetVersionEx(&versionInfo))
return false;
return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT);
}
int
#ifdef _MSC_VER
__cdecl
#endif
main
(
#ifndef _WIN32
int numArguments, const char *arguments[]
#endif
)
{
#ifdef CRC_GENERATE_TABLE
CrcGenerateTable();
#endif
g_StdStream = &g_StdOut;
#ifdef _UNICODE
if (!IsItWindowsNT())
{
(*g_StdStream) << "This program requires Windows NT/2000/XP/2003";
return NExitCode::kFatalError;
}
#else
g_IsNT = IsItWindowsNT();
#endif
#ifdef _WIN32
SetLargePageSize();
#endif
// setlocale(LC_COLLATE, ".OCP");
NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter;
int res = 0;
try
{
res = Main2(
#ifndef _WIN32
numArguments, arguments
#endif
);
}
catch(const CNewException &)
{
(*g_StdStream) << kMemoryExceptionMessage;
return (NExitCode::kMemoryError);
}
catch(const NConsoleClose::CCtrlBreakException &)
{
(*g_StdStream) << endl << kUserBreak;
return (NExitCode::kUserBreak);
}
catch(const CArchiveCommandLineException &e)
{
(*g_StdStream) << kExceptionErrorMessage << e << endl;
return (NExitCode::kUserError);
}
catch(const CSystemException &systemError)
{
if (systemError.ErrorCode == E_OUTOFMEMORY)
{
(*g_StdStream) << kMemoryExceptionMessage;
return (NExitCode::kMemoryError);
}
if (systemError.ErrorCode == E_ABORT)
{
(*g_StdStream) << endl << kUserBreak;
return (NExitCode::kUserBreak);
}
UString message;
NError::MyFormatMessage(systemError.ErrorCode, message);
(*g_StdStream) << endl << endl << "System error:" << endl <<
message << endl;
return (NExitCode::kFatalError);
}
catch(NExitCode::EEnum &exitCode)
{
(*g_StdStream) << kInternalExceptionMessage << exitCode << endl;
return (exitCode);
}
/*
catch(const NExitCode::CMultipleErrors &multipleErrors)
{
(*g_StdStream) << endl << multipleErrors.NumErrors << " errors" << endl;
return (NExitCode::kFatalError);
}
*/
catch(const UString &s)
{
(*g_StdStream) << kExceptionErrorMessage << s << endl;
return (NExitCode::kFatalError);
}
catch(const AString &s)
{
(*g_StdStream) << kExceptionErrorMessage << s << endl;
return (NExitCode::kFatalError);
}
catch(const char *s)
{
(*g_StdStream) << kExceptionErrorMessage << s << endl;
return (NExitCode::kFatalError);
}
catch(int t)
{
(*g_StdStream) << kInternalExceptionMessage << t << endl;
return (NExitCode::kFatalError);
}
catch(...)
{
(*g_StdStream) << kUnknownExceptionMessage;
return (NExitCode::kFatalError);
}
return res;
}
|