1
0
mirror of https://github.com/moparisthebest/Simba synced 2025-01-11 05:38:00 -05:00
git-svn-id: http://www.villavu.com/repositories/merlijn/mufasa@377 3f818213-9676-44b0-a9b4-5e4c4e03d09d
This commit is contained in:
Wizzup? 2010-01-05 23:05:03 +00:00
parent 906d4c9b98
commit aa5fb8bda8
3 changed files with 130 additions and 80 deletions

View File

@ -10,7 +10,7 @@
<TargetFileExt Value=""/> <TargetFileExt Value=""/>
<Icon Value="0"/> <Icon Value="0"/>
<UseXPManifest Value="True"/> <UseXPManifest Value="True"/>
<ActiveEditorIndexAtStart Value="1"/> <ActiveEditorIndexAtStart Value="0"/>
</General> </General>
<VersionInfo> <VersionInfo>
<ProjectVersion Value=""/> <ProjectVersion Value=""/>
@ -39,7 +39,7 @@
<Filename Value="project1.lpr"/> <Filename Value="project1.lpr"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="project1"/> <UnitName Value="project1"/>
<UsageCount Value="33"/> <UsageCount Value="35"/>
</Unit0> </Unit0>
<Unit1> <Unit1>
<Filename Value="unit1.pas"/> <Filename Value="unit1.pas"/>
@ -47,10 +47,10 @@
<ComponentName Value="Form1"/> <ComponentName Value="Form1"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="Unit1"/> <UnitName Value="Unit1"/>
<CursorPos X="30" Y="172"/> <CursorPos X="32" Y="174"/>
<TopLine Value="154"/> <TopLine Value="151"/>
<EditorIndex Value="0"/> <EditorIndex Value="0"/>
<UsageCount Value="33"/> <UsageCount Value="35"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit1> </Unit1>
<Unit2> <Unit2>
@ -59,8 +59,8 @@
<HasResources Value="True"/> <HasResources Value="True"/>
<ResourceBaseClass Value="Form"/> <ResourceBaseClass Value="Form"/>
<UnitName Value="colourhistory"/> <UnitName Value="colourhistory"/>
<CursorPos X="26" Y="184"/> <CursorPos X="67" Y="236"/>
<TopLine Value="156"/> <TopLine Value="211"/>
<UsageCount Value="16"/> <UsageCount Value="16"/>
</Unit2> </Unit2>
<Unit3> <Unit3>
@ -84,10 +84,10 @@
<Filename Value="settings.pas"/> <Filename Value="settings.pas"/>
<IsPartOfProject Value="True"/> <IsPartOfProject Value="True"/>
<UnitName Value="settings"/> <UnitName Value="settings"/>
<CursorPos X="75" Y="164"/> <CursorPos X="1" Y="194"/>
<TopLine Value="142"/> <TopLine Value="168"/>
<EditorIndex Value="1"/> <EditorIndex Value="1"/>
<UsageCount Value="31"/> <UsageCount Value="33"/>
<Loaded Value="True"/> <Loaded Value="True"/>
</Unit5> </Unit5>
<Unit6> <Unit6>
@ -146,124 +146,124 @@
</Units> </Units>
<JumpHistory Count="30" HistoryIndex="29"> <JumpHistory Count="30" HistoryIndex="29">
<Position1> <Position1>
<Filename Value="unit1.pas"/> <Filename Value="settings.pas"/>
<Caret Line="130" Column="15" TopLine="113"/> <Caret Line="173" Column="1" TopLine="161"/>
</Position1> </Position1>
<Position2> <Position2>
<Filename Value="unit1.pas"/> <Filename Value="settings.pas"/>
<Caret Line="97" Column="5" TopLine="79"/> <Caret Line="184" Column="3" TopLine="166"/>
</Position2> </Position2>
<Position3> <Position3>
<Filename Value="unit1.pas"/> <Filename Value="unit1.pas"/>
<Caret Line="96" Column="14" TopLine="78"/> <Caret Line="154" Column="1" TopLine="137"/>
</Position3> </Position3>
<Position4> <Position4>
<Filename Value="unit1.pas"/> <Filename Value="settings.pas"/>
<Caret Line="79" Column="33" TopLine="61"/> <Caret Line="76" Column="3" TopLine="56"/>
</Position4> </Position4>
<Position5> <Position5>
<Filename Value="unit1.pas"/> <Filename Value="unit1.pas"/>
<Caret Line="96" Column="12" TopLine="78"/> <Caret Line="65" Column="32" TopLine="39"/>
</Position5> </Position5>
<Position6> <Position6>
<Filename Value="unit1.pas"/> <Filename Value="unit1.pas"/>
<Caret Line="79" Column="12" TopLine="61"/> <Caret Line="42" Column="6" TopLine="42"/>
</Position6> </Position6>
<Position7> <Position7>
<Filename Value="unit1.pas"/> <Filename Value="unit1.pas"/>
<Caret Line="86" Column="46" TopLine="68"/> <Caret Line="70" Column="2" TopLine="56"/>
</Position7> </Position7>
<Position8> <Position8>
<Filename Value="unit1.pas"/> <Filename Value="unit1.pas"/>
<Caret Line="167" Column="23" TopLine="139"/> <Caret Line="75" Column="8" TopLine="62"/>
</Position8> </Position8>
<Position9> <Position9>
<Filename Value="settings.pas"/> <Filename Value="unit1.pas"/>
<Caret Line="141" Column="6" TopLine="111"/> <Caret Line="80" Column="1" TopLine="52"/>
</Position9> </Position9>
<Position10> <Position10>
<Filename Value="unit1.pas"/> <Filename Value="unit1.pas"/>
<Caret Line="167" Column="32" TopLine="148"/> <Caret Line="79" Column="3" TopLine="51"/>
</Position10> </Position10>
<Position11> <Position11>
<Filename Value="unit1.pas"/> <Filename Value="unit1.pas"/>
<Caret Line="196" Column="5" TopLine="166"/> <Caret Line="173" Column="19" TopLine="143"/>
</Position11> </Position11>
<Position12> <Position12>
<Filename Value="unit1.pas"/> <Filename Value="settings.pas"/>
<Caret Line="24" Column="1" TopLine="4"/> <Caret Line="38" Column="24" TopLine="24"/>
</Position12> </Position12>
<Position13> <Position13>
<Filename Value="unit1.pas"/> <Filename Value="settings.pas"/>
<Caret Line="197" Column="1" TopLine="164"/> <Caret Line="326" Column="45" TopLine="294"/>
</Position13> </Position13>
<Position14> <Position14>
<Filename Value="unit1.pas"/> <Filename Value="settings.pas"/>
<Caret Line="194" Column="30" TopLine="166"/> <Caret Line="314" Column="13" TopLine="296"/>
</Position14> </Position14>
<Position15> <Position15>
<Filename Value="unit1.pas"/> <Filename Value="settings.pas"/>
<Caret Line="20" Column="30" TopLine="12"/> <Caret Line="40" Column="21" TopLine="22"/>
</Position15> </Position15>
<Position16> <Position16>
<Filename Value="settings.pas"/> <Filename Value="settings.pas"/>
<Caret Line="156" Column="3" TopLine="136"/> <Caret Line="325" Column="30" TopLine="306"/>
</Position16> </Position16>
<Position17> <Position17>
<Filename Value="settings.pas"/> <Filename Value="unit1.pas"/>
<Caret Line="84" Column="19" TopLine="59"/> <Caret Line="49" Column="61" TopLine="23"/>
</Position17> </Position17>
<Position18> <Position18>
<Filename Value="settings.pas"/> <Filename Value="settings.pas"/>
<Caret Line="81" Column="11" TopLine="72"/> <Caret Line="242" Column="6" TopLine="215"/>
</Position18> </Position18>
<Position19> <Position19>
<Filename Value="settings.pas"/> <Filename Value="settings.pas"/>
<Caret Line="173" Column="1" TopLine="161"/> <Caret Line="235" Column="31" TopLine="213"/>
</Position19> </Position19>
<Position20> <Position20>
<Filename Value="settings.pas"/> <Filename Value="settings.pas"/>
<Caret Line="184" Column="3" TopLine="166"/> <Caret Line="14" Column="46" TopLine="1"/>
</Position20> </Position20>
<Position21> <Position21>
<Filename Value="unit1.pas"/> <Filename Value="settings.pas"/>
<Caret Line="154" Column="1" TopLine="137"/> <Caret Line="288" Column="26" TopLine="270"/>
</Position21> </Position21>
<Position22> <Position22>
<Filename Value="settings.pas"/> <Filename Value="settings.pas"/>
<Caret Line="76" Column="3" TopLine="56"/> <Caret Line="337" Column="1" TopLine="319"/>
</Position22> </Position22>
<Position23> <Position23>
<Filename Value="unit1.pas"/> <Filename Value="settings.pas"/>
<Caret Line="65" Column="32" TopLine="39"/> <Caret Line="248" Column="38" TopLine="224"/>
</Position23> </Position23>
<Position24> <Position24>
<Filename Value="unit1.pas"/> <Filename Value="settings.pas"/>
<Caret Line="42" Column="6" TopLine="42"/> <Caret Line="42" Column="28" TopLine="23"/>
</Position24> </Position24>
<Position25> <Position25>
<Filename Value="unit1.pas"/> <Filename Value="unit1.pas"/>
<Caret Line="70" Column="2" TopLine="56"/> <Caret Line="169" Column="51" TopLine="141"/>
</Position25> </Position25>
<Position26> <Position26>
<Filename Value="unit1.pas"/> <Filename Value="settings.pas"/>
<Caret Line="75" Column="8" TopLine="62"/> <Caret Line="251" Column="63" TopLine="1"/>
</Position26> </Position26>
<Position27> <Position27>
<Filename Value="unit1.pas"/> <Filename Value="settings.pas"/>
<Caret Line="80" Column="1" TopLine="52"/> <Caret Line="23" Column="53" TopLine="1"/>
</Position27> </Position27>
<Position28> <Position28>
<Filename Value="unit1.pas"/> <Filename Value="settings.pas"/>
<Caret Line="79" Column="3" TopLine="51"/> <Caret Line="194" Column="12" TopLine="176"/>
</Position28> </Position28>
<Position29> <Position29>
<Filename Value="unit1.pas"/> <Filename Value="settings.pas"/>
<Caret Line="173" Column="19" TopLine="143"/> <Caret Line="224" Column="9" TopLine="209"/>
</Position29> </Position29>
<Position30> <Position30>
<Filename Value="settings.pas"/> <Filename Value="settings.pas"/>
<Caret Line="38" Column="24" TopLine="24"/> <Caret Line="40" Column="21" TopLine="22"/>
</Position30> </Position30>
</JumpHistory> </JumpHistory>
</ProjectOptions> </ProjectOptions>

View File

@ -39,9 +39,10 @@ type
function KeyExists(KeyName: String): Boolean; function KeyExists(KeyName: String): Boolean;
function IsKey(KeyName: String): Boolean; function IsKey(KeyName: String): Boolean;
function IsDirectory(KeyName: String): Boolean; function IsDirectory(KeyName: String): Boolean;
procedure SetKey(KeyName: String; KeyValue: String); procedure SetKeyValue(KeyName: String; KeyValue: String);
function CreateKey(KeyName: String; CreatePath: Boolean = False): Boolean; function CreateKey(KeyName: String; CreatePath: Boolean = False): Boolean;
function GetKeyValue(KeyName: String): String; function GetKeyValue(KeyName: String): String;
function GetSetDefaultKeyValue(KeyName, defVal: String): String;
end; end;
@ -197,10 +198,7 @@ begin
while N <> nil do while N <> nil do
begin begin
if N.Text <> 'Value' then if N.Text <> 'Value' then
begin
writeln(N.text);
inc(i); inc(i);
end;
N := N.GetNextSibling; N := N.GetNextSibling;
end; end;
@ -221,17 +219,40 @@ function TMMLSettings.GetKeyValue(KeyName: String): String;
var var
N: TTreeNode; N: TTreeNode;
begin begin
if IsKey(KeyName) then if not KeyExists(KeyName) then
Exit(''); Exit('');
N := WalkToNode(KeyName); N := WalkToNode(KeyName);
if N <> nil then if N <> nil then
if N.GetFirstChild <> nil then N := N.GetFirstChild;
if assigned(n.GetFirstChild.Data) then while N <> nil do
Exit(TSettingData(n.GetFirstChild.Data).Val); begin
if N.Text = 'Value' then
if assigned(n.Data) then
Exit(TSettingData(n.Data).Val);
N := N.GetNextSibling;
end;
Exit(''); Exit('');
end; end;
function TMMLSettings.GetSetDefaultKeyValue(KeyName, defVal: String): String;
var
Res: String;
begin
if not IsKey(KeyName) then
begin
CreateKey(KeyName, True);
SetKeyValue(KeyName, defVal);
exit(defVal);
end;
Res := GetKeyValue(KeyName);
if Res = '' then
begin
SetKeyValue(KeyName, defVal);
exit(defVal);
end;
Exit(Res);
end;
function TMMLSettings.CreateKey(KeyName: String; CreatePath: Boolean = False): Boolean; function TMMLSettings.CreateKey(KeyName: String; CreatePath: Boolean = False): Boolean;
var var
N, newN, nParent: TTreeNode; N, newN, nParent: TTreeNode;
@ -242,7 +263,6 @@ var
begin begin
if KeyExists(KeyName) then if KeyExists(KeyName) then
begin begin
writeln('Key: ' + KeyName + ' exists');
Exit(False); Exit(False);
end; end;
NewPath := ''; NewPath := '';
@ -305,10 +325,37 @@ begin
newN.MoveTo(nParent, naAddChild); newN.MoveTo(nParent, naAddChild);
end; end;
procedure TMMLSettings.SetKey(KeyName: String; KeyValue: String); procedure TMMLSettings.SetKeyValue(KeyName: String; KeyValue: String);
var
N, NN: TTreeNode;
begin begin
if IsKey(KeyName) then if not KeyExists(KeyName) then
Exit; Exit;
if not IsKey(KeyName) then
Exit;
N := WalkToNode(KeyName);
if not N.HasChildren then
begin
NN := TTreeNode.Create(Nodes);
NN.Text := 'Value';
NN.MoveTo(N, naAddChild);
end;
if n <> nil then
N := N.GetFirstChild;
while N <> nil do
begin
if N.Text = 'Value' then
begin
if Assigned(N.Data) then
TSettingData(N.Data).Free;
N.Data := TSettingData.Create;
TSettingData(N.Data).Val := KeyValue;
end;
N := N.GetNextSibling;
end;
end; end;
end. end.

View File

@ -6,7 +6,7 @@ interface
uses uses
Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs, Classes, SysUtils, FileUtil, LResources, Forms, Controls, Graphics, Dialogs,
ComCtrls, StdCtrls, xml2, XMLRead, XMLWrite, DOM; ComCtrls, StdCtrls, XMLRead, XMLWrite, DOM;
type type
@ -44,7 +44,13 @@ var
DDataNode, DataNode: TDOMNode; DDataNode, DataNode: TDOMNode;
begin begin
XMLChild := XMLDoc.CreateElement(n.Text); if n.Text = 'Value' then
begin
XMLChild := XMLDoc.CreateTextNode(TSettingData(N.Data).Val);
end else
begin
XMLChild := XMLDoc.CreateElement(n.Text);
end;
Inc(C); Inc(C);
XMLNode.AppendChild(XMLChild); XMLNode.AppendChild(XMLChild);
end; end;
@ -156,19 +162,16 @@ var
begin begin
sett := TMMLSettings.Create(TreeView1.Items); sett := TMMLSettings.Create(TreeView1.Items);
sett.CreateKey('Settings/FullScreen/wat', true);
sett.SetKeyValue('Settings/FullScreen/wat', 'TRUE');
writeln(sett.GetKeyValue('Settings/FullScreen/wat'));
if sett.KeyExists('') then writeln(sett.GetSetDefaultKeyValue('Settings/FullScreen/wat2', 'OWAT'));
writeln('Tree exists');
if sett.KeyExists('Settings/a/b/c') then
writeln('Settings exists');
{writeln(sett.GetKeyValue('Settings/hoi0/Item1/Item2/Item3/wattt')); } writeln(sett.GetSetDefaultKeyValue('Settings/Component1/hoiii', 'NO U'));
sett.CreateKey('Settings/a/b/c', true);
if sett.iskey('Settings/a/b/c') then writeln(sett.GetSetDefaultKeyValue('Settings/Component2/hoi', 'OK'));
writeln('is key'); s := sett.ListKeys('Settings/FullScreen');
s := sett.ListKeys('Settings');
for i := 0 to high(s) do for i := 0 to high(s) do
writeln(s[i]); writeln(s[i]);