根据 Inno Setup 中选定的组件启动自定义代码

Launch custom code via according to selected Components in Inno Setup

我的查询与 Launch custom code via tasks in Inno Setup 有点相似,只是不是启动辅助选择页面,代码的变化是 运行,具体取决于所选组件。我希望将文本的变体插入到(设置)文档中。使用上述参考代码的初步尝试没有奏效,我猜是因为 inno 无法在安装过程的早期搜索文档的存在。我打算在下面使用的 Append 方法。 Append 似乎不支持组件标志。

[Components]
Name: "Adult"; Description: "Adult filters"; Flags: exclusive
Name: "PresetWordFilter"; Description: "Preset Word Filter"; Flags: exclusive
Name: "No_Security"; Description: "No filters"; Flags: exclusive
[Code]
procedure ?
begin
  if ? then
  begin
    FileName := ExpandConstant('{userappdata}\LLL’);
    FileName := AddBackslash(FileName) + 'lll.props';
    Lines := TStringList.Create;

    { Load existing lines from file }
    Lines.LoadFromFile(FileName);
    { Add your information to the end of the file }
    Lines.Append('xxx');
    Lines.Append('FILTER_ADULT=true');
    Lines.SaveToFile(FileName);
    Lines.Free;
  end;
end;

使用 WizardIsComponentSelected function. For example in the CurStepChanged event function(在 ssPostInstallssInstall 步骤中)。

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
  begin
    FileName := ExpandConstant('{userappdata}\LLL\lll.props');
    Lines := TStringList.Create;
    { Load existing lines from file }
    Lines.LoadFromFile(FileName);

    if WizardIsComponentSelected('Adult') then
    begin
      Lines.Append('FILTER_ADULT=true');
    end;

    if WizardIsComponentSelected('PresetWordFilter') then
    begin
      Lines.Append('PRESET_WORD_FILTER=true');
    end;

    Lines.SaveToFile(FileName);
    Lines.Free;    
  end;
end;