如何只允许在 InnoSetup 中安装特定组件? [英] How to allow to only install specific components in InnoSetup?

查看:16
本文介绍了如何只允许在 InnoSetup 中安装特定组件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以问题是这样的:我在这里问了一个问题:如何只允许安装到特定文件夹?

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

我该如何修改它,例如,我有 3 个文件要安装,其中 2 个是可选的,只有在存在某个文件/文件夹时才可以安装.如果不满足条件,我想将在列表中选择它们的选项设为灰色?

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?

提前谢谢你.Zsolt

Thank you in advance. Zsolt

推荐答案

我会尝试执行以下操作.它将访问组件列表项,通过它们的索引禁用和取消选中它们,从 [Components] 部分.没有 fixed 标志的项目(如本例)是默认情况下启用,因此您需要检查是否不满足条件.您还可以查看这篇文章的评论版本:

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;

上述解决方案至少有一个弱点.索引可能会从 [Components] 部分,当您设置 ComponentsList.Sorted为真.如果你不
使用它,使用上面的代码可能就足够了,如果是,那就更复杂了.

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.

没有简单的方法来获取组件名称(内部存储为TSetupComponentEntry对象在每个item的ItemObject中),只有描述,所以这里是另一种方法可以通过指定的描述来搜索项目索引.

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;

这篇关于如何只允许在 InnoSetup 中安装特定组件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆