Inno Setup-如何显示卸载程序中已完成的百分比,经过的时间和估计的时间进度? [英] Inno Setup - How to show percent done, elapsed time and estimated time progress at uninstaller?

查看:42
本文介绍了Inno Setup-如何显示卸载程序中已完成的百分比,经过的时间和估计的时间进度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用以下代码:

I am trying to use this code: How to show percent done, elapsed time and estimated time progress?

But I have problems, because i use this code to the installer too.

解决方案

Merging these two piece of code together:

[Code]

function SetTimer(hWnd: longword; nIDEvent, uElapse: LongWord;
  lpTimerFunc: LongWord): LongWord; external 'SetTimer@user32.dll stdcall';
function GetTickCount: DWORD;
  external 'GetTickCount@kernel32.dll stdcall';

var
  UninstallStartTick: DWORD;
  UninstallPercentLabel: TNewStaticText;
  UninstallElapsedLabel: TNewStaticText;
  UninstallRemainingLabel: TNewStaticText;

function TicksToStr(Value: DWORD): string;
var
  I: DWORD;
  Hours, Minutes, Seconds: Integer;
begin
  I := Value div 1000;
  Seconds := I mod 60;
  I := I div 60;
  Minutes := I mod 60;
  I := I div 60;
  Hours := I mod 24;
  Result := Format('%.2d:%.2d:%.2d', [Hours, Minutes, Seconds]);
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  if CurUninstallStep = usUninstall then
  begin
    UninstallStartTick := GetTickCount;
  end;
end;

procedure UninstallTimerProc(
  h: LongWord; AMsg: LongWord; IdEvent: LongWord; dwTime: LongWord);
var
  CurTick: DWORD;
  CurProgress: Integer;
  MaxProgress: Integer;
begin
  MaxProgress := UninstallProgressForm.ProgressBar.Max;
  CurProgress := UninstallProgressForm.ProgressBar.Position;

  if MaxProgress > 0 then
  begin
    CurTick := GetTickCount;
    UninstallPercentLabel.Caption :=
      Format('Done: %.2f %%', [(CurProgress * 100.0) / MaxProgress]);
    UninstallElapsedLabel.Caption := 
      Format('Elapsed: %s', [TicksToStr(CurTick - UninstallStartTick)]);
    if CurProgress > 0 then
    begin
      UninstallRemainingLabel.Caption :=
        Format('Remaining: %s', [TicksToStr(
          ((CurTick - UninstallStartTick) / CurProgress) *
           (MaxProgress - CurProgress))]);
    end;
  end;
end;

procedure InitializeUninstallProgressForm();
begin
  UninstallPercentLabel := TNewStaticText.Create(UninstallProgressForm);
  UninstallPercentLabel.Parent := UninstallProgressForm.ProgressBar.Parent;
  UninstallPercentLabel.Left := UninstallProgressForm.ProgressBar.Left;
  UninstallPercentLabel.Top := UninstallProgressForm.ProgressBar.Top +
    UninstallProgressForm.ProgressBar.Height + ScaleY(12);

  UninstallElapsedLabel := TNewStaticText.Create(UninstallProgressForm);
  UninstallElapsedLabel.Parent := UninstallProgressForm.ProgressBar.Parent;
  UninstallElapsedLabel.Left := UninstallPercentLabel.Left;
  UninstallElapsedLabel.Top :=
    UninstallPercentLabel.Top + UninstallPercentLabel.Height + ScaleY(4);

  UninstallRemainingLabel := TNewStaticText.Create(UninstallProgressForm);
  UninstallRemainingLabel.Parent := UninstallProgressForm.ProgressBar.Parent;
  UninstallRemainingLabel.Left := UninstallPercentLabel.Left;
  UninstallRemainingLabel.Top :=
    UninstallElapsedLabel.Top + UninstallElapsedLabel.Height + ScaleY(4);

  SetTimer(0, 0, 100, CreateCallback(@UninstallTimerProc)); { every 100 ms }
end;

For CreateCallback function, you need Inno Setup 6. If you are stuck with Inno Setup 5, you can use WrapCallback function from InnoTools InnoCallback library. Note the drawbacks of using extension DLL in the uninstaller described in the question linked from the first question above.

这篇关于Inno Setup-如何显示卸载程序中已完成的百分比,经过的时间和估计的时间进度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆