在Inno Setup中,我添加了一个自定义向导页面,用户可以在其中输入后缀代码,该代码应动态添加到默认目录中。
标准DefaultDirName
是c:\MyApp
。
当用户在额外的自定义向导页面中添加后缀01
时,DefaultDirName
应该更改为c:\MyApp01
。
这怎么办?显然,我无法使用[Setup]
部分中的代码,因为该代码是在任何向导页面之前进行评估的。
答案 0 :(得分:2)
离开“后缀”页面时,请将后缀附加到安装路径。
此外,您还必须处理:
#define AppId "your-app-id"
#define SetupReg "Software\Microsoft\Windows\CurrentVersion\Uninstall\" + AppId + "_is1"
#define SetupAppPathReg "Inno Setup: App Path"
[Setup]
AppId={#AppId}
[Code]
function IsUpgrade: Boolean;
var S: string;
begin
Result :=
RegQueryStringValue(HKLM, '{#SetupReg}', '{#SetupAppPathReg}', S) or
RegQueryStringValue(HKCU, '{#SetupReg}', '{#SetupAppPathReg}', S);
end;
var
SuffixPage: TInputQueryWizardPage;
procedure InitializeWizard();
begin
if not IsUpgrade then
begin
SuffixPage := CreateInputQueryPage(wpWelcome, 'Select suffix', '', '');
SuffixPage.Add('Suffix', False);
end;
end;
function NextButtonClick(CurPageID: Integer): Boolean;
begin
{ Add suffix to path, when leaving "suffix" page }
if (SuffixPage <> nil) and (CurPageID = SuffixPage.ID) then
begin
WizardForm.DirEdit.Text := WizardForm.DirEdit.Text + SuffixPage.Values[0];
end;
Result := True;
end;
function BackButtonClick(CurPageID: Integer): Boolean;
var
Suffix: string;
P: Integer;
begin
{ When going back from "select dir" page }
if (CurPageID = wpSelectDir) and (SuffixPage <> nil) then
begin
Suffix := SuffixPage.Values[0];
P := Length(WizardForm.DirEdit.Text) - Length(Suffix) + 1;
{ ... and the path still contains the suffix [was not edited out by the user] ... }
if Copy(WizardForm.DirEdit.Text, P, Length(Suffix)) = Suffix then
begin
{ ... remove it form the path }
WizardForm.DirEdit.Text := Copy(WizardForm.DirEdit.Text, 1, P - 1);
end
else
{ if the suffix was edited out by the user, clear suffix box }
begin
SuffixPage.Values[0] := '';
end;
end;
Result := True;
end;