Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Inno Setup - Conditional DisableDirPage

Using Inno Setup 5.5.2 I am trying to conditionally skip selection of the installation directory depending on the existence of a path. Specifically, if the 'D:\' drive is available I want installation to it in a predefined location with no prompts, and if it is not available, provide prompts with a reasonable default.

I have code that works for DefaultDirName, but not for 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}

I have tried using functions for DisableDirPage that return Strings of 'yes' and 'no', as well as Integers of 0 and 1. I have also tried inlining the call to DirExists. All have produced the same compiler error.

My best guess is that it has something to do with the fact that DisableDirPage takes a tri-state yes, no, or auto. Is there a specific type associated with the tri-state logic that needs to be returned? The Inno Help on Scripted Constants only says:

The called function must have 1 String parameter named Param, and must return a String or a Boolean value depending on where the constant is used.

like image 947
Terrance Avatar asked Oct 11 '12 13:10

Terrance


1 Answers

Using the ShouldSkipPage event handler you can skip the directory selection page when the DefaultDrive constant path exists with the following script:

[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;
like image 89
TLama Avatar answered Oct 14 '22 22:10

TLama