From 83d045d1f1a95c017e5260e05b28bf119205fd46 Mon Sep 17 00:00:00 2001 From: Margers Date: Thu, 9 Jan 2025 21:01:51 +0000 Subject: [PATCH] Command line parameter -C affects names of *.cfg, *.dsk and *.ini --- packages/ide/fp.pas | 5 ++++- packages/ide/fpconst.pas | 16 ++++++++----- packages/ide/fpdesk.pas | 4 ++-- packages/ide/fpide.pas | 2 +- packages/ide/fpini.pas | 47 ++++++++++++++++++++------------------- packages/ide/fpmopts.inc | 8 +++---- packages/ide/fpswitch.pas | 4 ++-- packages/ide/fptools.pas | 2 +- packages/ide/fputils.pas | 10 +++++++++ packages/ide/fpvars.pas | 10 ++++++--- 10 files changed, 66 insertions(+), 42 deletions(-) diff --git a/packages/ide/fp.pas b/packages/ide/fp.pas index b4e54636d0..d1b078230c 100644 --- a/packages/ide/fp.pas +++ b/packages/ide/fp.pas @@ -201,7 +201,10 @@ begin delete(param,1,1); // delete C if (length(Param)>=1) and (Param[1] in['=',':']) then Delete(Param,1,1); { eat optional separator } - IniFileName:=Param; + IniFileName:=MakeFileNameExt(Param,IniExt); + DesktopFileName:=MakeFileNameExt(Param,DesktopExt); + SwitchesFileName:=MakeFileNameExt(Param,SwitchesExt); + DirInfoFileName:=MakeFileNameExt(Param,DirInfoExt); end; {$ifdef GDBMI} 'G' : { custom GDB exec file (GDBMI mode only) } diff --git a/packages/ide/fpconst.pas b/packages/ide/fpconst.pas index 84c36051c6..302091ede8 100644 --- a/packages/ide/fpconst.pas +++ b/packages/ide/fpconst.pas @@ -67,11 +67,17 @@ const {$ifndef USE_SPECIAL_BASENAME} FPBaseName = 'fp'; {$endif not USE_SPECIAL_BASENAME} - ININame = FPBaseName+'.ini'; - DirInfoName = FPBaseName+'.dir'; - SwitchesName = FPBaseName+'.cfg'; - DesktopName = FPBaseName+'.dsk'; - BrowserName = FPBaseName+'.brw'; + INIExt = '.ini'; + DirInfoExt = '.dir'; + SwitchesExt = '.cfg'; + DesktopExt = '.dsk'; + BrowserExt = '.brw'; + + ININame = FPBaseName+INIExt; + DirInfoName = FPBaseName+DirInfoExt; + SwitchesName = FPBaseName+SwitchesExt; + DesktopName = FPBaseName+DesktopExt; + BrowserName = FPBaseName+BrowserExt; BackgroundName = 'fp.ans'; ReadmeName = 'readme.ide'; diff --git a/packages/ide/fpdesk.pas b/packages/ide/fpdesk.pas index c3e5553f56..fd782dfb27 100644 --- a/packages/ide/fpdesk.pas +++ b/packages/ide/fpdesk.pas @@ -138,9 +138,9 @@ const procedure InitDesktopFile; begin if DesktopLocation=dlCurrentDir then - DesktopPath:=FExpand(DesktopName) + DesktopPath:=FExpand(DesktopFileName) else - DesktopPath:=FExpand(DirOf(IniFileName)+DesktopName); + DesktopPath:=FExpand(DirOf(IniFilePath)+DesktopFileName); end; procedure DoneDesktopFile; diff --git a/packages/ide/fpide.pas b/packages/ide/fpide.pas index 9bcc5ae3e4..0377a4b5ef 100644 --- a/packages/ide/fpide.pas +++ b/packages/ide/fpide.pas @@ -1709,7 +1709,7 @@ end; procedure TIDEApp.UpdateINIFile; begin - SetMenuItemParam(SearchMenuItem(MenuBar^.Menu,cmSaveINI),SmartPath(IniFileName)); + SetMenuItemParam(SearchMenuItem(MenuBar^.Menu,cmSaveINI),SmartPath(IniFilePath)); end; procedure TIDEApp.UpdateRecentFileList; diff --git a/packages/ide/fpini.pas b/packages/ide/fpini.pas index aba7d2f54a..cbf3195bcd 100644 --- a/packages/ide/fpini.pas +++ b/packages/ide/fpini.pas @@ -204,10 +204,11 @@ end; procedure InitINIFile; var S: string; begin + IniFilePath:=INIFileName; S:=LocateFile(INIFileName); if S<>'' then - IniFileName:=S; - IniFileName:=FExpand(IniFileName); + IniFilePath:=S; + IniFilePath:=FExpand(IniFilePath); end; procedure CheckINIFile; @@ -215,42 +216,42 @@ var IniDir,CurDir: DirStr; INI: PINIFile; const Btns : array[1..2] of string = (btn_config_copyexisting,btn_config_createnew); begin - IniDir:=DirOf(IniFileName); CurDir:=GetCurDir; + IniDir:=DirOf(IniFilePath); CurDir:=GetCurDir; if CompareText(IniDir,CurDir)<>0 then - if not ExistsFile(CurDir+DirInfoName) then + if not ExistsFile(CurDir+DirInfoFileName) then if ConfirmBox(FormatStrStr(msg_doyouwanttocreatelocalconfigfile,IniDir),nil,false)=cmYes then begin - if (not ExistsFile(IniFileName)) or + if (not ExistsFile(IniFilePath )) or (ChoiceBox(msg_configcopyexistingorcreatenew,nil, Btns,false)=cmUserBtn2) then begin { create new config here } - IniFileName:=CurDir+IniName; - SwitchesPath:=CurDir+SwitchesName; + IniFilePath:=CurDir+IniFileName; + SwitchesPath:=CurDir+SwitchesFileName; end else begin { copy config here } - if CopyFile(IniFileName,CurDir+IniName)=false then - ErrorBox(FormatStrStr(msg_errorwritingfile,CurDir+IniName),nil) + if CopyFile(IniFilePath,CurDir+IniFileName)=false then + ErrorBox(FormatStrStr(msg_errorwritingfile,CurDir+IniFileName),nil) else - IniFileName:=CurDir+IniName; + IniFilePath:=CurDir+IniFileName; { copy also SwitchesPath to current dir, but only if 1) SwitchesPath exists 2) SwitchesPath is different from CurDir+SwitchesName } if ExistsFile(SwitchesPath) and - not SameFileName(SwitchesPath,CurDir+SwitchesName) then + not SameFileName(SwitchesPath,CurDir+SwitchesFileName) then begin - if CopyFile(SwitchesPath,CurDir+SwitchesName)=false then - ErrorBox(FormatStrStr(msg_errorwritingfile,CurDir+SwitchesName),nil) + if CopyFile(SwitchesPath,CurDir+SwitchesFileName)=false then + ErrorBox(FormatStrStr(msg_errorwritingfile,CurDir+SwitchesFileName),nil) else - SwitchesPath:=CurDir+SwitchesName; + SwitchesPath:=CurDir+SwitchesFileName; end; end; end else begin - New(INI, Init(CurDir+DirInfoName)); + New(INI, Init(CurDir+DirInfoFileName)); INI^.SetEntry(MainSectionName,'Comment','Do NOT delete this file!!!'); if INI^.Update=false then ErrorBox(FormatStrStr(msg_errorwritingfile,INI^.GetFileName),nil); @@ -404,10 +405,10 @@ var INIFile: PINIFile; W: word; crcv:cardinal; begin - OK:=ExistsFile(IniFileName); + OK:=ExistsFile(IniFilePath); if OK then begin - New(INIFile, Init(IniFileName)); + New(INIFile, Init(IniFilePath)); { Files } OpenExts:=INIFile^.GetEntry(secFiles,ieOpenExts,OpenExts); RecentFileCount:=High(RecentFiles); @@ -597,10 +598,10 @@ var INIFile: PINIFile; OK: boolean; begin {$ifdef Unix} - if not FromSaveAs and (DirOf(IniFileName)=DirOf(SystemIDEDir)) then + if not FromSaveAs and (DirOf(IniFilePath)=DirOf(SystemIDEDir)) then begin - IniFileName:=FExpand('~/.fp/'+IniName); - If not ExistsDir(DirOf(IniFileName)) then + IniFilePath:=FExpand('~/.fp/'+IniFileName); + If not ExistsDir(DirOf(IniFilePath)) then MkDir(FExpand('~/.fp')); end; {$endif Unix} @@ -608,12 +609,12 @@ begin if not FromSaveAs and (DirOf(IniFileName)=DirOf(SystemIDEDir)) and (GetEnv('APPDATA')<>'') then begin - IniFileName:=FExpand(GetEnv('APPDATA')+'/fp/'+IniName); - If not ExistsDir(DirOf(IniFileName)) then + IniFilePath:=FExpand(GetEnv('APPDATA')+'/fp/'+IniFileName); + If not ExistsDir(DirOf(IniFilePath)) then MkDir(FExpand(GetEnv('APPDATA')+'/fp')); end; {$endif WINDOWS} - New(INIFile, Init(IniFileName)); + New(INIFile, Init(IniFilePath)); { Files } { avoid keeping old files } INIFile^.DeleteSection(secFiles); diff --git a/packages/ide/fpmopts.inc b/packages/ide/fpmopts.inc index 7977f1490c..43d6b6e254 100644 --- a/packages/ide/fpmopts.inc +++ b/packages/ide/fpmopts.inc @@ -1628,14 +1628,14 @@ procedure TIDEApp.OpenINI; var D : PFPFileDialog; FileName: string; begin - New(D, Init('*'+ExtOf(INIFileName),dialog_openoptions,dialog_ini_filename,fdOpenButton,hidOpenIniFile)); + New(D, Init('*'+ExtOf(INIFilePath),dialog_openoptions,dialog_ini_filename,fdOpenButton,hidOpenIniFile)); D^.HelpCtx:=hcOpenIni; if Desktop^.ExecView(D)<>cmCancel then begin D^.GetFileName(FileName); if ExistsFile(FileName)=false then ErrorBox(msg_cantopenconfigfile,nil) else begin - IniFileName:=FileName; + IniFilePath:=FileName; ReadINIFile; Message(Application,evBroadcast,cmUpdate,nil); end; @@ -1654,7 +1654,7 @@ var D : PFPFileDialog; FileName: string; CanWrite: boolean; begin - New(D, Init('*'+ExtOf(INIFileName),dialog_saveoptions,dialog_ini_filename,fdOkButton,hidSaveIniFile)); + New(D, Init('*'+ExtOf(INIFilePath),dialog_saveoptions,dialog_ini_filename,fdOkButton,hidSaveIniFile)); D^.HelpCtx:=hcSaveAsINI; if Desktop^.ExecView(D)<>cmCancel then begin @@ -1664,7 +1664,7 @@ begin CanWrite:=ConfirmBox(FormatStrStr(msg_filealreadyexistsoverwrite,SmartPath(FileName)),nil,false)=cmYes; if CanWrite then begin - IniFileName:=FileName; + IniFilePath:=FileName; if WriteINIFile(true)=false then ErrorBox(msg_errorsavingconfigfile,nil); Message(Application,evBroadcast,cmUpdate,nil); diff --git a/packages/ide/fpswitch.pas b/packages/ide/fpswitch.pas index 0e8b2b4421..f0f86f5043 100644 --- a/packages/ide/fpswitch.pas +++ b/packages/ide/fpswitch.pas @@ -1441,9 +1441,9 @@ begin AddLongIntItem('~S~tack size','s'); AddLongIntItem('Local ~h~eap size','h'); end;} - SwitchesPath:=LocateFile(SwitchesName); + SwitchesPath:=LocateFile(SwitchesFileName); if SwitchesPath='' then - SwitchesPath:=SwitchesName; + SwitchesPath:=SwitchesFileName; SwitchesPath:=FExpand(SwitchesPath); end; diff --git a/packages/ide/fptools.pas b/packages/ide/fptools.pas index babeaf957f..ac76e203ae 100644 --- a/packages/ide/fptools.pas +++ b/packages/ide/fptools.pas @@ -1140,7 +1140,7 @@ begin if (WordS='$CONFIG') then begin if (Pass=1) then - I:=I+ReplacePart(LastWordStart,I-1,IniFileName)-1; + I:=I+ReplacePart(LastWordStart,I-1,IniFilePath)-1; end else if (WordS='$DIR') then begin diff --git a/packages/ide/fputils.pas b/packages/ide/fputils.pas index 1b2a614a34..7ceb78fce5 100644 --- a/packages/ide/fputils.pas +++ b/packages/ide/fputils.pas @@ -48,6 +48,7 @@ const function SmartPath(Path: string): string; Function FixPath(s:string;allowdot:boolean):string; function FixFileName(const s:string):string; +function MakeFileNameExt(const fn:string; const aExt: string):string; function MakeExeName(const fn:string):string; function Center(const S: string; Len: byte): string; function FitStr(const S: string; Len: byte): string; @@ -173,6 +174,15 @@ begin FixFileName[0]:=s[0]; end; +function MakeFileNameExt(const fn:string; const aExt: string):string; +var + d : DirStr; + n : NameStr; + e : ExtStr; +begin + FSplit(fn,d,n,e); + MakeFileNameExt:=d+n+aExt; +end; function MakeExeName(const fn:string):string; var diff --git a/packages/ide/fpvars.pas b/packages/ide/fpvars.pas index 32a609aafa..ea6067af3c 100644 --- a/packages/ide/fpvars.pas +++ b/packages/ide/fpvars.pas @@ -93,15 +93,19 @@ const ClipboardWindow : PClipboardWindow = nil; {$if defined(WINDOWS) or defined(Unix) or defined(Aros)} SystemIDEDir : string = ''; {$endif defined(WINDOWS) or defined(Unix)} - INIFileName : string = ININame; - SwitchesPath : string = SwitchesName; +var INIFilePath : string; + SwitchesPath : string; + DesktopPath : string; +const INIFileName : string = ININame; + SwitchesFileName : string = SwitchesName; + DesktopFileName : string = DesktopName; + DirInfoFileName : string = DirInfoName; CtrlMouseAction : integer = acTopicSearch; AltMouseAction : integer = acBrowseSymbol; StartupOptions : longint = 0; LastExitCode : integer = 0; ASCIIChart : PFPASCIIChart = nil; BackgroundPath : string = BackgroundName; - DesktopPath : string = DesktopName; DesktopFileFlags : longint = dfHistoryLists+dfOpenWindows+ dfCodeCompleteWords+dfCodeTemplates; DesktopLocation : byte = dlConfigFileDir;