Luan Pham
Luan Pham

Reputation: 187

Inno Setup - Progress bar doesn't show when uninstall

I'm using Inno Setup to create my own installer. When user uninstall app I want delete some folder.

So I use CurUninstallStepChanged event to delete folder and show "progress bar" with npbstMarquee style (based on Inno Setup: How to handle progress bar on [UninstallDelete] section?).

Here is the code:

procedure DeleteFolder();
var
  FindRec: TFindRec;
  fullPath: string;
  tmpMsg: string;
  StatusText: string;
  deletePath: string;
begin
  { find all and delete }
  UninstallProgressForm.ProgressBar.Style := npbstMarquee;       
  StatusText := UninstallProgressForm.StatusLabel.Caption;
  UninstallProgressForm.StatusLabel.WordWrap := True;
  UninstallProgressForm.StatusLabel.AutoSize := True;
  fullPath := 'C:\ProgramData\TestPath';
  if FindFirst(ExpandConstant(fullPath + '\*'), FindRec) then 
  try
    repeat
      if (FindRec.Attributes and FILE_ATTRIBUTE_DIRECTORY <> 0) and 
         (FindRec.Name <> '.') and (FindRec.Name <> '..') then begin
            deletePath := AddBackslash(fullPath) + FindRec.Name;
            tmpMsg := 'Deleting...' + #13#10 + deletePath;
            UninstallProgressForm.StatusLabel.Caption := tmpMsg;
            DelTree(deletePath, True, True, True);
        end;
    until
      not FindNext(FindRec);
  finally
    UninstallProgressForm.StatusLabel.Caption := StatusText;
    FindClose(FindRec);
  end;
  UninstallProgressForm.ProgressBar.Style := npbstNormal;
end;

{ Uninstall event }
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
   case CurUninstallStep of
    usUninstall:
     begin
       DeleteFolder();
    end;
  end;
end;

If I using debug each line, I can see progress bar running. But when I using unins000.exe then only Caption can show, progress bar is not showing.
How can I fix it?

Upvotes: 4

Views: 680

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202098

You have to pump the message queue to display/animate the progress bar.
Inno Setup: How to modify long running script so it will not freeze GUI?

Particularly, you can use the AppProcessMessage function from:
My SQL server discovery on LAN by listening port (Inno Setup)

enter image description here

Though with use of DelTree, the interval between calls to AppProcessMessage will be too big to animate the progress bar smoothly. You would have to implement a recursive delete explicitly to allow pumping the queue frequently enough.

Upvotes: 4

Related Questions