Changeset 169 for trunk


Ignore:
Timestamp:
Jun 15, 2019, 11:42:35 AM (5 years ago)
Author:
chronos
Message:
  • Modified: Store Saved and Maps subdirectory names only once in string variable.
Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/GameServer.pas

    r151 r169  
    556556  s: string[255];
    557557begin
    558   MapFile := TFileStream.Create(DataDir + 'Maps' + DirectorySeparator + FileName,
     558  MapFile := TFileStream.Create(GetMapsDir + DirectorySeparator + FileName,
    559559    fmCreate or fmShareExclusive);
    560560  MapFile.Position := 0;
     
    579579  MapFile := nil;
    580580  try
    581     MapFile := TFileStream.Create(DataDir + 'Maps' + DirectorySeparator + FileName,
     581    MapFile := TFileStream.Create(GetMapsDir + DirectorySeparator + FileName,
    582582      fmOpenRead or fmShareExclusive);
    583583    MapFile.Position := 0;
  • trunk/Packages/CevoComponents/Directories.pas

    r113 r169  
    44
    55var
    6   HomeDir, DataDir: string;
     6  HomeDir: string;
     7  DataDir: string;
    78  LocaleCode: string = '';
    89  LocaleCodeAuto: string = '';
     
    1011function LocalizedFilePath(const Path: string): string;
    1112procedure InitUnit;
     13function GetSavedDir(Home: Boolean = False): string;
     14function GetMapsDir(Home: Boolean = False): string;
    1215
    1316
     
    6972  else
    7073  begin
    71     if not DirectoryExists(AppDataDir) then
    72       CreateDir(AppDataDir);
     74    if not DirectoryExists(AppDataDir) then CreateDir(AppDataDir);
    7375    DataDir := AppDataDir;
    7476  end;
    75   if not DirectoryExists(DataDir + 'Saved') then
    76     CreateDir(DataDir + 'Saved');
    77   if not DirectoryExists(DataDir + 'Maps') then
    78     CreateDir(DataDir + 'Maps');
     77  if not DirectoryExists(GetSavedDir) then CreateDir(GetSavedDir);
     78  if not DirectoryExists(GetMapsDir) then CreateDir(GetMapsDir);
    7979
    8080  // Copy appdata if not done yet
    81   if FindFirst(HomeDir + 'Saved' + DirectorySeparator + '*.cevo', $21, src) = 0 then
     81  if FindFirst(GetSavedDir(True) + DirectorySeparator + '*.cevo', $21, src) = 0 then
    8282    repeat
    83       if (FindFirst(DataDir + 'Saved' + DirectorySeparator + src.Name, $21, dst) <> 0) or
     83      if (FindFirst(GetSavedDir(True) + DirectorySeparator + src.Name, $21, dst) <> 0) or
    8484        (dst.Time < src.Time) then
    85         CopyFile(PChar(HomeDir + 'Saved' + DirectorySeparator + src.Name),
    86           PChar(DataDir + 'Saved' + DirectorySeparator + src.Name), false);
     85        CopyFile(PChar(GetSavedDir(True) + DirectorySeparator + src.Name),
     86          PChar(GetSavedDir(True) + DirectorySeparator + src.Name), false);
    8787      FindClose(dst);
    8888    until FindNext(src) <> 0;
     
    9090
    9191  // Copy appdata if not done yet
    92   if FindFirst(HomeDir + 'Maps' + DirectorySeparator + '*.*', $21, src) = 0 then
     92  if FindFirst(GetMapsDir(True) + DirectorySeparator + '*.*', $21, src) = 0 then
    9393    repeat
    94       if (FindFirst(DataDir + 'Maps' + DirectorySeparator + src.Name, $21, dst) <> 0) or
     94      if (FindFirst(GetMapsDir(True) + DirectorySeparator + src.Name, $21, dst) <> 0) or
    9595        (dst.Time < src.Time) then
    96         CopyFile(PChar(HomeDir + 'Maps' + DirectorySeparator + src.Name),
    97           PChar(DataDir + 'Maps' + DirectorySeparator + src.Name), false);
     96        CopyFile(PChar(GetMapsDir(True) + DirectorySeparator + src.Name),
     97          PChar(GetMapsDir(True) + DirectorySeparator + src.Name), false);
    9898      FindClose(dst);
    9999    until FindNext(src) <> 0;
     
    101101end;
    102102
     103function GetSavedDir(Home: Boolean = False): string;
     104begin
     105  if Home then Result := HomeDir + 'Saved'
     106    else Result := DataDir + 'Saved';
     107end;
     108
     109function GetMapsDir(Home: Boolean = False): string;
     110begin
     111  if Home then Result := HomeDir + 'Maps'
     112    else Result := DataDir + 'Maps';
     113end;
     114
    103115end.
  • trunk/Start.lfm

    r124 r169  
    2525  OnPaint = FormPaint
    2626  OnShow = FormShow
    27   LCLVersion = '1.8.2.0'
     27  LCLVersion = '2.0.2.0'
    2828  object StartBtn: TButtonA
    2929    Tag = 15104
     
    199199    TabOrder = 0
    200200    TabStop = False
     201    TopIndex = -1
    201202    Visible = False
    202203  end
  • trunk/Start.pas

    r157 r169  
    7272    procedure FormShow(Sender: TObject);
    7373    procedure FormHide(Sender: TObject);
     74    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    7475    procedure FormCreate(Sender: TObject);
    7576    procedure FormDestroy(Sender: TObject);
    7677    procedure BrainClick(Sender: TObject);
     78    procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    7779    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;
    7880      Shift: TShiftState; x, y: integer);
     81    procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
     82      Shift: TShiftState; x, y: integer);
     83    procedure FormMouseMove(Sender: TObject; Shift: TShiftState; x, y: integer);
    7984    procedure Up1BtnClick(Sender: TObject);
    8085    procedure Down1BtnClick(Sender: TObject);
    81     procedure FormClose(Sender: TObject; var Action: TCloseAction);
    8286    procedure ListClick(Sender: TObject);
    8387    procedure RenameBtnClick(Sender: TObject);
     
    8892    procedure Down2BtnClick(Sender: TObject);
    8993    procedure QuitBtnClick(Sender: TObject);
    90     procedure FormKeyDown(Sender: TObject; var Key: Word; Shift: TShiftState);
    9194    procedure CustomizeBtnClick(Sender: TObject);
    9295    procedure AutoDiffUpBtnClick(Sender: TObject);
    9396    procedure AutoDiffDownBtnClick(Sender: TObject);
    94     procedure FormMouseUp(Sender: TObject; Button: TMouseButton;
    95       Shift: TShiftState; x, y: integer);
    96     procedure FormMouseMove(Sender: TObject; Shift: TShiftState; x, y: integer);
    9797    procedure AutoEnemyUpBtnClick(Sender: TObject);
    9898    procedure AutoEnemyDownBtnClick(Sender: TObject);
     
    926926      begin // load
    927927        FileName := List.Items[List.ItemIndex];
    928         if LoadGame(DataDir + 'Saved' + DirectorySeparator, FileName + CevoExt, LoadTurn, false)
     928        if LoadGame(GetSavedDir + DirectorySeparator, FileName + CevoExt, LoadTurn, false)
    929929        then
    930930          UnlistBackupFile(FileName)
     
    10101010        end;
    10111011
    1012         StartNewGame(DataDir + 'Saved' + DirectorySeparator, FileName + CevoExt, MapFileName,
     1012        StartNewGame(GetSavedDir + DirectorySeparator, FileName + CevoExt, MapFileName,
    10131013          lxpre[WorldSize], lypre[WorldSize], StartLandMass, MaxTurn);
    10141014        UnlistBackupFile(FileName);
     
    11451145    pgLoad:
    11461146      begin
    1147         AssignFile(LogFile, DataDir + 'Saved' + DirectorySeparator + List.Items[List.ItemIndex]
     1147        AssignFile(LogFile, GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex]
    11481148          + CevoExt);
    11491149        try
     
    11981198        if Page = pgEditMap then
    11991199          MapFileName := List.Items[List.ItemIndex] + CevoMapExt;
    1200         if LoadGraphicFile(Mini, DataDir + 'Maps' + DirectorySeparator + Copy(MapFileName, 1,
     1200        if LoadGraphicFile(Mini, GetMapsDir + DirectorySeparator + Copy(MapFileName, 1,
    12011201          Length(MapFileName) - 9) + '.png', gfNoError) then
    12021202        begin
     
    12151215        end;
    12161216
    1217         AssignFile(MapFile, DataDir + 'Maps' + DirectorySeparator + MapFileName);
     1217        AssignFile(MapFile, GetMapsDir + DirectorySeparator + MapFileName);
    12181218        try
    12191219          Reset(MapFile, 4);
     
    13951395begin
    13961396  FormerGames.Clear;
    1397   if FindFirst(DataDir + 'Saved' + DirectorySeparator + '*' + CevoExt, $21, F) = 0 then
     1397  if FindFirst(GetSavedDir + DirectorySeparator + '*' + CevoExt, $21, F) = 0 then
    13981398    repeat
    13991399      I := FormerGames.Count;
     
    14151415begin
    14161416  Maps.Clear;
    1417   if FindFirst(DataDir + 'Maps' + DirectorySeparator + '*' + CevoMapExt, $21, f) = 0 then
     1417  if FindFirst(GetMapsDir + DirectorySeparator + '*' + CevoMapExt, $21, f) = 0 then
    14181418    repeat
    14191419      Maps.Add(Copy(f.Name, 1, Length(f.Name) - 9));
     
    17901790        end;
    17911791      if Page = pgLoad then
    1792         AssignFile(f, DataDir + 'Saved' + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt)
     1792        AssignFile(f, GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt)
    17931793      else
    1794         AssignFile(f, DataDir + 'Maps'+ DirectorySeparator + List.Items[List.ItemIndex] +
     1794        AssignFile(f, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex] +
    17951795          CevoMapExt);
    17961796      ok := true;
    17971797      try
    17981798        if Page = pgLoad then
    1799           Rename(f, DataDir + 'Saved'+ DirectorySeparator + NewName + CevoExt)
     1799          Rename(f, GetSavedDir + DirectorySeparator + NewName + CevoExt)
    18001800        else
    1801           Rename(f, DataDir + 'Maps'+ DirectorySeparator + NewName + CevoMapExt);
     1801          Rename(f, GetMapsDir + DirectorySeparator + NewName + CevoMapExt);
    18021802      except
    18031803        // Play('INVALID');
     
    18061806      if Page <> pgLoad then
    18071807        try // rename map picture
    1808           AssignFile(f, DataDir + 'Maps'+ DirectorySeparator + List.Items[List.ItemIndex]
     1808          AssignFile(f, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex]
    18091809            + '.png');
    1810           Rename(f, DataDir + 'Maps'+ DirectorySeparator + NewName + '.png');
     1810          Rename(f, GetMapsDir + DirectorySeparator + NewName + '.png');
    18111811        except
    18121812        end;
     
    18421842    begin
    18431843      if Page = pgLoad then
    1844         AssignFile(f, DataDir + 'Saved' + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt)
     1844        AssignFile(f, GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt)
    18451845      else
    1846         AssignFile(f, DataDir + 'Maps' + DirectorySeparator + List.Items[List.ItemIndex] +
     1846        AssignFile(f, GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex] +
    18471847          CevoMapExt);
    18481848      Erase(f);
     
    20362036procedure TStartDlg.ReplayBtnClick(Sender: TObject);
    20372037begin
    2038   LoadGame(DataDir + 'Saved' + DirectorySeparator, List.Items[List.ItemIndex] + CevoExt,
     2038  LoadGame(GetSavedDir + DirectorySeparator, List.Items[List.ItemIndex] + CevoExt,
    20392039    LastTurn, True);
    20402040  SlotAvailable := -1;
Note: See TracChangeset for help on using the changeset viewer.