Inno Setup - 条件DisableDirPage

时间:2012-10-11 13:44:08

标签: installation inno-setup

使用Inno Setup 5.5.2我试图有条件地跳过选择安装目录,具体取决于路径的存在。具体来说,如果“D:\”驱动器可用,我希望在没有提示的预定义位置安装它,如果它不可用,则提供合理默认值的提示。

我的代码适用于DefaultDirName,但不适用于DisableDirPage

[Code]
const 
   DefaultDrive = 'D:\';
   AppFolder = 'SomeDir';

function GetDefaultDir( Param: String ) : String;
begin
   if DirExists( DefaultDrive ) then begin
      Result := DefaultDrive + AppFolder;
   end else begin
      Result := ExpandConstant('{pf}\') + AppFolder;
   end;
end;

function DefaultDirValid( Param: String ) : Boolean;
begin
   Result := DirExists( DefaultDrive );
end;

[Setup]
; Works as expected
DefaultDirName={code:GetDefaultDir}

...

; Compiler Error - Value of [Setup] section directive "DisableDirPage" is invalid.
DisableDirPage={code:DefaultDirValid}

我尝试使用DisableDirPage的函数返回“是”和“否”的字符串,以及0和1的整数。我也尝试将调用内联到DirExists。所有这些都产生了相同的编译器错误。

我最好的猜测是,它与DisableDirPage采用三态yes,no或auto的事实有关。是否存在需要返回的三态逻辑关联的特定类型? Scripted Constants上的Inno帮助只说:

  

被调用函数必须有1个名为Param的String参数,并且必须返回String或Boolean值,具体取决于使用常量的位置。

1 个答案:

答案 0 :(得分:6)

使用ShouldSkipPage事件处理程序,当DefaultDrive常量路径存在时,您可以使用以下脚本跳过目录选择页面:

[Setup]
AppName=My Program
AppVersion=1.5
DefaultDirName={code:GetDefaultDir}

[Code]
const 
  DefaultDrive = 'D:\';
  AppFolder = 'Some Folder';

function GetDefaultDir(Param: string): string;
begin
  Result := DefaultDrive + AppFolder;
  if not DirExists(DefaultDrive) then
    Result := ExpandConstant('{pf}\') + AppFolder;
end;

function ShouldSkipPage(PageID: Integer): Boolean;
begin
  Result := (PageID = wpSelectDir) and DirExists(DefaultDrive);
end;