Skip to content

Commit 9455588

Browse files
committed
Fix (and improve) Simba's settings.ini script methods for read/write simple things.
1 parent 19d2dc1 commit 9455588

File tree

2 files changed

+54
-18
lines changed

2 files changed

+54
-18
lines changed

Source/script/imports/simba.import_misc.pas

Lines changed: 31 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -70,27 +70,44 @@ procedure ClearSimbaOutput(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
7070
end;
7171

7272
(*
73-
SetSimbaSetting
74-
---------------
73+
GetSetting
74+
----------
7575
```
76-
function SetSimbaSetting(Name: String; DefValue: String = ''): String;
76+
function GetSetting(Section, Name: String; DefValue: String = ''): String;
7777
```
78+
Read a string setting from Simba's settings.ini.
79+
Returns `DefValue` if the setting does not exist.
7880
*)
79-
procedure _LapeGetSimpleSetting(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
81+
procedure _LapeGetSetting(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
8082
begin
81-
PString(Result)^ := SimbaSettings.GetSimpleSetting(PString(Params^[0])^, PString(Params^[1])^);
83+
PString(Result) ^:= SimbaSettings.GetSimpleSetting(PString(Params^[0])^, PString(Params^[1])^, PString(Params^[2])^);
8284
end;
8385

8486
(*
85-
GetSimbaSetting
86-
---------------
87+
SetSetting
88+
----------
8789
```
88-
procedure GetSimbaSetting(Name, Value: String);
90+
procedure SetSetting(Section, Name: String; Value: String);
8991
```
92+
Write a string setting in Simba's settings.ini.
9093
*)
91-
procedure _LapeSetSimpleSetting(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
94+
procedure _LapeSetSetting(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
9295
begin
93-
SimbaSettings.SetSimpleSetting(PString(Params^[0])^, PString(Params^[1])^);
96+
SimbaSettings.SetSimpleSetting(PString(Params^[0])^, PString(Params^[1])^, PString(Params^[2])^);
97+
end;
98+
99+
(*
100+
RemoveSetting
101+
-------------
102+
```
103+
procedure RemoveSetting(Section, Name: String);
104+
```
105+
Remove a setting from Simba's setting.ini.
106+
If `Name` is empty, will remove the entire section.
107+
*)
108+
procedure _LapeRemoveSetting(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
109+
begin
110+
SimbaSettings.RemoveSimpleSetting(PString(Params^[0])^, PString(Params^[1])^);
94111
end;
95112

96113
(*
@@ -581,8 +598,10 @@ procedure ImportMisc(Script: TSimbaScript);
581598
]);
582599

583600
addGlobalFunc('procedure ClearSimbaOutput', @ClearSimbaOutput);
584-
addGlobalFunc('function SetSimbaSetting(Name: String; DefValue: String = ""): String', @_LapeGetSimpleSetting);
585-
addGlobalFunc('procedure GetSimbaSetting(Name, Value: String);', @_LapeSetSimpleSetting);
601+
602+
addGlobalFunc('function GetSetting(Section, Name: String; DefValue: String = ""): String;', @_LapeGetSetting);
603+
addGlobalFunc('procedure SetSetting(Section, Name, Value: String);', @_LapeSetSetting);
604+
addGlobalFunc('procedure RemoveSetting(Section, Name: String);', @_LapeRemoveSetting);
586605
addGlobalFunc('procedure PlaySound(Sound: String)', @_LapePlaySound);
587606
addGlobalFunc('procedure StopSound', @_LapeStopSound);
588607
addGlobalFunc('procedure SetClipBoard(Data: string)', @_LapeSetClipBoard);

Source/simba.settings.pas

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -172,8 +172,9 @@ TSimbaSettings = class
172172
property FirstLaunch: Boolean read FFirstLaunch;
173173

174174
class function GetINIFile: TINIFile;
175-
class procedure SetSimpleSetting(AName, Value: String);
176-
class function GetSimpleSetting(AName: String; DefValue: String = ''): String;
175+
class procedure RemoveSimpleSetting(Section, Name: String);
176+
class procedure SetSimpleSetting(Section: String; Name, Value: String);
177+
class function GetSimpleSetting(Section: String; Name: String; DefValue: String = ''): String;
177178

178179
procedure Load;
179180
procedure Save;
@@ -425,27 +426,43 @@ class function TSimbaSettings.GetINIFile: TINIFile;
425426
Result.SetBoolStringValues(False, ['False']);
426427
end;
427428

428-
class procedure TSimbaSettings.SetSimpleSetting(AName, Value: String);
429+
class procedure TSimbaSettings.RemoveSimpleSetting(Section, Name: String);
429430
begin
430431
try
431432
with GetINIFile() do
432433
try
433-
WriteString('Other', AName, Value);
434+
if (Name = '') then
435+
EraseSection(Section)
436+
else
437+
DeleteKey(Section, Name);
434438
finally
435439
Free();
436440
end;
437441
except
438442
end;
439443
end;
440444

441-
class function TSimbaSettings.GetSimpleSetting(AName: String; DefValue: String): String;
445+
class procedure TSimbaSettings.SetSimpleSetting(Section: String; Name, Value: String);
446+
begin
447+
try
448+
with GetINIFile() do
449+
try
450+
WriteString(Section, Name, Value);
451+
finally
452+
Free();
453+
end;
454+
except
455+
end;
456+
end;
457+
458+
class function TSimbaSettings.GetSimpleSetting(Section: String; Name: String; DefValue: String): String;
442459
begin
443460
Result := '';
444461

445462
try
446463
with GetINIFile() do
447464
try
448-
Result := ReadString('Other', AName, DefValue);
465+
Result := ReadString(Section, Name, DefValue);
449466
finally
450467
Free();
451468
end;

0 commit comments

Comments
 (0)