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

雨燕双飞 提交于 2019-11-27 15:56:05

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

If you want to use one of the (the first) paths from the TInputDirWizardPage instead of the path from "Select Destination Location" page, you have three options.

  1. Disable the "Select Destination Location" page using DisableDirPage directive:

    DisableDirPage=yes
    

    Copy the path from the TInputDirWizardPage to the hidden "Select Destination Location" page, when the user presses Next button:

    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;
    

    To complement that you may also consider copying the initial WizardForm.DirEdit to your custom box. This way you make sure that 1) on re-install/upgrade, the previously selected value is reused; 2) /DIR command-line switch works. For that see How to make Inno Setup /DIR command line switch work with custom path page.

  2. Replace all uses of the {app} constant with {code:GetDir|0}.

    Make Inno Setup not create the {app} path using CreateAppDir directive:

    CreateAppDir=no
    

    (this implies DisableDirPage=yes).

    And have the uninstall files be stored in the first path using UninstallFilesDir directive:

    UninstallFilesDir={code:GetDir|0}
    

    Contrary to 1), with this approach the previous installation path won't get reused for the later upgrade/re-install. To implement that see Inno Setup Prompt user for a folder and store the value.

  3. Do not use the CreateInputDirPage, but rather add a second path input box on the "Select Destination Location" page (SelectDirPage).

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