Commit d7faf345b54fe1f4350d06a9533eac20fa988c46
1 parent
ddf310af
Exists in
master
experiment designer - improve cross plataform file handle
Showing
1 changed file
with
49 additions
and
7 deletions
Show diff stats
experiment_designer/form_main.pas
| ... | ... | @@ -176,6 +176,9 @@ type |
| 176 | 176 | procedure SpinEditOnConditionBeginAEditingDone(Sender: TObject); |
| 177 | 177 | procedure SpinEditTurnValueEditingDone(Sender: TObject); |
| 178 | 178 | procedure XMLPropStorageRestoreProperties(Sender: TObject); |
| 179 | + {$IFDEF WINDOWS} | |
| 180 | + procedure XMLPropStorageSaveProperties(Sender: TObject); | |
| 181 | + {$ENDIF} | |
| 179 | 182 | procedure XMLPropStorageSavingProperties(Sender: TObject); |
| 180 | 183 | procedure XMLPropStorageStoredValuesFileNameRestore(Sender: TStoredValue; |
| 181 | 184 | var Value: TStoredType); |
| ... | ... | @@ -213,6 +216,7 @@ type |
| 213 | 216 | procedure IncContingencyName(var AContingency : string; N : integer = 1); |
| 214 | 217 | procedure ReadContingencyNames(ASection, AContingency, AKeySuffix:string; S:TStrings); |
| 215 | 218 | procedure ReadContingencyValuesInSection(LS, LC : string; Keys:TStrings); |
| 219 | + procedure SetPropstorageFilename; | |
| 216 | 220 | public |
| 217 | 221 | { public declarations } |
| 218 | 222 | end; |
| ... | ... | @@ -222,7 +226,12 @@ var |
| 222 | 226 | |
| 223 | 227 | implementation |
| 224 | 228 | |
| 225 | -uses game_resources, game_actors, game_actors_point, string_methods, strutils; | |
| 229 | +uses game_resources, game_actors, game_actors_point, string_methods, strutils | |
| 230 | + {$IFDEF WINDOWS} | |
| 231 | + , Dos | |
| 232 | + {$ENDIF} | |
| 233 | + , Dos | |
| 234 | + ; | |
| 226 | 235 | |
| 227 | 236 | const SV_FILENAME : string = 'Filename'; |
| 228 | 237 | |
| ... | ... | @@ -240,7 +249,7 @@ begin |
| 240 | 249 | FExperiment.Free; |
| 241 | 250 | FExperiment := TIniFile.Create(OpenDialog.FileName); |
| 242 | 251 | XMLPropStorage.StoredValue[SV_FILENAME] := FExperiment.FileName; |
| 243 | - XMLPropStorage.FileName := ExtractFilePath(FExperiment.FileName)+'persistence.xml'; | |
| 252 | + SetPropstorageFilename; | |
| 244 | 253 | LoadExperiment; |
| 245 | 254 | |
| 246 | 255 | OpenDialog.InitialDir:=ExtractFilePath(FExperiment.FileName); |
| ... | ... | @@ -262,9 +271,7 @@ begin |
| 262 | 271 | CopyFile(LOldExperimentPath,SaveDialog.FileName); |
| 263 | 272 | FExperiment := TIniFile.Create(SaveDialog.FileName); |
| 264 | 273 | XMLPropStorage.StoredValue[SV_FILENAME] := FExperiment.FileName; |
| 265 | - | |
| 266 | - XMLPropStorage.FileName := ExtractFilePath(FExperiment.FileName)+'persistence.xml'; | |
| 267 | - | |
| 274 | + SetPropstorageFilename; | |
| 268 | 275 | OpenDialog.InitialDir:=ExtractFilePath(FExperiment.FileName); |
| 269 | 276 | SaveDialog.InitialDir:=ExtractFilePath(FExperiment.FileName); |
| 270 | 277 | end; |
| ... | ... | @@ -603,6 +610,20 @@ begin |
| 603 | 610 | TabSheetContingencies.Enabled := ComboCurrentCondition.Items.Count > 0; |
| 604 | 611 | end; |
| 605 | 612 | |
| 613 | +{$IFDEF WINDOWS} | |
| 614 | +procedure TFormDesigner.XMLPropStorageSaveProperties(Sender: TObject); | |
| 615 | +var | |
| 616 | + F : TextFile; | |
| 617 | +begin | |
| 618 | + if FileExists(XMLPropStorage.FileName) then | |
| 619 | + begin | |
| 620 | + AssignFile(F, XMLPropStorage.FileName); | |
| 621 | + SetFAttr(F,Hidden); | |
| 622 | + CloseFile(F); | |
| 623 | + end; | |
| 624 | +end; | |
| 625 | +{$ENDIF} | |
| 626 | + | |
| 606 | 627 | procedure TFormDesigner.XMLPropStorageSavingProperties(Sender: TObject); |
| 607 | 628 | procedure SavePropStorageFilename; |
| 608 | 629 | var |
| ... | ... | @@ -959,6 +980,24 @@ begin |
| 959 | 980 | end; |
| 960 | 981 | end; |
| 961 | 982 | |
| 983 | +procedure TFormDesigner.SetPropstorageFilename; | |
| 984 | +var | |
| 985 | + LRootPath : string; | |
| 986 | +begin | |
| 987 | + if FExperiment.FileName = '' then | |
| 988 | + LRootPath := ExtractFilePath(Application.ExeName) | |
| 989 | + else | |
| 990 | + LRootPath := ExtractFilePath(FExperiment.FileName); | |
| 991 | + | |
| 992 | + {$IFDEF WINDOWS} | |
| 993 | + XMLPropStorage.FileName := LRootPath+'persistence.xml'; | |
| 994 | + {$ENDIF} | |
| 995 | + | |
| 996 | + {$IFDEF LINUX} | |
| 997 | + XMLPropStorage.FileName := LRootPath+'.persistence'; | |
| 998 | + {$ENDIF} | |
| 999 | +end; | |
| 1000 | + | |
| 962 | 1001 | procedure TFormDesigner.SaveSectionExperiment; |
| 963 | 1002 | begin |
| 964 | 1003 | with FExperiment do |
| ... | ... | @@ -1335,12 +1374,15 @@ var |
| 1335 | 1374 | end |
| 1336 | 1375 | end; |
| 1337 | 1376 | begin |
| 1377 | + {$IFDEF WINDOWS} | |
| 1378 | + XMLPropStorage.OnSaveProperties := @XMLPropStorageSaveProperties; | |
| 1379 | + {$ENDIF} | |
| 1380 | + | |
| 1338 | 1381 | // TRadioGroup OnClick events are triggered programmatically by LCL code, not by us |
| 1339 | 1382 | // FLoading is a temporary workaround to avoid |
| 1340 | 1383 | // calls for SaveProcedures while loading FExperiment |
| 1341 | 1384 | FLoading := True; |
| 1342 | 1385 | |
| 1343 | - | |
| 1344 | 1386 | LRootPath := ExtractFilePath(Application.ExeName); |
| 1345 | 1387 | |
| 1346 | 1388 | // FPersistentTXTFilename must not change during runtime. |
| ... | ... | @@ -1349,7 +1391,7 @@ begin |
| 1349 | 1391 | // XMLPropStorage.FileName may change during runtime |
| 1350 | 1392 | XMLPropStorage.FileName := ReadLnFromFile(FPersistentTXTFilename,0); |
| 1351 | 1393 | if XMLPropStorage.FileName = '' then |
| 1352 | - XMLPropStorage.FileName := LRootPath+'persistence.xml'; | |
| 1394 | + SetPropstorageFilename; | |
| 1353 | 1395 | |
| 1354 | 1396 | // XMLPropStorage.StoredValue[SV_FILENAME] may change during runtime |
| 1355 | 1397 | XMLPropStorage.StoredValue[SV_FILENAME] := LRootPath+'persistence.ini'; | ... | ... |