在“文件”部分的自定义页面中使用 two/multiple 个选定的目录

Use two/multiple selected directories from custom page in Files section

我需要创建两个目的地的自定义页面。

我完成了:

#define MyAppName "TESTPROG"
[Setup]

AppName={#MyAppName}
DefaultDirName=C:\test\{#MyAppName}
DefaultGroupName={#MyAppName}

[Code]
var
  Page: TInputDirWizardPage;
  DataDir: String;

procedure InitializeWizard;
begin
  Page := CreateInputDirPage(wpWelcome,
    'Select Personal Data Location', 'Where should personal data files be stored?',
    'Personal data files will be stored in the following folder.'#13#10#13#10 +
    'To continue, click Next. ' +
      'If you would like to select a different folder, click Browse.',
    False, 'New Folder');

  Page.Add('Local APP');
  Page.Add('Local Storage');

  Page.Values[0] := ('C:\My Program');
  Page.Values[1] := ('D:\My Program');

  DataDir := Page.Values[0]; 
end;

我需要知道如何以及在何处使用 Page.Values[0]Page.Values[1]

设置 DefaultDirName

我需要它,因为我的部分文件将在一个文件夹中,而其他部分将在其他文件夹中。

例如:

[Files]
Source: C:\TEST\DLL1.bat; DestDir: Page.Values[0]\sys1;
Source: C:\TEST\DLL2.bat; DestDir: Page.Values[1]\sys2;

使用 scripted constant:

[Files]
Source: C:\TEST\DLL1.bat; DestDir: "{code:GetDir|0}\sys1"
Source: C:\TEST\DLL2.bat; DestDir: "{code:GetDir|1}\sys2"

[Code]

var
  Page: TInputDirWizardPage;

function GetDir(Param: string): string;
begin
  Result := Page.Values[StrToInt(Param)];
end;

procedure InitializeWizard;
begin
  Page := CreateInputDirPage(...);
  ...
end;

如果您想使用 TInputDirWizardPage 中的(第一个)路径之一而不是 "Select Destination Location" 页面中的路径,您有三个选项。

  1. 禁用 "Select Destination Location" 页面使用 DisableDirPage directive:

    DisableDirPage=yes
    

    复制从TInputDirWizardPage到隐藏的路径Select 目标位置页面,当用户按下下一步按钮时:

    var
      Page: TInputDirWizardPage;
    
    function InputDirPageNextButtonClick(Sender: TWizardPage): Boolean;
    begin
      { Use the first path as the "destination path" }
      WizardForm.DirEdit.Text := Page.Values[0];
      Result := True;
    end;
    
    procedure InitializeWizard();
    begin
      Page := CreateInputDirPage(...);
      ...
      Page.OnNextButtonClick := @InputDirPageNextButtonClick;
    end;
    

    作为补充,您还可以考虑将初始 WizardForm.DirEdit 复制到您的自定义框。通过这种方式,您可以确保 1) 在 re-install/upgrade 上重复使用之前选择的值; 2) /DIR command-line switch works. For that see .

  2. {app} constant 的所有用法替换为 {code:GetDir|0}

    使 Inno Setup 不使用 CreateAppDir directive:

    创建 {app} 路径
    CreateAppDir=no
    

    (这意味着 DisableDirPage=yes)。

    并使用 UninstallFilesDir directive:

    将卸载文件存储在第一个路径中
    UninstallFilesDir={code:GetDir|0}
    

    与 1) 相反,使用这种方法之前的安装路径将不会在以后的 upgrade/re-install 中重复使用。要实现它,请参阅 .

  3. 不使用CreateInputDirPage,而是在"Select Destination Location"页面添加第二个路径输入框(SelectDirPage).