基于Inno Setup中的可选组件跳过自定义页面

时间:2012-12-17 20:18:55

标签: inno-setup

在先前的问题中,我询问了如何使用三个可选组件,其中用户还可以单独指定每个组件的位置(例如,代码部分和两个HTML Web应用程序)。 @Miral给了我一个很好的答案,我现在已经实现了:
three components in three user defined locations

我还有一个小小的审美问题。我总是在向导中创建并询问用户CreateInputDirPage。问题出现在wpSelectComponents

之后

问题:如果未选择组件,如何跳过页面。也就是说,如何跳过我的自定义页面?

我觉得它与ShouldSkipPage()有关。但我不知道我的自定义页面的PageID是什么,以及如何测试以查看选择了哪些组件。

  

function ShouldSkipPage(PageID:Integer):Boolean;

     

向导调用此事件函数以确定是否应显示特定页面(由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;

2 个答案:

答案 0 :(得分:26)

正如您所正确的那样,您需要使用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;

答案 1 :(得分:5)

我对此的看法是使用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;

现在,OnShouldSkipPagewpSelectComponents之后按下TobyDirPage并在import sqlite3 conn = sqlite3.connect(r'\\some_host\some_shared_folder\example.db') #a drive map/mount will be helpful here as well ... ... #some kivy code that uses the connection above ... 被绘制之前立即触发,因为您可以将该事件附加到页面本身,您不需要提琴使用PageID。