|
@@ -7,7 +7,7 @@
|
|
Author : Kike Pérez
|
|
Author : Kike Pérez
|
|
Version : 1.0
|
|
Version : 1.0
|
|
Created : 18/10/2019
|
|
Created : 18/10/2019
|
|
- Modified : 05/04/2020
|
|
|
|
|
|
+ Modified : 15/04/2020
|
|
|
|
|
|
This file is part of QuickLib: https://github.com/exilon/QuickLib
|
|
This file is part of QuickLib: https://github.com/exilon/QuickLib
|
|
|
|
|
|
@@ -53,6 +53,7 @@ type
|
|
constructor Create;
|
|
constructor Create;
|
|
destructor Destroy; override;
|
|
destructor Destroy; override;
|
|
function Load(const aFilename : string; aSections : TSectionList; aFailOnSectionNotExists : Boolean) : Boolean; override;
|
|
function Load(const aFilename : string; aSections : TSectionList; aFailOnSectionNotExists : Boolean) : Boolean; override;
|
|
|
|
+ function LoadSection(const aFilename : string; aSections : TSectionList; aOptions: TOptions) : Boolean; override;
|
|
procedure Save(const aFilename : string; aSections : TSectionList); override;
|
|
procedure Save(const aFilename : string; aSections : TSectionList); override;
|
|
function GetFileSectionNames(const aFilename : string; out oSections : TArray<string>) : Boolean; override;
|
|
function GetFileSectionNames(const aFilename : string; out oSections : TArray<string>) : Boolean; override;
|
|
end;
|
|
end;
|
|
@@ -75,7 +76,6 @@ end;
|
|
function TJsonOptionsSerializer.GetFileSectionNames(const aFilename: string; out oSections: TArray<string>): Boolean;
|
|
function TJsonOptionsSerializer.GetFileSectionNames(const aFilename: string; out oSections: TArray<string>): Boolean;
|
|
var
|
|
var
|
|
json : TJsonObject;
|
|
json : TJsonObject;
|
|
- jpair : TJSONPair;
|
|
|
|
i : Integer;
|
|
i : Integer;
|
|
begin
|
|
begin
|
|
Result := False;
|
|
Result := False;
|
|
@@ -111,7 +111,6 @@ end;
|
|
function TJsonOptionsSerializer.Load(const aFilename : string; aSections : TSectionList; aFailOnSectionNotExists : Boolean) : Boolean;
|
|
function TJsonOptionsSerializer.Load(const aFilename : string; aSections : TSectionList; aFailOnSectionNotExists : Boolean) : Boolean;
|
|
var
|
|
var
|
|
option : TOptions;
|
|
option : TOptions;
|
|
- fileoptions : string;
|
|
|
|
json : TJsonObject;
|
|
json : TJsonObject;
|
|
jpair : TJSONPair;
|
|
jpair : TJSONPair;
|
|
found : Integer;
|
|
found : Integer;
|
|
@@ -151,6 +150,31 @@ begin
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|
|
|
|
|
|
|
|
+function TJsonOptionsSerializer.LoadSection(const aFilename : string; aSections : TSectionList; aOptions: TOptions) : Boolean;
|
|
|
|
+var
|
|
|
|
+ json : TJsonObject;
|
|
|
|
+ jpair : TJSONPair;
|
|
|
|
+begin
|
|
|
|
+ Result := False;
|
|
|
|
+ //read option file
|
|
|
|
+ if ParseFile(aFilename,json) then
|
|
|
|
+ begin
|
|
|
|
+ try
|
|
|
|
+ jpair := fSerializer.GetJsonPairByName(json,aOptions.Name);
|
|
|
|
+ if (jpair <> nil) and (jpair.JsonValue <> nil) then
|
|
|
|
+ begin
|
|
|
|
+ //deserialize option
|
|
|
|
+ fSerializer.DeserializeObject(aOptions,jpair.JsonValue as TJSONObject);
|
|
|
|
+ //validate loaded configuration
|
|
|
|
+ aOptions.ValidateOptions;
|
|
|
|
+ Result := True;
|
|
|
|
+ end;
|
|
|
|
+ finally
|
|
|
|
+ json.Free;
|
|
|
|
+ end;
|
|
|
|
+ end;
|
|
|
|
+end;
|
|
|
|
+
|
|
procedure TJsonOptionsSerializer.Save(const aFilename : string; aSections : TSectionList);
|
|
procedure TJsonOptionsSerializer.Save(const aFilename : string; aSections : TSectionList);
|
|
var
|
|
var
|
|
option : TOptions;
|
|
option : TOptions;
|
|
@@ -167,7 +191,7 @@ begin
|
|
//validate configuration before save
|
|
//validate configuration before save
|
|
option.ValidateOptions;
|
|
option.ValidateOptions;
|
|
//serialize option
|
|
//serialize option
|
|
- jpair := fSerializer.Serialize(option.Name,option);
|
|
|
|
|
|
+ jpair := TJSONPair.Create(option.Name,fSerializer.SerializeObject(option));
|
|
json.AddPair(jpair);
|
|
json.AddPair(jpair);
|
|
end;
|
|
end;
|
|
end;
|
|
end;
|