Inno Setup - 在准备安装页面上显示自定义组件

Inno Setup - Show custom components on Ready to Install page

我想将我的组件和从 ini 文件中选择的用户添加到 准备安装 页面。 这可能吗?

它应该像这个例子:

这是我的 ini 文件:

[Users]
user1=Program1,Program3
user2=Program1,Program2
user3=Program1,Program3
user4=Program1,Program2

还有我的剧本:

[Files]
Source: "TEST \Software\x64\Program_1"; DestDir: "{app}\Program_1"; \
  Flags: ignoreversion recursesubdirs; Check: ShouldInstallProgram('Program1') 
Source: "TEST \Software\x64\Program_2"; DestDir: "{app}\Program_2"; \
  Flags: ignoreversion recursesubdirs; Check: ShouldInstallProgram('Program2') 
Source: "TEST \Software\x64\Program_3"; DestDir: "{app}\Program_3"; \
  Flags: ignoreversion recursesubdirs; Check: ShouldInstallProgram('Program3') 
[Code]
function ShouldInstallProgram(ProgramName: string): Boolean;
var
  UserName: string;
  ProgramsStr: string;
  Programs: TStringList;
begin
  UserName := WizardSetupType(False);
  ProgramsStr :=
    GetIniString('Users', UserName, '', ExpandConstant('{src}\UserPrograms.ini'));
  Programs := TStringList.Create;
  Programs.CommaText := ProgramsStr;
  Result := (Programs.IndexOf(ProgramName) >= 0);
  Programs.Free;
end;

实现UpdateReadyMemo事件函数。参见 Add text to 'Ready Page' in Inno Setup

像这样:

function GetUserName: string;
begin
  Result := WizardSetupType(False);
end;

function GetProgramsToInstall: TStrings;
begin
  Result := TStringList.Create;
  Result.CommaText :=
    GetIniString('Users', GetUserName, '', ExpandConstant('{src}\UserPrograms.ini'));
end;

function ShouldInstallProgram(ProgramName: string): Boolean;
var
  Programs: TStrings;
begin
  Programs := GetProgramsToInstall;
  Result := (Programs.IndexOf(ProgramName) >= 0);
  Log(Format('Program [%s] - %d', [ProgramName, Result]));
  Programs.Free;
end;

procedure AddToReadyMemo(var Memo: string; Info, NewLine: string);
begin
  if Info <> '' then Memo := Memo + Info + Newline + NewLine;
end;

function UpdateReadyMemo(
  Space, NewLine, MemoUserInfoInfo, MemoDirInfo, MemoTypeInfo, MemoComponentsInfo,
  MemoGroupInfo, MemoTasksInfo: String): String;
var
  Programs: TStrings;
  I: Integer;
begin
  AddToReadyMemo(Result, MemoUserInfoInfo, NewLine);
  AddToReadyMemo(Result, MemoDirInfo, NewLine);
  AddToReadyMemo(Result, MemoTypeInfo, NewLine);
  AddToReadyMemo(Result, MemoComponentsInfo, NewLine);
  AddToReadyMemo(Result, MemoGroupInfo, NewLine);
  AddToReadyMemo(Result, MemoTasksInfo, NewLine);

  Result :=
    Result +
    'Selected user:' + NewLine +
    Space + GetUserName + NewLine + NewLine;
  Programs := GetProgramsToInstall;
  if Programs.Count > 0 then
  begin
    Result := Result + 'Components:' + NewLine;
    for I := 0 to Programs.Count - 1 do
      Result := Result + Space + Programs[I] + NewLine;
  end;
  Programs.Free;
end;