unit UUpdater;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls, IdHTTP, IdBaseComponent, IdComponent, IdTCPConnection, IdTCPClient,
xpman, Gauges, ComCtrls, UDownThread,
zlib;
type
TForm1 =
class(TForm)
msg: TMemo;
startdownload: TButton;
exit: TButton;
Progress: TProgressBar;
SpeedLabel: TLabel;
Status: TLabel;
procedure startdownloadClick(Sender: TObject);
private
{ Private declarations }
StartTime: Cardinal;
procedure download(wwwurl:
string);
procedure OnThreadWork(Sender: TThread; AWorkCount: Integer);
procedure OnThreadWorkBegin(Sender: TThread; AWorkCountMax: Integer);
procedure DownResultHandle(Sender: TObject; ResponseCode: Integer);
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure TForm1.OnThreadWork(Sender: TThread; AWorkCount: Integer);
var
speed: single;
begin
Progress.Position := AWorkCount;
speed := AWorkCount/(GetTickCount - StartTime + 1);
//+1 um DivbyZero zu verhindern
Status.caption := Format('
%f s|%.2f KB/s', [(((Sender
as TDownThread).WorkCountMax-AWorkCount)/1000)/speed, speed]);
end;
procedure TForm1.OnThreadWorkBegin(Sender: TThread; AWorkCountMax: Integer);
begin
Progress.Max := AWorkCountMax;
msg.Lines.Append(FormatFloat('
Dateigröße: 0, Bytes', AWorkCountMax));
StartTime := GetTickCount;
end;
procedure TForm1.download(wwwurl:
string);
var
path:
string;
Down: TDownThread;
begin
path := ExtractFilePath(paramstr(0)) + '
Update\file.zip';
Status.Caption := '
';
Progress.Position := 0;
msg.Lines.Append('
Downloade Datei ' + path);
Down := TDownThread.Create(true);
with Down
do
begin
FreeOnTerminate := true;
OnWork := OnThreadWork;
OnWorkBegin := OnThreadWorkBegin;
OnFinish := DownResultHandle;
URL := wwwurl;
FileName := path;
Resume;
end;
end;
procedure TForm1.startdownloadClick(Sender: TObject);
begin
msg.Lines.Append('
--------------------------');
msg.Lines.Append('
Starte Download ...');
download(link);
end;
procedure TForm1.DownResultHandle(Sender: TObject; ResponseCode: Integer);
begin
msg.Lines.Append('
Download abgeschlossen');
SpeedLabel.Caption := '
Fertig';
showmessage(IntToStr(ResponseCode));
end;
end.