Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
662 views
in Technique[技术] by (71.8m points)

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

I need create custom page of two destination.

I've done:

#define MyAppName "TESTPROG"
[Setup]

AppName={#MyAppName}
DefaultDirName=C:est{#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;

I need to know how and where I set DefaultDirName with Page.Values[0] and Page.Values[1]

I need it because some part of my files will be in a folder and others in other folder.

For example:

[Files]
Source: C:TESTDLL1.bat; DestDir: Page.Values[0]sys1;
Source: C:TESTDLL2.bat; DestDir: Page.Values[1]sys2;
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Use a scripted constant:

[Files]
Source: C:TESTDLL1.bat; DestDir: "{code:GetDir|0}sys1"
Source: C:TESTDLL2.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).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...