; Create installer for VPython using Inno Setup Compiler Version 5.
; Tested with Inno Setup 5.1.4 (www.innosetup.com)
; Assumes Python is already installed.

; This file is edited by config.status, which replaces all of the @...@ variables.
; PYTHON_VERSION is the major.minor version of Python.
; WIN32_PYTHON_VERSION is the same as PYTHON_VERSION, with the "." stripped out.
; PACKAGE_VERSION is the major.minor.tiny version of VPython.
; WIN32_CWD is the top-level build directory.
; WIN32_SRCDIR is the top-level source directory.

[Setup]
AppName=VPython for Python @PYTHON_VERSION@
AppVerName=VPython @PACKAGE_VERSION@
AppPublisherURL=http://vpython.org
DefaultDirName={code:MyConst}

SourceDir=C:\Python@WIN32_PYTHON_VERSION@
DisableProgramGroupPage=yes
DirExistsWarning=no
DisableStartupPrompt=yes
OutputBaseFilename=VPython-Win-Py@PYTHON_VERSION@-@PACKAGE_VERSION@
OutputDir=@WIN32_CWD@

[Files]
; Make sure that config-main.def has
; edit startup and autosave set to 1
; and help set for Visual before building package.
Source: "Lib\idlelib\config-main.def"; DestDir: "{app}\Lib\idlelib\"; Flags: uninsneveruninstall
;
Source: "@WIN32_CWD@\site-packages\*.dll"; DestDir: "{app}\Lib\site-packages\visual\"; Components: Visual
Source: "C:\MinGW\bin\mingwm10.dll"; DestDir: "{app}\Lib\site-packages\visual\"; Components: Visual
Source: "C:\MinGW\bin\boost_python.dll"; DestDir: "{app}\Lib\site-packages\visual\"; Components: Visual 
Source: "@WIN32_SRCDIR@\site-packages\visual\*.py"; DestDir: "{app}\Lib\site-packages\visual\"; Components: Visual
;
; Uncomment the following line after compiling .pyc files, and rebuild installer:
;Source: "Lib\site-packages\visual\*.pyc"; DestDir: "{app}\Lib\site-packages\visual\"; Components: Visual
; 
Source: "include\Numeric\*.h"; DestDir: "{app}\include\Numeric\"; Components: Numeric
Source: "Lib\site-packages\Numeric.pth"; DestDir: "{app}\Lib\site-packages\"; Components: Numeric
Source: "Lib\site-packages\Numeric\*.py"; DestDir: "{app}\Lib\site-packages\Numeric\"; Components: Numeric
Source: "Lib\site-packages\Numeric\*.pyc"; DestDir: "{app}\Lib\site-packages\Numeric\"; Components: Numeric
Source: "Lib\site-packages\Numeric\*.pyd"; DestDir: "{app}\Lib\site-packages\Numeric\"; Components: Numeric
Source: "Lib\site-packages\Numeric\FFT\*.py"; DestDir: "{app}\Lib\site-packages\Numeric\FFT\"; Components: Numeric
Source: "Lib\site-packages\Numeric\FFT\*.pyd"; DestDir: "{app}\Lib\site-packages\Numeric\FFT\"; Components: Numeric
Source: "Lib\site-packages\Numeric\MA\*.py"; DestDir: "{app}\Lib\site-packages\Numeric\MA\"; Components: Numeric
Source: "Lib\site-packages\Numeric\RNG\*.py"; DestDir: "{app}\Lib\site-packages\Numeric\RNG\"; Components: Numeric
Source: "Lib\site-packages\Numeric\RNG\*.pyd"; DestDir: "{app}\Lib\site-packages\Numeric\RNG\"; Components: Numeric
;
Source: "include\numarray\*.h"; DestDir: "{app}\include\numarray\"; Components: numarray
Source: "Lib\site-packages\numarray\*.py"; DestDir: "{app}\Lib\site-packages\numarray\"; Components: numarray
Source: "Lib\site-packages\numarray\*.pyc"; DestDir: "{app}\Lib\site-packages\numarray\"; Components: numarray
Source: "Lib\site-packages\numarray\*.pyd"; DestDir: "{app}\Lib\site-packages\numarray\"; Components: numarray
Source: "Lib\site-packages\numarray\LICENSE.txt"; DestDir: "{app}\Lib\site-packages\numarray\"; Components: numarray
Source: "Lib\site-packages\numarray\testdata.fits"; DestDir: "{app}\Lib\site-packages\numarray\"; Components: numarray
Source: "Lib\site-packages\numarray\codegenerator\*.py"; DestDir: "{app}\Lib\site-packages\numarray\codegenerator\"; Components: numarray
Source: "Lib\site-packages\numarray\convolve\*.py"; DestDir: "{app}\Lib\site-packages\numarray\convolve\"; Components: numarray
Source: "Lib\site-packages\numarray\convolve\*.pyd"; DestDir: "{app}\Lib\site-packages\numarray\convolve\"; Components: numarray
Source: "Lib\site-packages\numarray\examples\*.py"; DestDir: "{app}\Lib\site-packages\numarray\examples\"; Components: numarray
Source: "Lib\site-packages\numarray\examples\convolve\*.py"; DestDir: "{app}\Lib\site-packages\numarray\examples\convolve\"; Components: numarray
Source: "Lib\site-packages\numarray\examples\convolve\*.pyd"; DestDir: "{app}\Lib\site-packages\numarray\examples\convolve\"; Components: numarray
Source: "Lib\site-packages\numarray\fft\*.py"; DestDir: "{app}\Lib\site-packages\numarray\fft\"; Components: numarray
Source: "Lib\site-packages\numarray\fft\*.pyd"; DestDir: "{app}\Lib\site-packages\numarray\fft\"; Components: numarray
Source: "Lib\site-packages\numarray\image\*.py"; DestDir: "{app}\Lib\site-packages\numarray\image\"; Components: numarray
Source: "Lib\site-packages\numarray\image\*.pyd"; DestDir: "{app}\Lib\site-packages\numarray\image\"; Components: numarray
Source: "Lib\site-packages\numarray\linear_algebra\*.py"; DestDir: "{app}\Lib\site-packages\numarray\linear_algebra\"; Components: numarray
Source: "Lib\site-packages\numarray\linear_algebra\*.pyd"; DestDir: "{app}\Lib\site-packages\numarray\linear_algebra\"; Components: numarray
Source: "Lib\site-packages\numarray\ma\*.py"; DestDir: "{app}\Lib\site-packages\numarray\ma\"; Components: numarray
Source: "Lib\site-packages\numarray\ma\Legal.htm"; DestDir: "{app}\Lib\site-packages\numarray\ma\"; Components: numarray
Source: "Lib\site-packages\numarray\mlab\*.py"; DestDir: "{app}\Lib\site-packages\numarray\mlab\"; Components: numarray
Source: "Lib\site-packages\numarray\nd_image\*.py"; DestDir: "{app}\Lib\site-packages\numarray\nd_image\"; Components: numarray
Source: "Lib\site-packages\numarray\nd_image\*.pyd"; DestDir: "{app}\Lib\site-packages\numarray\nd_image\"; Components: numarray
Source: "Lib\site-packages\numarray\random_array\*.py"; DestDir: "{app}\Lib\site-packages\numarray\random_array\"; Components: numarray
Source: "Lib\site-packages\numarray\random_array\*.pyd"; DestDir: "{app}\Lib\site-packages\numarray\random_array\"; Components: numarray
;
Source: "@WIN32_SRCDIR@\examples\*.py"; DestDir: "{app}\Lib\site-packages\visual\examples\"; Components: Examples
;
Source: "@WIN32_SRCDIR@\docs\index.html"; DestDir: "{app}\Lib\site-packages\visual\docs\"; Components: Documentation
Source: "@WIN32_SRCDIR@\docs\visual\*.html"; DestDir: "{app}\Lib\site-packages\visual\docs\visual\"; Components: Documentation
Source: "@WIN32_SRCDIR@\docs\visual\*.gif"; DestDir: "{app}\Lib\site-packages\visual\docs\visual\"; Components: Documentation
Source: "@WIN32_SRCDIR@\docs\visual\*.css"; DestDir: "{app}\Lib\site-packages\visual\docs\visual\"; Components: Documentation
Source: "@WIN32_SRCDIR@\docs\visual\*.txt"; DestDir: "{app}\Lib\site-packages\visual\docs\visual\"; Components: Documentation
Source: "@WIN32_SRCDIR@\docs\visual\icons\*.gif"; DestDir: "{app}\Lib\site-packages\visual\docs\visual\icons\"; Components: Documentation

[Components]
Name: Visual; Description: "The Visual extension modue to Python"; Types: full compact custom; Flags: fixed
Name: Documentation; Description: "Documentation for the Visual extension to Python"; Types: full
Name: Examples; Description: "Example programs"; Types: full
Name: Numeric; Description: "Numeric Python 23.8 {code:NumericStatus|C:\Python@WIN32_PYTHON_VERSION@}"; Types: full; Check: CheckNumeric( 'C:\Python@WIN32_PYTHON_VERSION@' )
Name: numarray; Description: "Python Numarray 1.3.1 {code:NumarrayStatus|C:\Python@WIN32_PYTHON_VERSION@}"; Types: full; Check: CheckNumarray( 'C:\Python@WIN32_PYTHON_VERSION@' )

[Tasks]
Name: desktopicon; Description: "Create a desktop icon";

[Icons]
Name: "{userdesktop}\IDLE for VPython"; Filename: "{app}\pythonw.exe"; Parameters: "{app}\Lib\idlelib\idle.pyw"; WorkingDir: "{app}\Lib\site-packages\visual\examples"; IconFilename: "{app}\py.ico"; Tasks: desktopicon

; This code file contains a ShouldSkipPage function which looks
; for an appropriate version of python.exe,
; and if it is found we skip the "select a directory" page.

[Code]
program Setup;

// Try to discover where Python is actually installed.
function MyConst(Param: String): String;
var Exist1, Exist2: Boolean;
begin
    Exist1 := FileExists( ExpandConstant('{reg:HKLM\Software\Python\PythonCore\@PYTHON_VERSION@\InstallPath,}\python.exe'));
    if Exist1 then
      Result := ExpandConstant('{reg:HKLM\Software\Python\PythonCore\@PYTHON_VERSION@\InstallPath,}')
    else
      begin
      Exist2 := FileExists( ExpandConstant('{reg:HKCU\Software\Python\PythonCore\@PYTHON_VERSION@\InstallPath,}\python.exe'));
      if Exist2 then
        Result := ExpandConstant('{reg:HKCU\Software\Python\PythonCore\@PYTHON_VERSION@\InstallPath,}')
      else
        Result := 'C:\'
      end
end;

function ShouldSkipPage(CurPage: Integer): Boolean;
var Result1, Result2: Boolean;
begin
  case CurPage of
    wpSelectDir:
      begin
      Result1 := FileExists( ExpandConstant('{reg:HKLM\Software\Python\PythonCore\@PYTHON_VERSION@\InstallPath,}\python.exe'));
      Result2 := FileExists( ExpandConstant('{reg:HKCU\Software\Python\PythonCore\@PYTHON_VERSION@\InstallPath,}\python.exe'));
      Result := Result1 or Result2
      if not Result then
         MsgBox('Could not locate where Python @PYTHON_VERSION@ is installed.' #13 'You will be asked where python.exe is located.', mbInformation, MB_OK);
      end
    else
      Result := False;
  end;
end;

// Need a function to determine if Numeric is already installed.
function NumericAvailable( BasePath: String): Boolean;
begin
  Result := DirExists( BasePath + '\Lib\site-packages\Numeric');
end;

// Need a function to determine if numarray is already installed.
function NumarrayAvailable( BasePath: String): Boolean;
begin
  Result := DirExists( BasePath + '\Lib\site-packages\numarray');
end;

// Choose a modifying string for the user-visible Numeric component.
function NumericStatus( Param: String): String;
begin
  if NumericAvailable( Param) then
    Result := '(found)'
  else if NumarrayAvailable( Param) then
    Result := '(optional)'
  else
    Result := '(Numeric and/or Numarray must be selected)'
end;

// Choose a modifying string for the user-visible Numarray component.
function NumarrayStatus( Param: String): String;
begin
  if NumarrayAvailable( Param) then
    Result := '(found)'
  else if NumericAvailable( Param) then
    Result := '(optional)'
  else
    Result := '(Numeric and/or numarray must be selected)'
end;

// Don't clobber an existing installation of Numeric
function CheckNumeric( Param: String): Boolean;
begin
  Result := not NumericAvailable( Param);
end;

// Don't clobber an existing installation of Numarray
function CheckNumarray( Param: String): Boolean;
begin
  Result := not NumarrayAvailable( Param);
end;

// Verify that the user selected a sane combination of Numeric and/or Numarray
function NextButtonClick(CurPageID: Integer): Boolean;
begin
  case CurPageID of
    wpSelectComponents:
      begin
        if NumarrayAvailable( 'C:\Python@WIN32_PYTHON_VERSION@') or NumericAvailable( 'C:\Python@WIN32_PYTHON_VERSION@') then
          Result := True
        else if not IsComponentSelected( 'Numeric') and not IsComponentSelected( 'numarray') then
          begin
          Result := False
          MsgBox( 'You must select Numeric and/or Numarray', mbError, MB_OK)
          end
        else
          Result := True
      end
    else
      Result := True;
  end;
end;
