Changeset 209 for trunk/UCore.pas


Ignore:
Timestamp:
Sep 20, 2021, 12:25:22 PM (3 years ago)
Author:
chronos
Message:
  • Fixed: Correctly detect data application directories for Linux installation.
  • Modified: Use registry key and root from application info component.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UCore.pas

    r208 r209  
    4949    InitializeStarted: Boolean;
    5050    InitializeFinished: Boolean;
     51    function GetAppShareDir(Dir: string): string;
    5152    procedure Initialize;
    5253    procedure LoadConfig;
     
    5960  Core: TCore;
    6061
    61 const
    62   DefaultRegKey = '\Software\Chronosoft\Acronym Decoder';
    63 
    6462
    6563implementation
     
    8280
    8381procedure TCore.DataModuleCreate(Sender: TObject);
    84 const
    85   LinuxLanguagesDir = '/usr/share/AcronymDecoder/Languages';
    86 begin
    87   {$IFDEF Linux}
    88   // If installed in Linux system then use installation directory for po files
    89   if not DirectoryExists(Translator.POFilesFolder) and DirectoryExists(LinuxLanguagesDir) then
    90     Translator.POFilesFolder := LinuxLanguagesDir;
    91   {$ENDIF}
     82begin
     83  Translator.POFilesFolder := GetAppShareDir('Languages');
    9284
    9385  AcronymDb := nil;
     
    131123  {$ENDIF}
    132124  WriteLn(Text);
     125end;
     126
     127function TCore.GetAppShareDir(Dir: string): string;
     128var
     129  NewDir: string;
     130begin
     131  Result := ExtractFileDir(Application.ExeName) + DirectorySeparator + Dir;
     132  {$IFDEF Linux}
     133  // If installed in Linux system then try to use different installation directory
     134  if not DirectoryExists(Result) then begin
     135    NewDir := '/usr/share/' + ExtractFileNameOnly(Application.ExeName) + DirectorySeparator + Dir;
     136    if DirectoryExists(NewDir) then Result := NewDir;
     137  end;
     138  {$ENDIF}
    133139end;
    134140
     
    159165    end;
    160166
    161     ExamplesDir := ExtractFileDir(Application.ExeName) + DirectorySeparator +
    162       'Examples';
    163     {$IFDEF Linux}
    164     // If installed in Linux system then use installation directory for po files
    165     if Application.ExeName = '/usr/bin/' + ExtractFileNameOnly(Application.ExeName) then
    166       ExamplesDir := '/usr/share/' + ExtractFileNameOnly(Application.ExeName) +
    167         DirectorySeparator + 'Examples';
    168     {$ENDIF}
     167    ExamplesDir := GetAppShareDir('Examples');
    169168    ExampleFileName := ExamplesDir + DirectorySeparator + ExampleFile;
    170169
     
    212211  with TRegistryEx.Create do
    213212  try
    214     RootKey := HKEY_CURRENT_USER;
    215     OpenKey(DefaultRegKey, True);
     213    RootKey := RegistryRootHKEY[ApplicationInfo1.RegistryRoot];
     214    OpenKey(ApplicationInfo1.RegistryKey, True);
    216215    ScaleDPI1.DPI := Point(ReadIntegerWithDefault('DPIX', 96), ReadIntegerWithDefault('DPIY', 96));
    217216    ScaleDPI1.AutoDetect := ReadBoolWithDefault('DPIAuto', True);
     
    234233  with TRegistryEx.Create do
    235234  try
    236     RootKey := HKEY_CURRENT_USER;
    237     OpenKey(DefaultRegKey, True);
     235    RootKey := RegistryRootHKEY[ApplicationInfo1.RegistryRoot];
     236    OpenKey(ApplicationInfo1.RegistryKey, True);
    238237    WriteInteger('DPIX', ScaleDPI1.DPI.X);
    239238    WriteInteger('DPIY', ScaleDPI1.DPI.Y);
Note: See TracChangeset for help on using the changeset viewer.