Internet - componentes Indy, Idftp calculando tempo restante e previsto para download |
Top Previous Next |
|
// fazendo calculos de quanto falta (tempo) e tempo previsto para // downloads usando Indy
procedure TMarketClient.IdFTP1Disconnected(Sender: TObject); begin Caption := 'Desconectado'; Application.Title := Caption; end;
procedure TMarketClient.IdFTP1Status(axSender: TObject; const axStatus: TIdStatus; const asStatusText: String); begin DebugLista.ItemIndex := DebugLista.Items.Add(asStatusText); Caption := asStatusText; end;
procedure TMarketClient.IdFTP1Work(Sender: TObject; AWorkMode: TWorkMode; const AWorkCount: Integer); var S : string; TotalTime : TDateTime; H, M, Sec, MS : Word; DLTime, SegFaltam: Double; Segundos : Integer; begin TotalTime := Now - STime; // tempo decorrido até agora
// descobre a velocidade média DecodeTime(TotalTime, H, M, Sec, MS); Sec := Sec + M * 60 + H * 3600; DLTime := Sec + MS / 1000; if DLTime > 0 then VelMedia := (AWorkCount / 1024) / DLTime;
S := FormatFloat('0.00 KB/s', VelMedia); Caption := IntToStr(Gauge.PercentDone) + '% [' + ArquivoRemoto + '] - ' + S; Application.Title := Caption;
// Total que já veio, em bytes BytesLabel.Caption := FormatFloat('#,### de ',AWorkCount) + FormatFloat('#,###',Gauge.MaxValue);
// Nº de segundos que está copiando o arquivo atual. (transforma EM SEGUNDOS) Segundos := StrToIntDef(FormatDateTime('HH',TotalTime),0) * 3600 + StrToIntDef(FormatDateTime('NN',TotalTime),0) * 60 + StrToIntDef(FormatDateTime('SS',TotalTime),0); if Segundos < 1 then Segundos := 1; // Pra não dar divisao por zero
// Média de KBits por segundo // PacoteLabel.Caption:= FormatFloat('#,###', (AWorkCount - OldAWorkCount) * 8) + ' /'; // *8 para mostrar em bits MediaLabel.Caption := FormatFloat('#,###', (AWorkCount / Segundos) * 8 );
// Calcula o tempo previsto e tempo restante (AWorkCount é quantos bytes já vieram) try SegFaltam := 0; if Segundos > 0 then if (AWorkCount / Segundos) > 0 then SegFaltam := (Gauge.MaxValue - AWorkCount) / (AWorkCount / Segundos); except SegFaltam := 0; end; // Tempo Previsto (Decorrido + Restante) / Tempo Restante PrevistoLabel.Caption := TimeToStr( (SegFaltam / 3600 / 24) + TotalTime ); RestanteLabel.Caption := TimeToStr(SegFaltam / 3600 / 24); DecorridoLabel.Caption := TimeToStr(TotalTime);
if AbortaTransf then IdFTP1.Abort;
OldAWorkCount := AWorkCount; Gauge.Progress := AWorkCount; // Atualiza gauge AbortaTransf := False; end;
procedure TMarketClient.IdFTP1WorkBegin(Sender: TObject; AWorkMode: TWorkMode; const AWorkCountMax: Integer); begin Transferindo := True; CancelarBtn.Visible := True; FecharBtn.Visible := False; AbortaTransf := False; STime := Now; if AWorkCountMax > 0 then Gauge.MaxValue := AWorkCountMax else Gauge.MaxValue := BytesToTransf;
VelMedia := 0; end;
procedure TMarketClient.IdFTP1WorkEnd(Sender: TObject; AWorkMode: TWorkMode); begin CancelarBtn.Visible := False; FecharBtn.Visible := True; Caption := 'Transferência completa'; BytesToTransf := 0; Transferindo := False; Gauge.Progress := 0; VelMedia := 0; end;
procedure TMarketClient.IdLogDebug1LogItem(ASender: TComponent; var AText: String); var S: string; begin S := StrTran(AText, '<EOL>', ''); S := StrTran(S, 'Sent: ', ''); S := StrTran(S, 'Recv: ', ''); DebugLista.ItemIndex := DebugLista.Items.Add(S); end;
|