1 // MainAr.cpp |
|
2 |
|
3 #include "StdAfx.h" |
|
4 |
|
5 // #include <locale.h> |
|
6 |
|
7 #include "Windows/Error.h" |
|
8 |
|
9 #include "Common/StdOutStream.h" |
|
10 #include "Common/NewHandler.h" |
|
11 #include "Common/MyException.h" |
|
12 #include "Common/StringConvert.h" |
|
13 |
|
14 #include "../Common/ExitCode.h" |
|
15 #include "../Common/ArchiveCommandLine.h" |
|
16 #include "ConsoleClose.h" |
|
17 |
|
18 using namespace NWindows; |
|
19 |
|
20 CStdOutStream *g_StdStream = 0; |
|
21 |
|
22 #ifdef _WIN32 |
|
23 #ifndef _UNICODE |
|
24 bool g_IsNT = false; |
|
25 #endif |
|
26 #if !defined(_UNICODE) || !defined(_WIN64) |
|
27 static inline bool IsItWindowsNT() |
|
28 { |
|
29 OSVERSIONINFO versionInfo; |
|
30 versionInfo.dwOSVersionInfoSize = sizeof(versionInfo); |
|
31 if (!::GetVersionEx(&versionInfo)) |
|
32 return false; |
|
33 return (versionInfo.dwPlatformId == VER_PLATFORM_WIN32_NT); |
|
34 } |
|
35 #endif |
|
36 #endif |
|
37 |
|
38 extern int Main2( |
|
39 #ifndef _WIN32 |
|
40 int numArguments, const char *arguments[] |
|
41 #endif |
|
42 ); |
|
43 |
|
44 static const char *kExceptionErrorMessage = "\n\nError:\n"; |
|
45 static const char *kUserBreak = "\nBreak signaled\n"; |
|
46 |
|
47 static const char *kMemoryExceptionMessage = "\n\nERROR: Can't allocate required memory!\n"; |
|
48 static const char *kUnknownExceptionMessage = "\n\nUnknown Error\n"; |
|
49 static const char *kInternalExceptionMessage = "\n\nInternal Error #"; |
|
50 |
|
51 int |
|
52 #ifdef _MSC_VER |
|
53 __cdecl |
|
54 #endif |
|
55 main |
|
56 ( |
|
57 #ifndef _WIN32 |
|
58 int numArguments, const char *arguments[] |
|
59 #endif |
|
60 ) |
|
61 { |
|
62 g_StdStream = &g_StdOut; |
|
63 #ifdef _WIN32 |
|
64 |
|
65 #ifdef _UNICODE |
|
66 #ifndef _WIN64 |
|
67 if (!IsItWindowsNT()) |
|
68 { |
|
69 (*g_StdStream) << "This program requires Windows NT/2000/XP/2003/Vista"; |
|
70 return NExitCode::kFatalError; |
|
71 } |
|
72 #endif |
|
73 #else |
|
74 g_IsNT = IsItWindowsNT(); |
|
75 #endif |
|
76 |
|
77 #endif |
|
78 |
|
79 // setlocale(LC_COLLATE, ".OCP"); |
|
80 NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter; |
|
81 int res = 0; |
|
82 try |
|
83 { |
|
84 res = Main2( |
|
85 #ifndef _WIN32 |
|
86 numArguments, arguments |
|
87 #endif |
|
88 ); |
|
89 } |
|
90 catch(const CNewException &) |
|
91 { |
|
92 (*g_StdStream) << kMemoryExceptionMessage; |
|
93 return (NExitCode::kMemoryError); |
|
94 } |
|
95 catch(const NConsoleClose::CCtrlBreakException &) |
|
96 { |
|
97 (*g_StdStream) << endl << kUserBreak; |
|
98 return (NExitCode::kUserBreak); |
|
99 } |
|
100 catch(const CArchiveCommandLineException &e) |
|
101 { |
|
102 (*g_StdStream) << kExceptionErrorMessage << e << endl; |
|
103 return (NExitCode::kUserError); |
|
104 } |
|
105 catch(const CSystemException &systemError) |
|
106 { |
|
107 if (systemError.ErrorCode == E_OUTOFMEMORY) |
|
108 { |
|
109 (*g_StdStream) << kMemoryExceptionMessage; |
|
110 return (NExitCode::kMemoryError); |
|
111 } |
|
112 if (systemError.ErrorCode == E_ABORT) |
|
113 { |
|
114 (*g_StdStream) << endl << kUserBreak; |
|
115 return (NExitCode::kUserBreak); |
|
116 } |
|
117 UString message; |
|
118 NError::MyFormatMessage(systemError.ErrorCode, message); |
|
119 (*g_StdStream) << endl << endl << "System error:" << endl << |
|
120 message << endl; |
|
121 return (NExitCode::kFatalError); |
|
122 } |
|
123 catch(NExitCode::EEnum &exitCode) |
|
124 { |
|
125 (*g_StdStream) << kInternalExceptionMessage << exitCode << endl; |
|
126 return (exitCode); |
|
127 } |
|
128 /* |
|
129 catch(const NExitCode::CMultipleErrors &multipleErrors) |
|
130 { |
|
131 (*g_StdStream) << endl << multipleErrors.NumErrors << " errors" << endl; |
|
132 return (NExitCode::kFatalError); |
|
133 } |
|
134 */ |
|
135 catch(const UString &s) |
|
136 { |
|
137 (*g_StdStream) << kExceptionErrorMessage << s << endl; |
|
138 return (NExitCode::kFatalError); |
|
139 } |
|
140 catch(const AString &s) |
|
141 { |
|
142 (*g_StdStream) << kExceptionErrorMessage << s << endl; |
|
143 return (NExitCode::kFatalError); |
|
144 } |
|
145 catch(const char *s) |
|
146 { |
|
147 (*g_StdStream) << kExceptionErrorMessage << s << endl; |
|
148 return (NExitCode::kFatalError); |
|
149 } |
|
150 catch(int t) |
|
151 { |
|
152 (*g_StdStream) << kInternalExceptionMessage << t << endl; |
|
153 return (NExitCode::kFatalError); |
|
154 } |
|
155 catch(...) |
|
156 { |
|
157 (*g_StdStream) << kUnknownExceptionMessage; |
|
158 return (NExitCode::kFatalError); |
|
159 } |
|
160 return res; |
|
161 } |
|