Skip to content

Commit 74de209

Browse files
committed
Update httpclient imports to use properties
1 parent bcb5147 commit 74de209

16 files changed

+491
-488
lines changed

Source/ide/simba.form_downloadsimba.pas

+7-7
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ procedure TSimbaDownloadSimbaForm.FormCreate(Sender: TObject);
9595
FTreeView.FilterVisible := False;
9696
FTreeView.OnSelectionChange := @DoSelectionChange;
9797
if (SIMBA_COMMIT <> '') then
98-
FTreeView.OnGetNodeColor := @DoGetNodeColor;
98+
{%H-}FTreeView.OnGetNodeColor := @DoGetNodeColor;
9999

100100
FDownloadButton := TSimbaButton.Create(Self);
101101
FDownloadButton.Parent := Panel2;
@@ -195,7 +195,7 @@ procedure TSimbaDownloadSimbaForm.DoDownload;
195195
try
196196
OnDownloadProgress := @DoDownloadProgress;
197197

198-
GetFile(FDownloadURL, FDownloadFileName, [EHTTPStatus.OK]);
198+
GetFile(FDownloadURL, FDownloadFileName);
199199
finally
200200
Free();
201201
end;
@@ -217,25 +217,25 @@ procedure TSimbaDownloadSimbaForm.DoPopulate;
217217
I: Integer;
218218
Count: Integer;
219219
begin
220-
Lines := TSimbaHTTPClient.SimpleGet(URL_BUILD_ARCHIVE_README, []).Split(#10);
220+
Lines := URLFetch(URL_BUILD_ARCHIVE_README).Split(#10);
221221

222222
SetLength(FData, Length(Lines));
223223
Count := 0;
224224

225225
for I := 5 to High(Lines) do
226226
begin
227-
str := Lines[I].Split(' | ');
228-
if Length(Str) = 4 then
227+
Str := Lines[I].Split(' | ');
228+
if (Length(Str) = 4) then
229229
begin
230230
Str[2] := Str[2].Between('[', ']');
231231
Str[3] := Str[3].Between('(', ')');
232232

233233
with FData[Count] do
234234
begin
235-
Date := Str[0];
235+
Date := Str[0];
236236
Branch := Str[1];
237237
Commit := Str[2];
238-
Link := Str[3];
238+
Link := Str[3];
239239
end;
240240
Inc(Count);
241241
end;

Source/ide/simba.form_package.pas

+1-1
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ procedure TSimbaPackageForm.ButtonAddRepositoryClick(Sender: TObject);
177177
FListBox.ItemIndex := FListBox.Add(Package);
178178
end else
179179
begin
180-
SimbaErrorDlg('Package error', ['Package not found: %s', 'Error: %s'], [URL, ToStr(Package.EndPoint.LastHTTPStatus)]);
180+
SimbaErrorDlg('Package error', ['Package not found: %s', 'Error: %s'], [URL, Package.EndPoint.LastHTTPStatus.AsString]);
181181

182182
Package.Free();
183183
end;

Source/ide/simba.frame_settings_editorcolors.pas

+1-1
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,7 @@ procedure TEditorColorsFrame.ButtonLoadFromURLClick(Sender: TObject);
323323
begin
324324
if InputQuery('Simba - Editor Colors', 'Enter URL', Value) then
325325
try
326-
Contents := TSimbaHTTPClient.SimpleGet(Value, [EHTTPStatus.OK]);
326+
Contents := URLFetch(Value);
327327
if (Contents <> '') then
328328
FEditor.Attributes.LoadFromStream(TStringStream.Create(Contents), True);
329329
except

Source/ide/simba.ide_package.pas

+2-2
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ implementation
124124
function GetRemotePackageURLs: TStringArray;
125125
begin
126126
try
127-
Result := TSimbaHTTPClient.SimpleGet(SIMBA_PACKAGES_URL, []).Split(#10);
127+
Result := URLFetch(SIMBA_PACKAGES_URL).Split(#10);
128128
except
129129
Result := [];
130130
end;
@@ -191,7 +191,7 @@ function TSimbaPackageEndpoint.GetPage(URL: String): String;
191191

192192
with TSimbaHTTPClient.Create() do
193193
try
194-
Result := Get(URL, []);
194+
Result := Get(URL);
195195
if (ResponseStatus <> EHTTPStatus.OK) then
196196
Result := '';
197197

Source/ide/simba.ide_package_endpointgithub.pas

+2-2
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ procedure TSimbaPackageEndpoint_Github.DebugRateLimit;
263263
begin
264264
with TSimbaHTTPClient.Create() do
265265
try
266-
Get('https://api.github.com/rate_limit', []);
266+
Get('https://api.github.com/rate_limit');
267267

268268
DebugLn('Github rate limit remaining: %s', [ResponseHeader['X-RateLimit-Remaining']]);
269269
finally
@@ -286,7 +286,7 @@ procedure TSimbaPackageEndpoint_Github.DownloadBranches;
286286
Result := '';
287287

288288
try
289-
Data := TSimbaHTTPClient.SimpleGet(FBranchesAPI, [EHTTPStatus.OK]);
289+
Data := URLFetch(FBranchesAPI);
290290

291291
JsonData := Data.ParseJSON();
292292
if (JsonData <> nil) then

Source/ide/simba.ide_package_installer.pas

+4-4
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ TSimbaPackageInstaller = class
4444

4545
procedure DoConnectingProgress(Sender: TObject; URL: String);
4646
procedure DoDownloadingProgress(Sender: TObject; URL, ContentType: String; Pos, Size: Int64);
47-
procedure DoExtractingProgress(Sender: TObject; FileName: String; Percent: Double);
47+
procedure DoExtractingProgress(Sender: TObject; FileName: String; Pos, Size: Int64);
4848
procedure DoResponseStatus(Sender: TObject; Code: EHTTPStatus);
4949

5050
procedure DoDownloadingFinished(Sender: TObject);
@@ -204,9 +204,9 @@ procedure TSimbaPackageInstaller.DoDownloadingProgress(Sender: TObject; URL, Con
204204
Log(FDownloadProgress.Progress);
205205
end;
206206

207-
procedure TSimbaPackageInstaller.DoExtractingProgress(Sender: TObject; FileName: String; Percent: Double);
207+
procedure TSimbaPackageInstaller.DoExtractingProgress(Sender: TObject; FileName: String; Pos, Size: Int64);
208208
begin
209-
FExtractProgress.Progress := 'Extracting: %d%%'.Format([Round(Percent)]);
209+
FExtractProgress.Progress := 'Extracting: %f%%'.Format([Pos / Size * 100.0]);
210210
if (GetTickCount64() - FExtractProgress.Time) < 500 then
211211
Exit;
212212
FExtractProgress.Time := GetTickCount64();
@@ -239,7 +239,7 @@ procedure TSimbaPackageInstaller.SetVersion(Value: TSimbaPackageVersion);
239239
begin
240240
with TSimbaHTTPClient.Create() do
241241
try
242-
Strings.Text := Get(FVersion.OptionsURL, []);
242+
Strings.Text := Get(FVersion.OptionsURL);
243243
if (ResponseStatus <> EHTTPStatus.OK) then
244244
Strings.Text := '';
245245
finally

Source/script/imports/simba.import_async.pas

+7-1
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,11 @@ procedure _LapeASyncHTTP_Get2(const Params: PParamArray); LAPE_WRAPPER_CALLING_C
4242
ASyncHTTP.Get(PString(Params^[0])^, PString(Params^[1])^, TASyncHTTPFinishedEvent(Params^[2]^), TASyncHTTPProgressEvent(Params^[3]^));
4343
end;
4444

45+
procedure _LapeASyncHTTP_GetZip(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
46+
begin
47+
ASyncHTTP.GetZip(PString(Params^[0])^, PString(Params^[1])^, TASyncHTTPFinishedEvent(Params^[2]^), TASyncHTTPProgressEvent(Params^[3]^));
48+
end;
49+
4550
(*
4651
ASyncHTTP.Post
4752
-------------
@@ -157,9 +162,10 @@ procedure ImportASync(Compiler: TSimbaScript_Compiler);
157162
'TASyncHTTPResult');
158163

159164
addGlobalType('procedure(constref Result: TASyncHTTPResult) of object', 'TASyncHTTPFinishedEvent', FFI_DEFAULT_ABI);
160-
addGlobalType('procedure(URL, ContentType: String; Position, Size: Int64) of object', 'TASyncHTTPProgressEvent', FFI_DEFAULT_ABI);
165+
addGlobalType('procedure(URL: String; Position, Size: Int64) of object', 'TASyncHTTPProgressEvent', FFI_DEFAULT_ABI);
161166
addGlobalFunc('procedure ASyncHTTPClient.Get(URL: String; OnFetched: TASyncHTTPFinishedEvent; OnProgress: TASyncHTTPProgressEvent = nil); static; overload;', @_LapeASyncHTTP_Get1);
162167
addGlobalFunc('procedure ASyncHTTPClient.Get(URL, DestFile: String; OnFetched: TASyncHTTPFinishedEvent; OnProgress: TASyncHTTPProgressEvent = nil); static; overload;', @_LapeASyncHTTP_Get2);
168+
addGlobalFunc('procedure ASyncHTTPClient.GetZip(URL, DestFile: String; OnFinished: TASyncHTTPFinishedEvent; OnProgress: TASyncHTTPProgressEvent = nil); static;', @_LapeASyncHTTP_GetZip);
163169
addGlobalFunc('procedure ASyncHTTPClient.Post(URL, PostData: String); static; overload;', @_LapeASyncHTTP_Post1);
164170
addGlobalFunc('procedure ASyncHTTPClient.Post(URL, PostData: String; Headers: TStringArray); static; overload;', @_LapeASyncHTTP_Post2);
165171

Source/script/imports/simba.import_json.pas

+4
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ implementation
1616
lptypes,
1717
simba.json;
1818

19+
type
20+
PSimbaJSONElement = ^TSimbaJSONElement;
21+
PSimbaJSONParser = ^TSimbaJSONParser;
22+
1923
(*
2024
JSON
2125
====

Source/script/imports/simba.import_threading.pas

+11-59
Original file line numberDiff line numberDiff line change
@@ -18,57 +18,8 @@ procedure ImportThreading(Compiler: TSimbaScript_Compiler);
1818
implementation
1919

2020
uses
21-
lptypes, lpparser, ffi;
22-
23-
// All this is because we use cdecl on win32...
24-
type
25-
TScriptThreadMethod = procedure() of object; cdecl;
26-
27-
TSyncObject = object
28-
FMethod: TScriptThreadMethod;
29-
30-
procedure Execute;
31-
end;
32-
33-
TThreadObject = class(TThread)
34-
protected
35-
FMethod: TScriptThreadMethod;
36-
37-
procedure Execute; override;
38-
public
39-
constructor Create(Method: TScriptThreadMethod); reintroduce;
40-
end;
41-
42-
procedure TThreadObject.Execute;
43-
begin
44-
try
45-
if Assigned(FMethod) then
46-
FMethod();
47-
except
48-
on E: Exception do
49-
DebugLn('RunInThread exception: ' + E.Message);
50-
end;
51-
end;
52-
53-
constructor TThreadObject.Create(Method: TScriptThreadMethod);
54-
begin
55-
inherited Create(False, DefaultStackSize div 2);
56-
57-
FMethod := Method;
58-
59-
FreeOnTerminate := True;
60-
end;
61-
62-
procedure TSyncObject.Execute;
63-
begin
64-
try
65-
if Assigned(FMethod) then
66-
FMethod();
67-
except
68-
on E: Exception do
69-
DebugLn('RunOnMainThread exception: ' + E.Message);
70-
end;
71-
end;
21+
lptypes, lpparser, ffi,
22+
simba.threading;
7223

7324
procedure _LapeCurrentThreadID(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
7425
begin
@@ -80,19 +31,19 @@ procedure _LapeMainThreadID(const Params: PParamArray; const Result: Pointer); L
8031
TThreadID(Result^) := MainThreadID;
8132
end;
8233

83-
procedure _LapeRunInMainThread(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
84-
var
85-
{%H-}SyncObject: TSyncObject;
34+
procedure _LapeQueueInMainThread(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
8635
begin
87-
SyncObject := Default(TSyncObject);
88-
SyncObject.FMethod := TScriptThreadMethod(Params^[0]^);
36+
QueueOnMainThread(TThreadMethod(Params^[0]^));
37+
end;
8938

90-
TThread.Synchronize(nil, @SyncObject.Execute);
39+
procedure _LapeRunInMainThread(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
40+
begin
41+
RunInMainThread(TThreadMethod(Params^[0]^));
9142
end;
9243

9344
procedure _LapeRunInThread(const Params: PParamArray); LAPE_WRAPPER_CALLING_CONV
9445
begin
95-
TThreadObject.Create(TScriptThreadMethod(Params^[0]^));
46+
RunInThread(TThreadMethod(Params^[0]^), True);
9647
end;
9748

9849
procedure ImportThreading(Compiler: TSimbaScript_Compiler);
@@ -104,11 +55,12 @@ procedure ImportThreading(Compiler: TSimbaScript_Compiler);
10455
addGlobalVar(CPUCount, 'CPU_COUNT').isConstant := True;
10556

10657
addGlobalType(getBaseType(DetermineIntType(SizeOf(TThreadID), False)).createCopy(), 'TThreadID');
107-
addGlobalType('procedure() of object', 'TThreadMethod', {$IF DEFINED(CPU32) and DEFINED(LAPE_CDECL)}FFI_CDECL{$ELSE}FFI_DEFAULT_ABI{$ENDIF});
58+
addGlobalType('procedure() of object', 'TThreadMethod', FFI_DEFAULT_ABI);
10859

10960
addGlobalFunc('function CurrentThreadID: TThreadID', @_LapeCurrentThreadID);
11061
addGlobalFunc('function MainThreadID: TThreadID', @_LapeMainThreadID);
11162

63+
addGlobalFunc('procedure QueueInMainThread(Method: TThreadMethod)', @_LapeQueueInMainThread);
11264
addGlobalFunc('procedure RunInMainThread(Method: TThreadMethod)', @_LapeRunInMainThread);
11365
addGlobalFunc('procedure RunInThread(Method: TThreadMethod)', @_LapeRunInThread);
11466

0 commit comments

Comments
 (0)