Search code examples
inno-setuppascalscript

Inno Setup Remember selected setup type when Uninstallable=no


I am creating an Inno Setup installer that is a little non traditional. I am setting Uninstallable=no but I still need to be able to remember what the user selected for the type of install if they reinstall in the future. I thought about writing the type out to a file which I was able to do. I am not sure how to set the type when the installer is run the next time however. Here is my code for storing the type.

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if (CurStep = ssDone) then
    SaveStringToFile('{app}\type.dat', WizardSetupType(false), false);
end;

I know how to read this back in, but I am not sure how to set the type.

Edit:

Here is the new code

procedure CurPageChanged(CurPageID: Integer);
begin
  { We need to manually store and restore the install type since Uninstallable=no }
  if (CurPageID = wpSelectComponents) then
    WizardForm.TypesCombo.ItemIndex := GetIniInt('Settings', 'InstallType', 0, 0, 3, ExpandConstant('{app}\settings.ini'));
  if (CurPageID = wpInstalling) then
    SetIniInt('Settings', 'InstallType', WizardForm.TypesCombo.ItemIndex, ExpandConstant('{app}\settings.ini'));
end;

Solution

  • Save WizardForm.TypesCombo.ItemIndex instead of the WizardSetupType and set it back when restoring the selection.

    After restoring the WizardForm.TypesCombo.ItemIndex you have to call the WizardForm.TypesCombo.OnChange to update the components selection.


    I'd also suggest you use INI file functions SetIniInt and GetIniInt instead of the SaveStringToFile.


    Store:

    SetIniInt('Settings', 'InstallType', WizardForm.TypesCombo.ItemIndex,
              ExpandConstant('{app}\settings.ini'));
    

    Restore:

    WizardForm.TypesCombo.ItemIndex :=
      GetIniInt('Settings', 'InstallType', 0, 0, 3, ExpandConstant('{app}\settings.ini'));
    { The OnChange is not called automatically when ItemIndex is set programmatically. }
    { We have to call it to update components selection. }
    WizardForm.TypesCombo.OnChange(WizardForm.TypesCombo);
    

    For an explanation of the last code line, see What does it mean if we type WizardForm.TypesCombo.OnChange(WizardForm.TypesCombo) in Inno Setup?