Mazinger
Mazinger

Reputation: 653

Allow restricting and configuring Components for multiple installation Types in Inno Setup

I have two types of installation in the Components section, like these:

enter image description here

enter image description here

The behaviour I'd like to achieve is:

Installation type "Main1 installation", default type, all components checked but "Main2", which must be disabled.

Then if type "Main2 installation" is selected, component "Main1" must be disabled and unchecked and all "Optional" components unchecked but available to be checked.

This is my code by now:

[Types]
Name: "main1"; Description: "Main1 installation"
Name: "main2"; Description: "Main2 installation"; Flags: iscustom

[Components]
Name: "Main1"; Description: "Main 1"; Types: main1
Name: "Main2"; Description: "Main 2"; Types: main2
Name: "Optional1"; Description: "Optional 1"; Types: main1
Name: "Optional2"; Description: "Optional 2"; Types: main1
Name: "Optional3"; Description: "Optional 3"; Types: main1

Upvotes: 1

Views: 61

Answers (1)

Martin Prikryl
Martin Prikryl

Reputation: 202222

You cannot do this with Inno Setup Types. There can only be one custom type, not multiple (two in your case). Types also cannot disable the components.

But you can give up on Types and implement a custom type-like drop down.

Though your requirements are not completely defined, so I cannot give you complete solution (Does the component selection reset when type changes? What does happen with type when you customize the components selection? What happens on upgrade? Etc...).

But this should give you some idea:

[Types]
Name: "dummy"; Description: "dummy"; Flags: iscustom

[Components]
Name: "Main1"; Description: "Main 1"
Name: "Main2"; Description: "Main 2"
Name: "Optional1"; Description: "Optional 1"
Name: "Optional2"; Description: "Optional 2"
Name: "Optional3"; Description: "Optional 3"
[Code]

var
  MyTypesCombo: TNewComboBox;

procedure MyTypesComboChange(Sender: TObject);
var
  I: Integer;
begin
  for I := 0 to WizardForm.ComponentsList.Items.Count - 1 do
  begin
    WizardForm.ComponentsList.ItemEnabled[I] :=
      (I = MyTypesCombo.ItemIndex) or (I >= 2);
    WizardForm.ComponentsList.Checked[I] :=
      (I = MyTypesCombo.ItemIndex) or ((I >= 2) and (MyTypesCombo.ItemIndex = 0));
  end;
end;

procedure InitializeWizard();
var
  Delta: Integer;
begin
  MyTypesCombo := TNewComboBox.Create(WizardForm);
  MyTypesCombo.Parent := WizardForm.TypesCombo.Parent;
  MyTypesCombo.Left := WizardForm.TypesCombo.Left;
  MyTypesCombo.Top := WizardForm.TypesCombo.Top;
  MyTypesCombo.Width := WizardForm.TypesCombo.Width;
  MyTypesCombo.Height := WizardForm.TypesCombo.Height;
  MyTypesCombo.Style := WizardForm.TypesCombo.Style;
  MyTypesCombo.Anchors := WizardForm.TypesCombo.Anchors;
  MyTypesCombo.TabOrder := WizardForm.TypesCombo.TabOrder;
  MyTypesCombo.Items.Add('Main1 installation');
  MyTypesCombo.Items.Add('Main2 installation');
  MyTypesCombo.OnChange := @MyTypesComboChange;
  MyTypesCombo.ItemIndex := 0;
  MyTypesComboChange(nil);
   
  WizardForm.IncTopDecHeight(
    WizardForm.ComponentsList, MyTypesCombo.Height + ScaleY(3));
end;

enter image description here

enter image description here

Upvotes: 1

Related Questions