Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to allow to only install specific components in InnoSetup?

So the question is this: I asked a question back here: How to allow installation only to a specific folder?

How can I modify it a bit, so for example, I have 3 files to install, 2 of them are optional and should only be available to install, if a certain file/folder exists. I want to grey out the option to select them in the list, if the conditions are not met?

Thank you in advance. Zsolt

like image 662
user1320880 Avatar asked Apr 23 '12 15:04

user1320880


1 Answers

I would try to do the following. It will access the component list items, disable and uncheck them by their index, what is the number starting from 0 taken from the order of the [Components] section. The items without fixed flag (like in this case) are by default enabled, thus you need to check if the condition has not been met instead. You may check also the commented version of this post:

[Components]
Name: Component1; Description: Component 1
Name: Component2; Description: Component 2
Name: Component3; Description: Component 3

[code]
procedure CurPageChanged(CurPageID: Integer);
begin
  if CurPageID = wpSelectComponents then
    if not SomeCondition then
    begin
      WizardForm.ComponentsList.Checked[1] := False;
      WizardForm.ComponentsList.ItemEnabled[1] := False;
      WizardForm.ComponentsList.Checked[2] := False;
      WizardForm.ComponentsList.ItemEnabled[2] := False;
    end;
end;

The solution above has at least one weakness. The indexes might be shuffled from the original order from the [Components] section when you set the ComponentsList.Sorted to True. If you don't
use it, it might be enough to use the above code, if yes, then it's more complicated.

There is no simple way to get the component name (it is stored internally as TSetupComponentEntry object in the ItemObject of each item), only the description, so here is another way to do the same with the difference that the item indexes are being searched by their descriptions specified.

procedure CurPageChanged(CurPageID: Integer);
var
  Index: Integer;
begin
  if CurPageID = wpSelectComponents then
    if not SomeCondition then
    begin
      Index := WizardForm.ComponentsList.Items.IndexOf('Component 2');
      if Index <> -1 then
      begin
        WizardForm.ComponentsList.Checked[Index] := False;
        WizardForm.ComponentsList.ItemEnabled[Index] := False;
      end;
      Index := WizardForm.ComponentsList.Items.IndexOf('Component 3');
      if Index <> -1 then
      begin
        WizardForm.ComponentsList.Checked[Index] := False;
        WizardForm.ComponentsList.ItemEnabled[Index] := False;
      end;
    end;
end;
like image 56
TLama Avatar answered Nov 11 '22 08:11

TLama