📄 cmddata.cpp
字号:
#include "rar.hpp"CommandData::CommandData(){ FileArgs=ExclArgs=InclArgs=StoreArgs=ArcNames=NULL; Init();}CommandData::~CommandData(){ Close();}void CommandData::Init(){ Close(); *Command=0; *ArcName=0; *ArcNameW=0; FileLists=false; NoMoreSwitches=false; TimeConverted=false; FileArgs=new StringList; ExclArgs=new StringList; InclArgs=new StringList; StoreArgs=new StringList; ArcNames=new StringList;}void CommandData::Close(){ delete FileArgs; delete ExclArgs; delete InclArgs; delete StoreArgs; delete ArcNames; FileArgs=ExclArgs=InclArgs=StoreArgs=ArcNames=NULL; NextVolSizes.Reset();}#if !defined(SFX_MODULE)void CommandData::ParseArg(char *Arg,wchar *ArgW){ if (IsSwitch(*Arg) && !NoMoreSwitches) if (Arg[1]=='-') NoMoreSwitches=true; else ProcessSwitch(&Arg[1]); else if (*Command==0) { strncpyz(Command,Arg,ASIZE(Command)); if (ArgW!=NULL) strncpyw(CommandW,ArgW,sizeof(CommandW)/sizeof(CommandW[0])); if (etoupper(*Command)=='S') { const char *SFXName=Command[1] ? Command+1:DefSFXName; if (PointToName(SFXName)!=SFXName || FileExist(SFXName)) strcpy(SFXModule,SFXName); else GetConfigName(SFXName,SFXModule,true); }#ifndef GUI *Command=etoupper(*Command); if (*Command!='I' && *Command!='S') strupper(Command);#endif } else if (*ArcName==0) { strncpyz(ArcName,Arg,ASIZE(ArcName)); if (ArgW!=NULL) strncpyzw(ArcNameW,ArgW,ASIZE(ArcNameW)); } else { int Length=strlen(Arg); char EndChar=Arg[Length-1]; char CmdChar=etoupper(*Command); bool Add=strchr("AFUM",CmdChar)!=NULL; bool Extract=CmdChar=='X' || CmdChar=='E'; if ((IsDriveDiv(EndChar) || IsPathDiv(EndChar)) && !Add) { strncpyz(ExtrPath,Arg,ASIZE(ExtrPath)); if (ArgW!=NULL) strncpyzw(ExtrPathW,ArgW,ASIZE(ExtrPathW)); } else if ((Add || CmdChar=='T') && *Arg!='@') FileArgs->AddString(Arg); else { struct FindData FileData; bool Found=FindFile::FastFind(Arg,NULL,&FileData); if (!Found && *Arg=='@' && !IsWildcard(Arg)) { FileLists=true; RAR_CHARSET Charset=FilelistCharset;#if defined(_WIN_32) && !defined(GUI) // for compatibility reasons we use OEM encoding // in Win32 console version by default if (Charset==RCH_DEFAULT) Charset=RCH_OEM;#endif ReadTextFile(Arg+1,FileArgs,false,true,Charset,true,true); } else if (Found && FileData.IsDir && Extract && *ExtrPath==0) { strcpy(ExtrPath,Arg); AddEndSlash(ExtrPath); } else FileArgs->AddString(Arg); } }}#endifvoid CommandData::ParseDone(){ if (FileArgs->ItemsCount()==0 && !FileLists) FileArgs->AddString(MASKALL); char CmdChar=etoupper(*Command); bool Extract=CmdChar=='X' || CmdChar=='E'; if (Test && Extract) Test=false; BareOutput=(CmdChar=='L' || CmdChar=='V') && Command[1]=='B';}#if !defined(SFX_MODULE) && !defined(_WIN_CE)void CommandData::ParseEnvVar(){ char *EnvStr=getenv("RAR"); if (EnvStr!=NULL) ProcessSwitchesString(EnvStr);}#endif// return 'false' if -cfg- is present and preprocess switches// which must be processed before the rest of command line#ifndef SFX_MODULEbool CommandData::IsConfigEnabled(int argc,char *argv[]){ bool ConfigEnabled=true; for (int I=1;I<argc;I++) if (IsSwitch(*argv[I])) { if (stricomp(&argv[I][1],"cfg-")==0) ConfigEnabled=false;#ifndef GUI if (strnicomp(&argv[I][1],"ilog",4)==0) { // ensure that correct log file name is already set // if we need to report an error when processing the command line ProcessSwitch(&argv[I][1]); InitLogOptions(LogName); }#endif if (strnicomp(&argv[I][1],"sc",2)==0) { // process -cs before reading any file lists ProcessSwitch(&argv[I][1]); } } return(ConfigEnabled);}#endif#if !defined(GUI) && !defined(SFX_MODULE)void CommandData::ReadConfig(int argc,char *argv[]){ StringList List; if (ReadTextFile(DefConfigName,&List,true)) { char *Str; while ((Str=List.GetString())!=NULL) { while (isspace(*Str)) Str++; if (strnicomp(Str,"switches=",9)==0) ProcessSwitchesString(Str+9); } }}#endif#if !defined(SFX_MODULE) && !defined(_WIN_CE)void CommandData::ProcessSwitchesString(char *Str){ while (*Str) { while (!IsSwitch(*Str) && *Str!=0) Str++; if (*Str==0) break; char *Next=Str; while (!(Next[0]==' ' && IsSwitch(Next[1])) && *Next!=0) Next++; char NextChar=*Next; *Next=0; ProcessSwitch(Str+1); *Next=NextChar; Str=Next; }}#endif#if !defined(SFX_MODULE)void CommandData::ProcessSwitch(char *Switch){ switch(etoupper(Switch[0])) { case 'I': if (strnicomp(&Switch[1],"LOG",3)==0) { strncpyz(LogName,Switch[4] ? Switch+4:DefLogName,ASIZE(LogName)); break; } if (stricomp(&Switch[1],"SND")==0) { Sound=true; break; } if (stricomp(&Switch[1],"ERR")==0) { MsgStream=MSG_STDERR; break; } if (strnicomp(&Switch[1],"EML",3)==0) { strncpyz(EmailTo,Switch[4] ? Switch+4:"@",ASIZE(EmailTo)); EmailTo[sizeof(EmailTo)-1]=0; break; } if (stricomp(&Switch[1],"NUL")==0) { MsgStream=MSG_NULL; break; } if (etoupper(Switch[1])=='D') { for (int I=2;Switch[I]!=0;I++) switch(etoupper(Switch[I])) { case 'Q': MsgStream=MSG_ERRONLY; break; case 'C': DisableCopyright=true; break; case 'D': DisableDone=true; break; case 'P': DisablePercentage=true; break; } break; } if (stricomp(&Switch[1],"OFF")==0) { Shutdown=true; break; } break; case 'T': switch(etoupper(Switch[1])) { case 'K': ArcTime=ARCTIME_KEEP; break; case 'L': ArcTime=ARCTIME_LATEST; break; case 'O': FileTimeBefore.SetAgeText(Switch+2); break; case 'N': FileTimeAfter.SetAgeText(Switch+2); break; case 'B': FileTimeBefore.SetIsoText(Switch+2); break; case 'A': FileTimeAfter.SetIsoText(Switch+2); break; case 'S': { EXTTIME_MODE Mode=EXTTIME_HIGH3; bool CommonMode=Switch[2]>='0' && Switch[2]<='4'; if (CommonMode) Mode=(EXTTIME_MODE)(Switch[2]-'0'); if (Switch[2]=='-') Mode=EXTTIME_NONE; if (CommonMode || Switch[2]=='-' || Switch[2]=='+' || Switch[2]==0) xmtime=xctime=xatime=Mode; else { if (Switch[3]>='0' && Switch[3]<='4') Mode=(EXTTIME_MODE)(Switch[3]-'0'); if (Switch[3]=='-') Mode=EXTTIME_NONE; switch(etoupper(Switch[2])) { case 'M': xmtime=Mode; break; case 'C': xctime=Mode; break; case 'A': xatime=Mode; break; case 'R': xarctime=Mode; break; } } } break; case '-': Test=false; break; case 0: Test=true; break; default: BadSwitch(Switch); break; } break; case 'A': switch(etoupper(Switch[1])) { case 'C': ClearArc=true; break; case 'D': AppendArcNameToPath=true; break; case 'G': if (Switch[2]=='-' && Switch[3]==0) GenerateArcName=0; else { GenerateArcName=true; strncpyz(GenerateMask,Switch+2,ASIZE(GenerateMask)); } break; case 'N': //reserved for archive name break; case 'O': AddArcOnly=true; break; case 'P': strcpy(ArcPath,Switch+2); break; case 'S': SyncFiles=true; break; default: BadSwitch(Switch); break; } break; case 'D': if (Switch[2]==0) switch(etoupper(Switch[1])) { case 'S': DisableSortSolid=true; break; case 'H': OpenShared=true; break; case 'F': DeleteFiles=true; break; } break; case 'O': switch(etoupper(Switch[1])) { case '+': Overwrite=OVERWRITE_ALL; break; case '-': Overwrite=OVERWRITE_NONE; break; case 'R': Overwrite=OVERWRITE_AUTORENAME; break; case 'W': ProcessOwners=true; break;#ifdef SAVE_LINKS case 'L': SaveLinks=true; break;#endif#ifdef _WIN_32 case 'S': SaveStreams=true; break; case 'C': SetCompressedAttr=true; break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -