From 8a6d432b9ce6fc2ffe3d6c2e88c121bed4ff8aca Mon Sep 17 00:00:00 2001 From: Matteo Salvi Date: Sat, 8 Oct 2022 18:30:52 +0200 Subject: [PATCH] refactoring: some changes in path management --- Forms/Forms.About.pas | 2 +- Frame/Frame.Properties.General.Software.pas | 2 +- Library/AppConfig.Paths.pas | 49 ++++++++++++--------- Library/Kernel.Consts.pas | 1 + 4 files changed, 31 insertions(+), 23 deletions(-) diff --git a/Forms/Forms.About.pas b/Forms/Forms.About.pas index e4267780..d66e2626 100644 --- a/Forms/Forms.About.pas +++ b/Forms/Forms.About.pas @@ -76,7 +76,7 @@ procedure TfrmAbout.imgDonateClick(Sender: TObject); procedure TfrmAbout.imgLicenseClick(Sender: TObject); begin - OpenDocument(AppendPathDelim(ASuiteInstance.Paths.SuitePathWorking) + 'docs' + PathDelim + 'license.txt'); + OpenDocument(AppendPathDelim(ASuiteInstance.Paths.SuitePathDocs) + 'license.txt'); end; procedure TfrmAbout.lnklblWebSiteClick(Sender: TObject); diff --git a/Frame/Frame.Properties.General.Software.pas b/Frame/Frame.Properties.General.Software.pas index 30690b43..1d38beb3 100644 --- a/Frame/Frame.Properties.General.Software.pas +++ b/Frame/Frame.Properties.General.Software.pas @@ -106,7 +106,7 @@ function TfrmSWGeneralPropertyPage.InternalLoadData: Boolean; //lbInfo2.Caption := Format(lbInfo2.Caption, [ASuiteInstance.Paths.SuitePathWorking, ASuiteInstance.Paths.SuiteDrive]); //Strange bug. %asuite% and %drive% causing error "Invalid argument index in format...", so I'm using a workaround - lbInfo2.Caption := StringReplace(lbInfo2.Caption, '%s', ASuiteInstance.Paths.SuitePathWorking, [rfIgnoreCase]); + lbInfo2.Caption := StringReplace(lbInfo2.Caption, '%s', ASuiteInstance.Paths.SuitePathASuiteFolder, [rfIgnoreCase]); lbInfo2.Caption := StringReplace(lbInfo2.Caption, '%s', ASuiteInstance.Paths.SuiteDrive, [rfIgnoreCase]); if Assigned(CurrentNodeData) then diff --git a/Library/AppConfig.Paths.pas b/Library/AppConfig.Paths.pas index 3b5f5185..5d5201df 100644 --- a/Library/AppConfig.Paths.pas +++ b/Library/AppConfig.Paths.pas @@ -33,11 +33,11 @@ interface TConfigPaths = class private FSuitePathCurrentTheme: String; - FSuitePathList : String; - FSuiteDrive : String; - FSuitePathData : String; - FSuitePathSettings: String; - FSuitePathWorking : String; + FSuitePathASuiteFolder: String; + FSuitePathList : String; + FSuiteDrive : String; + FSuitePathData : String; + FSuitePathSettings : String; FEnvironmentVars : TPathList; FASuiteVars : TPathList; @@ -45,6 +45,7 @@ TConfigPaths = class function DeQuotedStr(AVar: AnsiString): AnsiString; function GetSuitePathBackup: String; function GetSuitePathCache: String; + function GetSuitePathDocs: String; function GetSuitePathLocale: String; function GetSuitePathMenuThemes: String; procedure SetSuitePathCurrentTheme(AValue: String); @@ -63,15 +64,16 @@ TConfigPaths = class procedure RemoveCacheFolders; procedure UpdatePathVariables; - property SuitePathList: String read FSuitePathList write FSuitePathList; - property SuitePathSettings: String read FSuitePathSettings write FSuitePathSettings; - property SuiteDrive: String read FSuiteDrive write FSuiteDrive; - property SuitePathData: String read FSuitePathData write FSuitePathData; - property SuitePathWorking: String read FSuitePathWorking write FSuitePathWorking; + property SuitePathList: String read FSuitePathList write FSuitePathList; //Path to list + property SuitePathSettings: String read FSuitePathSettings; //Path to settings + property SuiteDrive: String read FSuiteDrive; + property SuitePathData: String read FSuitePathData; //Path to folder data + property SuitePathASuiteFolder: String read FSuitePathASuiteFolder; //Path to asuite.exe property SuitePathLocale: String read GetSuitePathLocale; property SuitePathCache: String read GetSuitePathCache; property SuitePathBackup: String read GetSuitePathBackup; property SuitePathMenuThemes: String read GetSuitePathMenuThemes; + property SuitePathDocs: String read GetSuitePathDocs; property SuitePathCurrentTheme: String read FSuitePathCurrentTheme write SetSuitePathCurrentTheme; property EnvironmentVars: TPathList read FEnvironmentVars; @@ -164,14 +166,19 @@ function TConfigPaths.GetSuitePathCache: String; Result := AppendPathDelim(FSuitePathData + CACHE_DIR); end; +function TConfigPaths.GetSuitePathDocs: String; +begin + Result := AppendPathDelim(FSuitePathASuiteFolder + DOCS_DIR); +end; + function TConfigPaths.GetSuitePathLocale: String; begin - Result := AppendPathDelim(FSuitePathWorking + LOCALE_DIR); + Result := AppendPathDelim(FSuitePathASuiteFolder + LOCALE_DIR); end; function TConfigPaths.GetSuitePathMenuThemes: String; begin - Result := AppendPathDelim(FSuitePathWorking + MENUTHEMES_DIR); + Result := AppendPathDelim(FSuitePathASuiteFolder + MENUTHEMES_DIR); end; procedure TConfigPaths.UpdateASuiteVars; @@ -183,7 +190,7 @@ procedure TConfigPaths.UpdateASuiteVars; strFolderIcon := AppendPathDelim(FSuitePathCurrentTheme + ICONS_DIR); //CONST_PATH_ASuite = Launcher's path - FASuiteVars.Add(DeQuotedStr(CONST_PATH_ASUITE), ExcludeTrailingPathDelimiter(SuitePathWorking)); + FASuiteVars.Add(DeQuotedStr(CONST_PATH_ASUITE), ExcludeTrailingPathDelimiter(FSuitePathASuiteFolder)); //CONST_PATH_DRIVE = Launcher's Drive (ex. ASuite in H:\Software\ASuite.exe, CONST_PATH_DRIVE is H: ) FASuiteVars.Add(DeQuotedStr(CONST_PATH_DRIVE), SUITEDRIVE); @@ -201,7 +208,7 @@ constructor TConfigPaths.Create(APathExecutable: string); begin //Default paths strPathExe := APathExecutable; - FSuitePathWorking := ExtractFilePath(strPathExe); + FSuitePathASuiteFolder := ExtractFilePath(strPathExe); strFileListSql := ExtractFileNameOnly(strPathExe) + EXT_SQL; strFileListXml := ExtractFileNameOnly(strPathExe) + EXT_XML; @@ -212,18 +219,18 @@ constructor TConfigPaths.Create(APathExecutable: string); //In Linux, use the folder path of asuite FSuiteDrive := FSuitePathWorking; {$ENDIF} - SetCurrentDir(FSuitePathWorking); + SetCurrentDir(FSuitePathASuiteFolder); //If ASuite is started from a hard linked folder, it will be falsely unwritable //The user is unlikely to create a hard link for ASuite unless they use Scoop //In this case, however, the .sqlite files will already exist and you can //safely use them - if (IsDirectoryWritable(FSuitePathWorking)) or FileExists(FSuitePathWorking + strFileListXml) or - FileExists(FSuitePathWorking + strFileListSql) then - FSuitePathData := FSuitePathWorking + if (IsDirectoryWritable(FSuitePathASuiteFolder)) or FileExists(FSuitePathASuiteFolder + strFileListXml) or + FileExists(FSuitePathASuiteFolder + strFileListSql) then + FSuitePathData := FSuitePathASuiteFolder else begin - //FSuitePathWorking = ASuite.exe folder (ex C:\path\to\asuite_folder\) - //FSuitePathData = ASuite config folder (ex. C:\Users\user\AppData\Roaming\asuite\) + //FSuitePathASuiteFolder = ASuite.exe folder (ex C:\path\to\asuite_folder\) + //FSuitePathData = ASuite config folder (ex. C:\Users\user\AppData\Roaming\asuite\) FSuitePathData := GetAppConfigDir(True); SysUtils.ForceDirectories(FSuitePathData); end; @@ -285,7 +292,7 @@ function TConfigPaths.RelativeToAbsolute(const APath: String; //Note: Unfortunately old asuite vars is not quoted, but in format $var. // So these two vars are deprecated. This code remain for only backwards compatibility //CONST_PATH_ASuite_old = Launcher's path - Result := StringReplace(Result, CONST_PATH_ASuite_old, ExcludeTrailingPathDelimiter(SuitePathWorking), [rfIgnoreCase,rfReplaceAll]); + Result := StringReplace(Result, CONST_PATH_ASuite_old, ExcludeTrailingPathDelimiter(FSuitePathASuiteFolder), [rfIgnoreCase,rfReplaceAll]); //CONST_PATH_DRIVE_old = Launcher's Drive (ex. ASuite in H:\Software\ASuite.exe, CONST_PATH_DRIVE is H: ) Result := StringReplace(Result, CONST_PATH_DRIVE_old, SUITEDRIVE, [rfIgnoreCase,rfReplaceAll]); diff --git a/Library/Kernel.Consts.pas b/Library/Kernel.Consts.pas index 0614c280..efc770ca 100644 --- a/Library/Kernel.Consts.pas +++ b/Library/Kernel.Consts.pas @@ -39,6 +39,7 @@ interface MENUTHEMES_DIR = 'themes'; ICONS_DIR = 'icons'; BUTTONS_DIR = 'buttons'; + DOCS_DIR = 'docs'; //FileSystem DriveLetters = ['a'..'z', 'A'..'Z'];