summaryrefslogtreecommitdiff
path: root/fpcsrc/packages/fppkg/src/pkgwget.pp
blob: 163348b6d41ef6ab75b96491a4b249a40bd86a9f (plain)
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
{$mode objfpc}
{$h+}
unit pkgwget;

interface

uses Classes,pkgdownload,pkgoptions,fprepos;

Type
  TWGetDownloader = Class(TBaseDownloader)
  Private
    FWGet : String;
  Protected
    Constructor Create(AOwner: TComponent); override;
    Procedure WGetDownload(Const URL : String; Dest : TStream); virtual;
    Procedure FTPDownload(Const URL : String; Dest : TStream); override;
    Procedure HTTPDownload(Const URL : String; Dest : TStream); override;
 Public
    Property WGet : String Read FWGet Write FWGet;
 end;

implementation

uses
  sysutils,process,
  pkgglobals,
  pkgmessages;

Constructor TWGetDownloader.Create(AOwner: TComponent);

begin
  Inherited;
  wget:='wget';
end;


Procedure TWGetDownloader.WGetDownload(Const URL : String; Dest : TStream);

Var
  Buffer : Array[0..4096] of byte;
  Count : Integer;

begin
  With TProcess.Create(Self) do
    try
      CommandLine:=WGet+' -q --output-document=- '+url;
      Options:=[poUsePipes,poNoConsole];
      Execute;
      While Running do
        begin
        Count:=Output.Read(Buffer,SizeOf(Buffer));
        If (Count>0) then
          Dest.WriteBuffer(Buffer,Count);
        end;
      If (ExitStatus<>0) then
        Error(SErrDownloadFailed,['WGET',URL,Format('exit status %d',[ExitStatus])]);
    finally
      Free;
    end;
end;

Procedure TWGetDownloader.FTPDownload(Const URL : String; Dest : TStream);

begin
  WGetDownload(URL,Dest);
end;

Procedure TWGetDownloader.HTTPDownload(Const URL : String; Dest : TStream);

begin
  WGetDownload(URL,Dest);
end;

initialization
  RegisterDownloader('wget',TWGetDownloader);
end.