Search code examples
installationinno-setuppascalpascalscript

InnoSetup, prevent installation if any task is selected


My inno script has two tasks:

[Tasks]
Name: client; Description: Install FTP client
Name: server; Description: Install FTP server

I would like to deny the installation in a non-intrusive way if any task is selected, for non.intrusive I mean for example enabling/disabling the "next" button when one of both tasks are checked, no advertising messagbe-box.

I'm not sure if innosetup has a parameter or a "check" function to do this in a simple way

How I could do it?


Solution

  • There is no way to do what you want natively in Inno Setup. You will need to do it from code by yourself.

    You can cheat here a bit by using the WizardSelectedTasks function. This function returns a comma separated list of selected task names (or descriptions), and so it returns an empty string when no task is selected. The rest is about binding task list OnClickCheck event, and updating the next button enable state and writing a piece of code to initialize the next button state:

    [Setup]
    AppName=My Program
    AppVersion=1.5
    DefaultDirName={pf}\My Program
    
    [Tasks]
    Name: client; Description: Install FTP client
    Name: server; Description: Install FTP server
    
    [Code]
    // helper function
    function IsAnyTaskSelected: Boolean;
    begin
      Result := WizardSelectedTasks(False) <> '';
    end;
    
    // event handler for setting the next button initial state when
    // entering the tasks page
    procedure CurPageChanged(CurPageID: Integer);
    begin
      if CurPageID = wpSelectTasks then
        WizardForm.NextButton.Enabled := IsAnyTaskSelected;
    end;
    
    // method of the task list check click event
    procedure TasksListClickCheck(Sender: TObject);
    begin
      WizardForm.NextButton.Enabled := IsAnyTaskSelected;
    end;
    
    procedure InitializeWizard;
    begin
      WizardForm.TasksList.OnClickCheck := @TasksListClickCheck;
    end;