forked from Memnarch/Delphinus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
DN.JSonFile.Info.pas
142 lines (130 loc) · 4.26 KB
/
DN.JSonFile.Info.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
130
131
132
133
134
135
136
137
138
139
140
141
142
{
#########################################################
# Copyright by Alexander Benikowski #
# This unit is part of the Delphinus project hosted on #
# https://github.com/Memnarch/Delphinus #
#########################################################
}
unit DN.JSonFile.Info;
interface
uses
Classes,
Types,
SysUtils,
DN.Types,
DN.JSon,
DN.JSonFile,
DN.Compiler.Intf;
type
TInfoFile = class(TJSonFile)
private
FID: TGUID;
FPicture: string;
FFirstVersion: string;
FPackageCompilerMax: TCompilerVersion;
FPackageCompilerMin: TCompilerVersion;
FCompilerMin: TCompilerVersion;
FCompilerMax: TCompilerVersion;
FName: string;
FLicenseFile: string;
FLicenseType: string;
FPlatforms: TDNCompilerPlatforms;
protected
procedure Load(const ARoot: TJSONObject); override;
procedure Save(const ARoot: TJSONObject); override;
procedure LoadPlatforms(const APlatforms: string);
function GetPlatformString: string;
function ReadID(const AObject: TJSONObject): TGUID;
public
property Picture: string read FPicture;
property ID: TGUID read FID write FID;
property Name: string read FName write FName;
property LicenseType: string read FLicenseType write FLicenseType;
property LicenseFile: string read FLicenseFile write FLicenseFile;
property FirstVersion: string read FFirstVersion;
property PackageCompilerMin: TCompilerVersion read FPackageCompilerMin;
property PackageCompilerMax: TCompilerVersion read FPackageCompilerMax;
property CompilerMin: TCompilerVersion read FCompilerMin;
property CompilerMax: TCompilerVersion read FCompilerMax;
property Platforms: TDNCompilerPlatforms read FPlatforms;
end;
implementation
uses
StrUtils;
{ TInfoFile }
function TInfoFile.GetPlatformString: string;
var
LPlatform: TDNCompilerPlatform;
LNeedsSeperator: Boolean;
begin
Result := '';
LNeedsSeperator := False;
for LPlatform in FPlatforms do
begin
if LNeedsSeperator then
Result := Result + ';';
Result := Result + TDNCompilerPlatformName[LPlatform];
LNeedsSeperator := True;
end;
end;
procedure TInfoFile.Load(const ARoot: TJSONObject);
begin
inherited;
FPicture := ReadString(ARoot, 'picture');
FID := ReadID(ARoot);
FName := ReadString(ARoot, 'name');
FLicenseType := ReadString(ARoot, 'license_type');
FLicenseFile := ReadString(ARoot, 'license_file');
FFirstVersion := ReadString(ARoot, 'first_version');
FCompilerMin := ReadFloat(ARoot, 'compiler_min');
FCompilerMax := ReadFloat(ARoot, 'compiler_max');
FPackageCompilerMax := ReadFloat(ARoot, 'package_compiler_max', FCompilerMax);
FPackageCompilerMin := ReadFloat(ARoot, 'package_compiler_min', FCompilerMin);
LoadPlatforms(ReadString(ARoot, 'platforms'));
end;
procedure TInfoFile.LoadPlatforms(const APlatforms: string);
var
LPlatforms: TStringDynArray;
LPlatformString: string;
LPlatform: TDNCompilerPlatform;
begin
FPlatforms := [];
LPlatforms := SplitString(APlatforms, ';');
for LPlatformString in LPlatforms do
begin
if TryPlatformNameToCompilerPlatform(LPlatformString, LPlatform) then
Include(FPlatforms, LPlatform);
end;
if FPlatforms = [] then
Include(FPlatforms, cpWin32);
end;
function TInfoFile.ReadID(const AObject: TJSONObject): TGUID;
var
LID: string;
begin
LID := ReadString(AObject, 'id');
try
if LID <> '' then
Result := StringToGUID(LID)
else
Result := TGUID.Empty;
except
Result := TGUID.Empty;
end;
end;
procedure TInfoFile.Save(const ARoot: TJSONObject);
begin
inherited;
WritePath(ARoot, 'picture', FPicture);
WriteString(ARoot, 'id', FID.ToString);
WriteString(ARoot, 'name', FName);
WriteString(ARoot, 'license_type', FLicenseType);
WritePath(ARoot, 'license_file', FLicenseFile);
WriteString(ARoot, 'first_version', FFirstVersion);
WriteFloat(ARoot, 'package_compiler_max', FPackageCompilerMax);
WriteFloat(ARoot, 'package_compiler_min', FPackageCompilerMin);
WriteFloat(ARoot, 'compiler_min', FCompilerMin);
WriteFloat(ARoot, 'compiler_max', FCompilerMax);
WriteString(ARoot, 'platforms', GetPlatformString());
end;
end.