如何在 Inno Setup 卸载程序中显示完成百分比、已用时间和预计时间进度?

问题描述 投票:0回答:1

我正在尝试使用此代码:
如何显示完成百分比、已用时间和预计时间进度?

但是我有问题,因为我也想在 uninstaller 中使用这段代码。

inno-setup pascalscript
1个回答
3
投票

将这两段代码合并在一起:

[Code]

function SetTimer(hWnd: longword; nIDEvent, uElapse: LongWord;
  lpTimerFunc: LongWord): LongWord; external '[email protected] stdcall';
function GetTickCount: DWORD;
  external '[email protected] 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;

对于

CreateCallback
函数,您需要 Inno Setup 6。如果您无法使用 Inno Setup 5,您可以使用
InnoTools InnoCallback
库中的 WrapCallback 函数。请注意在上面第一个问题链接的问题中描述的卸载程序中使用扩展 DLL 的缺点。

Uninstall times

© www.soinside.com 2019 - 2024. All rights reserved.