2014-09-09 14:46:12 +02:00
|
|
|
unit uWebCtrls;
|
|
|
|
|
|
|
|
//////////////////////////////////////
|
|
|
|
/// Lina Web Controls Unit ///
|
|
|
|
/// **************************** ///
|
|
|
|
/// (c) 2014 Dennis G�hlert a.o. ///
|
|
|
|
//////////////////////////////////////
|
|
|
|
|
|
|
|
interface
|
|
|
|
|
|
|
|
uses
|
|
|
|
{ Standard-Units }
|
|
|
|
SysUtils, Classes,
|
2014-09-10 01:53:24 +02:00
|
|
|
{ Indy-Units }
|
|
|
|
idHTTP, idSSLOpenSSL, idComponent,
|
2014-09-09 14:46:12 +02:00
|
|
|
{ Andere Package-Units }
|
|
|
|
uBase;
|
|
|
|
|
2014-09-10 01:53:24 +02:00
|
|
|
type
|
|
|
|
{ Ereignisse }
|
|
|
|
TDownloadWorkEvent = procedure(Sender: TObject; AWorkMode: TWorkMode) of object;
|
|
|
|
TDownloadWorkBeginEvent = procedure(Sender: TObject; AWorkMode: TWorkMode) of object;
|
|
|
|
TDownloadWorkEndEvent = procedure(Sender: TObject; AWorkMode: TWorkMode) of object;
|
|
|
|
|
2014-09-09 14:46:12 +02:00
|
|
|
type
|
|
|
|
{ Hauptklassen }
|
|
|
|
TDownload = class(TComponent)
|
|
|
|
private
|
|
|
|
{ Private-Deklarationen }
|
2014-09-10 01:53:24 +02:00
|
|
|
idHTTPObject: TidHTTP;
|
|
|
|
SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
|
|
|
|
FAbout: TComponentAbout;
|
|
|
|
FAddress: String;
|
|
|
|
FProgress: Int64;
|
|
|
|
FProgressMax: Int64;
|
|
|
|
FSSL: Boolean;
|
|
|
|
{ Ereignisse }
|
|
|
|
FWorkEvent: TDownloadWorkEvent;
|
|
|
|
FWorkBeginEvent: TDownloadWorkBeginEvent;
|
|
|
|
FWorkEndEvent: TDownloadWorkEndEvent;
|
|
|
|
{ Methoden }
|
|
|
|
procedure idHTTPObjectWork(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Int64);
|
|
|
|
procedure idHTTPObjectWorkBegin(ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Int64);
|
|
|
|
procedure idHTTPObjectWorkEnd(ASender: TObject; AWorkMode: TWorkMode);
|
|
|
|
protected
|
|
|
|
{ Protected-Deklarationen }
|
|
|
|
procedure Prepare;
|
2014-09-09 14:46:12 +02:00
|
|
|
public
|
|
|
|
{ Public-Deklarationen }
|
|
|
|
constructor Create(AOwner: TComponent); override;
|
|
|
|
destructor Destroy; override;
|
2014-09-10 01:53:24 +02:00
|
|
|
{ Fortschritt }
|
|
|
|
function GetProgress: Int64;
|
|
|
|
function GetProgressMax: Int64;
|
2014-09-09 14:46:12 +02:00
|
|
|
function GetProgressPercent: Byte;
|
2014-09-10 01:53:24 +02:00
|
|
|
{ Herunterladen }
|
|
|
|
function GetText: String;
|
|
|
|
procedure SaveToFile(FileName: TFileName);
|
|
|
|
procedure SaveToStream(Stream: TStream);
|
2014-09-09 14:46:12 +02:00
|
|
|
published
|
|
|
|
{ Published-Deklarationen }
|
2014-09-10 01:53:24 +02:00
|
|
|
{ Ereignisse }
|
|
|
|
property OnWork: TDownloadWorkEvent read FWorkEvent write FWorkEvent;
|
|
|
|
property OnWorkBegin: TDownloadWorkBeginEvent read FWorkBeginEvent write FWorkBeginEvent;
|
|
|
|
property OnWorkEnd: TDownloadWorkEndEvent read FWorkEndEvent write FWorkEndEvent;
|
|
|
|
{ Eigenschaften }
|
|
|
|
property About: TComponentAbout read FAbout;
|
|
|
|
property Address: String read FAddress write FAddress;
|
|
|
|
property SSL: Boolean read FSSL write FSSL default False;
|
2014-09-09 14:46:12 +02:00
|
|
|
end;
|
|
|
|
|
2014-09-10 01:53:24 +02:00
|
|
|
procedure Register;
|
|
|
|
|
|
|
|
const
|
|
|
|
{ Meta-Daten }
|
|
|
|
DownloadComponent_Name = 'Download';
|
|
|
|
DownloadComponent_Version = 1.0;
|
|
|
|
DownloadComponent_Copyright = 'Copyright � 2014';
|
|
|
|
DownloadComponent_Author = 'Dennis G�hlert a.o.';
|
|
|
|
|
2014-09-09 14:46:12 +02:00
|
|
|
implementation
|
|
|
|
|
2014-09-10 01:53:24 +02:00
|
|
|
procedure Register;
|
|
|
|
begin
|
|
|
|
RegisterComponents(ComponentsPage,[TDownload]);
|
|
|
|
end;
|
|
|
|
|
2014-09-09 14:46:12 +02:00
|
|
|
constructor TDownload.Create(AOwner: TComponent);
|
|
|
|
begin
|
|
|
|
inherited;
|
2014-09-10 01:53:24 +02:00
|
|
|
FAbout := TComponentAbout.Create(DownloadComponent_Name,DownloadComponent_Version,DownloadComponent_Copyright,DownloadComponent_Author);
|
|
|
|
idHTTPObject := TidHTTP.Create(Self);
|
|
|
|
idHTTPObject.HandleRedirects := True;
|
|
|
|
idHTTPObject.OnWork := idHTTPObjectWork;
|
|
|
|
idHTTPObject.OnWorkBegin := idHTTPObjectWorkBegin;
|
|
|
|
idHTTPObject.OnWorkEnd := idHTTPObjectWorkEnd;
|
|
|
|
SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create(Self);
|
|
|
|
SSL := False;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TDownload.idHTTPObjectWork(ASender: TObject; AWorkMode: TWorkMode; AWorkCount: Int64);
|
|
|
|
begin
|
|
|
|
FProgress := AWorkCount;
|
|
|
|
if Assigned(OnWork) then
|
|
|
|
begin
|
|
|
|
OnWork(Self,AWorkMode);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TDownload.idHTTPObjectWorkBegin(ASender: TObject; AWorkMode: TWorkMode; AWorkCountMax: Int64);
|
|
|
|
begin
|
|
|
|
FProgressMax := AWorkCountMax;
|
|
|
|
if Assigned(OnWorkBegin) then
|
|
|
|
begin
|
|
|
|
OnWorkBegin(Self,AWorkMode);
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TDownload.idHTTPObjectWorkEnd(ASender: TObject; AWorkMode: TWorkMode);
|
|
|
|
begin
|
|
|
|
if Assigned(OnWorkEnd) then
|
|
|
|
begin
|
|
|
|
OnWorkEnd(Self,AWorkMode);
|
|
|
|
end;
|
2014-09-09 14:46:12 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
destructor TDownload.Destroy;
|
|
|
|
begin
|
2014-09-10 01:53:24 +02:00
|
|
|
FAbout.Free;
|
2014-09-09 14:46:12 +02:00
|
|
|
inherited;
|
|
|
|
end;
|
|
|
|
|
2014-09-10 01:53:24 +02:00
|
|
|
function TDownload.GetProgress: Int64;
|
2014-09-09 14:46:12 +02:00
|
|
|
begin
|
2014-09-10 01:53:24 +02:00
|
|
|
Result := FProgress;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TDownload.GetProgressMax: Int64;
|
|
|
|
begin
|
|
|
|
Result := FProgressMax;
|
2014-09-09 14:46:12 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
function TDownload.GetProgressPercent: Byte;
|
|
|
|
begin
|
2014-09-10 01:53:24 +02:00
|
|
|
if FProgressMax > 0 then
|
|
|
|
begin
|
|
|
|
Result := (FProgress div FProgressMax) * 100;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
{ Bei aktivierter SSL-Verschl�sselung wird keine insgesamte Dateigr��e
|
|
|
|
�bermittelt. Deshalb wird hier eine 0 angegeben, um das Ergebnis nicht
|
|
|
|
undefiniert zu lassen. }
|
|
|
|
Result := 0;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
function TDownload.GetText: String;
|
|
|
|
begin
|
|
|
|
Prepare;
|
|
|
|
Result := idHTTPObject.Get(Address);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TDownload.SaveToFile(FileName: TFileName);
|
|
|
|
var
|
|
|
|
FS: TFileStream;
|
|
|
|
begin
|
|
|
|
Prepare;
|
|
|
|
FS := TFileStream.Create(FileName, fmCreate or fmShareDenyWrite);
|
|
|
|
try
|
|
|
|
idHTTPObject.Get(Address,FS);
|
|
|
|
finally
|
|
|
|
FS.Free;
|
|
|
|
end;
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TDownload.SaveToStream(Stream: TStream);
|
|
|
|
begin
|
|
|
|
Prepare;
|
|
|
|
idHTTPObject.Get(Address,Stream);
|
|
|
|
end;
|
|
|
|
|
|
|
|
procedure TDownload.Prepare;
|
|
|
|
begin
|
|
|
|
if SSL = True then
|
|
|
|
begin
|
|
|
|
idHTTPObject.IOHandler := SSLHandler;
|
|
|
|
end else
|
|
|
|
begin
|
|
|
|
idHTTPObject := nil;
|
|
|
|
end;
|
2014-09-09 14:46:12 +02:00
|
|
|
end;
|
|
|
|
|
|
|
|
end.
|