Inno Setup - Show custom components on Ready to Install page

会有一股神秘感。 提交于 2020-08-26 08:33:46

问题


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:

this is my ini file:

user1=Program1,Program3
user2=Program1,Program2
user3=Program1,Program3
user4=Program1,Program2

Then the following script will do:


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

回答1:


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



来源:https://stackoverflow.com/questions/63029465/inno-setup-show-custom-components-on-ready-to-install-page

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!