- Timestamp:
- Jul 24, 2024, 10:51:34 AM (4 months ago)
- Location:
- trunk
- Files:
-
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/Brain.pas
r544 r589 104 104 begin 105 105 BasePath := ExtractFileDir(AIFileName); 106 FileName := ExtractFileName (ExtractFileNameWithoutExt(ExtractFileNameWithoutExt(AIFileName)));106 FileName := ExtractFileNameOnly(ExtractFileNameOnly(AIFileName)); 107 107 Name := FileName; 108 108 DLLName := BasePath + DirectorySeparator + Name + '.dll'; -
trunk/Direct.pas
r565 r589 239 239 if ExtractFileExt(FileName) = CevoExt then begin 240 240 Quick := True; 241 if not LoadGame(ExtractFilePath(ParamStr(1)), ExtractFileName(ParamStr(1) 242 ), -1, False) then begin 241 if not LoadGame(ParamStr(1), -1, False) then begin 243 242 SimpleMessage(Phrases.Lookup('LOADERR')); 244 243 Close; -
trunk/GameServer.pas
r558 r589 69 69 procedure Done; 70 70 71 procedure StartNewGame(const Path, FileName, Map: string;71 procedure StartNewGame(const FileName, AMapFileName: string; 72 72 Newlx, Newly, NewLandMass, NewMaxTurn: Integer); 73 function LoadGame(const Path,FileName: string; Turn: Integer;73 function LoadGame(const FileName: string; Turn: Integer; 74 74 MovieMode: Boolean): Boolean; 75 75 procedure EditMap(const Map: string; Newlx, Newly, NewLandMass: Integer); 76 76 procedure DirectHelp(Command: Integer); 77 function ToAutoSaveFileName(FileName: string): string; 78 function IsAutoSaveFileName(FileName: string): Boolean; 77 79 78 80 procedure ChangeClient; … … 391 393 end; 392 394 395 function ToAutoSaveFileName(FileName: string): string; 396 begin 397 Result := ExtractFileDir(FileName) + DirectorySeparator + '~' + ExtractFileName(FileName); 398 end; 399 400 function IsAutoSaveFileName(FileName: string): Boolean; 401 begin 402 FileName := ExtractFileName(FileName); 403 Result := (Length(FileName) > 0) and (FileName[1] = '~'); 404 end; 405 393 406 procedure LogChanges; 394 407 var … … 579 592 begin 580 593 Result := False; 581 MapFile := nil; 594 if not FileExists(FileName) then Exit; 595 MapFile := TFileStream.Create(FileName, fmOpenRead or fmShareExclusive); 582 596 try 583 MapFile := TFileStream.Create(FileName, fmOpenRead or fmShareExclusive);584 597 MapFile.Position := 0; 585 598 MapFile.Read(S[1], 8); { file id } … … 611 624 Result := True; 612 625 end; 626 finally 613 627 FreeAndNil(MapFile); 614 except615 if MapFile <> nil then616 FreeAndNil(MapFile);617 628 end; 618 629 end; … … 641 652 642 653 if Auto and AutoSaveExists then // append to existing file 643 LogFile := TFileStream.Create(SavePath + FileName, fmOpenReadWrite or 644 fmShareExclusive) 654 LogFile := TFileStream.Create(FileName, fmOpenReadWrite or fmShareExclusive) 645 655 else // create new file 646 LogFile := TFileStream.Create(SavePath + FileName, 647 fmCreate or fmShareExclusive); 656 LogFile := TFileStream.Create(FileName, fmCreate or fmShareExclusive); 648 657 649 658 Zero := 0; … … 1111 1120 end; 1112 1121 1113 function LoadGame(const Path, FileName: string; Turn: Integer; 1114 MovieMode: Boolean): Boolean; 1122 function LoadGame(const FileName: string; Turn: Integer; MovieMode: Boolean): Boolean; 1115 1123 var 1116 1124 J: TBrain; … … 1125 1133 Started, StatRequest: Boolean; 1126 1134 begin 1127 SavePath := Path;1135 SavePath := ExtractFileDir(FileName); 1128 1136 LogFileName := FileName; 1129 1137 LoadTurn := Turn; 1130 LogFile := TFileStream.Create( SavePath +LogFileName, fmOpenRead or1138 LogFile := TFileStream.Create(LogFileName, fmOpenRead or 1131 1139 fmShareExclusive); 1132 1140 LogFile.Position := 0; … … 1203 1211 else 1204 1212 Mode := moLoading_Fast; 1205 {$IFDEF TEXTLOG}AssignFile(TextLog, SavePath +LogFileName + '.txt');1213 {$IFDEF TEXTLOG}AssignFile(TextLog, LogFileName + '.txt'); 1206 1214 Rewrite(TextLog); {$ENDIF} 1207 1215 LoadOK := True; … … 1299 1307 NoLogChanges; 1300 1308 NoLogCityTileChanges; 1301 if LogFileName[1] = '~' then 1302 begin 1309 if IsAutoSaveFileName(LogFileName) then begin 1303 1310 Delete(LogFileName, 1, 1); 1304 1311 nLogOpened := -1; … … 1327 1334 if not LoadOK then 1328 1335 begin 1329 NotifyMessage := SavePath +LogFileName;1336 NotifyMessage := LogFileName; 1330 1337 Notify(ntLoadError); 1331 1338 end; … … 1360 1367 end; 1361 1368 1362 procedure StartNewGame(const Path, FileName, Map: string;1369 procedure StartNewGame(const FileName, AMapFileName: string; 1363 1370 Newlx, Newly, NewLandMass, NewMaxTurn: Integer); 1364 1371 var … … 1366 1373 begin 1367 1374 Notify(ntStartDone); 1368 SavePath := Path;1375 SavePath := ExtractFileDir(FileName); 1369 1376 LogFileName := FileName; 1370 MapFileName := Map;1377 MapFileName := AMapFileName; 1371 1378 {$IFDEF FastContact} 1372 1379 lx := 24; … … 3138 3145 begin 3139 3146 LogChanges; 3140 SaveGame( '~' + LogFileName, True);3147 SaveGame(ToAutoSaveFileName(LogFileName), True); 3141 3148 end; 3142 3149 {$ENDIF} … … 3268 3275 SaveGame(LogFileName, False); 3269 3276 end; 3270 DeleteFile( SavePath + '~' + LogFileName);3277 DeleteFile(ToAutoSaveFileName(LogFileName)); 3271 3278 EndGame; 3272 3279 case Command of … … 3276 3283 Notify(ntStartGo); 3277 3284 sNextRound: 3278 StartNewGame(SavePath, LogFileName, MapFileName, lx, ly, 3279 LandMass, MaxTurn); 3285 StartNewGame(LogFileName, MapFileName, lx, ly, LandMass, MaxTurn); 3280 3286 sReload: 3281 LoadGame( SavePath,LogFileName, Integer(Data), False);3287 LoadGame(LogFileName, Integer(Data), False); 3282 3288 end; 3283 3289 end -
trunk/Packages/CevoComponents/ScreenTools.pas
r570 r589 529 529 530 530 FileName := ExtractFileNameWithoutExt(FileName) + GraphicSetFileExt; 531 531 532 if FileExists(FileName) then 532 533 Result.LoadFromFile(FileName); -
trunk/Start.pas
r579 r589 6 6 uses 7 7 GameServer, Messg, ButtonBase, ButtonA, ButtonC, ButtonB, Area, Types, 8 LCLIntf, LCLType, SysUtils, Classes, BaseWin, ListBoxEx, 8 LCLIntf, LCLType, SysUtils, Classes, BaseWin, ListBoxEx, LazFileUtils, 9 9 Registry, DrawDlg, Generics.Collections, Protocol, MiniMap, Brain, Translator, 10 10 {$IFDEF DPI}System.UITypes, Dpi.Graphics, Dpi.Controls, Dpi.Forms, Dpi.StdCtrls, … … 905 905 S := Phrases.Lookup('MPMAP') 906 906 else if Page = pgStartMap then 907 S := Copy(MapFileName, 1, Length(MapFileName) - Length(CevoMapExt))907 S := ExtractFileNameOnly(MapFileName) 908 908 else if Page = pgEditMap then 909 909 S := List.Items[List.ItemIndex] … … 944 944 I: Integer; 945 945 begin 946 if FileName[1] <> '~'then947 FileName := '~' + FileName;946 if not IsAutoSaveFileName(FileName) then 947 FileName := ToAutoSaveFileName(FileName); 948 948 I := FormerGames.Count - 1; 949 while (I >= 0) and (AnsiCompareFileName(FormerGames[I], FileName) <> 0) do949 while (I >= 0) and (AnsiCompareFileName(FormerGames[I], ExtractFileNameOnly(FileName)) <> 0) do 950 950 Dec(I); 951 if I >= 0 then 952 begin 951 if I >= 0 then begin 953 952 FormerGames.Delete(I); 954 953 if ListIndex[tbNew] = I then … … 966 965 pgLoad: 967 966 begin // load 968 FileName := List.Items[List.ItemIndex];969 if LoadGame( GetSavedDir + DirectorySeparator, FileName + CevoExt, LoadTurn, False)967 FileName := GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt; 968 if LoadGame(FileName, LoadTurn, False) 970 969 then 971 970 UnlistBackupFile(FileName) … … 992 991 993 992 if (AutoDiff < 0) and (PlayersBrain[0].Kind = btNoTerm) then 994 FileName := 'Round' + IntToStr(GetProcessID())993 FileName := GetSavedDir + DirectorySeparator + 'Round' + IntToStr(GetProcessID()) + CevoExt 995 994 else begin 996 995 Inc(GameCount); 997 FileName := Format(Phrases.Lookup('GAME'), [GameCount]);996 FileName := GetSavedDir + DirectorySeparator + Format(Phrases.Lookup('GAME'), [GameCount]) + CevoExt; 998 997 end; 999 998 … … 1049 1048 end; 1050 1049 1051 StartNewGame( GetSavedDir + DirectorySeparator, FileName + CevoExt, MapFileName,1052 WorldSizes[WorldSize]. X, WorldSizes[WorldSize].Y, StartLandMass, MaxTurn);1050 StartNewGame(FileName, MapFileName, WorldSizes[WorldSize].X, 1051 WorldSizes[WorldSize].Y, StartLandMass, MaxTurn); 1053 1052 UnlistBackupFile(FileName); 1054 1053 end; 1055 1054 pgEditMap: 1056 EditMap( GetMapsDir + DirectorySeparator +MapFileName, lxmax, lymax, StartLandMass);1055 EditMap(MapFileName, lxmax, lymax, StartLandMass); 1057 1056 pgEditRandom: // new map 1058 1057 begin … … 1068 1067 Free; 1069 1068 end; 1070 MapFileName := Format(Phrases.Lookup('MAP'), [MapCount]) + CevoMapExt; 1071 EditMap(GetMapsDir + DirectorySeparator + MapFileName, 1072 WorldSizes[WorldSize].X, WorldSizes[WorldSize].Y, StartLandMass); 1069 MapFileName := GetMapsDir + DirectorySeparator + Format(Phrases.Lookup('MAP'), 1070 [MapCount]) + CevoMapExt; 1071 EditMap(MapFileName, WorldSizes[WorldSize].X, WorldSizes[WorldSize].Y, 1072 StartLandMass); 1073 1073 end; 1074 1074 end; … … 1120 1120 if Page = pgEditMap then begin 1121 1121 if List.ItemIndex >= 0 then 1122 MapFileName := List.Items[List.ItemIndex] + CevoMapExt1122 MapFileName := GetMapsDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoMapExt 1123 1123 else Exit; 1124 1124 end; 1125 MiniMap.LoadFromMapFile(GetMapsDir + DirectorySeparator + MapFileName, 1126 nMapLandTiles, nMapStartPositions); 1125 MiniMap.LoadFromMapFile(MapFileName, nMapLandTiles, nMapStartPositions); 1127 1126 if Page = pgEditMap then 1128 1127 SmartInvalidate(x0Mini - 112, y0Mini + 61, x0Mini + 112, y0Mini + 91); … … 1296 1295 while (I > 0) and (F.Time < Integer(FormerGames.Objects[I - 1])) do 1297 1296 Dec(I); 1298 FormerGames.InsertObject(I, Copy(F.Name, 1, Length(F.Name) - 5),1297 FormerGames.InsertObject(I, ExtractFileNameOnly(F.Name), 1299 1298 TObject(F.Time)); 1300 1299 until FindNext(F) <> 0; … … 1318 1317 Maps.Sort; 1319 1318 Maps.Insert(0, Phrases.Lookup('RANMAP')); 1320 ListIndex[tbMain] := Maps.IndexOf( Copy(MapFileName, 1, Length(MapFileName) - Length(CevoMapExt)));1319 ListIndex[tbMain] := Maps.IndexOf(ExtractFileNameOnly(MapFileName)); 1321 1320 if ListIndex[tbMain] < 0 then 1322 1321 ListIndex[tbMain] := 0; … … 1661 1660 InputDlg.ShowModal; 1662 1661 NewName := InputDlg.EditInput.Text; 1663 while (NewName <> '') and (NewName[1] = '~') do1662 while IsAutoSaveFileName(NewName) do 1664 1663 Delete(NewName, 1, 1); 1665 1664 if (InputDlg.ModalResult = mrOK) and (NewName <> '') and … … 1936 1935 procedure TStartDlg.ReplayBtnClick(Sender: TObject); 1937 1936 begin 1938 LoadGame(GetSavedDir + DirectorySeparator ,List.Items[List.ItemIndex] + CevoExt,1937 LoadGame(GetSavedDir + DirectorySeparator + List.Items[List.ItemIndex] + CevoExt, 1939 1938 LastTurn, True); 1940 1939 SlotAvailable := -1;
Note:
See TracChangeset
for help on using the changeset viewer.