| OLD | NEW |
| (Empty) |
| 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 MY_CDECL main | |
| 52 ( | |
| 53 #ifndef _WIN32 | |
| 54 int numArguments, const char *arguments[] | |
| 55 #endif | |
| 56 ) | |
| 57 { | |
| 58 g_StdStream = &g_StdOut; | |
| 59 #ifdef _WIN32 | |
| 60 | |
| 61 #ifdef _UNICODE | |
| 62 #ifndef _WIN64 | |
| 63 if (!IsItWindowsNT()) | |
| 64 { | |
| 65 (*g_StdStream) << "This program requires Windows NT/2000/2003/2008/XP/Vista"
; | |
| 66 return NExitCode::kFatalError; | |
| 67 } | |
| 68 #endif | |
| 69 #else | |
| 70 g_IsNT = IsItWindowsNT(); | |
| 71 #endif | |
| 72 | |
| 73 #endif | |
| 74 | |
| 75 // setlocale(LC_COLLATE, ".OCP"); | |
| 76 NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter; | |
| 77 int res = 0; | |
| 78 try | |
| 79 { | |
| 80 res = Main2( | |
| 81 #ifndef _WIN32 | |
| 82 numArguments, arguments | |
| 83 #endif | |
| 84 ); | |
| 85 } | |
| 86 catch(const CNewException &) | |
| 87 { | |
| 88 (*g_StdStream) << kMemoryExceptionMessage; | |
| 89 return (NExitCode::kMemoryError); | |
| 90 } | |
| 91 catch(const NConsoleClose::CCtrlBreakException &) | |
| 92 { | |
| 93 (*g_StdStream) << endl << kUserBreak; | |
| 94 return (NExitCode::kUserBreak); | |
| 95 } | |
| 96 catch(const CArchiveCommandLineException &e) | |
| 97 { | |
| 98 (*g_StdStream) << kExceptionErrorMessage << e << endl; | |
| 99 return (NExitCode::kUserError); | |
| 100 } | |
| 101 catch(const CSystemException &systemError) | |
| 102 { | |
| 103 if (systemError.ErrorCode == E_OUTOFMEMORY) | |
| 104 { | |
| 105 (*g_StdStream) << kMemoryExceptionMessage; | |
| 106 return (NExitCode::kMemoryError); | |
| 107 } | |
| 108 if (systemError.ErrorCode == E_ABORT) | |
| 109 { | |
| 110 (*g_StdStream) << endl << kUserBreak; | |
| 111 return (NExitCode::kUserBreak); | |
| 112 } | |
| 113 UString message; | |
| 114 NError::MyFormatMessage(systemError.ErrorCode, message); | |
| 115 (*g_StdStream) << endl << endl << "System error:" << endl << | |
| 116 message << endl; | |
| 117 return (NExitCode::kFatalError); | |
| 118 } | |
| 119 catch(NExitCode::EEnum &exitCode) | |
| 120 { | |
| 121 (*g_StdStream) << kInternalExceptionMessage << exitCode << endl; | |
| 122 return (exitCode); | |
| 123 } | |
| 124 /* | |
| 125 catch(const NExitCode::CMultipleErrors &multipleErrors) | |
| 126 { | |
| 127 (*g_StdStream) << endl << multipleErrors.NumErrors << " errors" << endl; | |
| 128 return (NExitCode::kFatalError); | |
| 129 } | |
| 130 */ | |
| 131 catch(const UString &s) | |
| 132 { | |
| 133 (*g_StdStream) << kExceptionErrorMessage << s << endl; | |
| 134 return (NExitCode::kFatalError); | |
| 135 } | |
| 136 catch(const AString &s) | |
| 137 { | |
| 138 (*g_StdStream) << kExceptionErrorMessage << s << endl; | |
| 139 return (NExitCode::kFatalError); | |
| 140 } | |
| 141 catch(const char *s) | |
| 142 { | |
| 143 (*g_StdStream) << kExceptionErrorMessage << s << endl; | |
| 144 return (NExitCode::kFatalError); | |
| 145 } | |
| 146 catch(int t) | |
| 147 { | |
| 148 (*g_StdStream) << kInternalExceptionMessage << t << endl; | |
| 149 return (NExitCode::kFatalError); | |
| 150 } | |
| 151 catch(...) | |
| 152 { | |
| 153 (*g_StdStream) << kUnknownExceptionMessage; | |
| 154 return (NExitCode::kFatalError); | |
| 155 } | |
| 156 return res; | |
| 157 } | |
| OLD | NEW |