Inno setup hide installation items when switching from one installation to ther other

拜拜、爱过 提交于 2020-01-05 03:06:11

问题


I should need your help.

I wonder if there is a possibility in Inno to set 2 different installation masks for 2 products (by selecting from the Dropdown).

We will call the 2 different installations “SETUP” and “PROGRAM”.

When Installing “SETUP” we should have the possibility to check/uncheck boxes for:
A.exe , B.exe, C.exe and D.exe that will be installed (no other check boxes should be seen).

When installing “PROGRAM” we should have the possibility to check/uncheck boxes for A.exe, B.exe (common to “SETUP”), F.exe and G.exe (no other boxes should be seen).

I tried to add the “Flags : fixed” in [Components] section but am unable to hide the checkboxes linked to the other installation (from the drop down menu when selecting to install SETUP or PROGRAM we see the “greyed ”check box).

Is there a way to hide completely “C.exe” and “D.exe” when installing “PROGRAM” and hide completely “F.exe” and “G.exe” when installing “SETUP” ?

Thanks in advance for your help.

Meleena.


回答1:


To hide components at runtime, the only way I can think of (in current version) is deleting the items from the components list. At this time, you can reliably identify component only by its description, so the idea in this code is making a list of component descriptions, iterating ComponentsList and deleting all that matches by its description:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program

[Components]
Name: "ProgramA"; Description: "{cm:CompDescrProgramA}";
Name: "ProgramB"; Description: "{cm:CompDescrProgramB}";
Name: "ProgramC"; Description: "{cm:CompDescrProgramC}";
Name: "ProgramD"; Description: "{cm:CompDescrProgramD}";

[CustomMessages]
; it's much better for maintenance to store component descriptions
; into the [CustomMessages] section
CompDescrProgramA=Program A
CompDescrProgramB=Program B
CompDescrProgramC=Program C
CompDescrProgramD=Program D

[Code]
function ShouldHideCD: Boolean;
begin
  // here return True, if you want to hide those components, False
  // otherwise; it is the function which identifies the setup type
  Result := True;
end;

procedure DeleteComponents(List: TStrings);
var
  I: Integer;
begin
  // iterate component list from bottom to top
  for I := WizardForm.ComponentsList.Items.Count - 1 downto 0 do
  begin
    // if the currently iterated component is found in the passed
    // string list, delete the component
    if List.IndexOf(WizardForm.ComponentsList.Items[I]) <> -1 then
      WizardForm.ComponentsList.Items.Delete(I);
  end;
end;

procedure InitializeWizard;
var
  List: TStringList;
begin
  // if components should be deleted, then...
  if ShouldHideCD then
  begin
    // create a list of component descriptions
    List := TStringList.Create;
    try
      // add component descriptions
      List.Add(ExpandConstant('{cm:CompDescrProgramC}'));
      List.Add(ExpandConstant('{cm:CompDescrProgramD}'));
      // call the procedure to delete components
      DeleteComponents(List);
    finally
      // and free the list
      List.Free;
    end;
  end;
end;

Note, that once you'll delete the items from the ComponentsList, you cannot add them back because each item is holding a TItemState object instance which is released at deletion and there's no way to create nor define such object from script.



来源:https://stackoverflow.com/questions/25158667/inno-setup-hide-installation-items-when-switching-from-one-installation-to-ther

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!