-
Notifications
You must be signed in to change notification settings - Fork 63
/
DN.JSonFile.Uninstallation.pas
129 lines (113 loc) · 3.76 KB
/
DN.JSonFile.Uninstallation.pas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
{
#########################################################
# Copyright by Alexander Benikowski #
# This unit is part of the Delphinus project hosted on #
# https://github.com/Memnarch/Delphinus #
#########################################################
}
unit DN.JSonFile.Uninstallation;
interface
uses
DN.JSon,
DN.JSonFile;
type
TPackage = record
BPLFile: string;
DCPFile: string;
Installed: Boolean;
end;
TInstalledExpert = record
Expert: string;
HotReload: Boolean;
end;
TUninstallationFile = class(TJSonFile)
private
FPackages: TArray<TPackage>;
FSearchPathes: string;
FBrowsingPathes: string;
FRawFiles: TArray<string>;
FExperts: TArray<TInstalledExpert>;
protected
procedure Load(const ARoot: TJSONObject); override;
procedure Save(const ARoot: TJSONObject); override;
public
property SearchPathes: string read FSearchPathes write FSearchPathes;
property BrowsingPathes: string read FBrowsingPathes write FBrowsingPathes;
property Packages: TArray<TPackage> read FPackages write FPackages;
property Experts: TArray<TInstalledExpert> read FExperts write FExperts;
property RawFiles: TArray<string> read FRawFiles write FRawFiles;
end;
implementation
uses
SysUtils;
{ TUninstallation }
procedure TUninstallationFile.Load(const ARoot: TJSONObject);
var
LPackages, LRawFiles, LExperts: TJSONArray;
LPackage: TJSONObject;
i: Integer;
begin
inherited;
FSearchPathes := ReadString(ARoot, 'search_pathes');
FBrowsingPathes := ReadString(ARoot, 'browsing_pathes');
if ReadArray(ARoot, 'packages', LPackages) then
begin
SetLength(FPackages, LPackages.Count);
for i := 0 to Pred(LPackages.Count) do
begin
LPackage := LPackages.Items[i] as TJSONObject;
FPackages[i].BPLFile := ReadString(LPackage, 'bpl_file');
FPackages[i].DCPFile := ReadString(LPackage, 'dcp_file');
FPackages[i].Installed := ReadBoolean(LPackage, 'installed')
end;
end;
if ReadArray(ARoot, 'raw_files', LRawFiles) then
begin
SetLength(FRawFiles, LRawFiles.Count);
for i := 0 to Pred(LRawFiles.Count) do
FRawFiles[i] := ReadString(LRawFiles.Items[i] as TJSONObject, 'file');
end;
if ReadArray(ARoot, 'experts', LExperts) then
begin
SetLength(FExperts, LExperts.Count);
for i := 0 to Pred(LExperts.Count) do
begin
FExperts[i].Expert := ReadString(LExperts.Items[i] as TJSONObject, 'expert');
FExperts[i].HotReload := ReadBoolean(LExperts.Items[i] as TJSONObject, 'hot_reload');
end;
end;
end;
procedure TUninstallationFile.Save(const ARoot: TJSONObject);
var
LPackages, LRawFiles, LExperts: TJSONArray;
LPackage: TPackage;
LJPackage, LJRawFile, LJExpert: TJSONObject;
LRawFile: string;
LExpert: TInstalledExpert;
begin
inherited;
WritePath(ARoot, 'search_pathes', FSearchPathes);
WritePath(ARoot, 'browsing_pathes', FBrowsingPathes);
LPackages := WriteArray(ARoot, 'packages');
for LPackage in FPackages do
begin
LJPackage := WriteArrayObject(LPackages);
WritePath(LJPackage, 'bpl_file', LPackage.BPLFile);
WritePath(LJPackage, 'dcp_file', LPackage.DCPFile);
WriteBoolean(LJPackage, 'installed', LPackage.Installed);
end;
LRawFiles := WriteArray(ARoot, 'raw_files');
for LRawFile in FRawFiles do
begin
LJRawFile := WriteArrayObject(LRawFiles);
WritePath(LJRawFile, 'file', LRawFile);
end;
LExperts := WriteArray(ARoot, 'experts');
for LExpert in FExperts do
begin
LJExpert := WriteArrayObject(LExperts);
WritePath(LJExpert, 'expert', LExpert.Expert);
WriteBoolean(LJExpert, 'hot_reload', LExpert.HotReload);
end;
end;
end.