-
Notifications
You must be signed in to change notification settings - Fork 6
/
HGI.GetItAPI.pas
353 lines (323 loc) · 9.55 KB
/
HGI.GetItAPI.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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
unit HGI.GetItAPI;
interface
uses
HGI.Item, System.SysUtils;
type
TGetIt = class
class var
Url, Version: string;
class function Get(out Items: TPackages; const Categories: string; Order: Integer; const Personalities: string; const Search: string = ''; const Count: Integer = 0; const Offset: Integer = 0): Boolean;
class function ParseDate(const Value: string): string; static;
end;
TIDEEntity = record
Version: string;
RootDir: string;
Personalities: string;
ServiceUrl: string;
RegPath: string;
IsCustom: Boolean;
Elements: TArray<string>;
function GetPathBin: string;
function GetPathGetItCmd: string;
procedure LoadInstalled(out Items: TPackages; const Search: string);
end;
TIDEList = class
class function List: TArray<TIDEEntity>;
end;
const
GetItCmdPath = 'GetItCmd.exe';
implementation
uses
Winapi.Windows, System.Net.HttpClient, System.Net.Mime, System.Classes,
Rest.Json, System.Win.Registry, System.IOUtils;
{ TGetIt }
class function TGetIt.ParseDate(const Value: string): string;
begin
var FormatDate: TFormatSettings;
var Date: TDateTime;
FormatDate.DateSeparator := '-';
FormatDate.ShortDateFormat := 'YYYY-MM-DD';
if (not Value.IsEmpty) and TryStrToDateTime(Value, Date, FormatDate) then
Result := FormatDateTime('DD.MM.YYYY', Date)
else
Result := 'Unkonwn';
end;
class function TGetIt.Get(out Items: TPackages; const Categories: string; Order: Integer; const Personalities: string; const Search: string; const Count, Offset: Integer): Boolean;
var
HTTP: THTTPClient;
begin
Result := False;
Items := nil;
HTTP := THTTPClient.Create;
try
var Body := TMultipartFormData.Create;
var Response := TStringStream.Create('', TEncoding.UTF8);
try
if Categories <> '' then
Body.AddField('Categories', Categories);
if not Search.IsEmpty then
Body.AddField('Search', Search);
if Offset > 0 then
Body.AddField('Start', Offset.ToString);
if Count > 0 then
Body.AddField('End', Count.ToString);
Body.AddField('Order', Order.ToString);
Body.AddField('Language', '0');
Body.AddField('CatalogVersion', '5');
Body.AddField('ProductSKU', '52');
Body.AddField('Personalities', Personalities); // delphi 1
//Body.AddField('Identity', 'C++'); //DELPHI
Body.AddField('Version', Version);
// Body.AddField('BuildNumber', '28.0.47991.2819');
// https://getit-104.embarcadero.com
// https://getit-1032.embarcadero.com
// https://getit-olympus.embarcadero.com
if HTTP.Post(Url + '/catalog/info', Body, Response).StatusCode = 200 then
begin
Items := TJson.JsonToObject<TPackages>('{ "items": ' + Response.DataString + '}');
Result := True;
end;
finally
Body.Free;
Response.Free;
end;
finally
HTTP.Free;
end;
end;
// Categories
// 4 - iot
// 20 - IntraWeb
// 25 - AndroidSDK-NDK
// 26 - jdk
// 27 - AndroidSDK-NDK
// 28 - AdoptOpenJDK
// 29 - AndroidSDK
//+ 1 - Libraries
//+ 2 - Components
// 3-13 - empty
//+ 14 - Fonts
//+ 15 - Platforms
//+ 16 - Samples
//+ 17 - Help
// 18-19 - empty
// 20 - empty (IntraWeb)
//+ 21 - TeeChart Standard
//+ 22 - DUnit Unit Testing Frameworks
//+ 23 - InterBase Express (IBX) Components
// 24-32 - empty
//+ 33 - Trial
// 34-35 - empty
//+ 36 - Industry Templates
//+ 37 - IDE Plugins
//+ 38 - Styles
// 39 - empty
//+ 40 - Introductory Samples
// 41 - empty
//+ 42 - InterBase 2020 Developer Edition
// 43-45 - empty
//+ 46 - Tools
//+ 47 - Python
// 48-97 - empty
//+ 98 - New
//+ 99 - Sample Projects
//+ 998 - Promoted
//+ 999 - Patches and Hotfixes
//+ 1001 - Tools
{ TIDEList }
class function TIDEList.List: TArray<TIDEEntity>;
function ReadSection(Reg: TRegistry; const Section: string; out Entity: TIDEEntity): Boolean;
begin
Result := False;
Reg.CloseKey;
if not Reg.OpenKeyReadOnly('Software\Embarcadero\BDS\' + Section) then
Exit;
if not Reg.KeyExists('CatalogRepository') then
Exit;
try
Entity.Version := Section;
Entity.RootDir := Reg.ReadString('RootDir');
if not Reg.OpenKeyReadOnly('Personalities') then
Exit;
Entity.Personalities := Reg.ReadString('');
Reg.CloseKey;
if not Reg.OpenKeyReadOnly('Software\Embarcadero\BDS\' + Section + '\CatalogRepository') then
Exit;
Entity.ServiceUrl := Reg.ReadString('ServiceUrl');
if Reg.OpenKeyReadOnly('Elements') then
begin
var Elements := TStringList.Create;
try
Reg.GetKeyNames(Elements);
Entity.Elements := Elements.ToStringArray;
finally
Elements.Free;
end;
end;
Result := True;
except
Exit;
end;
end;
begin
Result := [];
var Reg := TRegistry.Create(KEY_QUERY_VALUE);
try
Reg.RootKey := HKEY_CURRENT_USER;
if not Reg.OpenKeyReadOnly('Software\Embarcadero\BDS') then
Exit;
var Sections := TStringList.Create;
try
Reg.GetKeyNames(Sections);
var Entity: TIDEEntity;
for var Section in Sections do
if ReadSection(Reg, Section, Entity) then
begin
Entity.RegPath := 'Software\Embarcadero\BDS\' + Section;
SetLength(Result, Length(Result) + 1);
Result[High(Result)] := Entity;
end;
finally
Sections.Free;
end;
finally
Reg.Free;
end;
end;
{ TIDEEntity }
function TIDEEntity.GetPathBin: string;
begin
Result := TPath.Combine(RootDir, 'Bin');
end;
function TIDEEntity.GetPathGetItCmd: string;
begin
Result := TPath.Combine(GetPathBin, GetItCmdPath);
end;
procedure TIDEEntity.LoadInstalled(out Items: TPackages; const Search: string);
var
Reg: TRegistry;
SearchStr: string;
function ReadItem(Item: TGetItPackage): Boolean;
begin
Result := True;
Item.Name := Reg.ReadString('Name');
Item.Tags := Reg.ReadString('Tags');
Item.Description := Reg.ReadString('Description');
if not SearchStr.IsEmpty then
begin
if not Item.Name.ToLower.Contains(SearchStr) then
if not Item.Tags.ToLower.Contains(SearchStr) then
if not Item.Description.ToLower.Contains(SearchStr) then
Exit(False);
end;
Item.LibCode := Reg.ReadInteger('Code').ToString;
Item.LibCodeName := Reg.ReadString('CodeName');
Item.AllUsers := Reg.ReadInteger('AllUsers').ToString;
Item.Compatibility := Reg.ReadInteger('Compatibility').ToString;
Item.Icon := Reg.ReadString('Icon');
Item.Image := Reg.ReadString('Image');
Item.LibGenerateTmpUrl := Reg.ReadInteger('LibGenerateTmpUrl').ToString;
Item.LibLicenseName := Reg.ReadString('LicenseName');
Item.LicenseState := Reg.ReadInteger('LibGenerateTmpUrl').ToString;
Item.Modified := FormatDateTime('YYYY-MM-DD', Reg.ReadDateTime('Modified'));
Item.PurchaseUrl := Reg.ReadString('PurchaseUrl');
Item.RequireElevation := Reg.ReadInteger('RequireElevation').ToString;
Item.State := Reg.ReadInteger('State').ToString;
Item.TargetPath := Reg.ReadString('TargetPath');
Item.TypeDescription := Reg.ReadString('TypeDescription');
Item.TypeId := Reg.ReadInteger('TypeId').ToString;
Item.Vendor := Reg.ReadString('Vendor');
Item.VendorUrl := Reg.ReadString('VendorUrl');
Item.Version := Reg.ReadString('Version');
Item.LibUrl := Reg.ReadString('Url');
var List := TStringList.Create;
try
var Tmp := Reg.ReadString('OSes');
List.Delimiter := ';';
List.DelimitedText := Tmp;
var LibOSes: TArray<TLibOS>;
try
for var SItem in List do
begin
var Arr := SItem.Split(['=']);
if Length(Arr) > 1 then
begin
var OS := TLibOS.Create;
OS.Id := Arr[0];
OS.Name := Arr[1];
SetLength(LibOSes, Length(LibOSes) + 1);
LibOSes[High(LibOSes)] := OS;
end;
end;
finally
Item.LibOSes := LibOSes;
end;
Tmp := Reg.ReadString('Platforms');
List.Delimiter := ';';
List.DelimitedText := Tmp;
var Platforms: TArray<TLibPlatform>;
try
for var SItem in List do
begin
var
Arr := SItem.Split(['=']);
if Length(Arr) > 1 then
begin
var LibPlatform := TLibPlatform.Create;
LibPlatform.Id := Arr[0];
LibPlatform.Name := Arr[1];
SetLength(Platforms, Length(Platforms) + 1);
Platforms[High(Platforms)] := LibPlatform;
end;
end;
finally
Item.LibPlatforms := Platforms;
end;
finally
List.Free;
end;
end;
begin
Items := TPackages.Create;
SearchStr := Search.ToLower;
var
FItems: TArray<TGetItPackage>;
try
Reg := TRegistry.Create(KEY_QUERY_VALUE);
try
Reg.RootKey := HKEY_CURRENT_USER;
var RegRoot := RegPath + '\CatalogRepository\Elements';
if not Reg.OpenKeyReadOnly(RegRoot) then
Exit;
var List := TStringList.Create;
try
Reg.GetKeyNames(List);
for var Key in List do
begin
Reg.CloseKey;
if Reg.OpenKeyReadOnly(RegRoot + '\' + Key) then
begin
var Item := TGetItPackage.Create;
if not ReadItem(Item) then
begin
Item.Free;
Continue;
end;
Item.Id := Key;
SetLength(FItems, Length(FItems) + 1);
FItems[High(FItems)] := Item;
end;
end;
finally
List.Free;
end;
finally
Reg.Free;
end;
Items.Items := FItems;
except
Items.Items := FItems;
Items.Free;
end;
end;
end.