forked from NeeeeB/GameList_Editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathU_DownloadThread.pas
105 lines (93 loc) · 2.7 KB
/
U_DownloadThread.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
unit U_DownloadThread;
interface
uses
System.Classes, System.SysUtils,
Vcl.ExtCtrls, Vcl.Graphics, Vcl.Imaging.jpeg, Vcl.Imaging.pngimage,
U_Resources, System.Net.HttpClientComponent, System.Net.URLClient,
System.Net.HttpClient;
type
TDOwnThread = class( TThread )
private
Net_HTTPClient: TNetHTTPClient;
Img: TImage;
Graph: TGraphic;
procedure AddPicture;
protected
procedure Execute; override;
public
Url: string;
Ext: string;
constructor Create; reintroduce;
destructor Destroy; override;
end;
implementation
uses
F_Main;
constructor TDOwnThread.Create;
begin
inherited Create( True );
Net_HTTPClient:= TNetHTTPClient.Create(Net_HTTPClient);
if Frm_Editor.FProxyUse then begin
Net_HTTPClient.ProxySettings := TProxySettings.Create(
Frm_Editor.FProxyServer,
StrToInt( Frm_Editor.FProxyPort ),
Frm_Editor.FProxyUser,
Frm_Editor.FProxyPwd);
end else begin
Net_HTTPClient.ProxySettings := TProxySettings.Create('', 0, '', '');
end;
Img:= TImage.Create( nil );
Img.AutoSize:= True;
Img.Center:= True;
Img.Proportional:= True;
Img.Visible:= False;
FreeOnTerminate:= True;
end;
destructor TDOwnThread.Destroy;
begin
Net_HTTPClient.Free;
inherited;
end;
procedure TDOwnThread.Execute;
var
Stream: TBytesStream;
begin
Stream:= TBytesStream.Create;
try
try
Net_HTTPClient.Get( Url, Stream );
if ( Stream.Size = 0 ) then begin
Frm_Editor.WarnUser( Rst_StreamError );
Exit;
end;
Stream.Position:= 0;
//on crée le graphic qui va bien en fonction de l'extension
if ( Ext = Cst_PngExt ) then Graph:= TPngImage.Create
else Graph:= TJPEGImage.create;
Graph.LoadFromStream( Stream );
Img.Picture.Graphic:= Graph;
except
on E : Exception do
begin
// Legacy errors
// 400: WarnUser( Rst_ServerError1 );
// 401: WarnUser( Rst_ServerError2 );
// 403: WarnUser( Rst_ServerError3 );
// 404: WarnUser( Rst_ServerError4 );
// 423: WarnUser( Rst_ServerError5 );
// 426: WarnUser( Rst_ServerError6 );
// 429: WarnUser( Rst_ServerError7 );
Frm_Editor.WarnUserWithSafeUrl( Rst_ServerError8, E.Message, Url);
Exit;
end;
end;
finally
Stream.Free;
end;
Synchronize( AddPicture );
end;
procedure TDOwnThread.AddPicture;
begin
Frm_Editor.FImgList.Add( Img );
end;
end.