具有多个目标文件夹的 Inno Setup 自定义页面,其行为类似于普通文件夹 select 页面
Inno Setup custom page with multiple destination folders that behave like the normal folder select page
我有以下代码(取自):
[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;
我想让它的行为像传统的文件夹 select 页面一样,所以当 select 创建文件夹时,Inno Setup 应该保留默认文件夹名称,除非用户手动覆盖。即:如果我 select 文件夹 "C:\Program Files\"
它应该保留原始文件夹,如 "C:\Program Files\PHP"
或 "C:\Program Files\Apache"
。这可能吗?
获取浏览按钮的默认行为"Select Destination Location"(由AppendDefaultDirName
directive), for Browse buttons on your custom page, set these parameters of CreateInputDirPage
触发:
AAppendDir
到 True
ANewFolderName
到 "default folder name"
问题是,这会影响所有输入 boxes/buttons。虽然您只想影响第一个输入 box/button(或者您希望每个 box/button 有不同的 ANewFolderName
)。
要仅修改某些框的行为,您必须从头开始重新实现它们的功能。尽管未公开浏览对话框功能。只有BrowseForFolder
function,略有不同
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;
要使用相同的 "browse" 对话框获得准确的行为,您可以通过调用隐藏的 "Select Destination Location" 页面或其他页面的功能来破解它隐藏 TInputDirWizardPage
具有不同的设置 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 版本。奇怪的是调用HiddenPage.Buttons[0].OnClick
在Ansi版本中不起作用。
为了将来参考,这里是基于 Martin 的回答的完整工作代码。确保将 "DisableDirPage=yes" 添加到 [Setup] 部分。
注意:由于一个错误,下面的代码仅适用于 InnoSetup 的 unicode 版本。
[Code]
var
DirPage: TInputDirWizardPage;
HiddenPage: TInputDirWizardPage;
HiddenPage2: TInputDirWizardPage;
HiddenPage3: 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;
procedure AppendDirBrowseClick2(Sender: TObject);
begin
HiddenPage2.Values[0] := DirPage.Values[1];
HiddenPage2.Buttons[0].OnClick(HiddenPage2.Buttons[0]);
DirPage.Values[1] := HiddenPage2.Values[0];
end;
procedure AppendDirBrowseClick3(Sender: TObject);
begin
HiddenPage3.Values[0] := DirPage.Values[2];
HiddenPage3.Buttons[0].OnClick(HiddenPage3.Buttons[0]);
DirPage.Values[2] := HiddenPage3.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;
DirPage.Buttons[1].OnClick := @AppendDirBrowseClick2;
DirPage.Buttons[2].OnClick := @AppendDirBrowseClick3;
HiddenPage := CreateInputDirPage(
wpSelectDir, SetupMessage(msgWizardSelectDir), '', '', True, 'Apache');
HiddenPage.Add('');
HiddenPage.OnShouldSkipPage := @SkipPage;
HiddenPage2 := CreateInputDirPage(
wpSelectDir, SetupMessage(msgWizardSelectDir), '', '', True, 'PHP');
HiddenPage2.Add('');
HiddenPage2.OnShouldSkipPage := @SkipPage;
HiddenPage3 := CreateInputDirPage(
wpSelectDir, SetupMessage(msgWizardSelectDir), '', '', True, 'Server Files');
HiddenPage3.Add('');
HiddenPage3.OnShouldSkipPage := @SkipPage;
end;
我有以下代码(取自
[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;
我想让它的行为像传统的文件夹 select 页面一样,所以当 select 创建文件夹时,Inno Setup 应该保留默认文件夹名称,除非用户手动覆盖。即:如果我 select 文件夹 "C:\Program Files\"
它应该保留原始文件夹,如 "C:\Program Files\PHP"
或 "C:\Program Files\Apache"
。这可能吗?
获取浏览按钮的默认行为"Select Destination Location"(由AppendDefaultDirName
directive), for Browse buttons on your custom page, set these parameters of CreateInputDirPage
触发:
AAppendDir
到True
ANewFolderName
到 "default folder name"
问题是,这会影响所有输入 boxes/buttons。虽然您只想影响第一个输入 box/button(或者您希望每个 box/button 有不同的 ANewFolderName
)。
要仅修改某些框的行为,您必须从头开始重新实现它们的功能。尽管未公开浏览对话框功能。只有BrowseForFolder
function,略有不同
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;
要使用相同的 "browse" 对话框获得准确的行为,您可以通过调用隐藏的 "Select Destination Location" 页面或其他页面的功能来破解它隐藏 TInputDirWizardPage
具有不同的设置 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 版本。奇怪的是调用HiddenPage.Buttons[0].OnClick
在Ansi版本中不起作用。
为了将来参考,这里是基于 Martin 的回答的完整工作代码。确保将 "DisableDirPage=yes" 添加到 [Setup] 部分。
注意:由于一个错误,下面的代码仅适用于 InnoSetup 的 unicode 版本。
[Code]
var
DirPage: TInputDirWizardPage;
HiddenPage: TInputDirWizardPage;
HiddenPage2: TInputDirWizardPage;
HiddenPage3: 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;
procedure AppendDirBrowseClick2(Sender: TObject);
begin
HiddenPage2.Values[0] := DirPage.Values[1];
HiddenPage2.Buttons[0].OnClick(HiddenPage2.Buttons[0]);
DirPage.Values[1] := HiddenPage2.Values[0];
end;
procedure AppendDirBrowseClick3(Sender: TObject);
begin
HiddenPage3.Values[0] := DirPage.Values[2];
HiddenPage3.Buttons[0].OnClick(HiddenPage3.Buttons[0]);
DirPage.Values[2] := HiddenPage3.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;
DirPage.Buttons[1].OnClick := @AppendDirBrowseClick2;
DirPage.Buttons[2].OnClick := @AppendDirBrowseClick3;
HiddenPage := CreateInputDirPage(
wpSelectDir, SetupMessage(msgWizardSelectDir), '', '', True, 'Apache');
HiddenPage.Add('');
HiddenPage.OnShouldSkipPage := @SkipPage;
HiddenPage2 := CreateInputDirPage(
wpSelectDir, SetupMessage(msgWizardSelectDir), '', '', True, 'PHP');
HiddenPage2.Add('');
HiddenPage2.OnShouldSkipPage := @SkipPage;
HiddenPage3 := CreateInputDirPage(
wpSelectDir, SetupMessage(msgWizardSelectDir), '', '', True, 'Server Files');
HiddenPage3.Add('');
HiddenPage3.OnShouldSkipPage := @SkipPage;
end;