Inno Setup - How to show percent done, elapsed time and estimated time progress at uninstaller?

天大地大妈咪最大 提交于 2021-02-07 10:55:00

问题


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.


回答1:


Merging these two piece of code together:

  • Inno Setup uninstall progress bar change event
  • How to show percent done, elapsed time and estimated time progress?
[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.



来源:https://stackoverflow.com/questions/41698725/inno-setup-how-to-show-percent-done-elapsed-time-and-estimated-time-progress

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!