Final catel.iss fix

Final catel.iss fix

#define AppName "Catel"
#define SourceDirectory ""
; #define AppVersion "3.1"
#define AppVersion "[VERSION]"
; #define AppDisplayVersion "3.1 beta 1"
#define AppDisplayVersion "[VERSION_DISPLAY]"
#define AppNameWithDisplayVersion AppName + " " + AppDisplayVersion
#define AppNameWithVersion AppName + " " + AppVersion
#define Website "http://www.catelproject.com"
#define OutputPrefix "catel"
#define Company "CatenaLogic"

#define VS9Root "{pf32}\Microsoft Visual Studio 9.0"
#define VS10Root "{pf32}\Microsoft Visual Studio 10.0"
#define VS11Root "{pf32}\Microsoft Visual Studio 11.0"
#define VS12Root "{pf32}\Microsoft Visual Studio 12.0"

#define OutputFileWithSpaces OutputPrefix + "_" + AppDisplayVersion
#define OutputFile StringChange(OutputFileWithSpaces, " ", "_")

[_ISTool]
EnableISX=false
Use7zip=false

[Setup]
AppName={#AppNameWithVersion}
AppVerName={#AppNameWithDisplayVersion}
AppID={#AppNameWithVersion}
AppPublisher={#Company}
AppCopyright={#Company}
DefaultDirName={pf32}\{#AppNameWithVersion}
DefaultGroupName={#AppNameWithVersion}
UsePreviousSetupType=true
OutputDir=..\output
OutputBaseFilename={#OutputFile}
UninstallDisplayName={#AppNameWithVersion}
Compression=lzma2/Ultra64
UseSetupLdr=true
SolidCompression=true
ShowLanguageDialog=yes
VersionInfoVersion={#AppVersion}
AppVersion={#AppVersion}
InternalCompressLevel=Ultra64
AppPublisherURL={#Website}
AppSupportURL={#Website}
AppUpdatesURL={#Website}
AppContact={#Website}
VersionInfoCompany={#Company}
AppMutex={#AppNameWithVersion}
LanguageDetectionMethod=none
DisableStartupPrompt=True
WizardImageFile=resources\[WIZARDIMAGEFILE].bmp
;WizardImageFile=resources\logo_large.bmp
;WizardImageFile=resources\logo_large_beta.bmp
;WizardImageFile=resources\logo_large_rc1.bmp
;WizardImageFile=resources\logo_large_rc2.bmp
WizardSmallImageFile=resources\logo_small.bmp
SetupIconFile=resources\catel.ico
UninstallDisplayIcon={app}\resources\catel.ico
SetupLogging=true
; For signing, the following sign tool must be configured
; Name: Signtool
; Command: "C:\Source\CatenaLogic_Certificates\Tools\signtool.exe" sign /t "http://timestamp.comodoca.com/authenticode" /f "C:\Source\CatenaLogic_Certificates\CodeSigning\current.pfx" "$f"
;SignTool=Signtool

[InnoIDE_Settings]
UseRelativePaths=true

[Dirs]
Name: {app}\doc;
Name: {app}\libraries;
Name: {app}\resources;
Name: {app}\snippets;
Name: {app}\templates;

[Files]
Source: readme.txt; DestDir: {app};
; Source: doc\catel.chm; DestDir: {app}\doc;
Source: resources\*; DestDir: {app}\resources;
Source: resources\catel.ico; DestDir: {app}\resources;

;----------
; Libraries
;----------

; Copy all files, then register specific files
Source: libraries\*; DestDir: {app}\libraries\; Flags: createallsubdirs recursesubdirs; Components: libraries;

;----------
; Snippets
;----------

Source: snippets\C#\*; DestDir: {#VS9Root}\VC#\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9Installed;
Source: snippets\VB.NET\*; DestDir: {#VS9Root}\VB\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9Installed;
Source: snippets\C#\*; DestDir: {#VS9Root}\VC#\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9ExpressInstalled;
Source: snippets\VB.NET\*; DestDir: {#VS9Root}\VB\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9ExpressInstalled;

Source: snippets\C#\*; DestDir: {#VS10Root}\VC#\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10Installed;
Source: snippets\VB.NET\*; DestDir: {#VS10Root}\VB\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10Installed;
Source: snippets\C#\*; DestDir: {#VS10Root}\VC#\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10ExpressInstalled;
Source: snippets\VB.NET\*; DestDir: {#VS10Root}\VB\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10ExpressInstalled;

Source: snippets\C#\*; DestDir: {#VS11Root}\VC#\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11Installed;
Source: snippets\VB.NET\*; DestDir: {#VS11Root}\VB\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11Installed;
Source: snippets\C#\*; DestDir: {#VS11Root}\VC#\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11ExpressInstalled;
Source: snippets\VB.NET\*; DestDir: {#VS11Root}\VB\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11ExpressInstalled;

;----------
; Templates
;----------

; VS 9 (VS 2008)
Source: templates\C#\itemtemplates\*; DestDir: {#VS9Root}\Common7\IDE\ItemTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9Installed;
Source: templates\C#\projecttemplates\*; DestDir: {#VS9Root}\Common7\IDE\ProjectTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9Installed;
Source: templates\VB.NET\itemtemplates\*; DestDir: {#VS9Root}\Common7\IDE\ItemTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9Installed;
Source: templates\VB.NET\projecttemplates\*; DestDir: {#VS9Root}\Common7\IDE\ProjectTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9Installed;

; VS 9 (VS 2008 Express)
Source: templates\C#\itemtemplates\*; DestDir: {#VS9Root}\Common7\IDE\VCSExpress\ItemTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9ExpressInstalled;
Source: templates\C#\projecttemplates\*; DestDir: {#VS9Root}\Common7\IDE\VCSExpress\ProjectTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9ExpressInstalled;
Source: templates\VB.NET\itemtemplates\*; DestDir: {#VS9Root}\Common7\IDE\VCSExpress\ItemTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9ExpressInstalled;
Source: templates\VB.NET\projecttemplates\*; DestDir: {#VS9Root}\Common7\IDE\VCSExpress\ProjectTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9ExpressInstalled;

; VS 10 (VS 2010)
Source: templates\C#\itemtemplates\*; DestDir: {#VS10Root}\Common7\IDE\ItemTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10Installed;
Source: templates\C#\projecttemplates\*; DestDir: {#VS10Root}\Common7\IDE\ProjectTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10Installed;
Source: templates\VB.NET\itemtemplates\*; DestDir: {#VS10Root}\Common7\IDE\ItemTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10Installed;
Source: templates\VB.NET\projecttemplates\*; DestDir: {#VS10Root}\Common7\IDE\ProjectTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10Installed;

; VS 10 (VS 2010 Express)
Source: templates\C#\itemtemplates\*; DestDir: {#VS10Root}\Common7\IDE\VCSExpress\ItemTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10ExpressInstalled;
Source: templates\C#\projecttemplates\*; DestDir: {#VS10Root}\Common7\IDE\VCSExpress\ProjectTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10ExpressInstalled;
Source: templates\VB.NET\itemtemplates\*; DestDir: {#VS10Root}\Common7\IDE\VCSExpress\ItemTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10ExpressInstalled;
Source: templates\VB.NET\projecttemplates\*; DestDir: {#VS10Root}\Common7\IDE\VCSExpress\ProjectTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10ExpressInstalled;

; VS 11 (VS 11)
Source: templates\C#\itemtemplates\*; DestDir: {#VS11Root}\Common7\IDE\ItemTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11Installed;
Source: templates\C#\projecttemplates\*; DestDir: {#VS11Root}\Common7\IDE\ProjectTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11Installed;
Source: templates\VB.NET\itemtemplates\*; DestDir: {#VS11Root}\Common7\IDE\ItemTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11Installed;
Source: templates\VB.NET\projecttemplates\*; DestDir: {#VS11Root}\Common7\IDE\ProjectTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11Installed;

; VS 11 (VS 11 Express)
Source: templates\C#\itemtemplates\*; DestDir: {#VS11Root}\Common7\IDE\VCSExpress\ItemTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11ExpressInstalled;
Source: templates\C#\projecttemplates\*; DestDir: {#VS11Root}\Common7\IDE\VCSExpress\ProjectTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11ExpressInstalled;
Source: templates\VB.NET\itemtemplates\*; DestDir: {#VS11Root}\Common7\IDE\VCSExpress\ItemTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11ExpressInstalled;
Source: templates\VB.NET\projecttemplates\*; DestDir: {#VS11Root}\Common7\IDE\VCSExpress\ProjectTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11ExpressInstalled;

[CustomMessages]
DotNetMissing=This setup requires the .NET Framework. Please download and install the .NET Framework and run this setup again. Do you want to download the framework now?

[ThirdPartySettings]
CompileLogMethod=append

[UninstallDelete]
Name: {app}; Type: filesandordirs

[Registry]
Root: HKLM; SubKey: SOFTWARE\Microsoft\.NETFramework\v4.0.30319\AssemblyFoldersEx\Catel; ValueType: string; ValueData: {app}\Libraries\NET40; Flags: UninsDeleteKey
Root: HKLM; SubKey: SOFTWARE\Microsoft\.NETFramework\v4.5.40805\AssemblyFoldersEx\Catel; ValueType: string; ValueData: {app}\Libraries\NET45; Flags: UninsDeleteKey

Root: HKLM; SubKey: SOFTWARE\Microsoft\Microsoft SDKs\Silverlight\v4.0\AssemblyFoldersEx\Catel; ValueType: string; ValueData: {app}\Libraries\SL4; Flags: UninsDeleteKey
Root: HKLM; SubKey: SOFTWARE\Microsoft\Microsoft SDKs\Silverlight\v5.0\AssemblyFoldersEx\Catel; ValueType: string; ValueData: {app}\Libraries\SL5; Flags: UninsDeleteKey

Root: HKLM; SubKey: SOFTWARE\Microsoft\Microsoft SDKs\Silverlight for WindowsPhone\v4.0\AssemblyFoldersEx\Catel (WP7); ValueType: string; ValueData: {app}\Libraries\WP7; Flags: UninsDeleteKey
Root: HKLM; SubKey: SOFTWARE\Microsoft\Microsoft SDKs\WindowsPhone\v8.0\AssemblyFoldersEx\Catel (WP8); ValueType: string; ValueData: {app}\Libraries\WP8; Flags: UninsDeleteKey

;Root: HKLM; SubKey: SOFTWARE\Microsoft\Microsoft SDKs\Silverlight for WindowsPhone\v4.0\AssemblyFoldersEx\Catel (WinRT); ValueType: string; ValueData: {app}\Libraries\WinRT; Flags: UninsDeleteKey

[Icons]
Name: "{group}\Go to Catel homepage"; Filename: http://www.catelproject.com;
Name: "{group}\Documentation (online)"; Filename: http://www.catelproject.com/support/documentation;
;Name: "{group}\Documentation (offline)"; Filename: {app}\doc\catel.chm;
Name: "{group}\Uninstall Catel"; Filename: {app}\unins000.exe; WorkingDir: {app}; IconFilename: {app}\resources\catel.ico;

[Types]
Name: Full; Description: "Full installation";
Name: Custom; Description: Custom; Flags: IsCustom;

[Components]
Name: libraries; Description: Libraries; Types: Full Custom;
Name: snippets; Description: "Code snippets"; Types: Full Custom;
Name: templates; Description: "Project and Item templates"; Types: Full Custom;

[Languages]
Name: "English"; MessagesFile: "compiler:Default.isl"
Name: "Czech"; MessagesFile: "compiler:Languages\Czech.isl"
Name: "Danish"; MessagesFile: "compiler:Languages\Danish.isl"
Name: "Dutch"; MessagesFile: "compiler:Languages\Dutch.isl"
Name: "Finnish"; MessagesFile: "compiler:Languages\Finnish.isl"
Name: "French"; MessagesFile: "compiler:Languages\French.isl"
Name: "German"; MessagesFile: "compiler:Languages\German.isl"
Name: "Hungarian"; MessagesFile: "compiler:Languages\Hungarian.isl"
Name: "Italian"; MessagesFile: "compiler:Languages\Italian.isl"
Name: "Japanese"; MessagesFile: "compiler:Languages\Japanese.isl"
Name: "Norwegian"; MessagesFile: "compiler:Languages\Norwegian.isl"
Name: "Polish"; MessagesFile: "compiler:Languages\Polish.isl"
Name: "Portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl"
Name: "Russian"; MessagesFile: "compiler:Languages\Russian.isl"
Name: "Spanish"; MessagesFile: "compiler:Languages\Spanish.isl"

[Run]
; VS 9 (VS 2008)
Filename: {#VS9Root}\Common7\IDE\devenv.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2008 templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;
Filename: {#VS9Root}\Common7\IDE\VCSExpress.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2008 Express templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;

; VS 10 (VS 2010)
Filename: {#VS10Root}\Common7\IDE\devenv.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2010 templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;
Filename: {#VS10Root}\Common7\IDE\VCSExpress.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2010 Express templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;

; VS 11 (VS 2012)
Filename: {#VS11Root}\Common7\IDE\devenv.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2012 templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;
Filename: {#VS11Root}\Common7\IDE\VCSExpress.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2012 Express templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;

[UninstallRun]
; VS 9 (VS 2008)
Filename: {#VS9Root}\Common7\IDE\devenv.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2008 templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;
Filename: {#VS9Root}\Common7\IDE\VCSExpress.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2008 Express templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;

; VS 10 (VS 2010)
Filename: {#VS10Root}\Common7\IDE\devenv.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2010 templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;
Filename: {#VS10Root}\Common7\IDE\VCSExpress.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2010 Express templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;

; VS 11 (VS 2012)
Filename: {#VS11Root}\Common7\IDE\devenv.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2012 templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;
Filename: {#VS11Root}\Common7\IDE\VCSExpress.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2012 Express templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;

[ThirdParty]
CompileLogMethod=append

[Code]
//=========================================================================
// IsDotNetFrameworkInstalled
//=========================================================================
{
	Checks whether the right version of the .NET framework is installed
}

function IsDotNetFrameworkInstalled : Boolean;
var
    ErrorCode: Integer;
    NetFrameWorkInstalled : Boolean;
begin
	// Check if the .NET framework is installed
	//NetFrameWorkInstalled := RegKeyExists(HKLM,'SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727'); 	// 2.0
	//NetFrameWorkInstalled := RegKeyExists(HKLM,'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0'); 		// 3.0
	NetFrameWorkInstalled := RegKeyExists(HKLM,'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5'); 			// 3.5
	//NetFrameWorkInstalled := RegKeyExists(HKLM,'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4'); 			// 4.0

	// If the .NET framework is not installed, show message to user to download the framework
	if NetFrameWorkInstalled = false then
	begin
		if MsgBox(ExpandConstant('{cm:DotNetMissing}'), mbConfirmation, MB_YESNO) = idYes then
		begin
			ShellExec('open',
				//'http://www.microsoft.com/downloads/details.aspx?FamilyID=0856eacb-4362-4b0d-8edd-aab15c5e04f5&displaylang=en', // 2.0
				//'http://www.microsoft.com/downloads/details.aspx?FamilyID=10cc340b-f857-4a14-83f5-25634c3bf043&displaylang=en', // 3.0
				'http://www.microsoft.com/downloads/details.aspx?FamilyId=333325fd-ae52-4e35-b531-508d977d32a6&displaylang=en', // 3.5
				//'http://www.microsoft.com/downloads/details.aspx?familyid=9CFB2D51-5FF4-4491-B0E5-B386F32C0992&displaylang=en', // 4.0
				'','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
		end;
	end;

	// Return result
	Result := NetFrameWorkInstalled;
end;

//=========================================================================
// INITIALIZESETUP
//=========================================================================
{
	This function initializes the setup.
}

function InitializeSetup(): Boolean;
var
  sPrevPath: String;
begin
  // Check .NET framework
  if (IsDotNetFrameworkInstalled() = false) then
  begin
	Result := false;
	exit;
  end;

  Result := true;
end;

//=========================================================================
// VS checks
//=========================================================================

function IsVs9Installed : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS9Root}\Common7\IDE\devenv.exe');

  Log('Checking path "' + sPath + '" to determine whether VS9 is installed');

  Result := FileExists(sPath);
end;

function IsVs9ExpressInstalled : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS9Root}\Common7\IDE\VCSExpress.exe');

  Log('Checking path "' + sPath + '" to determine whether VS9 Express is installed');

  Result := FileExists(sPath);
end;

//================================

function IsVs10Installed : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS10Root}\Common7\IDE\devenv.exe');

  Log('Checking path "' + sPath + '" to determine whether VS10 is installed');

  Result := FileExists(sPath);
end;

function IsVs10ExpressInstalled : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS10Root}\Common7\IDE\VCSExpress.exe');

  Log('Checking path "' + sPath + '" to determine whether VS10 Express is installed');

  Result := FileExists(sPath);
end;

//================================

function IsVs11Installed : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS11Root}\Common7\IDE\devenv.exe');

  Log('Checking path "' + sPath + '" to determine whether VS11 is installed');

  Result := FileExists(sPath);
end;

function IsVs11ExpressInstalled : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS11Root}\Common7\IDE\VCSExpress.exe');

  Log('Checking path "' + sPath + '" to determine whether VS11 Express is installed');

  Result := FileExists(sPath);
end;

//================================

function IsVs12Installed : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS12Root}\Common7\IDE\devenv.exe');

  Log('Checking path "' + sPath + '" to determine whether VS12 is installed');

  Result := FileExists(sPath);
end;

function IsVs12ExpressInstalled : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS12Root}\Common7\IDE\VCSExpress.exe');

  Log('Checking path "' + sPath + '" to determine whether VS12 Express is installed');

  Result := FileExists(sPath);
end;

#define AppName "Catel"
#define SourceDirectory ""
; #define AppVersion "3.1"
#define AppVersion "[VERSION]"
; #define AppDisplayVersion "3.1 beta 1"
#define AppDisplayVersion "[VERSION_DISPLAY]"
#define AppNameWithDisplayVersion AppName AppDisplayVersion
#define AppNameWithVersion AppName AppVersion
#define Website "http://www.catelproject.com"
#define OutputPrefix "catel"
#define Company "CatenaLogic"

#define VS9Root "{pf32}\Microsoft Visual Studio 9.0"
#define VS10Root "{pf32}\Microsoft Visual Studio 10.0"
#define VS11Root "{pf32}\Microsoft Visual Studio 11.0"
#define VS12Root "{pf32}\Microsoft Visual Studio 12.0"

#define OutputFileWithSpaces OutputPrefix + "_" + AppDisplayVersion
#define OutputFile StringChange(OutputFileWithSpaces, " ", "_")

[_ISTool]
EnableISX=false
Use7zip=false

[Setup]
AppName={#AppNameWithVersion}
AppVerName={#AppNameWithDisplayVersion}
AppID={#AppNameWithVersion}
AppPublisher={#Company}
AppCopyright={#Company}
DefaultDirName={pf32}\{#AppNameWithVersion}
DefaultGroupName={#AppNameWithVersion}
UsePreviousSetupType=true
OutputDir=..\output
OutputBaseFilename={#OutputFile}
UninstallDisplayName={#AppNameWithVersion}
Compression=lzma2/Ultra64
UseSetupLdr=true
SolidCompression=true
ShowLanguageDialog=yes
VersionInfoVersion={#AppVersion}
AppVersion={#AppVersion}
InternalCompressLevel=Ultra64
AppPublisherURL={#Website}
AppSupportURL={#Website}
AppUpdatesURL={#Website}
AppContact={#Website}
VersionInfoCompany={#Company}
AppMutex={#AppNameWithVersion}
LanguageDetectionMethod=none
DisableStartupPrompt=True
WizardImageFile=resources\[WIZARDIMAGEFILE].bmp
;WizardImageFile=resources\logo_large.bmp
;WizardImageFile=resources\logo_large_beta.bmp
;WizardImageFile=resources\logo_large_rc1.bmp
;WizardImageFile=resources\logo_large_rc2.bmp
WizardSmallImageFile=resources\logo_small.bmp
SetupIconFile=resources\catel.ico
UninstallDisplayIcon={app}\resources\catel.ico
SetupLogging=true
; For signing, the following sign tool must be configured
; Name: Signtool
; Command: "C:\Source\CatenaLogic_Certificates\Tools\signtool.exe" sign /t "http://timestamp.comodoca.com/authenticode" /f "C:\Source\CatenaLogic_Certificates\CodeSigning\current.pfx" "$f"
;SignTool=Signtool

[InnoIDE_Settings]
UseRelativePaths=true

[Dirs]
Name: {app}\doc;
Name: {app}\libraries;
Name: {app}\resources;
Name: {app}\snippets;
Name: {app}\templates;

[Files]
Source: readme.txt; DestDir: {app};
; Source: doc\catel.chm; DestDir: {app}\doc;
Source: resources\*; DestDir: {app}\resources;
Source: resources\catel.ico; DestDir: {app}\resources;

;----------
; Libraries
;----------

; Copy all files, then register specific files
Source: libraries\*; DestDir: {app}\libraries\; Flags: createallsubdirs recursesubdirs; Components: libraries;

;----------
; Snippets
;----------

Source: snippets\C#\*; DestDir: {#VS9Root}\VC#\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9Installed;
Source: snippets\VB.NET\*; DestDir: {#VS9Root}\VB\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9Installed;
Source: snippets\C#\*; DestDir: {#VS9Root}\VC#\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9ExpressInstalled;
Source: snippets\VB.NET\*; DestDir: {#VS9Root}\VB\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9ExpressInstalled;

Source: snippets\C#\*; DestDir: {#VS10Root}\VC#\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10Installed;
Source: snippets\VB.NET\*; DestDir: {#VS10Root}\VB\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10Installed;
Source: snippets\C#\*; DestDir: {#VS10Root}\VC#\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10ExpressInstalled;
Source: snippets\VB.NET\*; DestDir: {#VS10Root}\VB\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10ExpressInstalled;

Source: snippets\C#\*; DestDir: {#VS11Root}\VC#\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11Installed;
Source: snippets\VB.NET\*; DestDir: {#VS11Root}\VB\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11Installed;
Source: snippets\C#\*; DestDir: {#VS11Root}\VC#\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11ExpressInstalled;
Source: snippets\VB.NET\*; DestDir: {#VS11Root}\VB\Snippets\1033\other\Catel; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11ExpressInstalled;

;----------
; Templates
;----------

; VS 9 (VS 2008)
Source: templates\C#\itemtemplates\*; DestDir: {#VS9Root}\Common7\IDE\ItemTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9Installed;
Source: templates\C#\projecttemplates\*; DestDir: {#VS9Root}\Common7\IDE\ProjectTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9Installed;
Source: templates\VB.NET\itemtemplates\*; DestDir: {#VS9Root}\Common7\IDE\ItemTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9Installed;
Source: templates\VB.NET\projecttemplates\*; DestDir: {#VS9Root}\Common7\IDE\ProjectTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9Installed;

; VS 9 (VS 2008 Express)
Source: templates\C#\itemtemplates\*; DestDir: {#VS9Root}\Common7\IDE\VCSExpress\ItemTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9ExpressInstalled;
Source: templates\C#\projecttemplates\*; DestDir: {#VS9Root}\Common7\IDE\VCSExpress\ProjectTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9ExpressInstalled;
Source: templates\VB.NET\itemtemplates\*; DestDir: {#VS9Root}\Common7\IDE\VCSExpress\ItemTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9ExpressInstalled;
Source: templates\VB.NET\projecttemplates\*; DestDir: {#VS9Root}\Common7\IDE\VCSExpress\ProjectTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs9ExpressInstalled;

; VS 10 (VS 2010)
Source: templates\C#\itemtemplates\*; DestDir: {#VS10Root}\Common7\IDE\ItemTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10Installed;
Source: templates\C#\projecttemplates\*; DestDir: {#VS10Root}\Common7\IDE\ProjectTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10Installed;
Source: templates\VB.NET\itemtemplates\*; DestDir: {#VS10Root}\Common7\IDE\ItemTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10Installed;
Source: templates\VB.NET\projecttemplates\*; DestDir: {#VS10Root}\Common7\IDE\ProjectTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10Installed;

; VS 10 (VS 2010 Express)
Source: templates\C#\itemtemplates\*; DestDir: {#VS10Root}\Common7\IDE\VCSExpress\ItemTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10ExpressInstalled;
Source: templates\C#\projecttemplates\*; DestDir: {#VS10Root}\Common7\IDE\VCSExpress\ProjectTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10ExpressInstalled;
Source: templates\VB.NET\itemtemplates\*; DestDir: {#VS10Root}\Common7\IDE\VCSExpress\ItemTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10ExpressInstalled;
Source: templates\VB.NET\projecttemplates\*; DestDir: {#VS10Root}\Common7\IDE\VCSExpress\ProjectTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs10ExpressInstalled;

; VS 11 (VS 11)
Source: templates\C#\itemtemplates\*; DestDir: {#VS11Root}\Common7\IDE\ItemTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11Installed;
Source: templates\C#\projecttemplates\*; DestDir: {#VS11Root}\Common7\IDE\ProjectTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11Installed;
Source: templates\VB.NET\itemtemplates\*; DestDir: {#VS11Root}\Common7\IDE\ItemTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11Installed;
Source: templates\VB.NET\projecttemplates\*; DestDir: {#VS11Root}\Common7\IDE\ProjectTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11Installed;

; VS 11 (VS 11 Express)
Source: templates\C#\itemtemplates\*; DestDir: {#VS11Root}\Common7\IDE\VCSExpress\ItemTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11ExpressInstalled;
Source: templates\C#\projecttemplates\*; DestDir: {#VS11Root}\Common7\IDE\VCSExpress\ProjectTemplates\CSharp\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11ExpressInstalled;
Source: templates\VB.NET\itemtemplates\*; DestDir: {#VS11Root}\Common7\IDE\VCSExpress\ItemTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11ExpressInstalled;
Source: templates\VB.NET\projecttemplates\*; DestDir: {#VS11Root}\Common7\IDE\VCSExpress\ProjectTemplates\VisualBasic\Catel\1033; Flags: createallsubdirs recursesubdirs; Components: templates; Check: IsVs11ExpressInstalled;

[CustomMessages]
DotNetMissing=This setup requires the .NET Framework. Please download and install the .NET Framework and run this setup again. Do you want to download the framework now?

[ThirdPartySettings]
CompileLogMethod=append

[UninstallDelete]
Name: {app}; Type: filesandordirs

[Registry]
Root: HKLM; SubKey: SOFTWARE\Microsoft\.NETFramework\v4.0.30319\AssemblyFoldersEx\Catel; ValueType: string; ValueData: {app}\Libraries\NET40; Flags: UninsDeleteKey
Root: HKLM; SubKey: SOFTWARE\Microsoft\.NETFramework\v4.5.40805\AssemblyFoldersEx\Catel; ValueType: string; ValueData: {app}\Libraries\NET45; Flags: UninsDeleteKey

Root: HKLM; SubKey: SOFTWARE\Microsoft\Microsoft SDKs\Silverlight\v4.0\AssemblyFoldersEx\Catel; ValueType: string; ValueData: {app}\Libraries\SL4; Flags: UninsDeleteKey
Root: HKLM; SubKey: SOFTWARE\Microsoft\Microsoft SDKs\Silverlight\v5.0\AssemblyFoldersEx\Catel; ValueType: string; ValueData: {app}\Libraries\SL5; Flags: UninsDeleteKey

Root: HKLM; SubKey: SOFTWARE\Microsoft\Microsoft SDKs\Silverlight for WindowsPhone\v4.0\AssemblyFoldersEx\Catel (WP7); ValueType: string; ValueData: {app}\Libraries\WP7; Flags: UninsDeleteKey
Root: HKLM; SubKey: SOFTWARE\Microsoft\Microsoft SDKs\WindowsPhone\v8.0\AssemblyFoldersEx\Catel (WP8); ValueType: string; ValueData: {app}\Libraries\WP8; Flags: UninsDeleteKey

;Root: HKLM; SubKey: SOFTWARE\Microsoft\Microsoft SDKs\Silverlight for WindowsPhone\v4.0\AssemblyFoldersEx\Catel (WinRT); ValueType: string; ValueData: {app}\Libraries\WinRT; Flags: UninsDeleteKey

[Icons]
Name: "{group}\Go to Catel homepage"; Filename: http://www.catelproject.com;
Name: "{group}\Documentation (online)"; Filename: http://www.catelproject.com/support/documentation;
;Name: "{group}\Documentation (offline)"; Filename: {app}\doc\catel.chm;
Name: "{group}\Uninstall Catel"; Filename: {app}\unins000.exe; WorkingDir: {app}; IconFilename: {app}\resources\catel.ico;

[Types]
Name: Full; Description: "Full installation";
Name: Custom; Description: Custom; Flags: IsCustom;

[Components]
Name: libraries; Description: Libraries; Types: Full Custom;
Name: snippets; Description: "Code snippets"; Types: Full Custom;
Name: templates; Description: "Project and Item templates"; Types: Full Custom;

[Languages]
Name: "English"; MessagesFile: "compiler:Default.isl"
Name: "Czech"; MessagesFile: "compiler:Languages\Czech.isl"
Name: "Danish"; MessagesFile: "compiler:Languages\Danish.isl"
Name: "Dutch"; MessagesFile: "compiler:Languages\Dutch.isl"
Name: "Finnish"; MessagesFile: "compiler:Languages\Finnish.isl"
Name: "French"; MessagesFile: "compiler:Languages\French.isl"
Name: "German"; MessagesFile: "compiler:Languages\German.isl"
Name: "Hungarian"; MessagesFile: "compiler:Languages\Hungarian.isl"
Name: "Italian"; MessagesFile: "compiler:Languages\Italian.isl"
Name: "Japanese"; MessagesFile: "compiler:Languages\Japanese.isl"
Name: "Norwegian"; MessagesFile: "compiler:Languages\Norwegian.isl"
Name: "Polish"; MessagesFile: "compiler:Languages\Polish.isl"
Name: "Portuguese"; MessagesFile: "compiler:Languages\Portuguese.isl"
Name: "Russian"; MessagesFile: "compiler:Languages\Russian.isl"
Name: "Spanish"; MessagesFile: "compiler:Languages\Spanish.isl"

[Run]
; VS 9 (VS 2008)
Filename: {#VS9Root}\Common7\IDE\devenv.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2008 templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;
Filename: {#VS9Root}\Common7\IDE\VCSExpress.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2008 Express templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;

; VS 10 (VS 2010)
Filename: {#VS10Root}\Common7\IDE\devenv.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2010 templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;
Filename: {#VS10Root}\Common7\IDE\VCSExpress.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2010 Express templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;

; VS 11 (VS 2012)
Filename: {#VS11Root}\Common7\IDE\devenv.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2012 templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;
Filename: {#VS11Root}\Common7\IDE\VCSExpress.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2012 Express templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;

[UninstallRun]
; VS 9 (VS 2008)
Filename: {#VS9Root}\Common7\IDE\devenv.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2008 templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;
Filename: {#VS9Root}\Common7\IDE\VCSExpress.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2008 Express templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;

; VS 10 (VS 2010)
Filename: {#VS10Root}\Common7\IDE\devenv.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2010 templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;
Filename: {#VS10Root}\Common7\IDE\VCSExpress.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2010 Express templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;

; VS 11 (VS 2012)
Filename: {#VS11Root}\Common7\IDE\devenv.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2012 templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;
Filename: {#VS11Root}\Common7\IDE\VCSExpress.exe; Parameters: /installvstemplates; StatusMsg: "Updating Visual Studio 2012 Express templates cache (can take a minute or two)"; Components: templates; Flags: SkipIfDoesntExist;

[ThirdParty]
CompileLogMethod=append

[Code]
//=========================================================================
// IsDotNetFrameworkInstalled
//=========================================================================
{
	Checks whether the right version of the .NET framework is installed
}

function IsDotNetFrameworkInstalled : Boolean;
var
    ErrorCode: Integer;
    NetFrameWorkInstalled : Boolean;
begin
	// Check if the .NET framework is installed
	//NetFrameWorkInstalled := RegKeyExists(HKLM,'SOFTWARE\Microsoft\NET Framework Setup\NDP\v2.0.50727'); 	// 2.0
	//NetFrameWorkInstalled := RegKeyExists(HKLM,'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.0'); 		// 3.0
	NetFrameWorkInstalled := RegKeyExists(HKLM,'SOFTWARE\Microsoft\NET Framework Setup\NDP\v3.5'); 			// 3.5
	//NetFrameWorkInstalled := RegKeyExists(HKLM,'SOFTWARE\Microsoft\NET Framework Setup\NDP\v4'); 			// 4.0

	// If the .NET framework is not installed, show message to user to download the framework
	if NetFrameWorkInstalled = false then
	begin
		if MsgBox(ExpandConstant('{cm:DotNetMissing}'), mbConfirmation, MB_YESNO) = idYes then
		begin
			ShellExec('open',
				//'http://www.microsoft.com/downloads/details.aspx?FamilyID=0856eacb-4362-4b0d-8edd-aab15c5e04f5&displaylang=en', // 2.0
				//'http://www.microsoft.com/downloads/details.aspx?FamilyID=10cc340b-f857-4a14-83f5-25634c3bf043&displaylang=en', // 3.0
				'http://www.microsoft.com/downloads/details.aspx?FamilyId=333325fd-ae52-4e35-b531-508d977d32a6&displaylang=en', // 3.5
				//'http://www.microsoft.com/downloads/details.aspx?familyid=9CFB2D51-5FF4-4491-B0E5-B386F32C0992&displaylang=en', // 4.0
				'','',SW_SHOWNORMAL,ewNoWait,ErrorCode);
		end;
	end;

	// Return result
	Result := NetFrameWorkInstalled;
end;

//=========================================================================
// INITIALIZESETUP
//=========================================================================
{
	This function initializes the setup.
}

function InitializeSetup(): Boolean;
var
  sPrevPath: String;
begin
  // Check .NET framework
  if (IsDotNetFrameworkInstalled() = false) then
  begin
	Result := false;
	exit;
  end;

  Result := true;
end;

//=========================================================================
// VS checks
//=========================================================================

function IsVs9Installed : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS9Root}\Common7\IDE\devenv.exe');

  Log('Checking path "' + sPath + '" to determine whether VS9 is installed');

  Result := FileExists(sPath);
end;

function IsVs9ExpressInstalled : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS9Root}\Common7\IDE\VCSExpress.exe');

  Log('Checking path "' + sPath + '" to determine whether VS9 Express is installed');

  Result := FileExists(sPath);
end;

//================================

function IsVs10Installed : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS10Root}\Common7\IDE\devenv.exe');

  Log('Checking path "' + sPath + '" to determine whether VS10 is installed');

  Result := FileExists(sPath);
end;

function IsVs10ExpressInstalled : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS10Root}\Common7\IDE\VCSExpress.exe');

  Log('Checking path "' + sPath + '" to determine whether VS10 Express is installed');

  Result := FileExists(sPath);
end;

//================================

function IsVs11Installed : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS11Root}\Common7\IDE\devenv.exe');

  Log('Checking path "' + sPath + '" to determine whether VS11 is installed');

  Result := FileExists(sPath);
end;

function IsVs11ExpressInstalled : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS11Root}\Common7\IDE\VCSExpress.exe');

  Log('Checking path "' + sPath + '" to determine whether VS11 Express is installed');

  Result := FileExists(sPath);
end;

//================================

function IsVs12Installed : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS12Root}\Common7\IDE\devenv.exe');

  Log('Checking path "' + sPath + '" to determine whether VS12 is installed');

  Result := FileExists(sPath);
end;

function IsVs12ExpressInstalled : Boolean;
var
  sPath: string;
begin
  sPath := ExpandConstant('{#VS12Root}\Common7\IDE\VCSExpress.exe');

  Log('Checking path "' + sPath + '" to determine whether VS12 Express is installed');

  Result := FileExists(sPath);
end;


do not take install.bat with installer download install script before installation

; Script generated by the Inno Script Studio Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#include <idp.iss>

#define MyAppName "Teigen"
#define MyAppVersion "1.0.0"
#define MyAppPublisher "University of West Bohemia, NTIS"
#define MyAppURL "http://mjirik.github.io/teigen/"

[Files]
; Source: "installer.bat"; DestDir: "{tmp}"
; Source: "applications\LISA.ico"; DestDir: "{app}"

[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={{28107EFB-FFBD-4968-AF2E-54EE04160219}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
;default is into c:\Users\Public if not, use userpf
;DefaultDirName={%PUBLIC|{userpf}}\{#MyAppName}
;DefaultDirName={commonappdata}\{#MyAppName}
;DefaultDirName={%HOMEPATH}\{#MyAppName}
DefaultDirName={userpf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup_teigen
Compression=lzma
SolidCompression=yes
;PrivilegesRequired=lowest
UsePreviousSetupType=False
UsePreviousTasks=False
UsePreviousLanguage=False
ExtraDiskSpaceRequired=43
SetupIconFile=..\lisa\applications\LISA.ico
UsePreviousAppDir=False
PrivilegesRequired=none

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

[Run]
;Filename: "{tmp}\Miniconda-latest-Windows-x86_64.exe"; Parameters: "/AddToPath=1 /RegisterPython=1 /InstallationType=AllUsers /D={%PUBLIC}\Minicoconda2"; Flags: waituntilterminated runasoriginaluser
Filename: "{tmp}\Miniconda-latest-Windows-x86_64.exe"; Parameters: "/AddToPath=1 /RegisterPython=1"; Flags: waituntilterminated; Check: not IsCondaInstalled
Filename: "msiexec.exe"; Parameters: "/i ""{tmp}\VCForPython27.msi"""; Flags: waituntilterminated; Check: not IsVCForPythonInstalled
Filename: "{cmd}"; Parameters: "/C ""{tmp}\installer.bat & pause"""; WorkingDir: "{tmp}"; Flags: waituntilterminated
;Filename: "{cmd}"; Parameters: "/C ""conda install --yes -c SimpleITK -c mjirik lisa"""; WorkingDir: "{%HOMEPATH}\Miniconda2\Scripts"; Flags: runasoriginaluser
;Filename: "{cmd}"; Parameters: "/C ""pause"""
;Filename: "conda"; Parameters: "create -y --no-default-packages -c mjirik -c SimpleITK -n lisa lisa pywget pip"

;[Components]
;Name: "VCForPython"; Description: "Visual Compiler for Python"

[Code]
function IsCondaInstalled: boolean;
begin
  result := not (FileExists('c:\Miniconda2\Scripts\conda.exe') or FileExists('{%HOMEPATH}\Miniconda2\Scripts\conda.exe') or FileExists('c:\Anaconda2\Scripts\conda.exe') or FileExists('c:\Miniconda\Scripts\conda.exe') or FileExists('c:\Anaconda\Scripts\conda.exe') or FileExists('{%HOMEPATH}\Miniconda2\Scripts\conda.exe') or FileExists('{%HOMEPATH}\Miniconda\Scripts\conda.exe') or FileExists('{%HOMEPATH}\Anaconda2\Scripts\conda.exe') or FileExists('{%HOMEPATH}\Anaconda\Scripts\conda.exe'));
  Log(Format('IsCondaInstalled: %d', [result]))
end;

function IsVCForPythonInstalled: boolean;
begin
  result := True
  Log(Format('IsVCForPythonInstalled: %d', [result]))
end;

procedure InitializeWizard();
begin
  idpAddFileSize('https://raw.githubusercontent.com/mjirik/teigen/master/installer.bat', ExpandConstant('{tmp}\installer.bat'), 1000);
  if not IsCondaInstalled then
  begin
    Log('Conda will be downloaded')
    idpAddFileSize('https://repo.continuum.io/miniconda/Miniconda-latest-Windows-x86_64.exe', ExpandConstant('{tmp}\Miniconda-latest-Windows-x86_64.exe'), 22743040);
  end;
  if not IsVCForPythonInstalled then
  begin
    idpAddFileSize('https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi', ExpandConstant('{tmp}\VCForPython27.msi'), 87891968);
  end;
  idpDownloadAfter(wpReady);
end;

[Icons]
Name: "{group}\Teigen"; Filename: "{cmd}"; WorkingDir: "{userdocs}"; Flags: runminimized; IconFilename: "{app}\LISA.ico"; IconIndex: 0; Parameters: "/C ""call activate teigen & python -m teigen"""
Name: "{commondesktop}\Teigen"; Filename: "{cmd}"; WorkingDir: "{commondocs}"; Flags: runminimized; IconFilename: "{app}\LISA.ico"; IconIndex: 0; Parameters: "/C ""call activate teigen & python -m teigen"""

; Script generated by the Inno Script Studio Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#include <idp.iss>

#define MyAppName "Teigen"
#define MyAppVersion "1.0.0"
#define MyAppPublisher "University of West Bohemia, NTIS"
#define MyAppURL "http://mjirik.github.io/teigen/"

[Files]
Source: "installer.bat"; DestDir: "{tmp}"
; Source: "applications\LISA.ico"; DestDir: "{app}"

[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={{28107EFB-FFBD-4968-AF2E-54EE04160219}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
;default is into c:\Users\Public if not, use userpf
;DefaultDirName={%PUBLIC|{userpf}}\{#MyAppName}
;DefaultDirName={commonappdata}\{#MyAppName}
;DefaultDirName={%HOMEPATH}\{#MyAppName}
DefaultDirName={userpf}\{#MyAppName}
DefaultGroupName={#MyAppName}
OutputBaseFilename=setup_teigen
Compression=lzma
SolidCompression=yes
;PrivilegesRequired=lowest
UsePreviousSetupType=False
UsePreviousTasks=False
UsePreviousLanguage=False
ExtraDiskSpaceRequired=43
SetupIconFile=..\lisa\applications\LISA.ico
UsePreviousAppDir=False
PrivilegesRequired=none

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

[Run]
;Filename: "{tmp}\Miniconda-latest-Windows-x86_64.exe"; Parameters: "/AddToPath=1 /RegisterPython=1 /InstallationType=AllUsers /D={%PUBLIC}\Minicoconda2"; Flags: waituntilterminated runasoriginaluser
Filename: "{tmp}\Miniconda-latest-Windows-x86_64.exe"; Parameters: "/AddToPath=1 /RegisterPython=1"; Flags: waituntilterminated; Check: not IsCondaInstalled
Filename: "msiexec.exe"; Parameters: "/i ""{tmp}\VCForPython27.msi"""; Flags: waituntilterminated; Check: not IsVCForPythonInstalled
Filename: "{cmd}"; Parameters: "/C ""{tmp}\installer.bat & pause"""; WorkingDir: "{tmp}"; Flags: waituntilterminated
;Filename: "{cmd}"; Parameters: "/C ""conda install --yes -c SimpleITK -c mjirik lisa"""; WorkingDir: "{%HOMEPATH}\Miniconda2\Scripts"; Flags: runasoriginaluser
;Filename: "{cmd}"; Parameters: "/C ""pause"""
;Filename: "conda"; Parameters: "create -y --no-default-packages -c mjirik -c SimpleITK -n lisa lisa pywget pip"

;[Components]
;Name: "VCForPython"; Description: "Visual Compiler for Python"

[Code]
function IsCondaInstalled: boolean;
begin
  result := not (FileExists('c:\Miniconda2\Scripts\conda.exe') or FileExists('{%HOMEPATH}\Miniconda2\Scripts\conda.exe') or FileExists('c:\Anaconda2\Scripts\conda.exe') or FileExists('c:\Miniconda\Scripts\conda.exe') or FileExists('c:\Anaconda\Scripts\conda.exe') or FileExists('{%HOMEPATH}\Miniconda2\Scripts\conda.exe') or FileExists('{%HOMEPATH}\Miniconda\Scripts\conda.exe') or FileExists('{%HOMEPATH}\Anaconda2\Scripts\conda.exe') or FileExists('{%HOMEPATH}\Anaconda\Scripts\conda.exe'));
  Log(Format('IsCondaInstalled: %d', [result]))
end;

function IsVCForPythonInstalled: boolean;
begin
  result := True
  Log(Format('IsVCForPythonInstalled: %d', [result]))
end;

procedure InitializeWizard();
begin
  if not IsCondaInstalled then
  begin
    Log('Conda will be downloaded')
    idpAddFileSize('https://repo.continuum.io/miniconda/Miniconda-latest-Windows-x86_64.exe', ExpandConstant('{tmp}\Miniconda-latest-Windows-x86_64.exe'), 22743040);
  end;
  if not IsVCForPythonInstalled then
  begin
    idpAddFileSize('https://download.microsoft.com/download/7/9/6/796EF2E4-801B-4FC4-AB28-B59FBF6D907B/VCForPython27.msi', ExpandConstant('{tmp}\VCForPython27.msi'), 87891968);
  end;
  idpDownloadAfter(wpReady);
end;

[Icons]
Name: "{group}\Teigen"; Filename: "{cmd}"; WorkingDir: "{userdocs}"; Flags: runminimized; IconFilename: "{app}\LISA.ico"; IconIndex: 0; Parameters: "/C ""call activate teigen & python -m teigen"""
Name: "{commondesktop}\Teigen"; Filename: "{cmd}"; WorkingDir: "{commondocs}"; Flags: runminimized; IconFilename: "{app}\LISA.ico"; IconIndex: 0; Parameters: "/C ""call activate teigen & python -m teigen"""


development

development

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define AppName "IoN"
#define AppVersion "0.0.6"
#define AppPublisher "Lagildo"
#define AppURL "http://www.lagildo.com/"
#define AppExeName "ion.exe"
#define BINDIR "..\..\Release"

[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={{958CD777-257D-4C68-A667-83E6C1F50A62}
AppName={#AppName}
AppVersion={#AppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#AppPublisher}
AppPublisherURL={#AppURL}
AppSupportURL={#AppURL}
AppUpdatesURL={#AppURL}
DefaultDirName={pf}\{#AppPublisher}\{#AppName}
DefaultGroupName={#AppName}
OutputDir={#BINDIR}
OutputBaseFilename={#AppName}_setup_{#AppVersion}
Compression=lzma
SolidCompression=yes

[Code]
#include "services.iss"

procedure CurStepChanged(CurStep: TSetupStep);
var
  executable: String;
begin
  if (CurStep=ssPostInstall) then
  begin
    executable := ExpandConstant('{app}') + '\{#AppExeName}';
    SimpleCreateService('{#AppName}','{#AppPublisher} {#AppName} Network Monitor',executable,SERVICE_AUTO_START,'','',false,false);
    SimpleStartService('{#AppName}',true,true);
  end;
end;

function InitializeUninstall : Boolean;
begin
  SimpleStopService('{#AppName}',true,true);
  SimpleDeleteService('{#AppName}');
  Result:=true;
end;

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

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "{#BINDIR}\ion.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "WinPcap_4_1_3.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#BINDIR}\ion.db"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\..\ion\ion.properties"; DestDir: "{app}"; Flags: ignoreversion

Source: "..\..\web\*"; DestDir: "{app}\web"; Flags: recursesubdirs

[Icons]
Name: "{group}\ion"; Filename: "http://localhost:9980/things.bin";

[Run]
Filename: "{app}\WinPcap_4_1_3.exe";

[UninstallDelete]
Type: filesandordirs; Name: "{app}"

; Script generated by the Inno Setup Script Wizard.
; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!
#define AppName "IoN"
#define AppVersion "0.0.5"
#define AppPublisher "Lagildo"
#define AppURL "http://www.lagildo.com/"
#define AppExeName "ion.exe"
#define BINDIR "..\..\Release"

[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={{958CD777-257D-4C68-A667-83E6C1F50A62}
AppName={#AppName}
AppVersion={#AppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#AppPublisher}
AppPublisherURL={#AppURL}
AppSupportURL={#AppURL}
AppUpdatesURL={#AppURL}
DefaultDirName={pf}\{#AppPublisher}\{#AppName}
DefaultGroupName={#AppName}
OutputDir={#BINDIR}
OutputBaseFilename={#AppName}_setup_{#AppVersion}
Compression=lzma
SolidCompression=yes

[Code]
#include "services.iss"

procedure CurStepChanged(CurStep: TSetupStep);
var
  executable: String;
begin
  if (CurStep=ssPostInstall) then
  begin
    executable := ExpandConstant('{app}') + '\{#AppExeName}';
    SimpleCreateService('{#AppName}','{#AppPublisher} {#AppName} Network Monitor',executable,SERVICE_AUTO_START,'','',false,false);
    SimpleStartService('{#AppName}',true,true);
  end;
end;

function InitializeUninstall : Boolean;
begin
  SimpleStopService('#{AppName}',true,true);
  SimpleDeleteService('#{AppName}');
  Result:=true;
end;

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

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked

[Files]
Source: "{#BINDIR}\ion.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "WinPcap_4_1_3.exe"; DestDir: "{app}"; Flags: ignoreversion
Source: "{#BINDIR}\ion.db"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\..\ion\ion.properties"; DestDir: "{app}\config"; Flags: ignoreversion

Source: "..\..\web\*"; DestDir: "{app}\web"; Flags: recursesubdirs

[Icons]
Name: "{group}\ion"; Filename: "http://localhost:9980/things.bin";

[Run]
Filename: "{app}\WinPcap_4_1_3.exe";

[UninstallDelete]
Type: filesandordirs; Name: "{app}"


try to fix uninstall startmenu entry

try to fix uninstall startmenu entry

;
;          _\|/_
;          (o o)
; +-----oOO-{_}-OOo------------------------------------------------------+
; |                                                                      |
; |  Unknown-Horizons - Inno Setup Script File                           |
; |  -------------------------------------------------------             |
; |                                                                      |
; |  Author:   Jens A. Koch <jakoch@web.de>                              |
; |  Author:   Thomas Kowaliczek-Schmer <thomas.kowaliczek@posteo.de>    |
; |  License:  MIT                                                       |
; |                                                                      |
; |  For the full copyright and license information, please view         |
; |  the LICENSE file that was distributed with this source code.        |
; |                                                                      |
; |  Note for developers                                                 |
; |  -------------------                                                 |
; |  A good resource for developing and understanding                    |
; |  Inno Setup Script files is the official "Inno Setup Help".          |
; |  Website:  http://jrsoftware.org/ishelp/index.php                    |
; |                                                                      |
; +---------------------------------------------------------------------<3

; version is set here, when the version isn't passed to the compiler on invocation
#ifndef APP_VERSION
#define APP_VERSION          "2017.1"
#endif

#define APP_NAME             "Unknown-Horizons"
#define APP_COMPILER         "VC14"
#define APP_PUBLISHER        "Unknown-Horizons Team"
#define APP_URL              "http://www.unknown-horizons.org/"
#define APP_SUPPORT_URL      "https://github.com/unknown-horizons/unknown-horizons/issues"
#define COPYRIGHT_YEAR        GetDateTimeString('yyyy', '', '');

[Setup]
AppId={{8A27DF0C-689B-4B76-8BFC-AFCDD90C1A31}

; set application meta-data
AppName={#APP_NAME}
AppVerName={#APP_NAME} {#APP_VERSION}
AppVersion={#APP_VERSION}
AppCopyright=© {#APP_PUBLISHER}
AppPublisher={#APP_PUBLISHER}
AppPublisherURL={#APP_URL}
AppSupportURL={#APP_SUPPORT_URL}
AppUpdatesURL={#APP_URL}

; default installation folder is "c:\Unknown-Horizons". users might change this via dialog.
DefaultDirName=c:\Unknown-Horizons
DefaultGroupName={#APP_NAME}
DirExistsWarning=No
EnableDirDoesntExistWarning=Yes
AllowNoIcons=yes

; compression
Compression=lzma2/ultra
LZMAUseSeparateProcess=yes
LZMANumBlockThreads=2
InternalCompressLevel=max
SolidCompression=true

; style
WizardImageFile=images\WizardImage.bmp
WizardSmallImageFile=images\WizardSmallImage.bmp
SetupIconFile=images\uh.ico

; this creates the installer executable in the build folder
; for example: "_build\Unknown-Horizons-2017.1-Setup-VC14-x86.exe"
OutputBaseFilename={#APP_NAME}-{#APP_VERSION}-Setup-{#APP_COMPILER}-x86
OutputDir=..\_build

; disable wizard pages: Welcome (by default), Ready
DisableReadyPage=yes

; enable wizard pages: Select Destination Location
DisableDirPage=no

; Tell Windows to reload the environment, because Registry change (env PATH change)
ChangesEnvironment=yes

; Tell Windows to reload the environment, because Registry change (file association change: .py)
ChangesAssociations=yes

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

; Define the types of installations
; The user gets a drop-down list to select one of these types.
; Selecting a type will selected a set of components.
[Types]
Name: "full";          Description: "Full installation (game, engine)"
Name: "custom";        Description: "Custom installation"; Flags: iscustom

; Define components to install
[Components]
Name: "unknown_horizons"; Description: "[unknown-horizons] Unknown-Horizons";              Types: full;
Name: fifengine;          Description: "[fifengine] Fifengine - Isometric Game Engine";    Types: full;
Name: "Python";           Description: "[build tools] Python - programming language";
Name: "Python\py27";      Description: "[build tools] Python v2.7";                        Types: full; Flags: exclusive

[Files]
Source: "..\repackage\unknown-horizons\*";      DestDir: "{app}\unknown-horizons";      Flags: recursesubdirs ignoreversion; Components: unknown_horizons
Source: "..\repackage\Python27\*";              DestDir: "{app}\python";                Flags: recursesubdirs ignoreversion; Components: "Python\py27"
; Fifengine below Python, because we are installing the python library into the Python installation folder
Source: "..\repackage\libfife.win32-py2.7.msi"; DestDir: "{app}\libfife";               Flags: recursesubdirs;               Components: fifengine

[Tasks]
Name: add_startmenu;       Description: Create Startmenu entries
Name: add_quicklaunchicon; Description: Create a &Quick Launch icon for Unknown Horizons; GroupDescription: Additional Icons:; Components: unknown_horizons
Name: add_desktopicon;     Description: Create a &Desktop icon for Unknown Horizons;      GroupDescription: Additional Icons:; Components: unknown_horizons

[Icons]
; define a group for the startmenu
Name: {group}\Start Unknown-Horizons; Filename: {app}\unknown-horizons\run_uh.bat; IconFilename: "{app}\unknown-horizons\content\gfx\uh.ico"; Tasks: add_startmenu
Name: {group}\Uninstall; Filename: {app}\unins000.exe; Flags: preventpinning excludefromshowinnewinstall; Tasks: add_startmenu
; desktop icon
Name: {userdesktop}\Unknown-Horizons; Filename: {app}\unknown-horizons\run_uh.bat; IconFilename: "{app}\unknown-horizons\content\gfx\uh.ico"; Tasks: add_desktopicon
; quick launch icon
Name: {userappdata}\Microsoft\Internet Explorer\Quick Launch\Unknown Horizons; Filename: {app}\run_uh.bat; IconFilename: "{app}\unknown-horizons\content\gfx\uh.ico"; Tasks: add_quicklaunchicon

; Define items to run automatically on installation...
[Run]
; install "libfife for python2.7" only when "python27" and "fifengine" are selected
; install silently into the target dir
Filename: "msiexec.exe"; Parameters: "/i ""{app}\libfife\libfife.win32-py2.7.msi"" TARGETDIR=""{app}\python"" /qn"; StatusMsg: "Installing libFife for Python2.7"; Components: Python\py27 and fifengine

; Define items to run automatically on un-installation...
[UninstallRun]
; un-install "libfife"
Filename: "msiexec.exe"; Parameters: "/x ""{app}\libfife\libfife.win32-py2.7.msi"" /qn"; StatusMsg: "Uninstalling libFife for Python2.7"; Flags: runascurrentuser runhidden

[UninstallDelete]
;Type: filesandordirs; Name: "{userdocs}\My Games\unknown-horizons"
Type: filesandordirs; Name: "{app}\python"
Type: filesandordirs; Name: "{app}\unknown-horizons"

[Registry]
; A registry change needs the following directive: [SETUP] ChangesEnvironment=yes
;
; add path to Python
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"PATH"; ValueData:"{olddata};{app}\python"; Flags: preservestringtype; Check: NeedsAddPathLocalUser(ExpandConstant('{app}\python')); Components: Python\py27;
;
; add path to libfife
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"PATH"; ValueData:"{olddata};{app}\python\Lib\site-packages\fife"; Flags: preservestringtype; Check: NeedsAddPathLocalUser(ExpandConstant('{app}\python\Lib\site-packages\fife')); Components: fifengine;
;
; Create File Association
Root: HKCR; Subkey: ".py";                            ValueType: string; ValueName: ""; ValueData: "Python.File"; Flags: uninsdeletevalue
Root: HKCR; Subkey: "Python.File";                    ValueType: string; ValueName: ""; ValueData: "Python File"; Flags: uninsdeletekey
Root: HKCR; Subkey: "Python.File\DefaultIcon";        ValueType: string; ValueName: ""; ValueData: "{app}\python\DLLs\py.ico"
Root: HKCR; Subkey: "Python.File\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\python\python.exe"" ""%1"" %*"

[Code]
// modification and path lookup helper for env PATH
#include "includes\envpath.iss"

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  // Removing a path from the PATH variable works in 3 steps:
  // 1. get the old env var PATH
  if (CurUninstallStep =  usUninstall) then
  begin
    SaveOldPathLocalUser();
  end;
  // 2. remove paths from the env var PATH
  if (CurUninstallStep = usPostUninstall) then
  begin
    RemovePathLocalUser(ExpandConstant('{app}') + '\python\Lib\site-packages\fife');
    RemovePathLocalUser(ExpandConstant('{app}') + '\python');
    // 3. refresh environment, so that the modified PATH var is activated
    RefreshEnvironment();
  end;
end;

;
;          _\|/_
;          (o o)
; +-----oOO-{_}-OOo------------------------------------------------------+
; |                                                                      |
; |  Unknown-Horizons - Inno Setup Script File                           |
; |  -------------------------------------------------------             |
; |                                                                      |
; |  Author:   Jens A. Koch <jakoch@web.de>                              |
; |  Author:   Thomas Kowaliczek-Schmer <thomas.kowaliczek@posteo.de>    |
; |  License:  MIT                                                       |
; |                                                                      |
; |  For the full copyright and license information, please view         |
; |  the LICENSE file that was distributed with this source code.        |
; |                                                                      |
; |  Note for developers                                                 |
; |  -------------------                                                 |
; |  A good resource for developing and understanding                    |
; |  Inno Setup Script files is the official "Inno Setup Help".          |
; |  Website:  http://jrsoftware.org/ishelp/index.php                    |
; |                                                                      |
; +---------------------------------------------------------------------<3

; version is set here, when the version isn't passed to the compiler on invocation
#ifndef APP_VERSION
#define APP_VERSION          "2017.1"
#endif

#define APP_NAME             "Unknown-Horizons"
#define APP_COMPILER         "VC14"
#define APP_PUBLISHER        "Unknown-Horizons Team"
#define APP_URL              "http://www.unknown-horizons.org/"
#define APP_SUPPORT_URL      "https://github.com/unknown-horizons/unknown-horizons/issues"
#define COPYRIGHT_YEAR        GetDateTimeString('yyyy', '', '');

[Setup]
AppId={{8A27DF0C-689B-4B76-8BFC-AFCDD90C1A31}

; set application meta-data
AppName={#APP_NAME}
AppVerName={#APP_NAME} {#APP_VERSION}
AppVersion={#APP_VERSION}
AppCopyright=© {#APP_PUBLISHER}
AppPublisher={#APP_PUBLISHER}
AppPublisherURL={#APP_URL}
AppSupportURL={#APP_SUPPORT_URL}
AppUpdatesURL={#APP_URL}

; default installation folder is "c:\Unknown-Horizons". users might change this via dialog.
DefaultDirName=c:\Unknown-Horizons
DefaultGroupName={#APP_NAME}
DirExistsWarning=No
EnableDirDoesntExistWarning=Yes
AllowNoIcons=yes

; compression
Compression=lzma2/ultra
LZMAUseSeparateProcess=yes
LZMANumBlockThreads=2
InternalCompressLevel=max
SolidCompression=true

; style
WizardImageFile=images\WizardImage.bmp
WizardSmallImageFile=images\WizardSmallImage.bmp
SetupIconFile=images\uh.ico

; this creates the installer executable in the build folder
; for example: "_build\Unknown-Horizons-2017.1-Setup-VC14-x86.exe"
OutputBaseFilename={#APP_NAME}-{#APP_VERSION}-Setup-{#APP_COMPILER}-x86
OutputDir=..\_build

; disable wizard pages: Welcome (by default), Ready
DisableReadyPage=yes

; enable wizard pages: Select Destination Location
DisableDirPage=no

; Tell Windows to reload the environment, because Registry change (env PATH change)
ChangesEnvironment=yes

; Tell Windows to reload the environment, because Registry change (file association change: .py)
ChangesAssociations=yes

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

; Define the types of installations
; The user gets a drop-down list to select one of these types.
; Selecting a type will selected a set of components.
[Types]
Name: "full";          Description: "Full installation (game, engine)"
Name: "custom";        Description: "Custom installation"; Flags: iscustom

; Define components to install
[Components]
Name: "unknown_horizons"; Description: "[unknown-horizons] Unknown-Horizons";              Types: full;
Name: fifengine;          Description: "[fifengine] Fifengine - Isometric Game Engine";    Types: full;
Name: "Python";           Description: "[build tools] Python - programming language";
Name: "Python\py27";      Description: "[build tools] Python v2.7";                        Types: full; Flags: exclusive

[Files]
Source: "..\repackage\unknown-horizons\*";      DestDir: "{app}\unknown-horizons";      Flags: recursesubdirs ignoreversion; Components: unknown_horizons
Source: "..\repackage\Python27\*";              DestDir: "{app}\python";                Flags: recursesubdirs ignoreversion; Components: "Python\py27"
; Fifengine below Python, because we are installing the python library into the Python installation folder
Source: "..\repackage\libfife.win32-py2.7.msi"; DestDir: "{app}\libfife";               Flags: recursesubdirs;               Components: fifengine

[Tasks]
Name: add_startmenu;       Description: Create Startmenu entries
Name: add_quicklaunchicon; Description: Create a &Quick Launch icon for Unknown Horizons; GroupDescription: Additional Icons:; Components: unknown_horizons
Name: add_desktopicon;     Description: Create a &Desktop icon for Unknown Horizons;      GroupDescription: Additional Icons:; Components: unknown_horizons

[Icons]
; define a group for the startmenu
Name: {group}\Start Unknown-Horizons; Filename: {app}\unknown-horizons\run_uh.bat; IconFilename: "{app}\unknown-horizons\content\gfx\uh.ico"; Tasks: add_startmenu
Name: {group}\Uninstall; Filename: {uninstallexe}; Flags: preventpinning excludefromshowinnewinstall; Tasks: add_startmenu
; desktop icon
Name: {userdesktop}\Unknown-Horizons; Filename: {app}\unknown-horizons\run_uh.bat; IconFilename: "{app}\unknown-horizons\content\gfx\uh.ico"; Tasks: add_desktopicon
; quick launch icon
Name: {userappdata}\Microsoft\Internet Explorer\Quick Launch\Unknown Horizons; Filename: {app}\run_uh.bat; IconFilename: "{app}\unknown-horizons\content\gfx\uh.ico"; Tasks: add_quicklaunchicon

; Define items to run automatically on installation...
[Run]
; install "libfife for python2.7" only when "python27" and "fifengine" are selected
; install silently into the target dir
Filename: "msiexec.exe"; Parameters: "/i ""{app}\libfife\libfife.win32-py2.7.msi"" TARGETDIR=""{app}\python"" /qn"; StatusMsg: "Installing libFife for Python2.7"; Components: Python\py27 and fifengine

; Define items to run automatically on un-installation...
[UninstallRun]
; un-install "libfife"
Filename: "msiexec.exe"; Parameters: "/x ""{app}\libfife\libfife.win32-py2.7.msi"" /qn"; StatusMsg: "Uninstalling libFife for Python2.7"; Flags: runascurrentuser runhidden

[UninstallDelete]
;Type: filesandordirs; Name: "{userdocs}\My Games\unknown-horizons"
Type: filesandordirs; Name: "{app}\python"
Type: filesandordirs; Name: "{app}\unknown-horizons"

[Registry]
; A registry change needs the following directive: [SETUP] ChangesEnvironment=yes
;
; add path to Python
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"PATH"; ValueData:"{olddata};{app}\python"; Flags: preservestringtype; Check: NeedsAddPathLocalUser(ExpandConstant('{app}\python')); Components: Python\py27;
;
; add path to libfife
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"PATH"; ValueData:"{olddata};{app}\python\Lib\site-packages\fife"; Flags: preservestringtype; Check: NeedsAddPathLocalUser(ExpandConstant('{app}\python\Lib\site-packages\fife')); Components: fifengine;
;
; Create File Association
Root: HKCR; Subkey: ".py";                            ValueType: string; ValueName: ""; ValueData: "Python.File"; Flags: uninsdeletevalue
Root: HKCR; Subkey: "Python.File";                    ValueType: string; ValueName: ""; ValueData: "Python File"; Flags: uninsdeletekey
Root: HKCR; Subkey: "Python.File\DefaultIcon";        ValueType: string; ValueName: ""; ValueData: "{app}\python\DLLs\py.ico"
Root: HKCR; Subkey: "Python.File\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\python\python.exe"" ""%1"" %*"

[Code]
// modification and path lookup helper for env PATH
#include "includes\envpath.iss"

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  // Removing a path from the PATH variable works in 3 steps:
  // 1. get the old env var PATH
  if (CurUninstallStep =  usUninstall) then
  begin
    SaveOldPathLocalUser();
  end;
  // 2. remove paths from the env var PATH
  if (CurUninstallStep = usPostUninstall) then
  begin
    RemovePathLocalUser(ExpandConstant('{app}') + '\python\Lib\site-packages\fife');
    RemovePathLocalUser(ExpandConstant('{app}') + '\python');
    // 3. refresh environment, so that the modified PATH var is activated
    RefreshEnvironment();
  end;
end;