Графический интерфейс в aria2c RPC http://blindage.org/?p=5385
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

unit1.pas 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. unit Unit1;
  2. {$mode objfpc}{$H+}
  3. interface
  4. uses
  5. Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, ComCtrls,
  6. StdCtrls, Menus, ActnList, ExtCtrls, PopupNotifier, Buttons, ValEdit,
  7. HTTPSend, SynaUtil, XMLRead, DOM, XMLUtils, fpjson, jsonparser, inifiles,
  8. vinfo, versiontypes;
  9. type
  10. { TForm1 }
  11. TForm1 = class(TForm)
  12. action_check_upgrade: TAction;
  13. action_update_server_list: TAction;
  14. action_settings: TAction;
  15. action_about: TAction;
  16. action_servers: TAction;
  17. action_quit: TAction;
  18. action_pauseselected: TAction;
  19. action_startall: TAction;
  20. action_pauseall: TAction;
  21. action_startselected: TAction;
  22. action_deleteselected: TAction;
  23. action_newdownload: TAction;
  24. ActionList1: TActionList;
  25. allimages: TImageList;
  26. BitBtn1: TBitBtn;
  27. ComboBox1: TComboBox;
  28. Label2: TLabel;
  29. ListView1: TListView;
  30. Panel2: TPanel;
  31. serv_images: TImageList;
  32. items_images: TImageList;
  33. Label1: TLabel;
  34. ListView2: TListView;
  35. MainMenu1: TMainMenu;
  36. Memo1: TMemo;
  37. MenuItem1: TMenuItem;
  38. MenuItem10: TMenuItem;
  39. MenuItem11: TMenuItem;
  40. MenuItem12: TMenuItem;
  41. MenuItem13: TMenuItem;
  42. MenuItem14: TMenuItem;
  43. MenuItem15: TMenuItem;
  44. MenuItem16: TMenuItem;
  45. MenuItem17: TMenuItem;
  46. MenuItem18: TMenuItem;
  47. MenuItem19: TMenuItem;
  48. MenuItem2: TMenuItem;
  49. MenuItem20: TMenuItem;
  50. MenuItem3: TMenuItem;
  51. MenuItem4: TMenuItem;
  52. MenuItem5: TMenuItem;
  53. MenuItem6: TMenuItem;
  54. MenuItem7: TMenuItem;
  55. MenuItem8: TMenuItem;
  56. MenuItem9: TMenuItem;
  57. Panel1: TPanel;
  58. PopupMenu1: TPopupMenu;
  59. PopupNotifier1: TPopupNotifier;
  60. PopupNotifierTimer: TTimer;
  61. Splitter1: TSplitter;
  62. ToolButton2: TToolButton;
  63. ToolButton3: TToolButton;
  64. ToolButton4: TToolButton;
  65. ToolButton5: TToolButton;
  66. ToolButton6: TToolButton;
  67. ToolButton8: TToolButton;
  68. UpdateListTimer: TTimer;
  69. ToolBar1: TToolBar;
  70. ToolButton1: TToolButton;
  71. TrayIcon1: TTrayIcon;
  72. procedure action_check_upgradeExecute(Sender: TObject);
  73. procedure action_update_server_listExecute(Sender: TObject);
  74. procedure action_aboutExecute(Sender: TObject);
  75. procedure action_deleteselectedExecute(Sender: TObject);
  76. procedure action_newdownloadExecute(Sender: TObject);
  77. procedure action_pauseselectedExecute(Sender: TObject);
  78. procedure action_quitExecute(Sender: TObject);
  79. procedure action_serversExecute(Sender: TObject);
  80. procedure action_settingsExecute(Sender: TObject);
  81. procedure action_startselectedExecute(Sender: TObject);
  82. procedure ComboBox1Change(Sender: TObject);
  83. procedure FormClose(Sender: TObject; var CloseAction: TCloseAction);
  84. procedure FormCreate(Sender: TObject);
  85. procedure FormHide(Sender: TObject);
  86. procedure FormShow(Sender: TObject);
  87. procedure ListBox1Click(Sender: TObject);
  88. procedure ListView1DblClick(Sender: TObject);
  89. procedure PopupNotifierTimerTimer(Sender: TObject);
  90. procedure TrayIcon1Click(Sender: TObject);
  91. procedure UpdateListTimerTimer(Sender: TObject);
  92. procedure show_baloon(bTitle, bText: string);
  93. procedure UpdateAll;
  94. function JSONQuery(query_array: TJSONObject): string;
  95. procedure Minimize(Sender: TObject);
  96. procedure ValueListEditor1Click(Sender: TObject);
  97. private
  98. { private declarations }
  99. public
  100. { public declarations }
  101. end;
  102. var
  103. Form1: TForm1;
  104. close_to_tray, minimized: boolean;
  105. implementation
  106. uses unitSettings, unitServers, unitAdd, json, about, unitInfo;
  107. {$R *.lfm}
  108. { TForm1 }
  109. procedure tform1.show_baloon(bTitle, bText: string);
  110. begin
  111. with Form1 do
  112. begin
  113. PopupNotifier1.Title := bTitle;
  114. PopupNotifier1.Text := bText;
  115. PopupNotifier1.Show;
  116. PopupNotifierTimer.Enabled := True;
  117. end;
  118. end;
  119. function download_update(download: TStringList): boolean;
  120. var
  121. ItemIndex: integer;
  122. myitem_details: TStringList;
  123. begin
  124. Result := False;
  125. myitem_details := TStringList.Create;
  126. with form1 do
  127. for ItemIndex := 0 to ListView1.Items.Count - 1 do
  128. begin
  129. if ListView1.Items.Item[ItemIndex].Caption = download.Strings[0] then
  130. begin
  131. ListView1.Items.Item[ItemIndex].SubItems.Clear;
  132. myitem_details.Add(download.Strings[1]); //state
  133. myitem_details.Add(download.Strings[2]); //uri
  134. myitem_details.Add(download.Strings[3]); //dest
  135. myitem_details.Add(download.Strings[4]); //%
  136. myitem_details.Add(download.Strings[5]); //threads
  137. myitem_details.Add(download.Strings[6]); //speed
  138. if download.Strings[1] = 'error' then
  139. begin
  140. ListView1.Items.Item[ItemIndex].ImageIndex := 2;
  141. Result := True;
  142. end;
  143. if download.Strings[1] = 'complete' then
  144. begin
  145. ListView1.Items.Item[ItemIndex].ImageIndex := 1;
  146. Result := True;
  147. end;
  148. if download.Strings[1] = 'active' then
  149. ListView1.Items.Item[ItemIndex].ImageIndex := 0;
  150. ListView1.Items.Item[ItemIndex].SubItems.AddStrings(myitem_details);
  151. end;
  152. end;
  153. end;
  154. procedure download_add(download: TStringList);
  155. var
  156. myitem: TListItem;
  157. myitem_details: TStringList;
  158. begin
  159. with Form1 do
  160. begin
  161. //ListView1.Items.Clear;
  162. myitem_details := TStringList.Create;
  163. myitem := TListItem.Create(ListView1.Items);
  164. myitem_details.Add(download.Strings[1]); //state
  165. myitem_details.Add(download.Strings[2]); //uri
  166. myitem_details.Add(download.Strings[3]); //dest
  167. myitem_details.Add(download.Strings[4]); //%
  168. myitem_details.Add(download.Strings[5]); //threads
  169. myitem_details.Add(download.Strings[6]); //speed
  170. if download.Strings[1] = 'error' then
  171. myitem.ImageIndex := 2;
  172. if download.Strings[1] = 'complete' then
  173. myitem.ImageIndex := 1;
  174. if download.Strings[1] = 'active' then
  175. myitem.ImageIndex := 0;
  176. if download.Strings[1] = 'paused' then
  177. myitem.ImageIndex := 3;
  178. if download.Strings[1] = 'removed' then
  179. myitem.ImageIndex := 4;
  180. if download.Strings[1] = 'waiting' then
  181. myitem.ImageIndex := 5;
  182. myitem.Caption := download.Strings[0]; //gid
  183. myitem.SubItems.AddStrings(myitem_details);
  184. ListView1.Items.AddItem(myitem);
  185. //show_baloon('Aria2G', 'URL Added to queue');
  186. end;
  187. end;
  188. function TForm1.JSONQuery(query_array: TJSONObject): string;
  189. var
  190. myHTTP: THTTPSend;
  191. doc: TStringList;
  192. begin
  193. myHTTP := THTTPSend.Create;
  194. doc := TStringList.Create;
  195. try
  196. WriteStrToStream(myHTTP.Document, query_array.FormatJSON);
  197. myHTTP.MimeType := 'application/json-rpc';
  198. if ComboBox1.Items.Count > 0 then
  199. if myHTTP.HTTPMethod('POST', ComboBox1.Text + '/jsonrpc') then
  200. begin
  201. myHTTP.Document.Position := 0;
  202. doc.LoadFromStream(myHTTP.Document);
  203. Result := doc.Text;
  204. end
  205. else
  206. begin
  207. Result := 'nil';
  208. Memo1.Lines.Insert(0, 'Cant connect to ' + ComboBox1.Text +
  209. '. Temporary deleted from server list');
  210. if ComboBox1.Items.Count > 0 then
  211. ComboBox1.Items.Delete(ComboBox1.ItemIndex);
  212. if ComboBox1.Items.Count > 0 then
  213. ComboBox1.ItemIndex := 0;
  214. UpdateAll;
  215. end
  216. else
  217. Result := 'nil';
  218. finally
  219. myHTTP.Free;
  220. doc.Free;
  221. end;
  222. end;
  223. procedure TForm1.PopupNotifierTimerTimer(Sender: TObject);
  224. begin
  225. PopupNotifierTimer.Enabled := False;
  226. PopupNotifier1.Hide;
  227. end;
  228. procedure TForm1.UpdateAll;
  229. var
  230. O, DownloadsActive, DownloadsStopped, DownloadsWaiting: TJSONObject;
  231. AllDownloads, A, F, U: TJSONArray;
  232. JS: TJSON;
  233. download: TStringList;
  234. ItemIndex, ResultIndex, percent, speed: integer;
  235. total: int64;
  236. json_result: string;
  237. begin
  238. DownloadsStopped := TJSONObject.Create(['methodName', 'aria2.tellStopped',
  239. 'params', TJSONArray.Create(
  240. [0, 100, TJSONArray.Create(['gid', 'status', 'connections', 'dir',
  241. 'files', 'downloadSpeed', 'totalLength', 'completedLength'])])]);
  242. DownloadsWaiting := TJSONObject.Create(['methodName', 'aria2.tellWaiting',
  243. 'params', TJSONArray.Create(
  244. [0, 100, TJSONArray.Create(['gid', 'status', 'connections', 'dir',
  245. 'files', 'downloadSpeed', 'totalLength', 'completedLength'])])]);
  246. DownloadsActive := TJSONObject.Create(['methodName', 'aria2.tellActive',
  247. 'params', TJSONArray.Create([TJSONArray.Create(
  248. ['gid', 'status', 'connections', 'dir', 'files', 'downloadSpeed',
  249. 'totalLength', 'completedLength'])])]);
  250. O := TJSONObject.Create(['jsonrpc', '2.0', 'id', 'qwer', 'method',
  251. 'system.multicall', 'params', TJSONArray.Create(
  252. [TJSONArray.Create([DownloadsActive, DownloadsWaiting, DownloadsStopped])])]);
  253. download := TStringList.Create;
  254. JS := TJSON.Create;
  255. json_result := JSONQuery(O);
  256. if json_result = 'nil' then
  257. Memo1.Lines.Insert(0, 'Cant update list. Server connection error.')
  258. else
  259. begin
  260. JS.Parse(json_result);
  261. //Memo1.Lines.Text:=json_result;
  262. AllDownloads := JS.Arrays['result'];
  263. form1.ListView1.Clear;
  264. for ResultIndex := 0 to AllDownloads.Count - 1 do
  265. begin
  266. A := AllDownloads.Arrays[ResultIndex].Arrays[0];
  267. for ItemIndex := 0 to A.Count - 1 do
  268. begin
  269. download.Clear;
  270. download.Add(A.Objects[ItemIndex].Extract('gid').AsString); //gid
  271. download.Add(A.Objects[ItemIndex].Extract('status').AsString); //status
  272. download.Add(A.Objects[ItemIndex].Arrays['files'].Objects[0].Extract(
  273. 'path').AsString); //uri torrent have no uri! and metalink i think too
  274. download.Add(A.Objects[ItemIndex].Extract('dir').AsString); //dest
  275. //%
  276. total := A.Objects[ItemIndex].Extract('totalLength').AsInt64;
  277. if total > 0 then
  278. percent := (A.Objects[ItemIndex].Extract('completedLength').AsInt64 *
  279. 100) div total
  280. else
  281. percent := 0;
  282. download.Add(IntToStr(percent));
  283. download.Add(A.Objects[ItemIndex].Extract('connections').AsString); //threads
  284. //speed
  285. speed := A.Objects[ItemIndex].Extract('downloadSpeed').AsInteger;
  286. if speed > 0 then
  287. download.Add(IntToStr(speed div 1024) + ' KB/s')
  288. else
  289. download.Add('0 KB/s');
  290. download_add(download);
  291. end;
  292. end;
  293. end;
  294. O.Free;
  295. end;
  296. procedure TForm1.UpdateListTimerTimer(Sender: TObject);
  297. var
  298. O, ActiveUpdate: TJSONObject;
  299. AllDownloads, A, F, U: TJSONArray;
  300. JS: TJSON;
  301. doc: TStringList;
  302. download: TStringList;
  303. ItemIndex, ResultIndex, percent, speed: integer;
  304. total: int64;
  305. item: TListItem;
  306. gid_array_len: integer;
  307. json_array: TJSONArray;
  308. json_result: string;
  309. need_update_all: boolean;
  310. begin
  311. need_update_all := False;
  312. //search active
  313. //form1.Memo1.Lines.Add('update');
  314. json_array := TJSONArray.Create;
  315. json_array.Clear;
  316. for ItemIndex := 0 to ListView1.Items.Count - 1 do
  317. begin
  318. gid_array_len := 0;
  319. if ListView1.Items.Item[ItemIndex].SubItems.Strings[0] = 'active' then
  320. begin
  321. //showmessage(IntToStr(ItemIndex));
  322. Inc(gid_array_len);
  323. json_array.Insert(gid_array_len - 1,
  324. TJSONObject.Create(['methodName', 'aria2.tellStatus', 'params',
  325. TJSONArray.Create([ListView1.Items.Item[ItemIndex].Caption,
  326. TJSONArray.Create(['gid', 'status', 'connections', 'dir',
  327. 'files', 'downloadSpeed', 'totalLength', 'completedLength'])])])
  328. );
  329. end;
  330. end;
  331. O := TJSONObject.Create(['jsonrpc', '2.0', 'id', 'qwer', 'method',
  332. 'system.multicall', 'params', TJSONArray.Create([json_array])]);
  333. download := TStringList.Create;
  334. JS := TJSON.Create;
  335. json_result := JSONQuery(O);
  336. if json_result = 'nil' then
  337. //Memo1.Lines.Insert(0, 'Cant update list by timer')
  338. else
  339. begin
  340. JS.Parse(json_result);
  341. //Memo1.Lines.Insert(0, json_result);
  342. AllDownloads := JS.Arrays['result'];
  343. for ResultIndex := 0 to AllDownloads.Count - 1 do
  344. begin
  345. A := AllDownloads.Arrays[ResultIndex];
  346. for ItemIndex := 0 to A.Count - 1 do
  347. begin
  348. download.Clear;
  349. download.Add(A.Objects[ItemIndex].Extract('gid').AsString); //gid
  350. download.Add(A.Objects[ItemIndex].Extract('status').AsString); //status
  351. F := A.Objects[ItemIndex].Arrays['files'].Objects[0].Arrays['uris'];
  352. //download.Add(F.Objects[0].Extract('uri').AsString); //uri
  353. download.Add(A.Objects[ItemIndex].Arrays['files'].Objects[0].Extract(
  354. 'path').AsString); //uri torrent have no uri! and metalink i think too
  355. download.Add(A.Objects[ItemIndex].Extract('dir').AsString); //dest
  356. //%
  357. total := A.Objects[ItemIndex].Extract('totalLength').AsInt64;
  358. if total > 0 then
  359. percent := (A.Objects[ItemIndex].Extract('completedLength').AsInt64 *
  360. 100) div total
  361. else
  362. percent := 0;
  363. download.Add(IntToStr(percent));
  364. download.Add(A.Objects[ItemIndex].Extract('connections').AsString); //threads
  365. //speed
  366. speed := A.Objects[ItemIndex].Extract('downloadSpeed').AsInteger;
  367. if speed > 0 then
  368. download.Add(IntToStr(speed div 1024) + ' KB/s')
  369. else
  370. download.Add('0 KB/s');
  371. if need_update_all then
  372. download_update(download)
  373. else
  374. need_update_all := download_update(download);
  375. end;
  376. end;
  377. end;
  378. O.Free;
  379. download.Free;
  380. if need_update_all then
  381. UpdateAll;
  382. end;
  383. procedure TForm1.action_newdownloadExecute(Sender: TObject);
  384. begin
  385. with formAdd do
  386. begin
  387. ShowModal;
  388. end;
  389. end;
  390. procedure TForm1.action_pauseselectedExecute(Sender: TObject);
  391. var
  392. gid_array_len, ItemIndex: integer;
  393. json_array: TJSONArray;
  394. JSONQueryObject: TJSONObject;
  395. begin
  396. //search selected
  397. json_array := TJSONArray.Create;
  398. json_array.Clear;
  399. for ItemIndex := 0 to ListView1.Items.Count - 1 do
  400. begin
  401. gid_array_len := 0;
  402. if ListView1.Items.Item[ItemIndex].Checked then
  403. begin
  404. //showmessage(IntToStr(ItemIndex));
  405. Inc(gid_array_len);
  406. json_array.Insert(gid_array_len - 1,
  407. TJSONObject.Create(['methodName', 'aria2.pause', 'params',
  408. TJSONArray.Create([ListView1.Items.Item[ItemIndex].Caption])])
  409. );
  410. end;
  411. end;
  412. JSONQueryObject := TJSONObject.Create(['jsonrpc', '2.0', 'id',
  413. 'qwer', 'method', 'system.multicall', 'params', TJSONArray.Create([json_array])]);
  414. JSONQuery(JSONQueryObject);
  415. UpdateAll;
  416. end;
  417. procedure TForm1.action_quitExecute(Sender: TObject);
  418. begin
  419. Close;
  420. end;
  421. procedure TForm1.action_serversExecute(Sender: TObject);
  422. begin
  423. formServers.ShowModal;
  424. ComboBox1.Items := unitservers.formServers.ListBox1.Items;
  425. ComboBox1.ItemIndex := 0;
  426. end;
  427. procedure TForm1.action_settingsExecute(Sender: TObject);
  428. begin
  429. formSettings.ShowModal;
  430. end;
  431. procedure TForm1.action_startselectedExecute(Sender: TObject);
  432. var
  433. gid_array_len, ItemIndex: integer;
  434. json_array: TJSONArray;
  435. JSONQueryObject: TJSONObject;
  436. begin
  437. //search selected
  438. json_array := TJSONArray.Create;
  439. json_array.Clear;
  440. for ItemIndex := 0 to ListView1.Items.Count - 1 do
  441. begin
  442. gid_array_len := 0;
  443. if ListView1.Items.Item[ItemIndex].Checked then
  444. begin
  445. //showmessage(IntToStr(ItemIndex));
  446. Inc(gid_array_len);
  447. json_array.Insert(gid_array_len - 1,
  448. TJSONObject.Create(['methodName', 'aria2.unpause', 'params',
  449. TJSONArray.Create([ListView1.Items.Item[ItemIndex].Caption])])
  450. );
  451. end;
  452. end;
  453. JSONQueryObject := TJSONObject.Create(['jsonrpc', '2.0', 'id',
  454. 'qwer', 'method', 'system.multicall', 'params', TJSONArray.Create([json_array])]);
  455. JSONQuery(JSONQueryObject);
  456. UpdateAll;
  457. end;
  458. procedure TForm1.ComboBox1Change(Sender: TObject);
  459. begin
  460. UpdateListTimer.Enabled := False;
  461. UpdateAll;
  462. UpdateListTimer.Enabled := True;
  463. end;
  464. procedure TForm1.FormClose(Sender: TObject; var CloseAction: TCloseAction);
  465. begin
  466. formServers.ListBox1.Items.SaveToFile('.aria2g.list');
  467. end;
  468. procedure TForm1.action_deleteselectedExecute(Sender: TObject);
  469. var
  470. gid_array_len, ItemIndex: integer;
  471. json_array: TJSONArray;
  472. JSONQueryObject: TJSONObject;
  473. begin
  474. //search selected
  475. json_array := TJSONArray.Create;
  476. json_array.Clear;
  477. for ItemIndex := 0 to ListView1.Items.Count - 1 do
  478. begin
  479. gid_array_len := 0;
  480. if ListView1.Items.Item[ItemIndex].Checked then
  481. begin
  482. //showmessage(IntToStr(ItemIndex));
  483. Inc(gid_array_len);
  484. json_array.Insert(gid_array_len - 1,
  485. TJSONObject.Create(['methodName', 'aria2.remove', 'params',
  486. TJSONArray.Create([ListView1.Items.Item[ItemIndex].Caption])])
  487. );
  488. end;
  489. end;
  490. JSONQueryObject := TJSONObject.Create(['jsonrpc', '2.0', 'id',
  491. 'qwer', 'method', 'system.multicall', 'params', TJSONArray.Create([json_array])]);
  492. JSONQuery(JSONQueryObject);
  493. UpdateAll;
  494. end;
  495. procedure TForm1.action_aboutExecute(Sender: TObject);
  496. begin
  497. form_about.ShowModal;
  498. end;
  499. procedure TForm1.action_update_server_listExecute(Sender: TObject);
  500. begin
  501. ComboBox1.Items := unitservers.formServers.ListBox1.Items;
  502. ComboBox1.ItemIndex := 0;
  503. UpdateAll;
  504. end;
  505. procedure TForm1.action_check_upgradeExecute(Sender: TObject);
  506. var
  507. update_page: TStringList;
  508. HTTP: THTTPSend;
  509. begin
  510. //http://aria.blindage.org/builds/last_versions.txt
  511. Memo1.Lines.Add('Checking for new version');
  512. HTTP := THTTPSend.Create;
  513. update_page := TStringList.Create;
  514. try
  515. HTTP.HTTPMethod('GET', 'http://aria.blindage.org/builds/last_versions.txt');
  516. update_page.LoadFromStream(HTTP.Document);
  517. ShowMessage('Installed: ' + about.form_about.Label5.Caption +
  518. #13 + #13 + 'Downloadable:' + #13 + update_page.Text)
  519. finally
  520. HTTP.Free;
  521. update_page.Free;
  522. end;
  523. end;
  524. procedure TForm1.FormCreate(Sender: TObject);
  525. begin
  526. Form1.ListView1.SortColumn := 1;
  527. end;
  528. procedure TForm1.FormShow(Sender: TObject);
  529. var
  530. BuildNum, ver: string;
  531. Info: TVersionInfo;
  532. ini: TIniFile;
  533. new_in_version: TStringList;
  534. begin
  535. ini := TIniFile.Create('.aria2g.ini');
  536. //TrayIcon1.Visible := ini.ReadBool('APP', 'TRAY_ICON', True);
  537. //close_to_tray := ini.ReadBool('APP', 'CLOSE_TO_TRAY_ICON', True);
  538. UpdateListTimer.Interval := ini.ReadInteger('APP', 'LIST_UPDATE_DELAY_MS', 2000);
  539. formSettings.Edit3.Text := IntToStr(ini.ReadInteger('APP',
  540. 'LIST_UPDATE_DELAY_MS', 2000));
  541. formSettings.Edit2.Text := IntToStr(ini.ReadInteger('APP', 'THREADS_DEFAULT', 5));
  542. formAdd.edit_threads.Text := IntToStr(ini.ReadInteger('APP', 'THREADS_DEFAULT', 5));
  543. //minimized := False;
  544. if close_to_tray then
  545. begin
  546. //Form1.OnClose := TrayIcon1Click(self);
  547. //TrayIcon1.OnClick:=@TrayeIcon1Click;
  548. //Form1.OnHide := @FormHide;
  549. end;
  550. ini.Free;
  551. if FileExists('.aria2g.list') = True then
  552. begin
  553. formServers.ListBox1.Items.LoadFromFile('.aria2g.list');
  554. ListView2.Items.Add;
  555. end;
  556. ComboBox1.Items := formServers.ListBox1.Items;
  557. ComboBox1.ItemIndex := 0;
  558. UpdateAll;
  559. UpdateListTimer.Enabled := True;
  560. Info := TVersionInfo.Create;
  561. Info.Load(HINSTANCE);
  562. // grab just the Build Number
  563. ver := IntToStr(Info.FixedInfo.FileVersion[0]) + '.' +
  564. IntToStr(Info.FixedInfo.FileVersion[1]) + '.' +
  565. IntToStr(Info.FixedInfo.FileVersion[2]) + '.' +
  566. IntToStr(Info.FixedInfo.FileVersion[3]);
  567. Info.Free;
  568. about.form_about.Label5.Caption := ver;
  569. new_in_version := TStringList.Create;
  570. new_in_version.LoadFromFile('last_changes.txt');
  571. Memo1.Lines.Add('New in this version:');
  572. Memo1.Lines.AddStrings(new_in_version);
  573. end;
  574. procedure TForm1.ListBox1Click(Sender: TObject);
  575. begin
  576. end;
  577. procedure TForm1.ListView1DblClick(Sender: TObject);
  578. begin
  579. if ListView1.SelCount > 0 then
  580. begin
  581. UpdateListTimer.Enabled := False;
  582. formInfo.memoInfo.Lines.Clear;
  583. formInfo.memoInfo.Lines.Add('GID: ' + ListView1.Selected.Caption);
  584. formInfo.memoInfo.Lines.Add('URL: ' + ListView1.Selected.SubItems.Strings[1]);
  585. formInfo.memoInfo.Lines.Add('Target: ' + ListView1.Selected.SubItems.Strings[2]);
  586. formInfo.memoInfo.Lines.Add('State: ' + ListView1.Selected.SubItems.Strings[0]);
  587. formInfo.memoInfo.Lines.Add('Threads: ' + ListView1.Selected.SubItems.Strings[4]);
  588. formInfo.memoInfo.Lines.Add('Progress: ' +
  589. ListView1.Selected.SubItems.Strings[3] + '%');
  590. formInfo.ProgressBar1.Position := StrToInt(ListView1.Selected.SubItems.Strings[3]);
  591. formInfo.memoFiles.Clear;
  592. formInfo.memoFiles.Lines.Add('Files:');
  593. formInfo.ShowModal;
  594. UpdateListTimer.Enabled := True;
  595. end;
  596. end;
  597. procedure TForm1.FormHide(Sender: TObject);
  598. begin
  599. end;
  600. procedure TForm1.Minimize(Sender: TObject);
  601. begin
  602. if close_to_tray then
  603. begin
  604. //TrayIcon1Click(self);
  605. end;
  606. end;
  607. procedure TForm1.ValueListEditor1Click(Sender: TObject);
  608. begin
  609. end;
  610. procedure TForm1.TrayIcon1Click(Sender: TObject);
  611. begin
  612. if Form1.Visible = False then
  613. begin
  614. Visible := True;
  615. end
  616. else
  617. begin
  618. Visible := False;
  619. end;
  620. end;
  621. end.