具有多个目标文件夹的Inno Setup自定义页面,其行为类似于普通文件夹选择页面 [英] Inno Setup custom page with multiple destination folders that behave like the normal folder select page

查看:73
本文介绍了具有多个目标文件夹的Inno Setup自定义页面,其行为类似于普通文件夹选择页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下代码(摘自在文件"部分的自定义页面中使用两个/多个所选目录):

I've the following code (taken from Use two/multiple selected directories from custom page in Files section):

[Code]
var
  DirPage: TInputDirWizardPage;

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

procedure InitializeWizard;
var
  S1, S2: String; 
begin
  S1 := SetupMessage(msgSelectDirDesc);
  StringChangeEx(S1, '[name]', 'ProgramName', false);
  S2 := SetupMessage(msgSelectDirLabel3);
  StringChangeEx(S2, '[name]', 'ProgramName', false);

  { create a directory input page }
  DirPage := CreateInputDirPage(
    wpSelectDir, SetupMessage(msgWizardSelectDir), S1, S2, False, '');
  { add directory input page items }
  DirPage.Add('Path to Apache:');
  DirPage.Add('Path to PHP:');
  DirPage.Add('Path to Server Files:');
  { assign default directories for the items from the previously stored data; if }
  { there are no data stored from the previous installation, use default folders }
  { of your choice }
  DirPage.Values[0] := GetPreviousData('Directory1', 'C:\Apache');
  DirPage.Values[1] := GetPreviousData('Directory2', 'C:\PHP');
  DirPage.Values[2] := GetPreviousData('Directory3', 'C:\Apache\htdocs\Server Files');
end;

procedure RegisterPreviousData(PreviousDataKey: Integer);
begin
  { store chosen directories for the next run of the setup }
  SetPreviousData(PreviousDataKey, 'Directory1', DirPage.Values[0]);
  SetPreviousData(PreviousDataKey, 'Directory2', DirPage.Values[1]);
  SetPreviousData(PreviousDataKey, 'Directory3', DirPage.Values[2]);
end; 

我想使它的行为类似于传统的文件夹选择页面,因此在选择文件夹时,除非用户手动覆盖,否则Inno Setup应该保留默认的文件夹名称.即:如果我选择文件夹"C:\Program Files\",则应保留原始文件夹,如"C:\Program Files\PHP""C:\Program Files\Apache".这可能吗?

I'd like to make this behave like the traditional folder select page, so when selecting a folder, Inno Setup should keep the default folder name unless manually overwritten by the user. I.e.: if I select the folder "C:\Program Files\" it should keep the original folder like "C:\Program Files\PHP" or "C:\Program Files\Apache". Is this possible?

推荐答案

要获取选择目标位置" 上的浏览按钮的默认行为(由 AppendDefaultDirName指令),用于您的浏览按钮自定义页面上,设置以下 CreateInputDirPage :

To get the default behavior of Browse button on "Select Destination Location" (triggered by AppendDefaultDirName directive), for Browse buttons on your custom page, set these parameters of CreateInputDirPage:

  • AAppendDirTrue
  • ANewFolderName更改为默认文件夹名称"
  • AAppendDir to True
  • ANewFolderName to the "default folder name"

问题是,这会影响所有输入框/按钮.如果您只想影响第一个输入框/按钮(或者每个框/按钮都希望使用不同的ANewFolderName).

The problem is, that this affects all input boxes/buttons. While you want to affect only the first input box/button (or you want a different ANewFolderName for each box/button).

要仅修改某些框的行为,必须从头开始重新实现其功能.虽然没有公开浏览对话框功能.仅有 BrowseForFolder函数,该方法稍有不同.

To modify a behavior of some box only, you have to reimplement their functionality from the scratch. Though the browse dialog functionality is not exposed. There's only BrowseForFolder function, which is slightly different.

var
  DirPage: TInputDirWizardPage;

procedure NormalBrowseClick(Sender: TObject);
var
  Directory: string;
begin
  Directory := DirPage.Values[TButton(Sender).Tag];
  if BrowseForFolder(SetupMessage(msgWizardSelectDir), Directory, False) then
  begin
    DirPage.Values[TButton(Sender).Tag] := Directory;
  end;
end;

procedure InitializeWizard();
begin
  DirPage := CreateInputDirPage(
    wpSelectDir, SetupMessage(msgWizardSelectDir), '', '', True, 'Apache');
  { add directory input page items }
  DirPage.Add('Path to Apache:');
  DirPage.Add('Path to PHP:');
  DirPage.Add('Path to Server Files:');

  DirPage.Buttons[1].Tag := 1;
  DirPage.Buttons[1].OnClick := @NormalBrowseClick;
  DirPage.Buttons[2].Tag := 2;
  DirPage.Buttons[2].OnClick := @NormalBrowseClick;
  { assign default directories for the items from the previously stored data; if }
  { there are no data stored from the previous installation, use default folders }
  { of your choice }
  DirPage.Values[0] := GetPreviousData('Directory1', 'C:\Apache');
  DirPage.Values[1] := GetPreviousData('Directory2', 'C:\PHP');
  DirPage.Values[2] := GetPreviousData('Directory3', 'C:\Apache\htdocs\Server Files');
end;


要使用相同的浏览"对话框获得确切的行为,您可以通过调用隐藏的选择目标位置"页面或另一个具有不同设置的隐藏TInputDirWizardPage功能来破解它的AAppendDir:


To get the exact behaviour with the same "browse" dialog, you can hack it be invoking a functionality of the hidden "Select Destination Location" page or of another hidden TInputDirWizardPage with different settings of AAppendDir:

var
  DirPage: TInputDirWizardPage;
  HiddenPage: TInputDirWizardPage;

procedure AppendDirBrowseClick(Sender: TObject);
begin
  HiddenPage.Values[0] := DirPage.Values[0];
  HiddenPage.Buttons[0].OnClick(HiddenPage.Buttons[0]);
  DirPage.Values[0] := HiddenPage.Values[0];
end;

function SkipPage(Sender: TWizardPage): Boolean;
begin
  Result := True;
end;

procedure InitializeWizard();
begin
  DirPage := CreateInputDirPage(
    wpSelectDir, SetupMessage(msgWizardSelectDir), '', '', False, '');

  DirPage.Add('Path to Apache:');
  DirPage.Add('Path to PHP:');
  DirPage.Add('Path to Server Files:');

  { assign default directories for the items from the previously stored data; if }
  { there are no data stored from the previous installation, use default folders }
  { of your choice }
  DirPage.Values[0] := GetPreviousData('Directory1', 'C:\Apache');
  DirPage.Values[1] := GetPreviousData('Directory2', 'C:\PHP');
  DirPage.Values[2] := GetPreviousData('Directory3', 'C:\Apache\htdocs\Server Files');

  DirPage.Buttons[0].OnClick := @AppendDirBrowseClick;

  HiddenPage := CreateInputDirPage(
    wpSelectDir, SetupMessage(msgWizardSelectDir), '', '', True, 'Apache');
  HiddenPage.Add('');
  HiddenPage.OnShouldSkipPage := @SkipPage;
end;

代码需要Inno Setup的Unicode版本.在Ansi版本中奇怪地调用HiddenPage.Buttons[0].OnClick无效.

The code needs Unicode version of Inno Setup. Calling HiddenPage.Buttons[0].OnClick strangely does not work in Ansi version.

这篇关于具有多个目标文件夹的Inno Setup自定义页面,其行为类似于普通文件夹选择页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆