Search code examples
inno-setupuninstallationpascalscript

Create a checkbox to optionally delete files in a custom page at Inno Setup uninstaller


I created custom pages for an uninstaller using this code: How to create a OuterNotebook/welcome page in the Inno Setup uninstaller? and I want to create a checkbox that allows me to optionally delete certain files in a custom page (before the uninstallation process). I am trying to use this code:

NewCheckBox1 := TNewCheckBox.Create(UninstallProgressForm);
with NewCheckBox1 do
begin
  Parent := UninstallfirstPage;
  Left := NewStaticText1.Left;
  Top := NewStaticText1.Top + NewStaticText1.Height + 8;
  Width := NewStaticText1.Width;
  Height := ScaleY(30);
  Caption := 'Eliminar partidas guardadas';
end;

But I do not know how to link this code to the action of removing the additional folder in the uninstallation.

For example:

enter image description here


Solution

  • Just test a value of the checkbox in the CurUninstallStepChanged event function and call DelTree function eventually.

    var
      NewCheckBox1: TNewCheckBox; // a global variable
    
    procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
    begin
      if CurUninstallStep = usUninstall then // or usPostUninstall
      begin
        if NewCheckBox1.Checked then
        begin
          Log('Deleting folder');
          if DelTree(ExpandConstant('{userappdata}\My Program'), True, True, True) then
          begin
            Log('Deleted folder');
          end
            else
          begin
            MsgBox('Error deleting folder', mbError, MB_OK);
          end;
        end;
      end;
    end;