2009-11-10 16:48:42 +01:00
|
|
|
#include "rar.hpp"
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
#if !defined(RARDLL)
|
2009-11-10 16:48:42 +01:00
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2020-07-15 00:40:26 +02:00
|
|
|
|
2009-11-10 16:48:42 +01:00
|
|
|
#ifdef _UNIX
|
|
|
|
setlocale(LC_ALL,"");
|
|
|
|
#endif
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
InitConsole();
|
2009-11-10 16:48:42 +01:00
|
|
|
ErrHandler.SetSignalHandlers(true);
|
|
|
|
|
|
|
|
#ifdef SFX_MODULE
|
2020-07-15 00:40:26 +02:00
|
|
|
wchar ModuleName[NM];
|
|
|
|
#ifdef _WIN_ALL
|
|
|
|
GetModuleFileName(NULL,ModuleName,ASIZE(ModuleName));
|
2009-11-10 16:48:42 +01:00
|
|
|
#else
|
2020-07-15 00:40:26 +02:00
|
|
|
CharToWide(argv[0],ModuleName,ASIZE(ModuleName));
|
2009-11-10 16:48:42 +01:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
#ifdef _WIN_ALL
|
2009-11-10 16:48:42 +01:00
|
|
|
SetErrorMode(SEM_NOALIGNMENTFAULTEXCEPT|SEM_FAILCRITICALERRORS|SEM_NOOPENFILEERRORBOX);
|
|
|
|
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
#if defined(_WIN_ALL) && !defined(SFX_MODULE)
|
|
|
|
// Must be initialized, normal initialization can be skipped in case of
|
|
|
|
// exception.
|
|
|
|
POWER_MODE ShutdownOnClose=POWERMODE_KEEP;
|
2009-11-10 16:48:42 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
CommandData *Cmd=new CommandData;
|
2009-11-10 16:48:42 +01:00
|
|
|
#ifdef SFX_MODULE
|
2020-07-15 00:40:26 +02:00
|
|
|
wcsncpyz(Cmd->Command,L"X",ASIZE(Cmd->Command));
|
|
|
|
char *Switch=argc>1 ? argv[1]:NULL;
|
|
|
|
if (Switch!=NULL && Cmd->IsSwitch(Switch[0]))
|
2009-11-10 16:48:42 +01:00
|
|
|
{
|
|
|
|
int UpperCmd=etoupper(Switch[1]);
|
|
|
|
switch(UpperCmd)
|
|
|
|
{
|
|
|
|
case 'T':
|
|
|
|
case 'V':
|
2020-07-15 00:40:26 +02:00
|
|
|
Cmd->Command[0]=UpperCmd;
|
2009-11-10 16:48:42 +01:00
|
|
|
break;
|
|
|
|
case '?':
|
2020-07-15 00:40:26 +02:00
|
|
|
Cmd->OutHelp(RARX_SUCCESS);
|
2009-11-10 16:48:42 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2020-07-15 00:40:26 +02:00
|
|
|
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)
|
2009-11-10 16:48:42 +01:00
|
|
|
{
|
2020-07-15 00:40:26 +02:00
|
|
|
Cmd->ReadConfig();
|
|
|
|
Cmd->ParseEnvVar();
|
2009-11-10 16:48:42 +01:00
|
|
|
}
|
2020-07-15 00:40:26 +02:00
|
|
|
Cmd->ParseCommandLine(false,argc,argv);
|
2009-11-10 16:48:42 +01:00
|
|
|
#endif
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
#if defined(_WIN_ALL) && !defined(SFX_MODULE)
|
|
|
|
ShutdownOnClose=Cmd->Shutdown;
|
|
|
|
if (ShutdownOnClose)
|
|
|
|
ShutdownCheckAnother(true);
|
2009-11-10 16:48:42 +01:00
|
|
|
#endif
|
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
uiInit(Cmd->Sound);
|
|
|
|
InitLogOptions(Cmd->LogName,Cmd->ErrlogCharset);
|
|
|
|
ErrHandler.SetSilent(Cmd->AllYes || Cmd->MsgStream==MSG_NULL);
|
2009-11-10 16:48:42 +01:00
|
|
|
|
2020-07-15 00:40:26 +02:00
|
|
|
Cmd->OutTitle();
|
|
|
|
Cmd->ProcessCommand();
|
|
|
|
delete Cmd;
|
2009-11-10 16:48:42 +01:00
|
|
|
}
|
2020-07-15 00:40:26 +02:00
|
|
|
catch (RAR_EXIT ErrCode)
|
2009-11-10 16:48:42 +01:00
|
|
|
{
|
|
|
|
ErrHandler.SetErrorCode(ErrCode);
|
|
|
|
}
|
2020-07-15 00:40:26 +02:00
|
|
|
catch (std::bad_alloc&)
|
2009-11-10 16:48:42 +01:00
|
|
|
{
|
2020-07-15 00:40:26 +02:00
|
|
|
ErrHandler.MemoryErrorMsg();
|
|
|
|
ErrHandler.SetErrorCode(RARX_MEMORY);
|
2009-11-10 16:48:42 +01:00
|
|
|
}
|
|
|
|
catch (...)
|
|
|
|
{
|
2020-07-15 00:40:26 +02:00
|
|
|
ErrHandler.SetErrorCode(RARX_FATAL);
|
2009-11-10 16:48:42 +01:00
|
|
|
}
|
2020-07-15 00:40:26 +02:00
|
|
|
|
|
|
|
#if defined(_WIN_ALL) && !defined(SFX_MODULE)
|
|
|
|
if (ShutdownOnClose!=POWERMODE_KEEP && ErrHandler.IsShutdownEnabled() &&
|
|
|
|
!ShutdownCheckAnother(false))
|
|
|
|
Shutdown(ShutdownOnClose);
|
2009-11-10 16:48:42 +01:00
|
|
|
#endif
|
2020-07-15 00:40:26 +02:00
|
|
|
ErrHandler.MainExit=true;
|
|
|
|
return ErrHandler.GetErrorCode();
|
2009-11-10 16:48:42 +01:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|