This repository has been archived by the owner on Nov 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unitformnewtask.pas
95 lines (65 loc) · 1.73 KB
/
unitformnewtask.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
unit unitformnewtask;
{$mode ObjFPC}{$H+}
interface
uses
Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ComCtrls, ExtCtrls,
StdCtrls, ceostypes, base64;
type
{ TFormNewTask }
TFormNewTask = class(TForm)
btnStart: TButton;
btnCancel: TButton;
btnBrowseTorrent: TButton;
edtDownloadURL: TLabeledEdit;
edtTorrentPath: TLabeledEdit;
OpenDialog1: TOpenDialog;
PageControl1: TPageControl;
TabSheet1: TTabSheet;
TabSheet2: TTabSheet;
procedure btnBrowseTorrentClick(Sender: TObject);
procedure btnCancelClick(Sender: TObject);
procedure btnStartClick(Sender: TObject);
private
public
end;
var
FormNewTask: TFormNewTask;
implementation
uses unitformmain, unitcommon;
{$R *.lfm}
{ TFormNewTask }
procedure TFormNewTask.btnCancelClick(Sender: TObject);
begin
Close;
end;
procedure TFormNewTask.btnBrowseTorrentClick(Sender: TObject);
begin
if OpenDialog1.Execute then edtTorrentPath.Text:=OpenDialog1.FileName;
end;
procedure TFormNewTask.btnStartClick(Sender: TObject);
var
req: TCeosRequestContent;
RawString: TStringStream;
EncodedString: string;
resp: string;
begin
req:=TCeosRequestContent.create;
req.Args.Add(AriaParamToken);
if PageControl1.ActivePageIndex = 0 then begin
req.Method:='aria2.addUri';
req.Args.Add(GetJSONArray([edtDownloadURL.Text]));
end;
if PageControl1.ActivePageIndex = 1 then begin
req.Method:='aria2.addTorrent';
RawString:=TStringStream.Create('');
RawString.LoadFromFile(edtTorrentPath.Text);
EncodedString:=EncodeStringBase64(RawString.DataString);
req.Args.Add(EncodedString);
RawString.Free;
end;
resp:=FormMain.client.call(req);
req.Free;
ShowMessage(resp);
Close;
end;
end.