![]() |
![]() ![]() ![]() |
acAutoUpgrader, acHTTP and acSendMail components.
|
type
|
TacAUProgressEvent = procedure(Sender: TObject;
|
const FileURL: String; FileSize, BytesRead, ElapsedTime,
|
EstimatedTimeLeft: Integer;
|
PercentsDone, TotalPercentsDone: Byte;
|
TransferRate: Single) of object;
|
|
property OnProgress: TacAUProgressEvent;
|
The OnProgress event occurs every time when component has successfully downloaded part of some file which should be updated.
|
|
Write the OnProgress event handler to show the download progress and implement your own, custom progess box instead of standard Application update wizard (then set Enabled property of Wizard structure to False), or use it as an addition to standard wizard.
|
|
There are following parameters which passes to the event handler:
|
Parameter | Meaning
|
FileURL | location of the file which currently downloading. (This file is one of that that listed in remote Info-file, from which we have gotten an upgrade information.);
|
FileSize | total size of file which we currently downloading, in bytes (if possible to determinate).
|
Note: usually server does not provide information about content-length for non-binary data (i.e: for "text/html" or "text/plain" MIME-types);
|
BytesRead | size of already received data, in bytes;
|
ElapsedTime | time elapsed from beginning of download (in seconds);
|
EstimatedTimeLeft | estimated time left before finishing of download. (Formula:
|
X := FileSize / BytesRead * ElapsedTime - ElapsedTime)
|
PercentsDone | progress for current file in percents (0%..100%);
|
TotalPercentsDone | progress for whole download queue in percents (0%..100%);
|
TransferRate | speed of data transfer (in Kb/s).
|
|
![]() |
procedure TForm1.acAutoUpgrader1Progress(Sender: TObject;
|
FileURL: string; FileSize, BytesRead, ElapsedTime,
|
EstimatedTimeLeft: Integer; PercentsDone,
|
TotalPercentsDone: Byte; TransferRate: Single);
|
begin
|
// two progress bars
|
ProgressCurrentFile.Position := PercentsDone;
|
ProgressAllFiles.Position := TotalPercentsDone;
|
|
// file size label (in Kb)
|
FileSizeLabel.Caption :=
|
Format('File size: %.1f Kb', [FileSize / 1024]);
|
|
// downloaded size label (in Kb)
|
DownloadedLabel.Caption :=
|
Format('Downloaded: %.1f Kb', [BytesRead / 1024]);
|
|
// transfer rate label (in Kb per second)
|
TransRateLabel.Caption :=
|
Format('Transfer rate: %.1f Kb/s', [TransferRate]);
|
|
// estimated time left label
|
EstTimeLabel.Caption :=
|
Format('Estimated time left: %d:%.2d:%.2d',
|
[EstimatedTimeLeft div 60 div 60, // hours
|
EstimatedTimeLeft div 60 mod 60, // minutes
|
EstimatedTimeLeft mod 60 mod 60]); // seconds
|
end;
|
void __fastcall TForm1::acAutoUpgrader1Progress(TObject *Sender,
|
AnsiString FileURL, int FileSize, int BytesRead,
|
int ElapsedTime, int EstimatedTimeLeft,
|
BYTE PercentsDone, BYTE TotalPercentsDone,
|
float TransferRate)
|
{
|
// two progress bars
|
ProgressCurrentFile->Position = PercentsDone;
|
ProgressAllFiles->Position = TotalPercentsDone;
|
|
// file size label (in Kb)
|
FileSizeLabel->Caption = Format("File size: %.1f Kb", ARRAYOFCONST(((float)FileSize / 1024)));
|
|
// downloaded size label (in Kb)
|
DownloadedLabel->Caption = Format("Downloaded: %.1f Kb", ARRAYOFCONST(((float)BytesRead / 1024)));
|
|
// transfer rate label (in Kb per second)
|
TransRateLabel->Caption = Format("Transfer rate: %.1f Kb/s", ARRAYOFCONST(((float)TransferRate)));
|
|
// estimated time left label
|
EstTimeLabel->Caption =
|
Format("Estimated time left: %d:%.2d:%.2d",
|
ARRAYOFCONST((EstimatedTimeLeft / 60 / 60, // hours
|
EstimatedTimeLeft / 60 % 60, // minutes
|
EstimatedTimeLeft % 60 % 60)));// seconds
|
}
|
Wizard structure; Info-file example;
|
OnBeginUpgrade, OnEndUpgrade and OnFileDone events.
|