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