Search code examples
componentsinno-setuppascalscript

Show custom components on Inno Setup Ready to Install page


I would like to add my components and the selected user from the ini file to the Ready to Install page. Is this even possible?

It should look like this example:

enter image description here

This is my ini file:

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

And my script:

[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;

Solution

  • Implement UpdateReadyMemo event function. See Add text to 'Ready Page' in Inno Setup

    Something like this:

    function GetUserName: string;
    begin
      Result := WizardSetupType(False);
    end;
    
    function GetProgramsToInstall: TStrings;
    var
      Path: string;
    begin
      Result := TStringList.Create;
      Path := ExpandConstant('{src}\UserPrograms.ini');
      Result.CommaText := GetIniString('Users', GetUserName, '', Path);
    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;
    

    enter image description here