简体   繁体   English

如何只允许在InnoSetup中安装特定组件?

[英]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. 如何修改它,例如,我有3个文件要安装,其中2个是可选的,如果存在某个文件/文件夹,应该只能安装。 I want to grey out the option to select them in the list, if the conditions are not met? 如果条件不满足,我想在列表中选择它们的灰色选项?

Thank you in advance. 先感谢您。 Zsolt 索尔特

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. 它将访问组件列表项,通过索引禁用和取消选中它们,从[Components]部分的顺序开始从0开始的数字是多少。 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. 默认情况下启用没有fixed标志的项目(如本例所示),因此您需要检查是否未满足条件。 You may check also the commented version of this post: 您也可以查看这篇文章的commented version

[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. 该指数可能从原来的顺序被打乱[Components]节当您将ComponentsList.Sorted为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. 没有简单的方法来获取组件名称(它在内部存储为每个项目的ItemObjectTSetupComponentEntry对象),只有描述,所以这里是另一种方法来做同样的事情,区别是项目索引被搜索他们的描述指定。

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何只在特定的蜡烛上绘图 - 不是全部 - How to plot only on specific candles - not all Excel-如何仅对包含特定文本的单元格查找重复单元格 - Excel - how to find duplicates cells ONLY for cells containing specific text 我可以允许Android活动仅在某些条件下更改为横向吗? - can i allow an android activity to change to landscape only on certain conditions? 如何仅从特定月份中找到一个范围内的前5个值? - How can I find the top 5 values from a range, only from a specific month? 如何仅在RTL模式下在Wordpress模板中加载特定样式表 - How to load a specific Stylesheet in my Wordpress template only when in RTL mode 使用ANT时,如果我有一些特定的java版本,我怎么才能定义任务? - When using ANT, how can I define a task only if I have some specific java version? 安装Shiled 2008-如何添加MSU(MSI?)作为先决条件并按条件安装 - Install Shiled 2008 - how to add a MSU (MSI?) as a prerequisite and install by condition 如何防止Angular中if-else条件下组件的重构 - How to prevent re-construction of components in if-else condition in Angular Gnuplot:使用线或线点仅绘制数据集的特定值 - Gnuplot: plotting only specific values of the dataset using lines or linespoints MySQL-在另一列中仅选择具有相同ID和特定值的记录 - MySQL - Select only records with same ID and specific value in another column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM