为什么在 Inno Setup 中多次调用 ShouldShipPage 函数

问题描述

以下是我在网上找到的用于安装 Excel 插件的 inno 安装脚本的相关部分。我的问题与 Excel 无关,而是与 Inno Setup 的运作方式有关。我很难理解这一点。包括设置脚本、执行脚本时显示页面序列、生成的日志文件的相关部分以及与我的问题相关的代码段。

为什么 ShouldSkipPage 函数被多次调用,如日志的第 06,07 和 09 行所示?

Page 1

Page 2

Page 3

[Setup]  
#ifexist "config.iss"          
  #include "config.iss"  
#else  
  #error config.iss not found. Please copy config-dist/config.dist.iss to config.iss and edit it with your information.  
#endif  
#include "inc/setup.iss"  

[Files]  
; The include file makes adds all .XLA and .XLAM files contained in the  
; SOURCEDIR to the project.  
#include "inc/files-addins.iss"  

; Define any additional files in the custom files.iss file.  
#ifexist "files.iss"  
  #include "files.iss"  
#endif  

[Tasks]  
; We make it optional for users to have the addin activated for use in  
; Excel. In most cases,this will be left enabled by users (everything  
; else does not make sense).  
Name: ActivateAddin; Description: {cm:taskActivate};   

; Define any additional tasks in the custom tasks.iss file.  
#ifexist "tasks.iss"  
  #include "tasks.iss"  
#endif  

[Code]

以下是代码部分中与问题相关的代码

procedure InitializeWizard();
var
    CallName: string;
begin
    CallName := 'InitializeWizard(): ';
    Log(CallName);

    if not IsExcelVersionInstalled(minexcelVersion,MaxExcelVersion) then
    begin
        Log(CallName+'Excel not installed!');
        CreateOutputMsgPage(wpWelcome,CustomMessage('Excelnotinstalled'),CustomMessage('ExcelnotinstalledCaption'),CustomMessage('ExcelnotinstalledExplanation'));
        Excelnotinstalled := true;
    end;
end;
function NextButtonClick(CurPageID:Integer): Boolean;
Begin
  Log('Trace: ' + 'NextButtonClick CurPage ' +  IntToStr(CurPageID));
  result := True;
End.
{
    This function is called by InnoSetup.
    It determines whether the "Tasks" page of the Wizard
    shall be displayed or not. If Excel is not installed
    on the system,this page will be skipped (returns TRUE).
}
function ShouldSkipPage(PageID: Integer): Boolean;
begin
  log('Trace: ' + 'ShouldSkipPage ' + IntToStr(PageID));
    Result := (PageID = wpSelectTasks) and Excelnotinstalled;
end;

{
    This function checks if any version of Excel from "MinVer"
    to "MaxVer" is installed by looking up an Excel-specific
    registry key. It is used in conjunction with a "Check"
    parameter in the [Files] section,and also by the
    InitializeWizard() function below. This can be used to
    install certain files only for specific versions of Excel.
    See Wikipedia for a list of Excel versions.
}
function IsExcelVersionInstalled(MinVer: integer; MaxVer: integer): boolean;
var
    xl: integer;
begin
  log('Trace : ' + 'IsExcelVersionInstalled' + '(' + IntToStr(MinVer) + ',' + IntToStr(MaxVer) + ')')
    for xl := MinVer to MaxVer do
        if RegKeyExists(HKEY_CURRENT_USER,'Software\Microsoft\Office\'+IntToStr(xl)+'.0\Excel\Options') then
        begin
            Result := true;
        end;
    Log('IsExcelVersionInstalled('+IntToStr(MinVer)+','+
        IntToStr(MaxVer)+') returns '+BoolToStr(result));
end;

产生的日志段:

01 2021-04-09 08:25:21.755 InitializeSetup():检查命令行...
02 2021-04-09 08:25:21.904 InitializeWizard():
03 2021-04-09 08:25:21.921 跟踪:IsExcelVersionInstalled(9,16)
04 2021-04-09 08:25:21.962 IsExcelVersionInstalled(9,16) 返回 TRUE
05 2021-04-09 08:25:21.983 跟踪:NextButtonClick CurPage 1
06 2021-04-09 08:25:22.001 跟踪:ShouldSkipPage 9
07 2021-04-09 08:25:22.014 跟踪:ShouldSkipPage 9
08 2021-04-09 08:25:23.688 跟踪:NextButtonClick CurPage 9
09 2021-04-09 08:25:23.696 跟踪:ShouldSkipPage 9
10 2021-04-09 08:25:23.699 跟踪:ShouldInstallFile (12,16)
11 2021-04-09 08:25:23.714 跟踪:IsExcelVersionInstalled(12,16)
12 2021-04-09 08:25:23.717 IsExcelVersionInstalled(12,16) 返回 TRUE
13 2021-04-09 08:25:23.734 GetDestDir():试图找到插件文件名称
14 2021-04-09 08:25:23.770 GetDestDir():找到第一个 Addins 键:版本 16,“AddIns”
15 2021-04-09 08:25:23.802 GetDestDir():安装到插件文件夹:C:\Users\djela\AppData\Roaming\Microsoft\AddIns

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)