Ignore:
Timestamp:
May 9, 2020, 4:02:07 PM (5 years ago)
Author:
chronos
Message:
  • Modified: Improved HighDPI branch. Imported new changes from trunk branch.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/highdpi/Packages/CevoComponents/Directories.pas

    r178 r210  
    44
    55var
    6   HomeDir, DataDir: string;
     6  HomeDir: string;
     7  DataDir: string;
    78  LocaleCode: string = '';
    89  LocaleCodeAuto: string = '';
    910
    1011function LocalizedFilePath(const Path: string): string;
    11 procedure InitUnit;
     12procedure UnitInit;
     13function GetSavedDir(Home: Boolean = False): string;
     14function GetMapsDir(Home: Boolean = False): string;
     15function GetGraphicsDir: string;
     16function GetSoundsDir: string;
     17function GetAiDir: string;
    1218
    1319
     
    2733
    2834  if Lang = '' then begin
    29       for i := 1 to Paramcount - 1 do
    30         if (ParamStrUTF8(i) = '--LANG') or (ParamStrUTF8(i) = '-l') or
    31           (ParamStrUTF8(i) = '--lang') then
     35    for i := 1 to Paramcount - 1 do
     36      if (ParamStrUTF8(i) = '--LANG') or (ParamStrUTF8(i) = '-l') or
     37        (ParamStrUTF8(i) = '--lang') then
    3238          Lang := ParamStrUTF8(i + 1);
    3339  end;
    3440  if Lang = '' then begin
     41    T := '';
    3542    LazGetLanguageIDs(Lang, T);
    3643    Lang := Copy(Lang, 1, 2);
     
    5158  if LocaleCode <> 'en' then begin
    5259    Result := HomeDir + 'Localization' + DirectorySeparator + LocaleCodeDir + DirectorySeparator + Path;
    53     if not FileExists(Result) then
     60    if not DirectoryExists(Result) and not FileExists(Result) then
    5461      Result := HomeDir + Path;
    5562  end else Result := HomeDir + Path;
    5663end;
    5764
    58 procedure InitUnit;
     65procedure UnitInit;
    5966var
    6067  AppDataDir: string;
     
    6976  else
    7077  begin
    71     if not DirectoryExists(AppDataDir) then
    72       CreateDir(AppDataDir);
     78    if not DirectoryExists(AppDataDir) then CreateDir(AppDataDir);
    7379    DataDir := AppDataDir;
    7480  end;
    75   if not DirectoryExists(DataDir + 'Saved') then
    76     CreateDir(DataDir + 'Saved');
    77   if not DirectoryExists(DataDir + 'Maps') then
    78     CreateDir(DataDir + 'Maps');
     81  if not DirectoryExists(GetSavedDir) then CreateDir(GetSavedDir);
     82  if not DirectoryExists(GetMapsDir) then CreateDir(GetMapsDir);
    7983
    8084  // Copy appdata if not done yet
    81   if FindFirst(HomeDir + 'Saved' + DirectorySeparator + '*.cevo', $21, src) = 0 then
     85  if FindFirst(GetSavedDir(True) + DirectorySeparator + '*.cevo', $21, src) = 0 then
    8286    repeat
    83       if (FindFirst(DataDir + 'Saved' + DirectorySeparator + src.Name, $21, dst) <> 0) or
     87      if (FindFirst(GetSavedDir(True) + DirectorySeparator + src.Name, $21, dst) <> 0) or
    8488        (dst.Time < src.Time) then
    85         CopyFile(PChar(HomeDir + 'Saved' + DirectorySeparator + src.Name),
    86           PChar(DataDir + 'Saved' + DirectorySeparator + src.Name), false);
     89        CopyFile(PChar(GetSavedDir(True) + DirectorySeparator + src.Name),
     90          PChar(GetSavedDir(True) + DirectorySeparator + src.Name), false);
    8791      FindClose(dst);
    8892    until FindNext(src) <> 0;
     
    9094
    9195  // Copy appdata if not done yet
    92   if FindFirst(HomeDir + 'Maps' + DirectorySeparator + '*.*', $21, src) = 0 then
     96  if FindFirst(GetMapsDir(True) + DirectorySeparator + '*.*', $21, src) = 0 then
    9397    repeat
    94       if (FindFirst(DataDir + 'Maps' + DirectorySeparator + src.Name, $21, dst) <> 0) or
     98      if (FindFirst(GetMapsDir(True) + DirectorySeparator + src.Name, $21, dst) <> 0) or
    9599        (dst.Time < src.Time) then
    96         CopyFile(PChar(HomeDir + 'Maps' + DirectorySeparator + src.Name),
    97           PChar(DataDir + 'Maps' + DirectorySeparator + src.Name), false);
     100        CopyFile(PChar(GetMapsDir(True) + DirectorySeparator + src.Name),
     101          PChar(GetMapsDir(True) + DirectorySeparator + src.Name), false);
    98102      FindClose(dst);
    99103    until FindNext(src) <> 0;
     
    101105end;
    102106
     107function GetSavedDir(Home: Boolean = False): string;
     108begin
     109  if Home then Result := HomeDir + 'Saved'
     110    else Result := DataDir + 'Saved';
     111end;
     112
     113function GetMapsDir(Home: Boolean = False): string;
     114begin
     115  if Home then Result := HomeDir + 'Maps'
     116    else Result := DataDir + 'Maps';
     117end;
     118
     119function GetGraphicsDir: string;
     120begin
     121  Result := HomeDir + 'Graphics';
     122end;
     123
     124function GetSoundsDir: string;
     125begin
     126  Result := HomeDir + 'Sounds';
     127end;
     128
     129function GetAiDir: string;
     130begin
     131  Result := HomeDir + 'AI';
     132end;
     133
    103134end.
Note: See TracChangeset for help on using the changeset viewer.