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