使用 Inno Setup 为每个选择生成一个配置文件

Generate a configuration file with an entry for each selection using Inno Setup

根据我在 Inno Setup 中选择的内容,安装程序应在 config.ini

中添加一个包含包名称后跟 , 的条目

并将少数特定设置所需的正确预制配置文件(存储在安装程序中)提取到 Config 文件夹中。

有很多像 Chrome/Firefox 这样的程序不需要任何参数或额外的配置即可安装。

所需的 config.ini 文件语法:

<package1>, <package2 /X /Y /Z>, <package 3> ...

等等

其中 <packageX> 是与安装程序选择菜单中的复选框关联的字符串值。

Inno Setup 完成后,它应该 运行 一个批处理文件。

奖励积分:再次......不仅输出 config.ini,而且还将特定程序的必要预制配置设置提取到文件夹 C:/NKsetup/Config/

将您的每个包作为组件添加到 Components section. Then in the Files section, you can choose what files get installed based on the components selected. For the packages list config file, you need to code that with use of the WizardIsComponentSelected function

[Setup]
DefaultDirName=C:\some\path

[Types]
Name: "custom"; Description: "-"; Flags: iscustom

[Components]
Name: "sqlserver"; Description: "Microsoft SQL server"
Name: "chrome"; Description: "Google Chrome"
Name: "firefox"; Description: "Mozilla Firefox"

[Files]
Source: "install.bat"; DestDir: "{app}"
Source: "common-config.ini"; DestDir: "{app}"
Source: "sqlserver-config.ini"; DestDir: "{app}"; Components: sqlserver
Source: "browsers-config.ini"; DestDir: "{app}"; Components: chrome firefox

[Run]
Filename: "{app}\install.bat"; StatusMsg: "Installing..."
[Code]

procedure CurStepChanged(CurStep: TSetupStep);
var
  ConfigPath: string;
  Packages: string;
begin
  if CurStep = ssPostInstall then
  begin
    if WizardIsComponentSelected('sqlserver') then
    begin
      Packages := Packages + ',sql-server-express /X /Y /Z';
    end;
    if WizardIsComponentSelected('chrome') then
    begin
      Packages := Packages + ',chrome';
    end;
    if WizardIsComponentSelected('firefox') then
    begin
      Packages := Packages + ',firefox';
    end;

    // Remove the leading comma
    if Packages <> '' then
    begin
      Delete(Packages, 1, 1);
    end;

    ConfigPath := ExpandConstant('{app}\config.ini');
    // This is not Unicode-safe
    if not SaveStringToFile(ConfigPath, Packages, False) then
    begin
      Log(Format('Error saving packages to %s', [ConfigPath]));
    end
      else
    begin
      Log(Format('Packages saved to %s: %s', [ConfigPath, Packages]));
    end;
  end;
end;