mirror of
https://github.com/moparisthebest/Simba
synced 2024-12-22 15:28:50 -05:00
DeleteKey + DeleteSubKeys + Less verbose + Test script.
This commit is contained in:
parent
eaeb1669c8
commit
fa173a3332
17
Tests/PS/settings_test.simb
Normal file
17
Tests/PS/settings_test.simb
Normal file
@ -0,0 +1,17 @@
|
||||
program new;
|
||||
begin
|
||||
SettingsGetSetDefaultKeyValue('Kanker/wat', 'YO WAT');
|
||||
SettingsGetSetDefaultKeyValue('Kanker/wat2', 'YO WAT2');
|
||||
writeln(SettingsGetKeyValue('Kanker/wat'));
|
||||
|
||||
if SettingsIsDirectory('Kanker') then
|
||||
writeln('Kanker has at least one child!');
|
||||
if SettingsIsKey('Kanker/wat') then
|
||||
writeln('wat exists!');
|
||||
SettingsDeleteKey('Kanker/wat');
|
||||
writeln(SettingsGetKeyValue('Kanker/wat2'));
|
||||
writeln(SettingsGetKeyValue('Kanker/wat'));
|
||||
SettingsDeleteSubKeys('Kanker');
|
||||
if SettingsIsKey('Kanker') then
|
||||
writeln('kanker is a key now!');
|
||||
end.
|
@ -61,3 +61,18 @@ begin
|
||||
setlength(KeyReturn, 0);
|
||||
end;
|
||||
|
||||
function SettingsDeleteKey(KeyName: String): Boolean;
|
||||
begin
|
||||
if CurrThread.Sett <> nil then
|
||||
Result := CurrThread.Sett.DeleteKey(KeyName)
|
||||
else
|
||||
result := False;
|
||||
end;
|
||||
|
||||
function SettingsDeleteSubKeys(KeyName: String): Boolean;
|
||||
begin
|
||||
if CurrThread.Sett <> nil then
|
||||
Result := CurrThread.Sett.DeleteSubKeys(KeyName)
|
||||
else
|
||||
result := False;
|
||||
end;
|
||||
|
@ -372,3 +372,6 @@ AddFunction(@SettingsIsDirectory, 'function SettingsIsDirectory(KeyName: String)
|
||||
AddFunction(@SettingsGetKeyValue, 'function SettingsGetKeyValue(KeyName: String): String;');
|
||||
AddFunction(@SettingsGetSetDefaultKeyValue, 'function SettingsGetSetDefaultKeyValue(KeyName, defVal: String): String;');
|
||||
AddFunction(@SettingsListKeys, 'procedure SettingsListKeys(KeyName: String; var KeyReturn: TStringArray);');
|
||||
|
||||
AddFunction(@SettingsDeleteKey, 'function SettingsDeleteKey(KeyName: String): Boolean;');
|
||||
AddFunction(@SettingsDeleteSubKeys, 'function SettingsDeleteSubKeys(KeyName: String): Boolean;');
|
||||
|
@ -77,9 +77,14 @@ type
|
||||
public
|
||||
function GetNodePath(Node: TTreeNode): String;
|
||||
function ListKeys(KeyName: String): TStringArray;
|
||||
|
||||
function KeyExists(KeyName: String): Boolean;
|
||||
function IsKey(KeyName: String): Boolean;
|
||||
function IsDirectory(KeyName: String): Boolean;
|
||||
|
||||
function DeleteKey(KeyName: String): Boolean;
|
||||
function DeleteSubKeys(KeyName: String): Boolean;
|
||||
|
||||
procedure SetKeyValue(KeyName: String; KeyValue: String);
|
||||
function CreateKey(KeyName: String; CreatePath: Boolean = False): Boolean;
|
||||
function GetKeyValue(KeyName: String): String;
|
||||
@ -364,6 +369,56 @@ begin
|
||||
Exit(Res);
|
||||
end;
|
||||
|
||||
function TMMLSettings.DeleteKey(KeyName: String): Boolean;
|
||||
var
|
||||
Node, C: TTreeNode;
|
||||
begin
|
||||
if not isKey(KeyName) and not IsDirectory(KeyName) then
|
||||
exit(false);
|
||||
Node := WalkToNode(KeyName);
|
||||
|
||||
if Node = nil then // This should not happen
|
||||
exit;
|
||||
|
||||
C := Node.GetFirstChild;
|
||||
if C = nil then
|
||||
begin
|
||||
TSettingData(Node.Data).Free;
|
||||
Node.Delete;
|
||||
exit;
|
||||
end;
|
||||
|
||||
While C <> nil do
|
||||
begin
|
||||
TSettingData(C.Data).Free;
|
||||
C := C.GetNextSibling;
|
||||
end;
|
||||
Node.DeleteChildren;
|
||||
|
||||
TSettingData(Node.Data).Free;
|
||||
Node.Delete;
|
||||
end;
|
||||
|
||||
function TMMLSettings.DeleteSubKeys(KeyName: String): Boolean;
|
||||
var
|
||||
Node, C: TTreeNode;
|
||||
begin
|
||||
if not isKey(KeyName) and not IsDirectory(KeyName) then
|
||||
exit(false);
|
||||
Node := WalkToNode(KeyName);
|
||||
if Node = nil then // This should not happen
|
||||
exit;
|
||||
|
||||
C := Node.GetFirstChild;
|
||||
While C <> nil do
|
||||
begin
|
||||
TSettingData(C.Data).Free;
|
||||
C := C.GetNextSibling;
|
||||
end;
|
||||
|
||||
Node.DeleteChildren;
|
||||
end;
|
||||
|
||||
{
|
||||
Clear the entire tree. Load from fileName. call GetSetDefaultKeyValue.
|
||||
}
|
||||
|
@ -40,6 +40,9 @@ type
|
||||
function GetKeyValue(KeyName: String): String;
|
||||
function GetSetDefaultKeyValue(KeyName, defVal: String): String;
|
||||
function ListKeys(KeyName: String): TStringArray;
|
||||
|
||||
function DeleteKey(KeyName: String): Boolean;
|
||||
function DeleteSubKeys(KeyName: String): Boolean;
|
||||
public
|
||||
function GetPrefix: String;
|
||||
procedure SetPrefix(s: String);
|
||||
@ -81,7 +84,6 @@ end;
|
||||
|
||||
function TMMLSettingsSandbox.GetKeyValue(KeyName: String): String;
|
||||
begin
|
||||
writeln('getkeyvalue');
|
||||
exit(ST.GetKeyValue(Prefix + KeyName))
|
||||
end;
|
||||
|
||||
@ -100,5 +102,15 @@ begin
|
||||
exit(ST.IsDirectory(Prefix + KeyName))
|
||||
end;
|
||||
|
||||
function TMMLSettingsSandbox.DeleteKey(KeyName: String): Boolean;
|
||||
begin
|
||||
exit(ST.DeleteKey(Prefix + KeyName));
|
||||
end;
|
||||
|
||||
function TMMLSettingsSandbox.DeleteSubKeys(KeyName: String): Boolean;
|
||||
begin
|
||||
exit(ST.DeleteSubKeys(Prefix + KeyName));
|
||||
end;
|
||||
|
||||
end.
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user