1 // MainAr.cpp 2 3 #include "StdAfx.h" 4 5 #include "../../../Common/MyException.h" 6 #include "../../../Common/StdOutStream.h" 7 8 #include "../../../Windows/ErrorMsg.h" 9 #include "../../../Windows/NtCheck.h" 10 11 #include "../Common/ArchiveCommandLine.h" 12 #include "../Common/ExitCode.h" 13 14 #include "ConsoleClose.h" 15 16 using namespace NWindows; 17 18 CStdOutStream *g_StdStream = 0; 19 20 extern int Main2( 21 #ifndef _WIN32 22 int numArgs, const char *args[] 23 #endif 24 ); 25 26 static const char *kException_CmdLine_Error_Message = "\n\nCommand Line Error:\n"; 27 static const char *kExceptionErrorMessage = "\n\nError:\n"; 28 static const char *kUserBreak = "\nBreak signaled\n"; 29 static const char *kMemoryExceptionMessage = "\n\nERROR: Can't allocate required memory!\n"; 30 static const char *kUnknownExceptionMessage = "\n\nUnknown Error\n"; 31 static const char *kInternalExceptionMessage = "\n\nInternal Error #"; 32 33 #define NT_CHECK_FAIL_ACTION (*g_StdStream) << "Unsupported Windows version"; return NExitCode::kFatalError; 34 main(int numArgs,const char * args[])35int MY_CDECL main 36 ( 37 #ifndef _WIN32 38 int numArgs, const char *args[] 39 #endif 40 ) 41 { 42 g_StdStream = &g_StdOut; 43 44 NT_CHECK 45 46 NConsoleClose::CCtrlHandlerSetter ctrlHandlerSetter; 47 int res = 0; 48 try 49 { 50 res = Main2( 51 #ifndef _WIN32 52 numArgs, args 53 #endif 54 ); 55 } 56 catch(const CNewException &) 57 { 58 (*g_StdStream) << kMemoryExceptionMessage; 59 return (NExitCode::kMemoryError); 60 } 61 catch(const NConsoleClose::CCtrlBreakException &) 62 { 63 (*g_StdStream) << endl << kUserBreak; 64 return (NExitCode::kUserBreak); 65 } 66 catch(const CArcCmdLineException &e) 67 { 68 (*g_StdStream) << kException_CmdLine_Error_Message << e << endl; 69 return (NExitCode::kUserError); 70 } 71 catch(const CSystemException &systemError) 72 { 73 if (systemError.ErrorCode == E_OUTOFMEMORY) 74 { 75 (*g_StdStream) << kMemoryExceptionMessage; 76 return (NExitCode::kMemoryError); 77 } 78 if (systemError.ErrorCode == E_ABORT) 79 { 80 (*g_StdStream) << endl << kUserBreak; 81 return (NExitCode::kUserBreak); 82 } 83 (*g_StdStream) << endl << endl << "System error:" << endl << 84 NError::MyFormatMessage(systemError.ErrorCode) << endl; 85 return (NExitCode::kFatalError); 86 } 87 catch(NExitCode::EEnum &exitCode) 88 { 89 (*g_StdStream) << kInternalExceptionMessage << exitCode << endl; 90 return (exitCode); 91 } 92 /* 93 catch(const NExitCode::CMultipleErrors &multipleErrors) 94 { 95 (*g_StdStream) << endl << multipleErrors.NumErrors << " errors" << endl; 96 return (NExitCode::kFatalError); 97 } 98 */ 99 catch(const UString &s) 100 { 101 (*g_StdStream) << kExceptionErrorMessage << s << endl; 102 return (NExitCode::kFatalError); 103 } 104 catch(const AString &s) 105 { 106 (*g_StdStream) << kExceptionErrorMessage << s << endl; 107 return (NExitCode::kFatalError); 108 } 109 catch(const char *s) 110 { 111 (*g_StdStream) << kExceptionErrorMessage << s << endl; 112 return (NExitCode::kFatalError); 113 } 114 catch(int t) 115 { 116 (*g_StdStream) << kInternalExceptionMessage << t << endl; 117 return (NExitCode::kFatalError); 118 } 119 catch(...) 120 { 121 (*g_StdStream) << kUnknownExceptionMessage; 122 return (NExitCode::kFatalError); 123 } 124 return res; 125 } 126