Skip to content

Commit

Permalink
refactoring: some changes in path management
Browse files Browse the repository at this point in the history
  • Loading branch information
salvadorbs committed Oct 8, 2022
1 parent cbd7f76 commit a324e9f
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 24 deletions.
2 changes: 1 addition & 1 deletion Forms/Forms.About.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion Frame/Frame.Properties.General.Software.pas
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 29 additions & 22 deletions Library/AppConfig.Paths.pas
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,19 @@ 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;

function DeQuotedStr(AVar: AnsiString): AnsiString;
function GetSuitePathBackup: String;
function GetSuitePathCache: String;
function GetSuitePathDocs: String;
function GetSuitePathLocale: String;
function GetSuitePathMenuThemes: String;
procedure SetSuitePathCurrentTheme(AValue: String);
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -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;
Expand All @@ -210,20 +217,20 @@ constructor TConfigPaths.Create(APathExecutable: string);
FSuiteDrive := LowerCase(ExtractFileDrive(strPathExe));
{$ELSE}
//In Linux, use the folder path of asuite
FSuiteDrive := FSuitePathWorking;
FSuiteDrive := FSuitePathASuiteFolder;
{$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;
Expand Down Expand Up @@ -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]);

Expand Down
1 change: 1 addition & 0 deletions Library/Kernel.Consts.pas
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ interface
MENUTHEMES_DIR = 'themes';
ICONS_DIR = 'icons';
BUTTONS_DIR = 'buttons';
DOCS_DIR = 'docs';

//FileSystem
DriveLetters = ['a'..'z', 'A'..'Z'];
Expand Down

0 comments on commit a324e9f

Please sign in to comment.