// Der Container
type
TAfterUpdateCheck =
procedure(Sender: TObject)
of Object;
TFileComplete =
procedure(Sender: TObject)
of Object;
TOnWorkEvent =
procedure(Sender: TObject; AWorkCount: Integer)
of object;
TContainer=class(TSimpleRWSync)
//[...]
private
FOnWorkEvent: TOnWorkEvent;
procedure InternalOnWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
procedure DoNotifyWork;
public
property OnWork: TOnWorkEvent
read FOnWorkEvent
write FOnWorkEvent;
// Der Thread
type
TDownloadThread =
class(TThread)
public
FParent: TContainer;
SeekUpdates: Boolean;
Download: Boolean;
DownloadDest:
String;
DownloadPath:
String;
DownloadFile:
String;
private
procedure WorkProgress(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
protected
procedure Execute;
override;
end;
procedure TDownloadThread.Execute;
var
www: TIdHTTP;
fs: TFileStream;
ini: TMemInifile;
i, size, imp: Integer;
Title, Filename, Version, Desc, Path:
String;
PlugIn: Boolean;
tmpUpdates, Updates: TStrings;
begin
www:=TIdHTTP.Create(
nil);
try
//[...]
if (Download)
then
begin
www:=TIdHttp.Create(
nil);
[
url]www.OnWork:=FParent.InternalOnWork;[/
url]
fs:=TFileStream.Create(DownloadDest+DownloadFile, fmCreate);
try
www.Get(DownloadPath+'
/'+DownloadFile, fs);
finally
[
url]www.Free;[/
url]
end;
if Assigned(FParent.fOnFileComplete)
then Synchronize(FParent.DoFileComplete);
end;
finally
fs.Free;
ini.Free;
Updates.Free;
end;
end;
//===== Container =======
procedure TContainer.InternalOnWork(Sender: TObject; AWorkMode: TWorkMode;
const AWorkCount: Integer);
begin
FWorkCount := AWorkCount;
TDownloadThread.Synchronize(
nil, DoNotifyWork);
end;
procedure TContainer.DoNotifyWork;
begin
Assert(Assigned(FOnFileComplete));
OnWork(Self, FWorkCount);
end;
procedure TContainer.SeekUpdates;
var
Dt: TDownloadThread;
begin
Dt:=TDownloadThread.Create(True);
Dt.FreeOnTerminate:=True;
Dt.FParent:=Self;
Dt.SeekUpdates:=True;
Dt.Download:=False;
Dt.Resume;
end;