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

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

问题描述

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

如何进行一些修改,例如,我有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。将 排序为True。如果您不使用它,使用上面的代码可能就足够了,如果是,那么它就更复杂了。

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.

没有简单的方法可以获取组件名称(它在每个项目的 ItemObject 中作为 TSetupComponentEntry 对象存储在内部),因此,这是另一种方法,区别在于通过指定的描述搜索项目索引。

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天全站免登陆