基于在Inno Setup的可选组件跳过自定义页面(Skipping custom pages ba

2019-07-05 15:04发布

在先前的问题,我问怎么有三个可选组件,用户还可以分别指定每个组件的位置(如代码部分和两个HTML的Web应用程序)。 @Miral给了我一个伟大的答案,我现在已经实现:
在三个用户定义的位置三个组分

我有一个小问题美观剩余。 我一直在创造并要求用户输入一个CreateInputDirPage ,在向导中。 问题来了后wpSelectComponents

问:如何跳过页面,如果没有被选中的组件。 也就是说,我怎么跳过我的自定义页面?

我有一种感觉它与做ShouldSkipPage() 但我不知道该怎样PageID为我定制的页面,以及如何测试,看看选择哪些组件。

功能ShouldSkipPage(PAGEID:整数):布尔值;

该向导调用这个事件函数来确定是否一个特定页面(由PAGEID指定)应在所有的显示。 如果你返回True,页面会被跳过; 如果你返回False,该页面可以显示。

我的脚本是封闭如下:

[Components]
Name: "Watson"; Description: "Watson Component"; Types: onlywatson full
Name: "Toby"; Description: "Toby Component"; Types: onlytoby full
Name: "Sherlock"; Description: "Sherlock Component"; Types: onlysherlock full

[Code]
var 
    TobyDirPage: TInputDirWizardPage;
    SherlockDirPage: TInputDirWizardPage;

procedure InitializeWizard;
begin
  TobyDirPage := CreateInputDirPage(wpSelectComponents,
    'Select Location for Toby Web Pages', 'Where should we store the sample Toby application files?',
    'The sample Toby stand-alone map application will be saved 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');
  { Add item (with an empty caption) }
  TobyDirPage.Add('');
  { Set initial value (optional) }
  TobyDirPage.Values[0] := ExpandConstant('c:\wwwroot\Toby');

  SherlockDirPage := CreateInputDirPage(wpSelectComponents,
    'Select Location for Sherlock Web Pages', 'Where should we store the Sherlock Catalog Search Tool?',
    'Sherlock.html and it'#39 + 's associated files will be saved 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');
  { Add item (with an empty caption) }
  SherlockDirPage.Add('');
  { Set initial value (optional) }
  SherlockDirPage.Values[0] := ExpandConstant('c:\wwwroot\Sherlock');
end;

function GetTobyDir(Param: String): String;
begin
  { Return the selected TobyDir }
  Result := TobyDirPage.Values[0];
end;

function GetSherlockDir(Param: String): String;
begin
  { Return the selected TobyDir }
  Result := SherlockDirPage.Values[0];
end;

Answer 1:

当你正确forefelt,您需要使用ShouldSkipPage事件处理程序有条件地跳过页面。 要检查是否选择某一组件使用IsComponentSelected功能,最后,让您的自定义页面的ID,你需要存储的ID 。 把所有在一起,可能会给你下面的示例脚本:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={pf}\My Program
OutputDir=userdocs:Inno Setup Examples Output

[Components]
Name: "help"; Description: "Help File";

[Code]
var
  CustomPageID: Integer;

procedure InitializeWizard;
var
  CustomPage: TInputDirWizardPage;
begin
  CustomPage := CreateInputDirPage(wpSelectComponents, 'Caption', 
    'Description', 'SubCaption', False, 'NewFolderName');
  CustomPage.Add('Input');
  { store your custom page ID to further use in the ShouldSkipPage event }
  CustomPageID := CustomPage.ID;
end;

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  { initialize result to not skip any page (not necessary, but safer) }
  Result := False;
  { if the page that is asked to be skipped is your custom page, then... }
  if PageID = CustomPageID then
    { if the component is not selected, skip the page }
    Result := not IsComponentSelected('help');
end;


Answer 2:

我对这个问题的看法是使用TWizardPageShouldSkipEvent,我做了唯一的一个案例和点脚本:

[Code]
var 
    TobyDirPage: TInputDirWizardPage;

function SkipEvent (Sender: TWizardPage): Boolean;
begin
    Result := not IsComponentSelected('Toby');
end; 

procedure InitializeWizard;
begin
    TobyDirPage := CreateInputDirPage(wpSelectComponents, yadda yadda yadda
    TobyDirPage.OnShouldSkipPage := @SkipEvent;
end;

现在, OnShouldSkipPage大火按Next后右wpSelectComponents之前TobyDirPage被涂因为你可以在事件附加到页面本身就不需要用PAGEID的拨弄。



文章来源: Skipping custom pages based on optional components in Inno Setup
标签: inno-setup