pkgwget.pp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. {$mode objfpc}
  2. {$h+}
  3. unit pkgwget;
  4. interface
  5. uses Classes,pkgdownload,pkgoptions,fprepos;
  6. Type
  7. TWGetDownloader = Class(TBaseDownloader)
  8. Private
  9. FWGet : String;
  10. Protected
  11. Constructor Create(AOwner: TComponent); override;
  12. Procedure WGetDownload(Const URL : String; Dest : TStream); virtual;
  13. Procedure FTPDownload(Const URL : String; Dest : TStream); override;
  14. Procedure HTTPDownload(Const URL : String; Dest : TStream); override;
  15. Public
  16. Property WGet : String Read FWGet Write FWGet;
  17. end;
  18. implementation
  19. uses
  20. sysutils,process,
  21. pkgglobals,
  22. pkgmessages;
  23. Constructor TWGetDownloader.Create(AOwner: TComponent);
  24. begin
  25. Inherited;
  26. wget:='wget';
  27. end;
  28. Procedure TWGetDownloader.WGetDownload(Const URL : String; Dest : TStream);
  29. Var
  30. Buffer : Array[0..4096] of byte;
  31. Count : Integer;
  32. begin
  33. With TProcess.Create(Self) do
  34. try
  35. CommandLine:=WGet+' -q --output-document=- '+url;
  36. Options:=[poUsePipes,poNoConsole];
  37. Execute;
  38. While Running do
  39. begin
  40. Count:=Output.Read(Buffer,SizeOf(Buffer));
  41. If (Count>0) then
  42. Dest.WriteBuffer(Buffer,Count);
  43. end;
  44. If (ExitStatus<>0) then
  45. Error(SErrDownloadFailed,['WGET',URL,Format('exit status %d',[ExitStatus])]);
  46. finally
  47. Free;
  48. end;
  49. end;
  50. Procedure TWGetDownloader.FTPDownload(Const URL : String; Dest : TStream);
  51. begin
  52. WGetDownload(URL,Dest);
  53. end;
  54. Procedure TWGetDownloader.HTTPDownload(Const URL : String; Dest : TStream);
  55. begin
  56. WGetDownload(URL,Dest);
  57. end;
  58. initialization
  59. RegisterDownloader('wget',TWGetDownloader);
  60. end.