Commit d7faf345b54fe1f4350d06a9533eac20fa988c46

Authored by Carlos Picanco
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,6 +176,9 @@ type
176 procedure SpinEditOnConditionBeginAEditingDone(Sender: TObject); 176 procedure SpinEditOnConditionBeginAEditingDone(Sender: TObject);
177 procedure SpinEditTurnValueEditingDone(Sender: TObject); 177 procedure SpinEditTurnValueEditingDone(Sender: TObject);
178 procedure XMLPropStorageRestoreProperties(Sender: TObject); 178 procedure XMLPropStorageRestoreProperties(Sender: TObject);
  179 + {$IFDEF WINDOWS}
  180 + procedure XMLPropStorageSaveProperties(Sender: TObject);
  181 + {$ENDIF}
179 procedure XMLPropStorageSavingProperties(Sender: TObject); 182 procedure XMLPropStorageSavingProperties(Sender: TObject);
180 procedure XMLPropStorageStoredValuesFileNameRestore(Sender: TStoredValue; 183 procedure XMLPropStorageStoredValuesFileNameRestore(Sender: TStoredValue;
181 var Value: TStoredType); 184 var Value: TStoredType);
@@ -213,6 +216,7 @@ type @@ -213,6 +216,7 @@ type
213 procedure IncContingencyName(var AContingency : string; N : integer = 1); 216 procedure IncContingencyName(var AContingency : string; N : integer = 1);
214 procedure ReadContingencyNames(ASection, AContingency, AKeySuffix:string; S:TStrings); 217 procedure ReadContingencyNames(ASection, AContingency, AKeySuffix:string; S:TStrings);
215 procedure ReadContingencyValuesInSection(LS, LC : string; Keys:TStrings); 218 procedure ReadContingencyValuesInSection(LS, LC : string; Keys:TStrings);
  219 + procedure SetPropstorageFilename;
216 public 220 public
217 { public declarations } 221 { public declarations }
218 end; 222 end;
@@ -222,7 +226,12 @@ var @@ -222,7 +226,12 @@ var
222 226
223 implementation 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 const SV_FILENAME : string = 'Filename'; 236 const SV_FILENAME : string = 'Filename';
228 237
@@ -240,7 +249,7 @@ begin @@ -240,7 +249,7 @@ begin
240 FExperiment.Free; 249 FExperiment.Free;
241 FExperiment := TIniFile.Create(OpenDialog.FileName); 250 FExperiment := TIniFile.Create(OpenDialog.FileName);
242 XMLPropStorage.StoredValue[SV_FILENAME] := FExperiment.FileName; 251 XMLPropStorage.StoredValue[SV_FILENAME] := FExperiment.FileName;
243 - XMLPropStorage.FileName := ExtractFilePath(FExperiment.FileName)+'persistence.xml'; 252 + SetPropstorageFilename;
244 LoadExperiment; 253 LoadExperiment;
245 254
246 OpenDialog.InitialDir:=ExtractFilePath(FExperiment.FileName); 255 OpenDialog.InitialDir:=ExtractFilePath(FExperiment.FileName);
@@ -262,9 +271,7 @@ begin @@ -262,9 +271,7 @@ begin
262 CopyFile(LOldExperimentPath,SaveDialog.FileName); 271 CopyFile(LOldExperimentPath,SaveDialog.FileName);
263 FExperiment := TIniFile.Create(SaveDialog.FileName); 272 FExperiment := TIniFile.Create(SaveDialog.FileName);
264 XMLPropStorage.StoredValue[SV_FILENAME] := FExperiment.FileName; 273 XMLPropStorage.StoredValue[SV_FILENAME] := FExperiment.FileName;
265 -  
266 - XMLPropStorage.FileName := ExtractFilePath(FExperiment.FileName)+'persistence.xml';  
267 - 274 + SetPropstorageFilename;
268 OpenDialog.InitialDir:=ExtractFilePath(FExperiment.FileName); 275 OpenDialog.InitialDir:=ExtractFilePath(FExperiment.FileName);
269 SaveDialog.InitialDir:=ExtractFilePath(FExperiment.FileName); 276 SaveDialog.InitialDir:=ExtractFilePath(FExperiment.FileName);
270 end; 277 end;
@@ -603,6 +610,20 @@ begin @@ -603,6 +610,20 @@ begin
603 TabSheetContingencies.Enabled := ComboCurrentCondition.Items.Count > 0; 610 TabSheetContingencies.Enabled := ComboCurrentCondition.Items.Count > 0;
604 end; 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 procedure TFormDesigner.XMLPropStorageSavingProperties(Sender: TObject); 627 procedure TFormDesigner.XMLPropStorageSavingProperties(Sender: TObject);
607 procedure SavePropStorageFilename; 628 procedure SavePropStorageFilename;
608 var 629 var
@@ -959,6 +980,24 @@ begin @@ -959,6 +980,24 @@ begin
959 end; 980 end;
960 end; 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 procedure TFormDesigner.SaveSectionExperiment; 1001 procedure TFormDesigner.SaveSectionExperiment;
963 begin 1002 begin
964 with FExperiment do 1003 with FExperiment do
@@ -1335,12 +1374,15 @@ var @@ -1335,12 +1374,15 @@ var
1335 end 1374 end
1336 end; 1375 end;
1337 begin 1376 begin
  1377 + {$IFDEF WINDOWS}
  1378 + XMLPropStorage.OnSaveProperties := @XMLPropStorageSaveProperties;
  1379 + {$ENDIF}
  1380 +
1338 // TRadioGroup OnClick events are triggered programmatically by LCL code, not by us 1381 // TRadioGroup OnClick events are triggered programmatically by LCL code, not by us
1339 // FLoading is a temporary workaround to avoid 1382 // FLoading is a temporary workaround to avoid
1340 // calls for SaveProcedures while loading FExperiment 1383 // calls for SaveProcedures while loading FExperiment
1341 FLoading := True; 1384 FLoading := True;
1342 1385
1343 -  
1344 LRootPath := ExtractFilePath(Application.ExeName); 1386 LRootPath := ExtractFilePath(Application.ExeName);
1345 1387
1346 // FPersistentTXTFilename must not change during runtime. 1388 // FPersistentTXTFilename must not change during runtime.
@@ -1349,7 +1391,7 @@ begin @@ -1349,7 +1391,7 @@ begin
1349 // XMLPropStorage.FileName may change during runtime 1391 // XMLPropStorage.FileName may change during runtime
1350 XMLPropStorage.FileName := ReadLnFromFile(FPersistentTXTFilename,0); 1392 XMLPropStorage.FileName := ReadLnFromFile(FPersistentTXTFilename,0);
1351 if XMLPropStorage.FileName = '' then 1393 if XMLPropStorage.FileName = '' then
1352 - XMLPropStorage.FileName := LRootPath+'persistence.xml'; 1394 + SetPropstorageFilename;
1353 1395
1354 // XMLPropStorage.StoredValue[SV_FILENAME] may change during runtime 1396 // XMLPropStorage.StoredValue[SV_FILENAME] may change during runtime
1355 XMLPropStorage.StoredValue[SV_FILENAME] := LRootPath+'persistence.ini'; 1397 XMLPropStorage.StoredValue[SV_FILENAME] := LRootPath+'persistence.ini';