如何使 Inno Setup /DIR 命令行开关与自定义路径页面一起使用

How to make Inno Setup /DIR command line switch work with custom path page

当我使用/DIR命令行开关时

"Mysoft.exe" /VERYSILENT /installerbusiness /DIR="C:\Program Files (x86)"

我的自定义页面上的路径框没有使用指定的路径:

我正在使用基于 的代码。

这是我使用的代码示例。

[Code]

var
  Install: TInputDirWizardPage;

procedure InitializeWizard();
begin
  Install :=
    CreateInputDirPage(
      wpSelectDir, CustomMessage('Readyinstall'), 
      CustomMessage('Readyinstallpc'), #13#10#13#10 + CustomMessage('Tocontinuet'),
      True, 'Mysoft');

  Install.Add(CustomMessage('DestFolder'));

  Install.Values[0] := ('C:\Program Files\Mysoft');
  { ... }
end;

如果您想要 Inno Setup "installation path" 的标准行为,其中包括 /DIR= command-line switch 的处理,您必须 link 将您的自定义路径框设置为标准框。

特别是,您必须将 WizardForm.DirEdit 的初始值复制到您的自定义框:

var
  Page: TInputDirWizardPage;

procedure InitializeWizard();
begin
  ...
  Page := CreateInputDirPage(...);
  Page.Add(...);
  Page.Values[0] := WizardForm.DirEdit.Text;
end;

此解决方案不仅可以处理 /DIR=,还可以处理 /LOADINF=

要补充上面的代码,您应该将值复制回 WizardForm.DirEdit。这样您就可以确保在 re-install/upgrade 上重复使用之前选择的值。这显示在我对 .

的回答的第 1) 点中

如果以上内容过于复杂(或不明显)而无法实施,因为您的安装程序逻辑复杂,您可以自己以编程方式处理 /DIR= 开关。参见

procedure InitializeWizard();
var
  DirSwitchValue: string;
begin
  Install := ...;

  Install.Add(...);

  DirSwitchValue := ExpandConstant('{param:DIR}');
  if DirSwitchValue <> '' then
  begin
    Install.Values[0] := DirSwitchValue;
  end
    else
  begin
    Install.Values[0] := ExpandConstant('{pf}\Mysoft');
  end;
end;

这个解决方案显然不能处理/LOADINF=.

中显示了如何处理 .inf 个文件

此外,使用此解决方案,之前使用的安装路径将不会用于 upgrades/re-installs。 Inno Setup with three destination folders.

中显示了如何实现