Changeset 647 for trunk/Packages


Ignore:
Timestamp:
Feb 19, 2025, 9:18:32 AM (4 days ago)
Author:
chronos
Message:
  • Modified: Detect data files usr/share/c-evo directory on Linux as relative directory to usr/bin directory.
Location:
trunk/Packages/CevoComponents
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Packages/CevoComponents/Directories.pas

    r447 r647  
    44
    55var
    6   HomeDir: string;
    76  DataDir: string;
    87  LocaleCode: string = '';
     
    1615function GetSoundsDir: string;
    1716function GetAiDir: string;
     17function GetAppShareDir(Dir: string): string;
     18function GetAppShareFile(FileName: string): string;
    1819
    1920
     
    2122
    2223uses
    23   FileUtil, LCLIntf, LCLType, LCLProc, LazUTF8, SysUtils;
     24  FileUtil, LCLIntf, LCLType, LCLProc, LazUTF8, SysUtils, LazFileUtils, Forms;
     25
     26function GetAppShareDir(Dir: string): string;
     27{$IFDEF UNIX}
     28var
     29  NewDir: string;
     30{$ENDIF}
     31begin
     32  Result := ExtractFileDir(Application.ExeName) + DirectorySeparator + Dir;
     33  {$IFDEF UNIX}
     34  // If installed in Linux system then try to use different installation directory
     35  if not DirectoryExists(Result) then begin
     36    NewDir := ExtractFileDir(Application.ExeName) + DirectorySeparator + '..' +
     37      DirectorySeparator + 'share' + DirectorySeparator +
     38      ExtractFileNameOnly(Application.ExeName) + DirectorySeparator + Dir;
     39    if DirectoryExists(NewDir) then Result := NewDir;
     40  end;
     41  {$ENDIF}
     42end;
     43
     44function GetAppShareFile(FileName: string): string;
     45{$IFDEF UNIX}
     46var
     47  NewFile: string;
     48{$ENDIF}
     49begin
     50  Result := ExtractFileDir(Application.ExeName) + DirectorySeparator + FileName;
     51  {$IFDEF UNIX}
     52  // If installed in Linux system then try to use different installation directory
     53  if not FileExists(Result) then begin
     54    NewFile := ExtractFileDir(Application.ExeName) + DirectorySeparator + '..' +
     55      DirectorySeparator + 'share' + DirectorySeparator +
     56      ExtractFileNameOnly(Application.ExeName) + DirectorySeparator + FileName;
     57    if FileExists(NewFile) then Result := NewFile;
     58  end;
     59  {$ENDIF}
     60end;
    2461
    2562function GetLocale: string;
     
    5794
    5895  if LocaleCode <> 'en' then begin
    59     Result := HomeDir + 'Localization' + DirectorySeparator + LocaleCodeDir + DirectorySeparator + Path;
     96    Result := GetAppShareFile('Localization' + DirectorySeparator + LocaleCodeDir + DirectorySeparator + Path);
    6097    if not DirectoryExists(Result) and not FileExists(Result) then
    61       Result := HomeDir + Path;
    62   end else Result := HomeDir + Path;
     98      Result := GetAppShareFile(Path);
     99  end else Result := GetAppShareFile(Path);
    63100end;
    64101
     
    92129begin
    93130  LocaleCode := '';
    94   HomeDir := ExtractFilePath(ParamStr(0));
    95131
    96132  AppDataDir := GetAppConfigDir(False);
    97   if AppDataDir = '' then DataDir := HomeDir
     133  if AppDataDir = '' then DataDir := GetAppShareDir('')
    98134  else begin
    99135    if not DirectoryExists(AppDataDir) then ForceDirectories(AppDataDir);
     
    105141function GetSavedDir(Home: Boolean = False): string;
    106142begin
    107   if Home then Result := HomeDir + 'Saved'
     143  if Home then Result := GetAppShareDir('Saved')
    108144    else Result := DataDir + 'Saved';
    109145end;
     
    111147function GetMapsDir(Home: Boolean = False): string;
    112148begin
    113   if Home then Result := HomeDir + 'Maps'
     149  if Home then Result := GetAppShareDir('Maps')
    114150    else Result := DataDir + 'Maps';
    115151end;
     
    117153function GetGraphicsDir: string;
    118154begin
    119   Result := HomeDir + 'Graphics';
     155  Result := GetAppShareDir('Graphics');
    120156end;
    121157
    122158function GetSoundsDir: string;
    123159begin
    124   Result := HomeDir + 'Sounds';
     160  Result := GetAppShareDir('Sounds');
    125161end;
    126162
    127163function GetAiDir: string;
    128164begin
    129   Result := HomeDir + 'AI';
     165  Result := GetAppShareDir('AI');
    130166end;
    131167
  • trunk/Packages/CevoComponents/ScreenTools.pas

    r608 r647  
    16091609    else
    16101610    begin
    1611       Phrases2.LoadFromFile(HomeDir + 'Language2.txt');
     1611      Phrases2.LoadFromFile(GetAppShareFile('Language2.txt'));
    16121612      Phrases2FallenBackToEnglish := True;
    16131613    end;
     
    16151615  else
    16161616  begin
    1617     Phrases.LoadFromFile(HomeDir + 'Language.txt');
    1618     Phrases2.LoadFromFile(HomeDir + 'Language2.txt');
     1617    Phrases.LoadFromFile(GetAppShareFile('Language.txt'));
     1618    Phrases2.LoadFromFile(GetAppShareFile('Language2.txt'));
    16191619  end;
    16201620
Note: See TracChangeset for help on using the changeset viewer.