David Eaton
David Eaton

Reputation: 564

Inno Setup Trying to create a new Install DirectX Template Product for Modular InnoSetup Dependency Installer

I am uing Modular Inno Setup

http://www.codeproject.com/Articles/20868/NET-Framework-1-1-2-0-3-5-Installer-for-InnoSetup#xx3672600xx

I am modifying an existing DirectX Detector method

http://www.vincenzo.net/isxkb/index.php?title=DirectX_-_How_to_detect_DirectX_version

I am trying to create a new product to install DirectX 9

Here is what I have so far.

//========================================
//detectDirectX.iss
//=======================================


[CustomMessages]
directx_title=DirectX End-User Runtimes (June 2010)

en.directx_size=95.6 MB
de.directx_size=95.6 MB

[Code]
const
    directx_url = 'http://download.microsoft.com/download/8/4/A/84A35BF1-DAFE-4AE8-82AF-AD2AE20B6B14/directx_Jun2010_redist.exe';


procedure DecodeVersion( verstr: String; var verint: array of Integer );
var
  i,p: Integer; s: string;
begin
  // initialize array
  verint := [0,0,0,0];
  i := 0;
  while ( (Length(verstr) > 0) and (i < 4) ) do
  begin
    p := pos('.', verstr);
    if p > 0 then
    begin
      if p = 1 then s:= '0' else s:= Copy( verstr, 1, p - 1 );
      verint[i] := StrToInt(s);
      i := i + 1;
      verstr := Copy( verstr, p+1, Length(verstr));
    end
    else
    begin
      verint[i] := StrToInt( verstr );
      verstr := '';
    end;
  end;

end;

// This function compares version string
// return -1 if ver1 < ver2
// return  0 if ver1 = ver2
// return  1 if ver1 > ver2
function CompareVersion2( ver1, ver2: String ) : Integer;
var
  verint1, verint2: array of Integer;
  i: integer;
begin

  SetArrayLength( verint1, 4 );
  DecodeVersion( ver1, verint1 );

  SetArrayLength( verint2, 4 );
  DecodeVersion( ver2, verint2 );

  Result := 0; i := 0;
  while ( (Result = 0) and ( i < 4 ) ) do
  begin
    if verint1[i] > verint2[i] then
      Result := 1
    else
      if verint1[i] < verint2[i] then
        Result := -1
      else
        Result := 0;

    i := i + 1;
  end;

end;

// DirectX version is stored in registry as 4.majorversion.minorversion
// DirectX 8.0 is 4.8.0
// DirectX 8.1 is 4.8.1
// DirectX 9.0 is 4.9.0

function GetDirectXVersion(): String;
var
  sVersion:  String;
begin
  sVersion := '';

  RegQueryStringValue( HKLM, 'SOFTWARE\Microsoft\DirectX', 'Version', sVersion );

  Result := sVersion;
end;

procedure directX();
var ErrorCode: Integer;
begin
  // in this case program needs at least directx 9.0
  if CompareVersion2( GetDirectXVersion(), '4.9.0') < 0 then
  begin
                AddProduct('directx_Jun2010_redist.exe',
                    '/t:' + ExpandConstant('{tmp}\DirectX') + ' /q /c',
                    CustomMessage('directx_title'),
                    CustomMessage('directx_size'),
                    directx_url,
                    false, false);

          //Is there any way to wait until directx_Jun2010_redist.exe has extracted it self before calling the next line? 
         ShellExec('open', ExpandConstant('{tmp}\DirectX\DXSETUP.exe'), '/silent', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode)
  end;
end;

In the main setup file whatever.iss under [RUN]

I included the file.

#include "scripts\products\custom\detectDirectX.iss"

In the main setup file whatever.iss under [CODE]

I included this method

directX();

The problem I am having is that it's downloading like it should and placing it in the Temp folder.

        AddProduct('directx_Jun2010_redist.exe',
            '/t:' + ExpandConstant('{tmp}\DirectX') + ' /q /c',
            CustomMessage('directx_title'),
            CustomMessage('directx_size'),
            directx_url,
            false, false);

since I am using the extra pars

'/t:' + ExpandConstant('{tmp}\DirectX') + ' /q /c'

once it's downloaded it creating a folder called DirectX and Extracting everything into it. which takes a bit.

It seems while directx_Jun2010_redist.exe is extracting..

ShellExec('open', ExpandConstant('{tmp}\DirectX\DXSETUP.exe'), '/silent', '', SW_SHOW, ewWaitUntilTerminated, ErrorCode)

is getting called to early and the file {tmp}\DirectX\DXSETUP.exe does not exist yet.. so it does not get called.

Once extracting is finished, the user clicks finish on the installed and it delete the Temp folder.

Is there a way to fix this problem so that after directx_Jun2010_redist.exe has extracted it's files it can run DXSETUP.exe before the installer finishes?

Upvotes: 1

Views: 2088

Answers (1)

David Eaton
David Eaton

Reputation: 564

Ok I think I finally got it to working correctly.. I had to move things around a bit.. it seems some things get called at start up but do not actually fire they are qued until later. With that In mind I was able to solve this problem. Here is the code.

In your main setupfile.iss add the following under [RUN]

Filename: "{tmp}\DirectX\DXSETUP.exe"; WorkingDir: "{tmp}\DirectX"; Parameters: "/silent"; Check: checkDirectX; Flags: waituntilterminated;


#include "scripts\products\custom\detectDirectX.iss"

Also in your main setupfile.iss add the following under [Code]

directX();

Here is the code for detectDirectX.iss

[CustomMessages]
directx_title=DirectX End-User Runtimes (June 2010)

en.directx_size=95.6 MB
de.directx_size=95.6 MB

[Code]
const
    directx_url = 'http://download.microsoft.com/download/8/4/A/84A35BF1-DAFE-4AE8-82AF-AD2AE20B6B14/directx_Jun2010_redist.exe';


procedure DecodeVersion( verstr: String; var verint: array of Integer );
var
  i,p: Integer; s: string;
begin
  // initialize array
  verint := [0,0,0,0];
  i := 0;
  while ( (Length(verstr) > 0) and (i < 4) ) do
  begin
    p := pos('.', verstr);
    if p > 0 then
    begin
      if p = 1 then s:= '0' else s:= Copy( verstr, 1, p - 1 );
      verint[i] := StrToInt(s);
      i := i + 1;
      verstr := Copy( verstr, p+1, Length(verstr));
    end
    else
    begin
      verint[i] := StrToInt( verstr );
      verstr := '';
    end;
  end;

end;

// This function compares version string
// return -1 if ver1 < ver2
// return  0 if ver1 = ver2
// return  1 if ver1 > ver2
function CompareDirectXVersion( ver1, ver2: String ) : Integer;
var
  verint1, verint2: array of Integer;
  i: integer;
begin

  SetArrayLength( verint1, 4 );
  DecodeVersion( ver1, verint1 );

  SetArrayLength( verint2, 4 );
  DecodeVersion( ver2, verint2 );

  Result := 0; i := 0;
  while ( (Result = 0) and ( i < 4 ) ) do
  begin
    if verint1[i] > verint2[i] then
      Result := 1
    else
      if verint1[i] < verint2[i] then
        Result := -1
      else
        Result := 0;

    i := i + 1;
  end;

end;

// DirectX version is stored in registry as 4.majorversion.minorversion
// DirectX 8.0 is 4.8.0
// DirectX 8.1 is 4.8.1
// DirectX 9.0 is 4.9.0

function GetDirectXVersion(): String;
var
  sVersion:  String;
begin
  sVersion := '';

  RegQueryStringValue( HKLM, 'SOFTWARE\Microsoft\DirectX', 'Version', sVersion );

  Result := sVersion;
end;


function checkDirectX(): boolean;
begin
  // in this case program needs at least directx 9.0
  if CompareDirectXVersion( GetDirectXVersion(), '4.9.0') < 0 then
  begin
       Result := true;
  end
  else
  begin
    Result := false;
   end;

end;



procedure directX();
begin
  // in this case program needs at least directx 9.0
  if CompareDirectXVersion( GetDirectXVersion(), '4.9.0') < 0 then
  begin
                AddProduct('directx_Jun2010_redist.exe',
                    '/t:' + ExpandConstant('{tmp}\DirectX') + ' /q /c',
                    CustomMessage('directx_title'),
                    CustomMessage('directx_size'),
                    directx_url,
                    false, false);

  end;
end;

I hope this helps someone else.. The Entire Idea is that I could ship my software and not worry about DirectX, at a minimum my software needed DirectX 9 some XP users may not have updated their machines.. Or some may have deleted it on vista or 7, Windows 8 ships out of the box with a newer version so no worries there.

Upvotes: 2

Related Questions