pkgwget.pp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. {$mode objfpc}
  2. {$h+}
  3. unit pkgwget;
  4. interface
  5. uses Classes,pkgdownload,pkgropts,fprepos;
  6. Type
  7. TWGetDownloader = Class(TBasePackageDownloader)
  8. Private
  9. FWGet : String;
  10. Protected
  11. Constructor Create(AOwner: TComponent; ADefaults:TPackagerOptions; APackage: TFPPackage); 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 process,pkghandler,pkgmessages;
  20. Constructor TWGetDownloader.Create(AOwner: TComponent; ADefaults:TPackagerOptions; APackage: TFPPackage);
  21. begin
  22. Inherited;
  23. wget:='wget';
  24. end;
  25. Procedure TWGetDownloader.WGetDownload(Const URL : String; Dest : TStream);
  26. Var
  27. Buffer : Array[0..4096] of byte;
  28. Count : Integer;
  29. begin
  30. With TProcess.Create(Self) do
  31. try
  32. CommandLine:=WGet+' -q --output-document=- '+url;
  33. Options:=[poUsePipes,poNoConsole];
  34. Execute;
  35. While Running do
  36. begin
  37. Count:=Output.Read(Buffer,SizeOf(Buffer));
  38. If (Count>0) then
  39. Dest.WriteBuffer(Buffer,Count);
  40. end;
  41. If (ExitStatus<>0) then
  42. Error(SErrWGetDownloadFailed,[ExitStatus]);
  43. finally
  44. Free;
  45. end;
  46. end;
  47. Procedure TWGetDownloader.FTPDownload(Const URL : String; Dest : TStream);
  48. begin
  49. WGetDownload(URL,Dest);
  50. end;
  51. Procedure TWGetDownloader.HTTPDownload(Const URL : String; Dest : TStream);
  52. begin
  53. WGetDownload(URL,Dest);
  54. end;
  55. initialization
  56. DownloaderClass:=TWGetDownloader;
  57. end.