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: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92:
| 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 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 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); 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. |