我想将我的组件和选定的用户从 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
事件功能。请参阅将文本添加到 Inno Setup 中的“就绪页面”
类似这样的:
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;