Call runvistrails.py when starting normally on windows.

This makes sure the paths are set up correctly.

[Dirs]
Name: {app}\vistrails
Name: {app}\examples; Components: examples; Tasks:
Name: {app}\extensions; Components: extensions; Tasks:
Name: {app}\doc; Components: usersguide; Tasks:
Name: {app}\scripts
Name: {app}\scripts\gen_vtk_examples
Name: {app}\libsrc
Name: {app}\{#python}
Name: {app}\{#python}\DLLs
Name: {app}\{#python}\include
Name: {app}\{#python}\Lib
Name: {app}\{#python}\libs
Name: {app}\{#python}\Scripts
Name: {app}\{#python}\sip
Name: {app}\{#python}\tcl
Name: {app}\{#python}\Tools
[Components]
Name: main; Description: Main Files; Types: full compact custom; Flags: fixed
Name: examples; Description: Example Files; Types: full
Name: extensions; Description: Extension Files; Types: full
Name: usersguide; Description: User's Guide PDF document; Types: full

[Icons]
Name: {group}\VisTrails; Filename: {app}\{#python}\python.exe; WorkingDir: {app}; IconFilename: {app}\vistrails\gui\resources\images\vistrails_icon_small.ico; IconIndex: 0; Components: ; Parameters: vistrails\run.py
Name: {commondesktop}\VisTrails; Filename: {app}\{#python}\python.exe; WorkingDir: {app}; IconFilename: {app}\vistrails\gui\resources\images\vistrails_icon_small.ico; IconIndex: 0; Parameters: """{app}\{#python}\python.exe"" ""runvistrails.py"" ""{#python}\python.exe"" ""vistrails\run.py"" ""{app}"""; Components: main; Tasks: desktopicon
Name: {group}\Uninstall VisTrails; Filename: {uninstallexe}
Name: {group}\VisTrails.pdf; Filename: {app}\doc\VisTrails.pdf; Components: usersguide
[Tasks]
Name: desktopicon; Description: Create a &desktop icon; GroupDescription: Additional icons:; Components: main
Name: desktopicon\common; Description: For all users; GroupDescription: Additional icons:; Components: main; Flags: exclusive
Name: desktopicon\user; Description: For the current user only; GroupDescription: Additional icons:; Components: main; Flags: exclusive unchecked
Name: quicklaunchicon; Description: Create a &Quick Launch icon; GroupDescription: Additional icons:; Components: main; Flags: unchecked
Name: associatefiles; Description: Associate *.vt files with VisTrails; GroupDescription: File Association:; Components: main
[_ISTool]
LogFile=Output\build.log
LogFileAppend=false
[Registry]
Root: HKCR; Subkey: .vt; ValueType: string; ValueData: VisTrailsFile; Flags: uninsdeletevalue; Tasks: associatefiles
Root: HKCR; Subkey: VisTrailsFile; ValueType: string; ValueData: VisTrails File; Flags: uninsdeletekey; Tasks: associatefiles
Root: HKCR; Subkey: VisTrailsFile\DefaultIcon; ValueType: string; ValueData: {app}\vistrails\gui\resources\images\vistrails_icon_small.ico; Tasks: associatefiles; Flags: uninsdeletekey
Root: HKCR; Subkey: VisTrailsFile\shell\open\command; ValueType: string; ValueData: """{app}\{#python}\python.exe"" ""{app}\runvistrails.py"" ""{app}\{#python}\python.exe"" ""{app}\vistrails\run.py"" ""{app}"" ""%1"""; Tasks: associatefiles; Flags: uninsdeletekey
Root: HKCR; Subkey: .vtl; ValueType: string; ValueData: VisTrailsFile; Flags: uninsdeletevalue; Tasks: associatefiles
[InstallDelete]
Name: {app}\dot.exe; Type: files
Name: {app}\freetype6.dll; Type: files
Name: {app}\jpeg.dll; Type: files
Name: {app}\libexpat.dll; Type: files
Name: {app}\libexpatw.dll; Type: files
Name: {app}\png.dll; Type: files
Name: {app}\z.dll; Type: files
Name: {app}\zlib1.dll; Type: files
Name: {app}\{#python}; Type: filesandordirs
Name: {app}\*.pyd; Type: files
Name: {app}\dgnlib.dll; Type: files
Name: {app}\_Xdmf.dll; Type: files
Name: {app}\geotiff.dll; Type: files
Name: {app}\libmysql.dll; Type: files
Name: {app}\vistrails; Type: filesandordirs
Name: {app}\vistrails\packages\gridfield; Type: filesandordirs
Name: {app}\lib\site-packages; Type: filesandordirs
[Run]
Filename: {tmp}\vcredist_{#bits}.exe; Parameters: /Q; Components: ; Tasks:

[ThirdPartySettings]
CompileLogFile=Output\build.log
CompileLogMethod=append

[PreCompile]
Name: "C:\{#python_src}\python.exe"; Parameters: "C:\Users\vistrails\code\vistrails\scripts\dist\windows\Input\download_usersguide.py"; Flags: abortonerror cmdprompt

[PreCompile]
Name: "C:\{#python_src}\python.exe"; Parameters: "-m compileall C:\Users\vistrails\code"; Flags: abortonerror cmdprompt

[Code]
var
  FinishedInstall: Boolean;
function CustomAppDir(Param: String): String;
begin
  if IsAdminLoggedOn then
    Result := ExpandConstant('{pf}')
  else
    Result := ExpandConstant('{userappdata}')
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
    FinishedInstall := True;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
end;

procedure DeleteVCRedistRuntimeTemporaryFiles();
var
   i : Integer;
   byCounter : Byte;
   byDrive : Byte;
   strFile1, strFile2, strFile3 : String;
   strRootDrivePath : String;
   //totally there are 24 files to be deleted
   arrFiles : Array [1..24] Of String;
begin

   //We will check the following root drives
   //C, D, E, F, G, H, I, J, K, L, M
   For byCounter := 67 to 77 do
   Begin
      strRootDrivePath := Chr(byCounter) + ':\';
      arrFiles[1] := strRootDrivePath + 'vcredist.bmp';
      arrFiles[2] := strRootDrivePath + 'VC_RED.cab';
      arrFiles[3] := strRootDrivePath + 'VC_RED.MSI';

      //If these 3 files then we have found the right
      //drive in which the VC runtime files are extracted
      If (FileExists(arrFiles[1]) And
          FileExists(arrFiles[2]) And
          FileExists(arrFiles[3])) Then
      Begin

          arrFiles[4] := strRootDrivePath + 'eula.1028.txt';
          arrFiles[5] := strRootDrivePath + 'eula.1031.txt';
          arrFiles[6] := strRootDrivePath + 'eula.1033.txt';
          arrFiles[7] := strRootDrivePath + 'eula.1036.txt';
          arrFiles[8] := strRootDrivePath + 'eula.1040.txt';
          arrFiles[9] := strRootDrivePath + 'eula.1041.txt';
          arrFiles[10] := strRootDrivePath + 'eula.1042.txt';
          arrFiles[11] := strRootDrivePath + 'eula.2052.txt';
          arrFiles[12] := strRootDrivePath + 'eula.3082.txt';
          arrFiles[13] := strRootDrivePath + 'globdata.ini';
          arrFiles[14] := strRootDrivePath + 'install.exe';
          arrFiles[15] := strRootDrivePath + 'install.ini';
          arrFiles[16] := strRootDrivePath + 'install.res.1028.dll';
          arrFiles[17] := strRootDrivePath + 'install.res.1031.dll';
          arrFiles[18] := strRootDrivePath + 'install.res.1033.dll';
          arrFiles[19] := strRootDrivePath + 'install.res.1036.dll';
          arrFiles[20] := strRootDrivePath + 'install.res.1040.dll';
          arrFiles[21] := strRootDrivePath + 'install.res.1041.dll';
          arrFiles[22] := strRootDrivePath + 'install.res.1042.dll';
          arrFiles[23] := strRootDrivePath + 'install.res.2052.dll';
          arrFiles[24] := strRootDrivePath + 'install.res.3082.dll';

          For i := 1 to 24 Do
          Begin
            DeleteFile(arrFiles[i]);
          End;

          //Now that we have found and deleted all the files
          //we will break
          Break;
      End;
   End;
End;

procedure DeinitializeSetup();
var
  qvtk: String;
begin
  if FinishedInstall then begin
      qvtk := ExpandConstant('{app}') + '\vistrails\packages\spreadsheet\widgets\QVTKWidget';
    if DirExists(qvtk) then
    DelTree(qvtk, True, True, True);
  end;
  DeleteVCRedistRuntimeTemporaryFiles();
end;

[InnoIDE_Settings]
LogFile=Output\build.log
LogFileOverwrite=false

[Dirs]
Name: {app}\vistrails
Name: {app}\examples; Components: examples; Tasks:
Name: {app}\extensions; Components: extensions; Tasks:
Name: {app}\doc; Components: usersguide; Tasks:
Name: {app}\scripts
Name: {app}\scripts\gen_vtk_examples
Name: {app}\libsrc
Name: {app}\{#python}
Name: {app}\{#python}\DLLs
Name: {app}\{#python}\include
Name: {app}\{#python}\Lib
Name: {app}\{#python}\libs
Name: {app}\{#python}\Scripts
Name: {app}\{#python}\sip
Name: {app}\{#python}\tcl
Name: {app}\{#python}\Tools
[Components]
Name: main; Description: Main Files; Types: full compact custom; Flags: fixed
Name: examples; Description: Example Files; Types: full
Name: extensions; Description: Extension Files; Types: full
Name: usersguide; Description: User's Guide PDF document; Types: full

[Icons]
Name: {group}\VisTrails; Filename: {app}\{#python}\python.exe; WorkingDir: {app}; IconFilename: {app}\vistrails\gui\resources\images\vistrails_icon_small.ico; IconIndex: 0; Components: ; Parameters: vistrails\run.py
Name: {commondesktop}\VisTrails; Filename: {app}\{#python}\python.exe; WorkingDir: {app}; IconFilename: {app}\vistrails\gui\resources\images\vistrails_icon_small.ico; IconIndex: 0; Parameters: vistrails\run.py; Components: main; Tasks: desktopicon
Name: {group}\Uninstall VisTrails; Filename: {uninstallexe}
Name: {group}\VisTrails.pdf; Filename: {app}\doc\VisTrails.pdf; Components: usersguide
[Tasks]
Name: desktopicon; Description: Create a &desktop icon; GroupDescription: Additional icons:; Components: main
Name: desktopicon\common; Description: For all users; GroupDescription: Additional icons:; Components: main; Flags: exclusive
Name: desktopicon\user; Description: For the current user only; GroupDescription: Additional icons:; Components: main; Flags: exclusive unchecked
Name: quicklaunchicon; Description: Create a &Quick Launch icon; GroupDescription: Additional icons:; Components: main; Flags: unchecked
Name: associatefiles; Description: Associate *.vt files with VisTrails; GroupDescription: File Association:; Components: main
[_ISTool]
LogFile=Output\build.log
LogFileAppend=false
[Registry]
Root: HKCR; Subkey: .vt; ValueType: string; ValueData: VisTrailsFile; Flags: uninsdeletevalue; Tasks: associatefiles
Root: HKCR; Subkey: VisTrailsFile; ValueType: string; ValueData: VisTrails File; Flags: uninsdeletekey; Tasks: associatefiles
Root: HKCR; Subkey: VisTrailsFile\DefaultIcon; ValueType: string; ValueData: {app}\vistrails\gui\resources\images\vistrails_icon_small.ico; Tasks: associatefiles; Flags: uninsdeletekey
Root: HKCR; Subkey: VisTrailsFile\shell\open\command; ValueType: string; ValueData: """{app}\{#python}\python.exe"" ""{app}\runvistrails.py"" ""{app}\{#python}\python.exe"" ""{app}\vistrails\run.py"" ""{app}"" ""%1"""; Tasks: associatefiles; Flags: uninsdeletekey
Root: HKCR; Subkey: .vtl; ValueType: string; ValueData: VisTrailsFile; Flags: uninsdeletevalue; Tasks: associatefiles
[InstallDelete]
Name: {app}\dot.exe; Type: files
Name: {app}\freetype6.dll; Type: files
Name: {app}\jpeg.dll; Type: files
Name: {app}\libexpat.dll; Type: files
Name: {app}\libexpatw.dll; Type: files
Name: {app}\png.dll; Type: files
Name: {app}\z.dll; Type: files
Name: {app}\zlib1.dll; Type: files
Name: {app}\{#python}; Type: filesandordirs
Name: {app}\*.pyd; Type: files
Name: {app}\dgnlib.dll; Type: files
Name: {app}\_Xdmf.dll; Type: files
Name: {app}\geotiff.dll; Type: files
Name: {app}\libmysql.dll; Type: files
Name: {app}\vistrails; Type: filesandordirs
Name: {app}\vistrails\packages\gridfield; Type: filesandordirs
Name: {app}\lib\site-packages; Type: filesandordirs
[Run]
Filename: {tmp}\vcredist_{#bits}.exe; Parameters: /Q; Components: ; Tasks:

[ThirdPartySettings]
CompileLogFile=Output\build.log
CompileLogMethod=append

[PreCompile]
Name: "C:\{#python_src}\python.exe"; Parameters: "C:\Users\vistrails\code\vistrails\scripts\dist\windows\Input\download_usersguide.py"; Flags: abortonerror cmdprompt

[PreCompile]
Name: "C:\{#python_src}\python.exe"; Parameters: "-m compileall C:\Users\vistrails\code"; Flags: abortonerror cmdprompt

[Code]
var
  FinishedInstall: Boolean;
function CustomAppDir(Param: String): String;
begin
  if IsAdminLoggedOn then
    Result := ExpandConstant('{pf}')
  else
    Result := ExpandConstant('{userappdata}')
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssPostInstall then
    FinishedInstall := True;
end;

procedure CurPageChanged(CurPageID: Integer);
begin
end;

procedure DeleteVCRedistRuntimeTemporaryFiles();
var
   i : Integer;
   byCounter : Byte;
   byDrive : Byte;
   strFile1, strFile2, strFile3 : String;
   strRootDrivePath : String;
   //totally there are 24 files to be deleted
   arrFiles : Array [1..24] Of String;
begin

   //We will check the following root drives
   //C, D, E, F, G, H, I, J, K, L, M
   For byCounter := 67 to 77 do
   Begin
      strRootDrivePath := Chr(byCounter) + ':\';
      arrFiles[1] := strRootDrivePath + 'vcredist.bmp';
      arrFiles[2] := strRootDrivePath + 'VC_RED.cab';
      arrFiles[3] := strRootDrivePath + 'VC_RED.MSI';

      //If these 3 files then we have found the right
      //drive in which the VC runtime files are extracted
      If (FileExists(arrFiles[1]) And
          FileExists(arrFiles[2]) And
          FileExists(arrFiles[3])) Then
      Begin

          arrFiles[4] := strRootDrivePath + 'eula.1028.txt';
          arrFiles[5] := strRootDrivePath + 'eula.1031.txt';
          arrFiles[6] := strRootDrivePath + 'eula.1033.txt';
          arrFiles[7] := strRootDrivePath + 'eula.1036.txt';
          arrFiles[8] := strRootDrivePath + 'eula.1040.txt';
          arrFiles[9] := strRootDrivePath + 'eula.1041.txt';
          arrFiles[10] := strRootDrivePath + 'eula.1042.txt';
          arrFiles[11] := strRootDrivePath + 'eula.2052.txt';
          arrFiles[12] := strRootDrivePath + 'eula.3082.txt';
          arrFiles[13] := strRootDrivePath + 'globdata.ini';
          arrFiles[14] := strRootDrivePath + 'install.exe';
          arrFiles[15] := strRootDrivePath + 'install.ini';
          arrFiles[16] := strRootDrivePath + 'install.res.1028.dll';
          arrFiles[17] := strRootDrivePath + 'install.res.1031.dll';
          arrFiles[18] := strRootDrivePath + 'install.res.1033.dll';
          arrFiles[19] := strRootDrivePath + 'install.res.1036.dll';
          arrFiles[20] := strRootDrivePath + 'install.res.1040.dll';
          arrFiles[21] := strRootDrivePath + 'install.res.1041.dll';
          arrFiles[22] := strRootDrivePath + 'install.res.1042.dll';
          arrFiles[23] := strRootDrivePath + 'install.res.2052.dll';
          arrFiles[24] := strRootDrivePath + 'install.res.3082.dll';

          For i := 1 to 24 Do
          Begin
            DeleteFile(arrFiles[i]);
          End;

          //Now that we have found and deleted all the files
          //we will break
          Break;
      End;
   End;
End;

procedure DeinitializeSetup();
var
  qvtk: String;
begin
  if FinishedInstall then begin
      qvtk := ExpandConstant('{app}') + '\vistrails\packages\spreadsheet\widgets\QVTKWidget';
    if DirExists(qvtk) then
    DelTree(qvtk, True, True, True);
  end;
  DeleteVCRedistRuntimeTemporaryFiles();
end;

[InnoIDE_Settings]
LogFile=Output\build.log
LogFileOverwrite=false


Changed Qt directory on Windows build server.

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "glimpse"
#define MyAppVersion "0.1"
#define MyAppPublisher "Hochschule Augsburg"
#define MyAppURL "http://www.measure-it.de"
#define MyAppExeName "mobile.exe"

#define QtDir         "C:\Qt\5.3\msvc2013_64"
#define ThirdPartyDir "C:\glimpse_3rdparty"
#define BuildDir      "../"

[Setup]
; Restrict to 64 bit
ArchitecturesInstallIn64BitMode=x64
ArchitecturesAllowed=x64

; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{CF7758A3-6828-4C4F-8C34-48FE8E75251B}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename={#MyAppName}_{#MyAppVersion}_x64_setup
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "german"; MessagesFile: "compiler:Languages\German.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1

[Files]
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
; Third party installation files

Source: "{#ThirdPartyDir}\vcredist_x64_2008_pac.exe"; DestDir: {tmp}; Flags: deleteafterinstall
Source: "{#ThirdPartyDir}\vcredist_x64_2013.exe"; DestDir: {tmp}; Flags: deleteafterinstall
Source: "{#ThirdPartyDir}\Win64OpenSSL_Light-1_0_1h.exe"; DestDir: {tmp}; Flags: deleteafterinstall
Source: "{#ThirdPartyDir}\WinPcap_4_1_3.exe"; DestDir: {tmp}; Flags: deleteafterinstall

; Glimpse Files

; Libclient
Source: "{#BuildDir}\build-install\client.dll"; DestDir: "{app}"; Flags: ignoreversion

; Commandline
Source: "{#BuildDir}\build-install\mplane.exe"; DestDir: "{app}"; Flags: ignoreversion

; Mobile Ui
Source: "{#BuildDir}\build-install\mobile.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#BuildDir}\src\mobile\qml\*"; DestDir: "{app}\qml"; Flags: ignoreversion createallsubdirs recursesubdirs
Source: "{#BuildDir}\build-install\qt.conf"; DestDir: "{app}"; Flags: ignoreversion

; Url Files
Source: "urls\*.url"; DestDir: "{app}\urls"; Flags: ignoreversion createallsubdirs recursesubdirs

; Qt Files
Source: "{#QtDir}\plugins\*"; DestDir: "{app}\plugins"; Excludes: "*d.dll,*.pdb"; Flags: ignoreversion createallsubdirs recursesubdirs
Source: "{#QtDir}\qml\*"; DestDir: "{app}\plugins\qml"; Excludes: "*d.dll,*.pdb,*.qmltypes"; Flags: ignoreversion createallsubdirs recursesubdirs

Source: "{#QtDir}\bin\d3dcompiler_47.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\icudt52.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\icuin52.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\icuuc52.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\libEGL.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\libGLESv2.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\Qt5Core.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\Qt5Gui.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\Qt5Network.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\Qt5Qml.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\Qt5Quick.dll"; DestDir: "{app}"; Flags: ignoreversion
;Source: "{#QtDir}\bin\Qt5V8.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\Qt5Widgets.dll"; DestDir: "{app}"; Flags: ignoreversion

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; WorkingDir: "{app}"
Name: "{group}\{cm:WebsiteUrls}\Glimpse"; Filename: "{app}\urls\measure-it.url"
Name: "{group}\{cm:WebsiteUrls}\Hochschule Augsburg"; Filename: "{app}\urls\hsa.url"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; WorkingDir: "{app}"; Tasks: quicklaunchicon

[Run]
; Install all needed programs silently despite WinPcap which cannot be installed silently
Filename: "{tmp}\vcredist_x64_2008_pac.exe"; Check: VCRedist2008PacNeedsInstall; Parameters: /q
Filename: "{tmp}\vcredist_x64_2013.exe"; Check: VCRedist2013NeedsInstall; Parameters: /SILENT
Filename: "{tmp}\Win64OpenSSL_Light-1_0_1h.exe"; Parameters: /SILENT
Filename: "{tmp}\WinPcap_4_1_3.exe"

Filename: "{app}\{#MyAppExeName}"; WorkingDir: "{app}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

[CustomMessages]
german.WebsiteUrls=Webseiten
english.WebsiteUrls=Websites

[Messages]
BeveledLabel=Hochschule Augsburg

[Code]
#IFDEF UNICODE
  #DEFINE AW "W"
#ELSE
  #DEFINE AW "A"
#ENDIF
type
  INSTALLSTATE = Longint;
const
  INSTALLSTATE_INVALIDARG = -2;  // An invalid parameter was passed to the function.
  INSTALLSTATE_UNKNOWN = -1;     // The product is neither advertised or installed.
  INSTALLSTATE_ADVERTISED = 1;   // The product is advertised but not installed.
  INSTALLSTATE_ABSENT = 2;       // The product is installed for a different user.
  INSTALLSTATE_DEFAULT = 5;      // The product is installed for the current user.

  VC_2005_REDIST_X86 = '{A49F249F-0C91-497F-86DF-B2585E8E76B7}';
  VC_2005_REDIST_X64 = '{6E8E85E8-CE4B-4FF5-91F7-04999C9FAE6A}';
  VC_2005_REDIST_IA64 = '{03ED71EA-F531-4927-AABD-1C31BCE8E187}';
  VC_2005_SP1_REDIST_X86 = '{7299052B-02A4-4627-81F2-1818DA5D550D}';
  VC_2005_SP1_REDIST_X64 = '{071C9B48-7C32-4621-A0AC-3F809523288F}';
  VC_2005_SP1_REDIST_IA64 = '{0F8FB34E-675E-42ED-850B-29D98C2ECE08}';
  VC_2005_SP1_ATL_SEC_UPD_REDIST_X86 = '{837B34E3-7C30-493C-8F6A-2B0F04E2912C}';
  VC_2005_SP1_ATL_SEC_UPD_REDIST_X64 = '{6CE5BAE9-D3CA-4B99-891A-1DC6C118A5FC}';
  VC_2005_SP1_ATL_SEC_UPD_REDIST_IA64 = '{85025851-A784-46D8-950D-05CB3CA43A13}';

  VC_2008_REDIST_X86 = '{FF66E9F6-83E7-3A3E-AF14-8DE9A809A6A4}';
  VC_2008_REDIST_X64 = '{350AA351-21FA-3270-8B7A-835434E766AD}';
  VC_2008_REDIST_IA64 = '{2B547B43-DB50-3139-9EBE-37D419E0F5FA}';
  VC_2008_SP1_REDIST_X86 = '{9A25302D-30C0-39D9-BD6F-21E6EC160475}';
  VC_2008_SP1_REDIST_X64 = '{8220EEFE-38CD-377E-8595-13398D740ACE}';
  VC_2008_SP1_REDIST_IA64 = '{5827ECE1-AEB0-328E-B813-6FC68622C1F9}';
  VC_2008_SP1_ATL_SEC_UPD_REDIST_X86 = '{1F1C2DFC-2D24-3E06-BCB8-725134ADF989}';
  VC_2008_SP1_ATL_SEC_UPD_REDIST_X64 = '{4B6C7001-C7D6-3710-913E-5BC23FCE91E6}';
  VC_2008_SP1_ATL_SEC_UPD_REDIST_IA64 = '{977AD349-C2A8-39DD-9273-285C08987C7B}';
  VC_2008_SP1_MFC_SEC_UPD_REDIST_X86 = '{9BE518E6-ECC6-35A9-88E4-87755C07200F}';
  VC_2008_SP1_MFC_SEC_UPD_REDIST_X64 = '{5FCE6D76-F5DC-37AB-B2B8-22AB8CEDB1D4}';
  VC_2008_SP1_MFC_SEC_UPD_REDIST_IA64 = '{515643D1-4E9E-342F-A75A-D1F16448DC04}';

  VC_2010_REDIST_X86 = '{196BB40D-1578-3D01-B289-BEFC77A11A1E}';
  VC_2010_REDIST_X64 = '{DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}';
  VC_2010_REDIST_IA64 = '{C1A35166-4301-38E9-BA67-02823AD72A1B}';
  VC_2010_SP1_REDIST_X86 = '{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}';
  VC_2010_SP1_REDIST_X64 = '{1D8E6291-B0D5-35EC-8441-6616F567A0F7}';
  VC_2010_SP1_REDIST_IA64 = '{88C73C1C-2DE5-3B01-AFB8-B46EF4AB41CD}';

  VC_2013_REDIST_X86 = '{CE085A78-074E-4823-8DC1-8A721B94B76D}'; // 12.0.21005
  VC_2013_REDIST_X64 = '{7F51BDB9-EE21-49EE-94D6-90AFC321780E}';

function MsiQueryProductState(szProduct: string): INSTALLSTATE;
  external 'MsiQueryProductState{#AW}@msi.dll stdcall';

function VCVersionInstalled(const ProductID: string): Boolean;
begin
  Result := MsiQueryProductState(ProductID) = INSTALLSTATE_DEFAULT;
end;

function VCRedist2008PacNeedsInstall: Boolean;
begin
  // here the Result must be True when you need to install your VCRedist
  // or False when you don't need to, so now it's upon you how you build
  // this statement, the following won't install your VC redist only when
  // the Visual C++ 2010 Redist (x86) and Visual C++ 2010 SP1 Redist(x86)
  // are installed for the current user
  Result := not (VCVersionInstalled(VC_2008_REDIST_X64) and
    VCVersionInstalled(VC_2008_SP1_REDIST_X64));
end;

function VCRedist2013NeedsInstall: Boolean;
begin
  Result := not (VCVersionInstalled(VC_2013_REDIST_X64));
end;

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "glimpse"
#define MyAppVersion "0.1"
#define MyAppPublisher "Hochschule Augsburg"
#define MyAppURL "http://www.measure-it.de"
#define MyAppExeName "mobile.exe"

#define QtDir         "C:\Qt\Qt5.3.0\5.3\msvc2013_64"
#define ThirdPartyDir "C:\glimpse_3rdparty"
#define BuildDir      "../"

[Setup]
; Restrict to 64 bit
ArchitecturesInstallIn64BitMode=x64
ArchitecturesAllowed=x64

; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{CF7758A3-6828-4C4F-8C34-48FE8E75251B}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename={#MyAppName}_{#MyAppVersion}_x64_setup
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "german"; MessagesFile: "compiler:Languages\German.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked
Name: "quicklaunchicon"; Description: "{cm:CreateQuickLaunchIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked; OnlyBelowVersion: 0,6.1

[Files]
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
; Third party installation files

Source: "{#ThirdPartyDir}\vcredist_x64_2008_pac.exe"; DestDir: {tmp}; Flags: deleteafterinstall
Source: "{#ThirdPartyDir}\vcredist_x64_2013.exe"; DestDir: {tmp}; Flags: deleteafterinstall
Source: "{#ThirdPartyDir}\Win64OpenSSL_Light-1_0_1h.exe"; DestDir: {tmp}; Flags: deleteafterinstall
Source: "{#ThirdPartyDir}\WinPcap_4_1_3.exe"; DestDir: {tmp}; Flags: deleteafterinstall

; Glimpse Files

; Libclient
Source: "{#BuildDir}\build-install\client.dll"; DestDir: "{app}"; Flags: ignoreversion

; Commandline
Source: "{#BuildDir}\build-install\mplane.exe"; DestDir: "{app}"; Flags: ignoreversion

; Mobile Ui
Source: "{#BuildDir}\build-install\mobile.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#BuildDir}\src\mobile\qml\*"; DestDir: "{app}\qml"; Flags: ignoreversion createallsubdirs recursesubdirs
Source: "{#BuildDir}\build-install\qt.conf"; DestDir: "{app}"; Flags: ignoreversion

; Url Files
Source: "urls\*.url"; DestDir: "{app}\urls"; Flags: ignoreversion createallsubdirs recursesubdirs

; Qt Files
Source: "{#QtDir}\plugins\*"; DestDir: "{app}\plugins"; Excludes: "*d.dll,*.pdb"; Flags: ignoreversion createallsubdirs recursesubdirs
Source: "{#QtDir}\qml\*"; DestDir: "{app}\plugins\qml"; Excludes: "*d.dll,*.pdb,*.qmltypes"; Flags: ignoreversion createallsubdirs recursesubdirs

Source: "{#QtDir}\bin\d3dcompiler_47.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\icudt52.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\icuin52.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\icuuc52.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\libEGL.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\libGLESv2.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\Qt5Core.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\Qt5Gui.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\Qt5Network.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\Qt5Qml.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\Qt5Quick.dll"; DestDir: "{app}"; Flags: ignoreversion
;Source: "{#QtDir}\bin\Qt5V8.dll"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#QtDir}\bin\Qt5Widgets.dll"; DestDir: "{app}"; Flags: ignoreversion

[Icons]
Name: "{group}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; WorkingDir: "{app}"
Name: "{group}\{cm:WebsiteUrls}\Glimpse"; Filename: "{app}\urls\measure-it.url"
Name: "{group}\{cm:WebsiteUrls}\Hochschule Augsburg"; Filename: "{app}\urls\hsa.url"
Name: "{commondesktop}\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; Tasks: desktopicon
Name: "{userappdata}\Microsoft\Internet Explorer\Quick Launch\{#MyAppName}"; Filename: "{app}\{#MyAppExeName}"; WorkingDir: "{app}"; Tasks: quicklaunchicon

[Run]
; Install all needed programs silently despite WinPcap which cannot be installed silently
Filename: "{tmp}\vcredist_x64_2008_pac.exe"; Check: VCRedist2008PacNeedsInstall; Parameters: /q
Filename: "{tmp}\vcredist_x64_2013.exe"; Check: VCRedist2013NeedsInstall; Parameters: /SILENT
Filename: "{tmp}\Win64OpenSSL_Light-1_0_1h.exe"; Parameters: /SILENT
Filename: "{tmp}\WinPcap_4_1_3.exe"

Filename: "{app}\{#MyAppExeName}"; WorkingDir: "{app}"; Description: "{cm:LaunchProgram,{#StringChange(MyAppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent

[CustomMessages]
german.WebsiteUrls=Webseiten
english.WebsiteUrls=Websites

[Messages]
BeveledLabel=Hochschule Augsburg

[Code]
#IFDEF UNICODE
  #DEFINE AW "W"
#ELSE
  #DEFINE AW "A"
#ENDIF
type
  INSTALLSTATE = Longint;
const
  INSTALLSTATE_INVALIDARG = -2;  // An invalid parameter was passed to the function.
  INSTALLSTATE_UNKNOWN = -1;     // The product is neither advertised or installed.
  INSTALLSTATE_ADVERTISED = 1;   // The product is advertised but not installed.
  INSTALLSTATE_ABSENT = 2;       // The product is installed for a different user.
  INSTALLSTATE_DEFAULT = 5;      // The product is installed for the current user.

  VC_2005_REDIST_X86 = '{A49F249F-0C91-497F-86DF-B2585E8E76B7}';
  VC_2005_REDIST_X64 = '{6E8E85E8-CE4B-4FF5-91F7-04999C9FAE6A}';
  VC_2005_REDIST_IA64 = '{03ED71EA-F531-4927-AABD-1C31BCE8E187}';
  VC_2005_SP1_REDIST_X86 = '{7299052B-02A4-4627-81F2-1818DA5D550D}';
  VC_2005_SP1_REDIST_X64 = '{071C9B48-7C32-4621-A0AC-3F809523288F}';
  VC_2005_SP1_REDIST_IA64 = '{0F8FB34E-675E-42ED-850B-29D98C2ECE08}';
  VC_2005_SP1_ATL_SEC_UPD_REDIST_X86 = '{837B34E3-7C30-493C-8F6A-2B0F04E2912C}';
  VC_2005_SP1_ATL_SEC_UPD_REDIST_X64 = '{6CE5BAE9-D3CA-4B99-891A-1DC6C118A5FC}';
  VC_2005_SP1_ATL_SEC_UPD_REDIST_IA64 = '{85025851-A784-46D8-950D-05CB3CA43A13}';

  VC_2008_REDIST_X86 = '{FF66E9F6-83E7-3A3E-AF14-8DE9A809A6A4}';
  VC_2008_REDIST_X64 = '{350AA351-21FA-3270-8B7A-835434E766AD}';
  VC_2008_REDIST_IA64 = '{2B547B43-DB50-3139-9EBE-37D419E0F5FA}';
  VC_2008_SP1_REDIST_X86 = '{9A25302D-30C0-39D9-BD6F-21E6EC160475}';
  VC_2008_SP1_REDIST_X64 = '{8220EEFE-38CD-377E-8595-13398D740ACE}';
  VC_2008_SP1_REDIST_IA64 = '{5827ECE1-AEB0-328E-B813-6FC68622C1F9}';
  VC_2008_SP1_ATL_SEC_UPD_REDIST_X86 = '{1F1C2DFC-2D24-3E06-BCB8-725134ADF989}';
  VC_2008_SP1_ATL_SEC_UPD_REDIST_X64 = '{4B6C7001-C7D6-3710-913E-5BC23FCE91E6}';
  VC_2008_SP1_ATL_SEC_UPD_REDIST_IA64 = '{977AD349-C2A8-39DD-9273-285C08987C7B}';
  VC_2008_SP1_MFC_SEC_UPD_REDIST_X86 = '{9BE518E6-ECC6-35A9-88E4-87755C07200F}';
  VC_2008_SP1_MFC_SEC_UPD_REDIST_X64 = '{5FCE6D76-F5DC-37AB-B2B8-22AB8CEDB1D4}';
  VC_2008_SP1_MFC_SEC_UPD_REDIST_IA64 = '{515643D1-4E9E-342F-A75A-D1F16448DC04}';

  VC_2010_REDIST_X86 = '{196BB40D-1578-3D01-B289-BEFC77A11A1E}';
  VC_2010_REDIST_X64 = '{DA5E371C-6333-3D8A-93A4-6FD5B20BCC6E}';
  VC_2010_REDIST_IA64 = '{C1A35166-4301-38E9-BA67-02823AD72A1B}';
  VC_2010_SP1_REDIST_X86 = '{F0C3E5D1-1ADE-321E-8167-68EF0DE699A5}';
  VC_2010_SP1_REDIST_X64 = '{1D8E6291-B0D5-35EC-8441-6616F567A0F7}';
  VC_2010_SP1_REDIST_IA64 = '{88C73C1C-2DE5-3B01-AFB8-B46EF4AB41CD}';

  VC_2013_REDIST_X86 = '{CE085A78-074E-4823-8DC1-8A721B94B76D}'; // 12.0.21005
  VC_2013_REDIST_X64 = '{7F51BDB9-EE21-49EE-94D6-90AFC321780E}';

function MsiQueryProductState(szProduct: string): INSTALLSTATE;
  external 'MsiQueryProductState{#AW}@msi.dll stdcall';

function VCVersionInstalled(const ProductID: string): Boolean;
begin
  Result := MsiQueryProductState(ProductID) = INSTALLSTATE_DEFAULT;
end;

function VCRedist2008PacNeedsInstall: Boolean;
begin
  // here the Result must be True when you need to install your VCRedist
  // or False when you don't need to, so now it's upon you how you build
  // this statement, the following won't install your VC redist only when
  // the Visual C++ 2010 Redist (x86) and Visual C++ 2010 SP1 Redist(x86)
  // are installed for the current user
  Result := not (VCVersionInstalled(VC_2008_REDIST_X64) and
    VCVersionInstalled(VC_2008_SP1_REDIST_X64));
end;

function VCRedist2013NeedsInstall: Boolean;
begin
  Result := not (VCVersionInstalled(VC_2013_REDIST_X64));
end;


fixed path for pip/setuptools packages; spelling

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "tellurium"
;#define MyAppVersion "0.0.0"  read from file, see below
#define MyAppPublisher "University of Washington, Seattle, WA, USA"
#define MyAppURL "http://tellurium.analogmachine.org/"
#define MyAppSetupIconFile "tellurium_icon_64x64.ico"
#define ThisInstallerPostfix "win32-superpack-setup"

#define LibRoadRunnerInstaller "pylibroadrunner-1.1.0-beta2-win_32"
;leave .zip off the LibRoadRunnerInstaller var above
#define Sbml2matlabInstaller "sbml2matlab_1.2.0_win32"
;leave .zip off the Sbml2matlabInstaller var above

#define AntimonyInstaller "AntimonyPythonBindings-2.5.1-win32.exe"
#define TelPluginsInstaller "telplugins-1.0.9-Python-2.7-win32-minimal-setup.exe"
#define PyInstaller "python-2.7.6.msi"
#define NumpyInstaller "numpy-1.8.0-win32-superpack-python2.7.exe"
#define MatplotlibInstaller "matplotlib-1.3.1.win32-py2.7.exe"
;#define DateutilInstaller "python-dateutil-2.2.win32-py2.7.exe"
;#define PyparsingInstaller "pyparsing-2.0.1.win32-py2.7.exe"
;#define SixInstaller "six-1.5.2.win32-py2.7.exe"

#define PyQtInstaller "PyQt4"
#define SipInstaller "sip.pyd"
#define PipInstaller "pip-1.5.4"
#define SetupToolsInstaller "setuptools-3.3"
#define SpyderInstaller "spyder-2.2.5-tellurium.win32.exe"
#define Unzip "unzip.exe"

;add spyder source
;then do ":python setup.py install" to install

;downloads turned off, installers packaged
;#define LibRoadRunnerInstallerURL "http://sourceforge.net/projects/libroadrunner/files/roadrunner-1.0.1-rc1-win32-minimal-setup.exe"
;#define AntimonyInstallerURL "http://sourceforge.net/projects/antimony/files/Windows%20binaries/2.5/AntimonyPythonBindings-2.5.0-win32.exe"
;#define PyInstallerURL "http://python.org/ftp/python/2.7.6/python-2.7.6.msi"
;#define NumpyInstallerURL "http://downloads.sourceforge.net/project/numpy/NumPy/1.8.0/numpy-1.8.0-win32-superpack-python2.7.exe?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fnumpy%2Ffiles%2FNumPy%2F&ts=1390956336&use_mirror=softlayer-ams"
;#define MatplotlibInstallerURL "https://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.3.1/matplotlib-1.3.1.win32-py2.7.exe"
;#define DateutilInstallerURL "http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-dateutil" ;there does not appear to be a direct URL to the file
;#define PyparsingInstallerURL "http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyparsing" The one from "http://downloads.sourceforge.net/project/pyparsing/pyparsing/pyparsing-2.0.1/pyparsing-2.0.1.win32-py2.7.exe" did not work.
;#define SixInstallerURL "http://www.lfd.uci.edu/~gohlke/pythonlibs/#six"
;#define PyQtInstallerURL "http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.10.3/PyQt4-4.10.3-gpl-Py2.7-Qt4.8.5-x32.exe/download"
;#define SipInstallerURL "http://www.riverbankcomputing.com/software/sip/download" #using file from bin install
;#define PipInstallerURL "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz" #then it was untared and re-zipped
;#define SetupToolsInstallerURL "https://pypi.python.org/packages/source/s/setuptools/setuptools-3.3.zip"
;#define SpyderInstallerURL "https://bitbucket.org/spyder-ide/spyderlib/downloads/spyder-2.2.5.win32.exe"
;#define unzipURL "http://stahlworks.com/dev/unzip.exe"

#define Py "Python"
#define PyVer "2.7"
#define Numpy "numpy"
;#define NumpyVer "1.0"
#define Matplotlib "matplotlib"
;#define MatplotlibVer "1.0"
#define AppDir "tellurium"
#define Pip "pip.exe"

; Get version from VERSION.txt file
#define VerFile FileOpen("../../VERSION.txt")
#define MyAppVersion FileRead(VerFile)
#expr FileClose(VerFile)
#undef VerFile

;Used for downloader
;#include ReadReg(HKEY_LOCAL_MACHINE,'Software\Sherlock Software\InnoTools\Downloader','ScriptPath','');

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{2EA1F666-39FE-4A26-BCC9-4D534219C9AE}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DisableWelcomePage=yes
DefaultDirName={code:SetAppDirPath}
;DefaultDirName=C:\Python27\Lib\site-packages\{#AppDir}

;enable the next line for debug only
;DisableDirPage=yes

;DefaultGroupName=libRoadRunner
DisableProgramGroupPage=yes
;LicenseFile=..\..\LICENSE
;InfoBeforeFile=..\..\NOTICE.txt
;InfoAfterFile=README.md
DisableReadyPage=yes
;DisableFinishedPage=yes   ;finished page is good feedback
OutputDir=.
OutputBaseFilename={#MyAppName}-{#MyAppVersion}-{#Py}-{#PyVer}-{#ThisInstallerPostfix}
SetupIconFile={#MyAppSetupIconFile}
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "../../tellurium.py"; DestDir: "{app}"; Flags: ignoreversion
Source: "../../__init__.py"; DestDir: "{app}"; Flags: ignoreversion
;copy example to app dir, for temp file, this will open by default at first run
Source: "../../examples/tellurium-files/*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs
;copy example to tellurium-files as example file
Source: "../../examples/tellurium-files/*"; DestDir: "{userdocs}\tellurium-files"; Flags: ignoreversion recursesubdirs

Source: "../../NEWS.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "../../LICENSE.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "../../VERSION.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "../../README.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "../../NOTICE.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "super_installer_dependencies\{#LibRoadRunnerInstaller}.zip"; DestDir: "{tmp}"; Flags: ignoreversion
Source: "super_installer_dependencies\{#Sbml2matlabInstaller}.zip"; DestDir: "{tmp}"; Flags: ignoreversion
Source: "super_installer_dependencies\{#AntimonyInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion
Source: "super_installer_dependencies\{#TelPluginsInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion
Source: "super_installer_dependencies\{#Unzip}"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall
Source: "libRoadrunner-installer-dependencies\{#MatplotlibInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion onlyifdoesntexist
;-Source: "libRoadrunner-installer-dependencies\{#DateutilInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion onlyifdoesntexist
;-Source: "libRoadrunner-installer-dependencies\{#PyparsingInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion onlyifdoesntexist
;-Source: "libRoadrunner-installer-dependencies\{#SixInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion onlyifdoesntexist
Source: "libRoadrunner-installer-dependencies\{#NumpyInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion onlyifdoesntexist
Source: "libRoadrunner-installer-dependencies\{#PyInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion onlyifdoesntexist
Source: "super_installer_dependencies\{#PipInstaller}.zip"; DestDir: "{tmp}"; Flags: ignoreversion
Source: "super_installer_dependencies\{#SetupToolsInstaller}.zip"; DestDir: "{tmp}"; Flags: ignoreversion
Source: "super_installer_dependencies\wheel\*"; DestDir: "{tmp}\wheel"; Flags: ignoreversion recursesubdirs

Source: "spyder_dependencies\{#PyQtInstaller}\*"; DestDir: "{code:SetPythonSitePackagesPath}\{#PyQtInstaller}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "spyder_dependencies\{#SipInstaller}"; DestDir: "{code:SetPythonSitePackagesPath}"; Flags: ignoreversion
;Source: "{#SpyderInstaller}\*"; DestDir: "{tmp}\{#SpyderInstaller}"; Flags: ignoreversion recursesubdirs createallsubdirs
;the line above was tried to attempt a direct install using setup.py, but this process does not install icons/ shortcuts for windows, there is no way to do that w/o serious work
;the line below copies the exe spyder installer
Source: "spyder_dependencies\{#SpyderInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion onlyifdoesntexist
;Spyder installer is a custom distro with the following mod at the end of scientific_startup.py
;from tellurium import *
Source: "../../roadrunner.conf"; DestDir: "{tmp}"; Flags: ignoreversion ; AfterInstall: CopyConfToRoadRunner()

; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Run]
Filename: "{tmp}\{#Unzip}"; Parameters: "{tmp}\{#SetupToolsInstaller}.zip -d {tmp}"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
Filename: "{code:SetPythonPath}\python.exe"; Parameters: "setup.py install"; WorkingDir: "{tmp}\{#SetupToolsInstaller}"; Flags: shellexec waituntilterminated
Filename: "{tmp}\{#Unzip}"; Parameters: "{tmp}\{#PipInstaller}.zip -d {tmp}"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
Filename: "{code:SetPythonPath}\python.exe"; Parameters: "setup.py install"; WorkingDir: "{tmp}\{#PipInstaller}"; Flags: shellexec waituntilterminated
Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install --no-index --find-links {tmp}/wheel astroid backports.ssl_match_hostname colorama docutils ipython jinja2 logilab-common markupsafe nose pep8 psutil pyflakes pygments pylint pyparsing python-dateutil pyzmq six sphinx tornado wheel"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;in the line above the --no-index --find-links {tmp}/pip_cache means no network, some subpackages are still missing, these flags are removed below
;;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install python-dateutil docutils pyparsing six sphinx pyflakes pylint pep8 psutil pygments ipython[all]"; WorkingDir: "{tmp}/pip_cache"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install pyparsing"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install six"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated

;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install ipython[all]"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install sphinx"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install pyflakes"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install pylint"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install pep8"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install psutil"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install python-dateutil"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install jinja2"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated

Filename: "{tmp}\{#Unzip}"; Parameters: "{tmp}\{#LibRoadRunnerInstaller}.zip -d {tmp}"; WorkingDir: "{tmp}";
Filename: "{code:SetPythonPath}\python.exe"; Parameters: "setup.py install"; WorkingDir: "{tmp}\{#LibRoadRunnerInstaller}"; Flags: shellexec waituntilterminated
Filename: "{tmp}\{#Unzip}"; Parameters: "{tmp}\{#Sbml2matlabInstaller}.zip -d {tmp}"; WorkingDir: "{tmp}";
Filename: "{code:SetPythonPath}\python.exe"; Parameters: "setup.py install"; WorkingDir: "{tmp}\{#Sbml2matlabInstaller}"; Flags: shellexec waituntilterminated
Filename: "{#AntimonyInstaller}"; Parameters: "/SILENT"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
Filename: "{#TelPluginsInstaller}"; Parameters: "/SILENT"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\python.exe"; Parameters: "setup.py install --install-script spyder_win_post_install.py"; WorkingDir: "{tmp}\{#SpyderInstaller}"; Flags: shellexec waituntilterminated
;the line above will not install the icons/ shortcuts for spyder in windows, bdist_wininst
;the line below will run the exe spyder installer which will work properly
Filename: "{#SpyderInstaller}"; Parameters: "/SILENT"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated

Filename: "{app}\README.TXT"; Description: "View the README file"; Flags: postinstall shellexec skipifsilent unchecked
Filename: "{code:SetPythonPath}\pythonw.exe"; Parameters:"{code:SetPythonPath}\scripts\spyder -w {userdocs}\tellurium-files"; Description: "Run Spyder for Tellurium"; Flags: postinstall shellexec skipifsilent waituntilterminated

;SCIPY pip install has an error, may need a fortran compiler! mingw, but do we need Scipy?
;Filename: "{#Pip}"; Parameters: "install scipy"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated runmaximized

;MATPLOTLIB, on pip install, cannot find vcvarsall.bat, a symptom of missing the 2008 VS++ <-seriously you need to install a compiler
;Filename: "{#Pip}"; Parameters: "install matplotlib"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated runmaximized

;NUMPY, on pip install, cannot find vcvarsall.bat, a symptom of missing the 2008 VS++ <-seriously you need to install a compiler
;Filename: "{#Pip}"; Parameters: "install numpy"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated runmaximized

[Code]
//////////////////////////////////////////////////////////////////////////////
const
  appDir = '{#AppDir}';
  pyReg = 'SOFTWARE\{#Py}\PythonCore\{#PyVer}\InstallPath';
  pyRegWow6443Node = 'SOFTWARE\Wow6432Node\{#Py}\PythonCore\{#PyVer}\InstallPath';

var
  installPython, installMatplot, installNumpy: Boolean;
  AppDirPath: String;
  PythonPath: String;
  PythonSitePackagesPath: String;

//////////////////////////////////////////////////////////////////////////////
procedure ExitProcess(exitCode:integer);
  external 'ExitProcess@kernel32.dll stdcall';

//////////////////////////////////////////////////////////////////////////////
function GetPathForPython(): string;
var
  InstallPath: string;
begin

  if RegQueryStringValue(HKEY_LOCAL_MACHINE, pyReg, '', InstallPath) then
    begin
    Log('HKLM pyReg: '+ InstallPath);
    Result := InstallPath;
    end
  else
  if RegQueryStringValue(HKEY_CURRENT_USER, pyReg, '', InstallPath) then
    begin
    Log('HKCU pyReg: '+ InstallPath);
    Result := InstallPath;
    end
  else
  if RegQueryStringValue(HKEY_LOCAL_MACHINE, pyRegWow6443Node, '', InstallPath) then
    begin
    Log('HKLM pyRegWow6443Node: '+ InstallPath);
    Result := InstallPath;
    end
  else
    begin
    MsgBox('Our installer did not find your Python installation. You need '
    + 'Python to run {#MyAppName}. In the next step use [Your Python installation'
    + ' location]\Lib\site-packages\{#AppDir} directory.',mbError,MB_OK);
    //ExitProcess(1);
    end
end;

//////////////////////////////////////////////////////////////////////////////
function GetPathForPythonSitePackages(PythonPath: String): string;
begin
  Result := PythonPath + 'Lib\site-packages\';
end;

//////////////////////////////////////////////////////////////////////////////
function IsPythonInstalled(): Boolean;
var
  InstallPath: string; //not really used here
begin

  if RegQueryStringValue(HKEY_LOCAL_MACHINE, pyReg, '', InstallPath) then
    begin
    Result := True;
    end
  else
  if RegQueryStringValue(HKEY_CURRENT_USER, pyReg, '', InstallPath) then
    begin
    Result := True;
    end
  else
  if RegQueryStringValue(HKEY_LOCAL_MACHINE, pyRegWow6443Node, '', InstallPath) then
    begin
    Result := True;
    end
  else
    begin
    Result := False;
    end
end;

//////////////////////////////////////////////////////////////////////////////
procedure GetPythonPaths();
begin
  PythonPath := GetPathForPython();
  PythonSitePackagesPath := GetPathForPythonSitePackages(PythonPath);
  AppDirPath := PythonSitePackagesPath + AppDir;
end;

//////////////////////////////////////////////////////////////////////////////
function SetPythonPath(Param: String): String;
begin
  Result := PythonPath;
end;

//////////////////////////////////////////////////////////////////////////////
function SetPythonSitePackagesPath(Param: String): String;
begin
  Result := PythonSitePackagesPath;
end;

//////////////////////////////////////////////////////////////////////////////
function SetAppDirPath(Param: String): String;
begin
  Result := AppDirPath;
end;

//////////////////////////////////////////////////////////////////////////////
function IsInstalled(name: String): Boolean;
//function IsInstalled(name: string; version: string): boolean;  //ver not neeeded
var
  InstallPath: string;
  reg : string;
begin
  //reg := 'Software\' + name + '\' + version
  // + '\InstallPath'
  // Log('reg Python: ' + reg)

  //if Numpy/ matplotlib installed - direct check for file
  InstallPath := PythonSitePackagesPath + name + '/__init__.py'
  Log('install dir: ' + InstallPath)
  if FileExists(InstallPath) then
  //if RegQueryStringValue(HKEY_CURRENT_USER, reg, 'InstallPath', InstallPath) then
   //numpy doesnt have a reg entry! (also gets its install path, not used here)
    begin
    Result := True;
    end
  else
    begin
    Result := False;
    end;
end;

//////////////////////////////////////////////////////////////////////////////
procedure RunMsiInstaller(execName: string);
var
  ResultCode: Integer;
  ExecPath: String;
  ExecCommand: String;
begin
  ExecPath := ExpandConstant('{tmp}\') + execName;
  ExecCommand := '/i ' + ExecPath + ''; //+ ' /qb'; //qb does it silently

  //Check that the msi installer file is present
  if FileExists(ExecPath) then
    begin
    Log('ExecPath exists : ' + ExecPath);
    end
  else
    begin
    Log('ExecPath doe not exist : ' + ExecPath);
    MsgBox('Could not find ' + execName + ' installer',mbError,MB_OK);
    ExitProcess(1);
    //something went wrong: hell or high water python installer must be there
    end;

  //execute msi installer, otherwie error and exit
  if not ShellExec('', 'msiexec.exe', ExecCommand, '', SW_SHOWNORMAL,
                   ewWaitUntilTerminated, ResultCode) then
      //msi exec not working
      MsgBox('Msi installer failed to run!' + #13#10 + ExecCommand + ' ' +
             SysErrorMessage(ResultCode), mbError, MB_OK);
end;

//////////////////////////////////////////////////////////////////////////////
function InitializeSetup(): Boolean;
var
tmpPy: String;
begin
  //if python installed get path for python site-packages
  //if isInstalled('{#Py}\PythonCore','{#PyVer}') then
  if IsPythonInstalled() then
  begin
    Log('Python: ' + 'True');
    installPython := False;
    //Python must be installed, get its path
    GetPythonPaths();
    Log('SetDefaultAppDirName: ' + AppDirPath);
  end
  else //Add Python to tmp folder [ // or download list.. ]
  begin
    Log('Python: ' + 'False');
    installPython := True;
    tmpPy := ExpandConstant('{tmp}\{#PyInstaller}');
    //FileCopy(ExpandConstant('{#PyInstaller}'), tmpPy, false);
    ExtractTemporaryFile('{#PyInstaller}')
    Log('tmpPy: '+ tmpPy);

    AppDirPath := 'C:\Python27\Lib\site-packages\{#AppDir}' //pretend default path
                                                            //will be used when python is installed
                                                            //not seeing another way to prepopulate
                                                            //the Dir Destination page.
                                                            //installing Python earlier not an option
                                                            //as {tmp} was not created yet, so cant
                                                            //extract python installer yet
    //itd_addfile('{#PyInstallerURL}',ExpandConstant('{tmp}\{#PyInstaller}'));
    //itd_addfile('http://sbol.bhi.washington.edu/ppp/setup-dummyPython.exe',ExpandConstant('{tmp}\setup-dummyPython.exe'));
    PythonPath := 'C:\Python27';
    PythonSitePackagesPath := 'C:\Python27\Lib\site-packages\';
  end;

  Result := True; //Required for fwd progress, false would exist
end;

//////////////////////////////////////////////////////////////////////////////
procedure InitializeWizard();
begin
 //itd_init;  //turned off when packaging installers

  //Install Python now if needed, we want it in place before anything else is done
  if (installPython) then
     RunMsiInstaller('{#PyInstaller}');

  //Python must be installed, get its path
  GetPythonPaths();
  Log('SetDefaultAppDirName: ' + AppDirPath);

  //Check if Numpy is installed
  if IsInstalled('{#Numpy}') then
  //if IsInstalled('{#Numpy}','{#NumpyVer}') then  //ver not needed
    begin
    Log('Numpy: ' + 'True');
    installNumpy := False;
    end
  else
    //Add Numpy to d/l list
    begin
    Log('Numpy: ' + 'False');
    installNumpy := True;

    //filecopy(ExpandConstant('{#NumpyInstaller}'),ExpandConstant('{tmp}\{#NumpyInstaller}'),false);
    ExtractTemporaryFile('{#NumpyInstaller}');

    //The following were used to test downloader srategy
    //itd_addfile('http://sbol.bhi.washington.edu/ppp/setup-dummyNump.exe',
    //            ExpandConstant('{tmp}\setup-dummyNump.exe'));
    end;

  //Check if Matplotlib is installed
  if IsInstalled('{#Matplotlib}') then
  //if IsInstalled('{#Matplotlib}','{#MatplotlibVer}') then   //ver not needed
    begin
    Log('Matplotlib: ' + 'True');
    installMatplot := False;
    end
  else
    //Add Matplotlib to d/l list
    begin
    Log('Matplotlib: ' + 'False');
    installMatplot := True;

    //filecopy(ExpandConstant('{#MatplotlibInstaller}'),ExpandConstant('{tmp}\{#MatplotlibInstaller}'),false);
    ExtractTemporaryFile('{#MatplotlibInstaller}');
    //ExtractTemporaryFile('{#DateutilInstaller}');
    //ExtractTemporaryFile('{#PyparsingInstaller}');
    //ExtractTemporaryFile('{#SixInstaller}');

    //The following were used to test downloader srategy
    //td_addfile('http://sbol.bhi.washington.edu/ppp/setup-dummyMatplot.exe',
    //            ExpandConstant('{tmp}\setup-dummyMatplot.exe'));
    end;

  //Downloads turned off, packaging installers.
  //Start the download after the "Ready to install" screen is shown
  //itd_downloadafter(wpReady);
end;

//////////////////////////////////////////////////////////////////////////////
procedure RunOtherInstaller(execName: string);
var
  ResultCode: Integer;
begin
  if not Exec(ExpandConstant('{tmp}\' + execName), '', '', SW_SHOWNORMAL,
    ewWaitUntilTerminated, ResultCode)
  then
    MsgBox('Other installer failed to run!' + #13#10 + execName +
      SysErrorMessage(ResultCode), mbError, MB_OK);
end;

//////////////////////////////////////////////////////////////////////////////
// Install Numpy and Matplotlib if mising
procedure CurStepChanged(CurStep: TSetupStep);
var
   ResultCode: Integer;
begin
  if CurStep=ssInstall then //If on the installation step
  //Lets install those files that were downloaded for us
    begin
    if ForceDirectories(ExpandConstant('{app}')) then
      begin
      Log('app: ' + ExpandConstant('{app}'));
      if (installNumpy) then
        RunOtherInstaller('{#NumpyInstaller}');
      if (installMatplot) then
        begin
        RunOtherInstaller('{#MatplotlibInstaller}');
        //RunOtherInstaller('{#DateutilInstaller}');
        //RunOtherInstaller('{#PyparsingInstaller}');
        //RunOtherInstaller('{#SixInstaller}');
        end;
      end;
    end;
end;

//////////////////////////////////////////////////////////////////////////////
// Install tellurium mod in spyder
//procedure MakeTelSpyder(FileName: String);
//begin
    //tmpPy := ExpandConstant('{tmp}\{#PyInstaller}');
//    FileCopy(ExpandConstant('{tmp}\scientific_startup.py'), FileName, false);
//    Log(ExpandConstant('{tmp}\scientific_startup.py') + ' :to: ' + FileName)
//end;

procedure CopyConfToRoadRunner();
var
   FromFile: String;
   ToFile: String;
begin
  FromFile := ExpandConstant('{tmp}/roadrunner.conf')
  ToFile := PythonSitePackagesPath + '/roadrunner/roadrunner.conf'
  FileCopy(FromFile, ToFile, true)
end;

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

#define MyAppName "tellurium"
;#define MyAppVersion "0.0.0"  read from file, see below
#define MyAppPublisher "University of Washington, Seattle, WA, USA"
#define MyAppURL "http://tellurium.analogmachine.org/"
#define MyAppSetupIconFile "tellurium_icon_64x64.ico"
#define ThisInstallerPostfix "win32-superpack-setup"

#define LibRoadRunnerInstaller "pylibroadrunner-1.1.0-beta2-win_32"
;leave .zip off the LibRoadRunnerInstaller var above
#define Sbml2matlabInstaller "sbml2matlab_1.2.0_win32"
;leave .zip off the Sbml2matlabInstaller var above

#define AntimonyInstaller "AntimonyPythonBindings-2.5.1-win32.exe"
#define TelPluginsInstaller "telplugins-1.0.9-Python-2.7-win32-minimal-setup.exe"
#define PyInstaller "python-2.7.6.msi"
#define NumpyInstaller "numpy-1.8.0-win32-superpack-python2.7.exe"
#define MatplotlibInstaller "matplotlib-1.3.1.win32-py2.7.exe"
;#define DateutilInstaller "python-dateutil-2.2.win32-py2.7.exe"
;#define PyparsingInstaller "pyparsing-2.0.1.win32-py2.7.exe"
;#define SixInstaller "six-1.5.2.win32-py2.7.exe"

#define PyQtInstaller "PyQt4"
#define SipInstaller "sip.pyd"
#define PipInstaller "pip-1.5.4"
#define SetupToolsInstaller "setuptools-3.3"
#define SpyderInstaller "spyder-2.2.5-tellurium.win32.exe"
#define Unzip "unzip.exe"

;add spyder source
;then do ":python setup.py install" to install

;downloads turned off, installers packaged
;#define LibRoadRunnerInstallerURL "http://sourceforge.net/projects/libroadrunner/files/roadrunner-1.0.1-rc1-win32-minimal-setup.exe"
;#define AntimonyInstallerURL "http://sourceforge.net/projects/antimony/files/Windows%20binaries/2.5/AntimonyPythonBindings-2.5.0-win32.exe"
;#define PyInstallerURL "http://python.org/ftp/python/2.7.6/python-2.7.6.msi"
;#define NumpyInstallerURL "http://downloads.sourceforge.net/project/numpy/NumPy/1.8.0/numpy-1.8.0-win32-superpack-python2.7.exe?r=http%3A%2F%2Fsourceforge.net%2Fprojects%2Fnumpy%2Ffiles%2FNumPy%2F&ts=1390956336&use_mirror=softlayer-ams"
;#define MatplotlibInstallerURL "https://downloads.sourceforge.net/project/matplotlib/matplotlib/matplotlib-1.3.1/matplotlib-1.3.1.win32-py2.7.exe"
;#define DateutilInstallerURL "http://www.lfd.uci.edu/~gohlke/pythonlibs/#python-dateutil" ;there does not appear to be a direct URL to the file
;#define PyparsingInstallerURL "http://www.lfd.uci.edu/~gohlke/pythonlibs/#pyparsing" The one from "http://downloads.sourceforge.net/project/pyparsing/pyparsing/pyparsing-2.0.1/pyparsing-2.0.1.win32-py2.7.exe" did not work.
;#define SixInstallerURL "http://www.lfd.uci.edu/~gohlke/pythonlibs/#six"
;#define PyQtInstallerURL "http://sourceforge.net/projects/pyqt/files/PyQt4/PyQt-4.10.3/PyQt4-4.10.3-gpl-Py2.7-Qt4.8.5-x32.exe/download"
;#define SipInstallerURL "http://www.riverbankcomputing.com/software/sip/download" #using file from bin install
;#define PipInstallerURL "https://pypi.python.org/packages/source/p/pip/pip-1.5.4.tar.gz" #then it was untared and re-zipped
;#define SetupToolsInstallerURL "https://pypi.python.org/packages/source/s/setuptools/setuptools-3.3.zip"
;#define SpyderInstallerURL "https://bitbucket.org/spyder-ide/spyderlib/downloads/spyder-2.2.5.win32.exe"
;#define unzipURL "http://stahlworks.com/dev/unzip.exe"

#define Py "Python"
#define PyVer "2.7"
#define Numpy "numpy"
;#define NumpyVer "1.0"
#define Matplotlib "matplotlib"
;#define MatplotlibVer "1.0"
#define AppDir "tellurium"
#define Pip "pip.exe"

; Get version from VERSION.txt file
#define VerFile FileOpen("../../VERSION.txt")
#define MyAppVersion FileRead(VerFile)
#expr FileClose(VerFile)
#undef VerFile

;Used for downloader
;#include ReadReg(HKEY_LOCAL_MACHINE,'Software\Sherlock Software\InnoTools\Downloader','ScriptPath','');

[Setup]
; NOTE: The value of AppId uniquely identifies this application.
; Do not use the same AppId value in installers for other applications.
; (To generate a new GUID, click Tools | Generate GUID inside the IDE.)
AppId={{2EA1F666-39FE-4A26-BCC9-4D534219C9AE}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DisableWelcomePage=yes
DefaultDirName={code:SetAppDirPath}
;DefaultDirName=C:\Python27\Lib\site-packages\{#AppDir}

;enable the next line for debug only
;DisableDirPage=yes

;DefaultGroupName=libRoadRunner
DisableProgramGroupPage=yes
;LicenseFile=..\..\LICENSE
;InfoBeforeFile=..\..\NOTICE.txt
;InfoAfterFile=README.md
DisableReadyPage=yes
;DisableFinishedPage=yes   ;finished page is good feedback
OutputDir=.
OutputBaseFilename={#MyAppName}-{#MyAppVersion}-{#Py}-{#PyVer}-{#ThisInstallerPostfix}
SetupIconFile={#MyAppSetupIconFile}
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"

[Files]
Source: "../../tellurium.py"; DestDir: "{app}"; Flags: ignoreversion
Source: "../../__init__.py"; DestDir: "{app}"; Flags: ignoreversion
;copy example to app dir, for temp file, this will open by default at first run
Source: "../../examples/tellurium-files/*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs
;copy example to tellurium-files as example file
Source: "../../examples/tellurium-files/*"; DestDir: "{userdocs}\tellurium-files"; Flags: ignoreversion recursesubdirs

Source: "../../NEWS.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "../../LICENSE.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "../../VERSION.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "../../README.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "../../NOTICE.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "super_installer_dependencies\{#LibRoadRunnerInstaller}.zip"; DestDir: "{tmp}"; Flags: ignoreversion
Source: "super_installer_dependencies\{#Sbml2matlabInstaller}.zip"; DestDir: "{tmp}"; Flags: ignoreversion
Source: "super_installer_dependencies\{#AntimonyInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion
Source: "super_installer_dependencies\{#TelPluginsInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion
Source: "super_installer_dependencies\{#Unzip}"; DestDir: "{tmp}"; Flags: ignoreversion deleteafterinstall
Source: "libRoadrunner-installer-dependencies\{#MatplotlibInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion onlyifdoesntexist
;-Source: "libRoadrunner-installer-dependencies\{#DateutilInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion onlyifdoesntexist
;-Source: "libRoadrunner-installer-dependencies\{#PyparsingInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion onlyifdoesntexist
;-Source: "libRoadrunner-installer-dependencies\{#SixInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion onlyifdoesntexist
Source: "libRoadrunner-installer-dependencies\{#NumpyInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion onlyifdoesntexist
Source: "libRoadrunner-installer-dependencies\{#PyInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion onlyifdoesntexist
Source: "libRoadrunner-installer-dependencies\{#PipInstaller}.zip"; DestDir: "{tmp}"; Flags: ignoreversion
Source: "libRoadrunner-installer-dependencies\{#SetupToolsInstaller}.zip"; DestDir: "{tmp}"; Flags: ignoreversion
Source: "super_installer_dependencies\wheel\*"; DestDir: "{tmp}\wheel"; Flags: ignoreversion recursesubdirs

Source: "spyder_dependencies\{#PyQtInstaller}\*"; DestDir: "{code:SetPythonSitePackagesPath}\{#PyQtInstaller}"; Flags: ignoreversion recursesubdirs createallsubdirs
Source: "spyder_dependencies\{#SipInstaller}"; DestDir: "{code:SetPythonSitePackagesPath}"; Flags: ignoreversion
;Source: "{#SpyderInstaller}\*"; DestDir: "{tmp}\{#SpyderInstaller}"; Flags: ignoreversion recursesubdirs createallsubdirs
;the line above was tried to attempt a direct install using setup.py, but this process does not install icons/ shortcuts for windows, there is no way to do that w/o serious work
;the line below copies the exe spyder installer
Source: "spyder_dependencies\{#SpyderInstaller}"; DestDir: "{tmp}"; Flags: ignoreversion onlyifdoesntexist
;Spyder installer is a custom distro with the following mod at the end of scientific_startup.py
;from tellurium import *
Source: "../../roadrunner.conf"; DestDir: "{tmp}"; Flags: ignoreversion ; AfterInstall: CopyConfToRoadRunner()

; NOTE: Don't use "Flags: ignoreversion" on any shared system files

[Run]
Filename: "{tmp}\{#Unzip}"; Parameters: "{tmp}\{#SetupToolsInstaller}.zip -d {tmp}"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
Filename: "{code:SetPythonPath}\python.exe"; Parameters: "setup.py install"; WorkingDir: "{tmp}\{#SetupToolsInstaller}"; Flags: shellexec waituntilterminated
Filename: "{tmp}\{#Unzip}"; Parameters: "{tmp}\{#PipInstaller}.zip -d {tmp}"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
Filename: "{code:SetPythonPath}\python.exe"; Parameters: "setup.py install"; WorkingDir: "{tmp}\{#PipInstaller}"; Flags: shellexec waituntilterminated
Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install --no-index --find-links {tmp}/wheel astroid backports.ssl_match_hostname colorama docutils ipython jinja2 logilab-common markupsafe nose pep8 psutil pyflakes pygments pylint pyparsing python-dateutil pyzmq six sphinx tornado wheel"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;in the line above the --no-index --find-links {tmp}/pip_cache means no network, some subpackages are still missing, these flags are removed below
;;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install python-dateutil docutils pyparsing six sphinx pyflakes pylint pep8 psutil pygments ipython[all]"; WorkingDir: "{tmp}/pip_cache"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install pyparsing"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install six"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated

;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install ipython[all]"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install sphinx"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install pyflakes"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install pylint"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install pep8"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install psutil"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install python-dateutil"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;;Filename: "{code:SetPythonPath}\scripts\{#Pip}"; Parameters: "install jinja2"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated

Filename: "{tmp}\{#Unzip}"; Parameters: "{tmp}\{#LibRoadRunnerInstaller}.zip -d {tmp}"; WorkingDir: "{tmp}";
Filename: "{code:SetPythonPath}\python.exe"; Parameters: "setup.py install"; WorkingDir: "{tmp}\{#LibRoadRunnerInstaller}"; Flags: shellexec waituntilterminated
Filename: "{tmp}\{#Unzip}"; Parameters: "{tmp}\{#Sbml2matlabInstaller}.zip -d {tmp}"; WorkingDir: "{tmp}";
Filename: "{code:SetPythonPath}\python.exe"; Parameters: "setup.py install"; WorkingDir: "{tmp}\{#Sbml2matlabInstaller}"; Flags: shellexec waituntilterminated
Filename: "{#AntimonyInstaller}"; Parameters: "/SILENT"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
Filename: "{#TelPluginsInstaller}"; Parameters: "/SILENT"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
;Filename: "{code:SetPythonPath}\python.exe"; Parameters: "setup.py install --install-script spyder_win_post_install.py"; WorkingDir: "{tmp}\{#SpyderInstaller}"; Flags: shellexec waituntilterminated
;the line above will not install the icons/ shortcuts for spyder in windows, bdist_wininst
;the line below will run the exe spyder installer which will work properly
Filename: "{#SpyderInstaller}"; Parameters: "/SILENT"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated
Filename: "{app}\README.TXT"; Description: "View the README file"; Flags: postinstall shellexec skipifsilent unchecked
Filename: "{code:SetPythonPath}\pythonw.exe"; Parameters:"{code:SetPythonPath}\scripts\spyder -w {userdocs}\tellurium-files"; Description: "Run Spyder for Tellurium"; Flags: postinstall shellexec skipifsilent waituntilterminated

;SCIPY pip install has an error, may need a fortran compiler! mingw, but do we need Scipy?
;Filename: "{#Pip}"; Parameters: "install scipy"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated runmaximized

;MATPLOTLIB, on pip install, cannot find vcvarsall.bat, a symptom of missing the 2008 VS++ <-seriously you need to install a compiler
;Filename: "{#Pip}"; Parameters: "install matplotlib"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated runmaximized

;NUMPY, on pip install, cannot find vcvarsall.bat, a symptom of missing the 2008 VS++ <-seriously you need to install a compiler
;Filename: "{#Pip}"; Parameters: "install numpy"; WorkingDir: "{tmp}"; Flags: shellexec waituntilterminated runmaximized

[Code]
//////////////////////////////////////////////////////////////////////////////
const
  appDir = '{#AppDir}';
  pyReg = 'SOFTWARE\{#Py}\PythonCore\{#PyVer}\InstallPath';
  pyRegWow6443Node = 'SOFTWARE\Wow6432Node\{#Py}\PythonCore\{#PyVer}\InstallPath';

var
  installPython, installMatplot, installNumpy: Boolean;
  AppDirPath: String;
  PythonPath: String;
  PythonSitePackagesPath: String;

//////////////////////////////////////////////////////////////////////////////
procedure ExitProcess(exitCode:integer);
  external 'ExitProcess@kernel32.dll stdcall';

//////////////////////////////////////////////////////////////////////////////
function GetPathForPython(): string;
var
  InstallPath: string;
begin

  if RegQueryStringValue(HKEY_LOCAL_MACHINE, pyReg, '', InstallPath) then
    begin
    Log('HKLM pyReg: '+ InstallPath);
    Result := InstallPath;
    end
  else
  if RegQueryStringValue(HKEY_CURRENT_USER, pyReg, '', InstallPath) then
    begin
    Log('HKCU pyReg: '+ InstallPath);
    Result := InstallPath;
    end
  else
  if RegQueryStringValue(HKEY_LOCAL_MACHINE, pyRegWow6443Node, '', InstallPath) then
    begin
    Log('HKLM pyRegWow6443Node: '+ InstallPath);
    Result := InstallPath;
    end
  else
    begin
    MsgBox('Our installer did not find your Python installation. You need '
    + 'Python to run {#MyAppName}. In the next step use [Your Python installation'
    + ' location]\Lib\site-packages\{#AppDir} directory.',mbError,MB_OK);
    //ExitProcess(1);
    end
end;

//////////////////////////////////////////////////////////////////////////////
function GetPathForPythonSitePackages(PythonPath: String): string;
begin
  Result := PythonPath + 'Lib\site-packages\';
end;

//////////////////////////////////////////////////////////////////////////////
function IsPythonInstalled(): Boolean;
var
  InstallPath: string; //not really used here
begin

  if RegQueryStringValue(HKEY_LOCAL_MACHINE, pyReg, '', InstallPath) then
    begin
    Result := True;
    end
  else
  if RegQueryStringValue(HKEY_CURRENT_USER, pyReg, '', InstallPath) then
    begin
    Result := True;
    end
  else
  if RegQueryStringValue(HKEY_LOCAL_MACHINE, pyRegWow6443Node, '', InstallPath) then
    begin
    Result := True;
    end
  else
    begin
    Result := False;
    end
end;

//////////////////////////////////////////////////////////////////////////////
procedure GetPythonPaths();
begin
  PythonPath := GetPathForPython();
  PythonSitePackagesPath := GetPathForPythonSitePackages(PythonPath);
  AppDirPath := PythonSitePackagesPath + AppDir;
end;

//////////////////////////////////////////////////////////////////////////////
function SetPythonPath(Param: String): String;
begin
  Result := PythonPath;
end;

//////////////////////////////////////////////////////////////////////////////
function SetPythonSitePackagesPath(Param: String): String;
begin
  Result := PythonSitePackagesPath;
end;

//////////////////////////////////////////////////////////////////////////////
function SetAppDirPath(Param: String): String;
begin
  Result := AppDirPath;
end;

//////////////////////////////////////////////////////////////////////////////
function IsInstalled(name: String): Boolean;
//function IsInstalled(name: string; version: string): boolean;  //ver not neeeded
var
  InstallPath: string;
  reg : string;
begin
  //reg := 'Software\' + name + '\' + version
  // + '\InstallPath'
  // Log('reg Python: ' + reg)

  //if Numpy/ matplotlib installed - direct check for file
  InstallPath := PythonSitePackagesPath + name + '/__init__.py'
  Log('install dir: ' + InstallPath)
  if FileExists(InstallPath) then
  //if RegQueryStringValue(HKEY_CURRENT_USER, reg, 'InstallPath', InstallPath) then
   //numpy doesnt have a reg entry! (also gets its install path, not used here)
    begin
    Result := True;
    end
  else
    begin
    Result := False;
    end;
end;

//////////////////////////////////////////////////////////////////////////////
procedure RunMsiInstaller(execName: string);
var
  ResultCode: Integer;
  ExecPath: String;
  ExecCommand: String;
begin
  ExecPath := ExpandConstant('{tmp}\') + execName;
  ExecCommand := '/i ' + ExecPath + ''; //+ ' /qb'; //qb does it silently

  //Check that the msi installer file is present
  if FileExists(ExecPath) then
    begin
    Log('ExecPath exists : ' + ExecPath);
    end
  else
    begin
    Log('ExecPath doe not exist : ' + ExecPath);
    MsgBox('Could not find ' + execName + ' installer',mbError,MB_OK);
    ExitProcess(1);
    //something went wrong: hell or high water python installer must be there
    end;

  //execute msi installer, otherwie error and exit
  if not ShellExec('', 'msiexec.exe', ExecCommand, '', SW_SHOWNORMAL,
                   ewWaitUntilTerminated, ResultCode) then
      //msi exec not working
      MsgBox('Msi installer failed to run!' + #13#10 + ExecCommand + ' ' +
             SysErrorMessage(ResultCode), mbError, MB_OK);
end;

//////////////////////////////////////////////////////////////////////////////
function InitializeSetup(): Boolean;
var
tmpPy: String;
begin
  //if python installed get path for python site-packages
  //if isInstalled('{#Py}\PythonCore','{#PyVer}') then
  if IsPythonInstalled() then
  begin
    Log('Python: ' + 'True');
    installPython := False;
    //Python must be installed, get its path
    GetPythonPaths();
    Log('SetDefaultAppDirName: ' + AppDirPath);
  end
  else //Add Python to tmp folder [ // or download list.. ]
  begin
    Log('Python: ' + 'False');
    installPython := True;
    tmpPy := ExpandConstant('{tmp}\{#PyInstaller}');
    //FileCopy(ExpandConstant('{#PyInstaller}'), tmpPy, false);
    ExtractTemporaryFile('{#PyInstaller}')
    Log('tmpPy: '+ tmpPy);

    AppDirPath := 'C:\Python27\Lib\site-packages\{#AppDir}' //pretend default path
                                                            //will be used when python is installed
                                                            //not seeing another way to prepopulate
                                                            //the Dir Destination page.
                                                            //installing Pyton earlier not an option
                                                            //as {tmp} was not created yet, so cant
                                                            //extract python installer yet
    //itd_addfile('{#PyInstallerURL}',ExpandConstant('{tmp}\{#PyInstaller}'));
    //itd_addfile('http://sbol.bhi.washington.edu/ppp/setup-dummyPython.exe',ExpandConstant('{tmp}\setup-dummyPython.exe'));
    PythonPath := 'C:\Python27';
    PythonSitePackagesPath := 'C:\Python27\Lib\site-packages\';
  end;

  Result := True; //Required for fwd progress, false would exist
end;

//////////////////////////////////////////////////////////////////////////////
procedure InitializeWizard();
begin
 //itd_init;  //turned off when packaging installers

  //Install Python now if needed, we want it in place before anything else is done
  if (installPython) then
     RunMsiInstaller('{#PyInstaller}');

  //Python must be installed, get its path
  GetPythonPaths();
  Log('SetDefaultAppDirName: ' + AppDirPath);

  //Check if Numpy is installed
  if IsInstalled('{#Numpy}') then
  //if IsInstalled('{#Numpy}','{#NumpyVer}') then  //ver not needed
    begin
    Log('Numpy: ' + 'True');
    installNumpy := False;
    end
  else
    //Add Numpy to d/l list
    begin
    Log('Numpy: ' + 'False');
    installNumpy := True;

    //filecopy(ExpandConstant('{#NumpyInstaller}'),ExpandConstant('{tmp}\{#NumpyInstaller}'),false);
    ExtractTemporaryFile('{#NumpyInstaller}');

    //The following were used to test downloader srategy
    //itd_addfile('http://sbol.bhi.washington.edu/ppp/setup-dummyNump.exe',
    //            ExpandConstant('{tmp}\setup-dummyNump.exe'));
    end;

  //Check if Matplotlib is installed
  if IsInstalled('{#Matplotlib}') then
  //if IsInstalled('{#Matplotlib}','{#MatplotlibVer}') then   //ver not needed
    begin
    Log('Matplotlib: ' + 'True');
    installMatplot := False;
    end
  else
    //Add Matplotlib to d/l list
    begin
    Log('Matplotlib: ' + 'False');
    installMatplot := True;

    //filecopy(ExpandConstant('{#MatplotlibInstaller}'),ExpandConstant('{tmp}\{#MatplotlibInstaller}'),false);
    ExtractTemporaryFile('{#MatplotlibInstaller}');
    //ExtractTemporaryFile('{#DateutilInstaller}');
    //ExtractTemporaryFile('{#PyparsingInstaller}');
    //ExtractTemporaryFile('{#SixInstaller}');

    //The following were used to test downloader srategy
    //td_addfile('http://sbol.bhi.washington.edu/ppp/setup-dummyMatplot.exe',
    //            ExpandConstant('{tmp}\setup-dummyMatplot.exe'));
    end;

  //Downloads turned off, packaging installers.
  //Start the download after the "Ready to install" screen is shown
  //itd_downloadafter(wpReady);
end;

//////////////////////////////////////////////////////////////////////////////
procedure RunOtherInstaller(execName: string);
var
  ResultCode: Integer;
begin
  if not Exec(ExpandConstant('{tmp}\' + execName), '', '', SW_SHOWNORMAL,
    ewWaitUntilTerminated, ResultCode)
  then
    MsgBox('Other installer failed to run!' + #13#10 + execName +
      SysErrorMessage(ResultCode), mbError, MB_OK);
end;

//////////////////////////////////////////////////////////////////////////////
// Install Numpy and Matplotlib if mising
procedure CurStepChanged(CurStep: TSetupStep);
var
   ResultCode: Integer;
begin
  if CurStep=ssInstall then //If on the installation step
  //Lets install those files that were downloaded for us
    begin
    if ForceDirectories(ExpandConstant('{app}')) then
      begin
      Log('app: ' + ExpandConstant('{app}'));
      if (installNumpy) then
        RunOtherInstaller('{#NumpyInstaller}');
      if (installMatplot) then
        begin
        RunOtherInstaller('{#MatplotlibInstaller}');
        //RunOtherInstaller('{#DateutilInstaller}');
        //RunOtherInstaller('{#PyparsingInstaller}');
        //RunOtherInstaller('{#SixInstaller}');
        end;
      end;
    end;
end;

//////////////////////////////////////////////////////////////////////////////
// Install tellurium mod in spyder
//procedure MakeTelSpyder(FileName: String);
//begin
    //tmpPy := ExpandConstant('{tmp}\{#PyInstaller}');
//    FileCopy(ExpandConstant('{tmp}\scientific_startup.py'), FileName, false);
//    Log(ExpandConstant('{tmp}\scientific_startup.py') + ' :to: ' + FileName)
//end;

procedure CopyConfToRoadRunner();
var
   FromFile: String;
   ToFile: String;
begin
  FromFile := ExpandConstant('{tmp}/roadrunner.conf')
  ToFile := PythonSitePackagesPath + '/roadrunner/roadrunner.conf'
  FileCopy(FromFile, ToFile, true)
end;