Command line parameter -C affects names of *.cfg, *.dsk and *.ini

This commit is contained in:
Margers 2025-01-09 21:01:51 +00:00 committed by Michael Van Canneyt
parent 12bc05d2b4
commit 83d045d1f1
10 changed files with 66 additions and 42 deletions

View File

@ -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) }

View File

@ -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';

View File

@ -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;

View File

@ -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;

View File

@ -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);

View File

@ -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);

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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;