rar.cpp 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #include "rar.hpp"
  2. #if !defined(RARDLL)
  3. int main(int argc, char *argv[])
  4. {
  5. #ifdef _UNIX
  6. setlocale(LC_ALL,"");
  7. #endif
  8. InitConsole();
  9. ErrHandler.SetSignalHandlers(true);
  10. #ifdef SFX_MODULE
  11. wchar ModuleName[NM];
  12. #ifdef _WIN_ALL
  13. GetModuleFileName(NULL,ModuleName,ASIZE(ModuleName));
  14. #else
  15. CharToWide(argv[0],ModuleName,ASIZE(ModuleName));
  16. #endif
  17. #endif
  18. #ifdef _WIN_ALL
  19. SetErrorMode(SEM_NOALIGNMENTFAULTEXCEPT|SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
  20. #endif
  21. #if defined(_WIN_ALL) && !defined(SFX_MODULE)
  22. // Must be initialized, normal initialization can be skipped in case of
  23. // exception.
  24. POWER_MODE ShutdownOnClose=POWERMODE_KEEP;
  25. #endif
  26. try
  27. {
  28. CommandData *Cmd=new CommandData;
  29. #ifdef SFX_MODULE
  30. wcsncpyz(Cmd->Command,L"X",ASIZE(Cmd->Command));
  31. char *Switch=argc>1 ? argv[1]:NULL;
  32. if (Switch!=NULL && Cmd->IsSwitch(Switch[0]))
  33. {
  34. int UpperCmd=etoupper(Switch[1]);
  35. switch(UpperCmd)
  36. {
  37. case 'T':
  38. case 'V':
  39. Cmd->Command[0]=UpperCmd;
  40. break;
  41. case '?':
  42. Cmd->OutHelp(RARX_SUCCESS);
  43. break;
  44. }
  45. }
  46. Cmd->AddArcName(ModuleName);
  47. Cmd->ParseDone();
  48. Cmd->AbsoluteLinks=true; // If users runs SFX, he trusts an archive source.
  49. #else // !SFX_MODULE
  50. Cmd->ParseCommandLine(true,argc,argv);
  51. if (!Cmd->ConfigDisabled)
  52. {
  53. Cmd->ReadConfig();
  54. Cmd->ParseEnvVar();
  55. }
  56. Cmd->ParseCommandLine(false,argc,argv);
  57. #endif
  58. #if defined(_WIN_ALL) && !defined(SFX_MODULE)
  59. ShutdownOnClose=Cmd->Shutdown;
  60. if (ShutdownOnClose)
  61. ShutdownCheckAnother(true);
  62. #endif
  63. uiInit(Cmd->Sound);
  64. InitLogOptions(Cmd->LogName,Cmd->ErrlogCharset);
  65. ErrHandler.SetSilent(Cmd->AllYes || Cmd->MsgStream==MSG_NULL);
  66. Cmd->OutTitle();
  67. Cmd->ProcessCommand();
  68. delete Cmd;
  69. }
  70. catch (RAR_EXIT ErrCode)
  71. {
  72. ErrHandler.SetErrorCode(ErrCode);
  73. }
  74. catch (std::bad_alloc&)
  75. {
  76. ErrHandler.MemoryErrorMsg();
  77. ErrHandler.SetErrorCode(RARX_MEMORY);
  78. }
  79. catch (...)
  80. {
  81. ErrHandler.SetErrorCode(RARX_FATAL);
  82. }
  83. #if defined(_WIN_ALL) && !defined(SFX_MODULE)
  84. if (ShutdownOnClose!=POWERMODE_KEEP && ErrHandler.IsShutdownEnabled() &&
  85. !ShutdownCheckAnother(false))
  86. Shutdown(ShutdownOnClose);
  87. #endif
  88. ErrHandler.MainExit=true;
  89. return ErrHandler.GetErrorCode();
  90. }
  91. #endif