Fixed some file references and updated to InnoSetup 5.1.6.

; Basic setup script for the Inno Setup installer builder.  For more
; information on the free installer builder, see www.jrsoftware.org.
;
; This script was contributed by Tim Peters.
; The current version is used with Inno Setup 2.0.19.

[Setup]
AppName=expat
AppId=expat
AppVersion=2.0.0
AppVerName=expat 2.0.0
AppCopyright=Copyright  1998-2006 Thai Open Source Software Center, Clark Cooper, and the Expat maintainers
DefaultDirName={sd}\Expat-2.0.0
AppPublisher=The Expat Developers
AppPublisherURL=http://www.libexpat.org/
AppSupportURL=http://www.libexpat.org/
AppUpdatesURL=http://www.libexpat.org/
UninstallDisplayName=Expat XML Parser (version 2.0.0)
UninstallFilesDir={app}\Uninstall

Compression=bzip/9
SourceDir=..
OutputDir=win32
DisableStartupPrompt=yes
AllowNoIcons=yes
DisableProgramGroupPage=yes
DisableReadyPage=yes

[Files]
Flags: ignoreversion; Source: xmlwf\Release\*.exe;        DestDir: "{app}"
Flags: ignoreversion; Source: win32\MANIFEST.txt;         DestDir: "{app}"
Flags: ignoreversion; Source: Changes;                    DestDir: "{app}"; DestName: Changes.txt
Flags: ignoreversion; Source: COPYING;                    DestDir: "{app}"; DestName: COPYING.txt
Flags: ignoreversion; Source: README;                     DestDir: "{app}"; DestName: README.txt
Flags: ignoreversion; Source: doc\*.html;                 DestDir: "{app}\Doc"
Flags: ignoreversion; Source: doc\*.css;                  DestDir: "{app}\Doc"
Flags: ignoreversion; Source: doc\*.png;                  DestDir: "{app}\Doc"
Flags: ignoreversion; Source: lib\Release\*.dll;          DestDir: "{app}\Libs"
Flags: ignoreversion; Source: lib\Release\*.lib;          DestDir: "{app}\Libs"
Flags: ignoreversion; Source: lib\Release-w\*.dll;        DestDir: "{app}\Libs"
Flags: ignoreversion; Source: lib\Release-w\*.lib;        DestDir: "{app}\Libs"
Flags: ignoreversion; Source: lib\Release_static\*.lib;   DestDir: "{app}\StaticLibs"
Flags: ignoreversion; Source: lib\Release-w_static\*.lib; DestDir: "{app}\StaticLibs"
Flags: ignoreversion; Source: expat.dsw;                  DestDir: "{app}\Source"
Flags: ignoreversion; Source: win32\README.txt;           DestDir: "{app}\Source"
Flags: ignoreversion; Source: bcb5\*.bp*;                 DestDir: "{app}\Source\bcb5"
Flags: ignoreversion; Source: bcb5\*.mak;                 DestDir: "{app}\Source\bcb5"
Flags: ignoreversion; Source: bcb5\*.def;                 DestDir: "{app}\Source\bcb5"
Flags: ignoreversion; Source: bcb5\*.txt;                 DestDir: "{app}\Source\bcb5"
Flags: ignoreversion; Source: bcb5\*.bat;                 DestDir: "{app}\Source\bcb5"
Flags: ignoreversion; Source: lib\*.c;                    DestDir: "{app}\Source\lib"
Flags: ignoreversion; Source: lib\*.h;                    DestDir: "{app}\Source\lib"
Flags: ignoreversion; Source: lib\*.def;                  DestDir: "{app}\Source\lib"
Flags: ignoreversion; Source: lib\*.dsp;                  DestDir: "{app}\Source\lib"
Flags: ignoreversion; Source: examples\*.c;               DestDir: "{app}\Source\examples"
Flags: ignoreversion; Source: examples\*.dsp;             DestDir: "{app}\Source\examples"
Flags: ignoreversion; Source: tests\*.c;                  DestDir: "{app}\Source\tests"
Flags: ignoreversion; Source: tests\*.cpp;                DestDir: "{app}\Source\tests"
Flags: ignoreversion; Source: tests\*.h;                  DestDir: "{app}\Source\tests"
Flags: ignoreversion; Source: tests\README.txt;           DestDir: "{app}\Source\tests"
Flags: ignoreversion; Source: tests\benchmark\*.c;        DestDir: "{app}\Source\tests\benchmark"
Flags: ignoreversion; Source: tests\benchmark\*.ds*;      DestDir: "{app}\Source\tests\benchmark"
Flags: ignoreversion; Source: tests\benchmark\README.txt; DestDir: "{app}\Source\tests\benchmark"
Flags: ignoreversion; Source: xmlwf\*.c*;                 DestDir: "{app}\Source\xmlwf"
Flags: ignoreversion; Source: xmlwf\*.h;                  DestDir: "{app}\Source\xmlwf"
Flags: ignoreversion; Source: xmlwf\*.dsp;                DestDir: "{app}\Source\xmlwf"

[Messages]
WelcomeLabel1=Welcome to the Expat XML Parser Setup Wizard
WelcomeLabel2=This will install [name/ver] on your computer.%n%nExpat is an XML parser with a C-language API, and is primarily made available to allow developers to build applications which use XML using a portable API and fast implementation.%n%nIt is strongly recommended that you close all other applications you have running before continuing. This will help prevent any conflicts during the installation process.

; Basic setup script for the Inno Setep installer builder.  For more
; information on the free installer builder, see www.jrsoftware.org.
;
; This script was contributed by Tim Peters.
; The current version is used with Inno Setup 2.0.19.

[Setup]
AppName=expat
AppId=expat
AppVersion=1.95.8
AppVerName=expat 1.95.8
AppCopyright=Copyright  1998-2003 Thai Open Source Software Center, Clark Cooper, and the Expat maintainers
DefaultDirName={sd}\Expat-1.95.8
AppPublisher=The Expat Developers
AppPublisherURL=http://www.libexpat.org/
AppSupportURL=http://www.libexpat.org/
AppUpdatesURL=http://www.libexpat.org/
UninstallDisplayName=Expat XML Parser (version 1.95.8)
UninstallFilesDir={app}\Uninstall

Compression=bzip/9
SourceDir=..
OutputDir=win32
DisableStartupPrompt=yes
AllowNoIcons=yes
DisableProgramGroupPage=yes
DisableReadyPage=yes

[Files]
CopyMode: alwaysoverwrite; Source: xmlwf\Release\*.exe;        DestDir: "{app}"
CopyMode: alwaysoverwrite; Source: win32\MANIFEST.txt;         DestDir: "{app}"
CopyMode: alwaysoverwrite; Source: Changes;                    DestDir: "{app}"; DestName: Changes.txt
CopyMode: alwaysoverwrite; Source: COPYING;                    DestDir: "{app}"; DestName: COPYING.txt
CopyMode: alwaysoverwrite; Source: README;                     DestDir: "{app}"; DestName: README.txt
CopyMode: alwaysoverwrite; Source: doc\*.html;                 DestDir: "{app}\Doc"
CopyMode: alwaysoverwrite; Source: doc\*.css;                  DestDir: "{app}\Doc"
CopyMode: alwaysoverwrite; Source: doc\*.png;                  DestDir: "{app}\Doc"
CopyMode: alwaysoverwrite; Source: lib\Release\*.dll;          DestDir: "{app}\Libs"
CopyMode: alwaysoverwrite; Source: lib\Release\*.lib;          DestDir: "{app}\Libs"
CopyMode: alwaysoverwrite; Source: lib\Release-w\*.dll;        DestDir: "{app}\Libs"
CopyMode: alwaysoverwrite; Source: lib\Release-w\*.lib;        DestDir: "{app}\Libs"
CopyMode: alwaysoverwrite; Source: lib\Release_static\*.lib;   DestDir: "{app}\StaticLibs"
CopyMode: alwaysoverwrite; Source: lib\Release-w_static\*.lib; DestDir: "{app}\StaticLibs"
CopyMode: alwaysoverwrite; Source: expat.dsw;                  DestDir: "{app}\Source"
CopyMode: alwaysoverwrite; Source: win32\README.txt;           DestDir: "{app}\Source"
CopyMode: alwaysoverwrite; Source: bcb5\*.*;                   DestDir: "{app}\Source\bcb5"
CopyMode: alwaysoverwrite; Source: lib\*.c;                    DestDir: "{app}\Source\lib"
CopyMode: alwaysoverwrite; Source: lib\*.h;                    DestDir: "{app}\Source\lib"
CopyMode: alwaysoverwrite; Source: lib\*.def;                  DestDir: "{app}\Source\lib"
CopyMode: alwaysoverwrite; Source: lib\*.dsp;                  DestDir: "{app}\Source\lib"
CopyMode: alwaysoverwrite; Source: examples\*.c;               DestDir: "{app}\Source\examples"
CopyMode: alwaysoverwrite; Source: examples\*.dsp;             DestDir: "{app}\Source\examples"
CopyMode: alwaysoverwrite; Source: tests\*.c;                  DestDir: "{app}\Source\tests"
CopyMode: alwaysoverwrite; Source: tests\*.cpp;                DestDir: "{app}\Source\tests"
CopyMode: alwaysoverwrite; Source: tests\*.h;                  DestDir: "{app}\Source\tests"
CopyMode: alwaysoverwrite; Source: tests\README.txt;           DestDir: "{app}\Source\tests"
CopyMode: alwaysoverwrite; Source: xmlwf\*.c*;                 DestDir: "{app}\Source\xmlwf"
CopyMode: alwaysoverwrite; Source: xmlwf\*.h;                  DestDir: "{app}\Source\xmlwf"
CopyMode: alwaysoverwrite; Source: xmlwf\*.dsp;                DestDir: "{app}\Source\xmlwf"

[Messages]
WelcomeLabel1=Welcome to the Expat XML Parser Setup Wizard
WelcomeLabel2=This will install [name/ver] on your computer.%n%nExpat is an XML parser with a C-language API, and is primarily made available to allow developers to build applications which use XML using a portable API and fast implementation.%n%nIt is strongly recommended that you close all other applications you have running before continuing. This will help prevent any conflicts during the installation process.


Updated installer script for 6.01.0.

Updated installer script for 6.01.0.

  ; C S O U N D   6   I N N O   S E T U P   S C R I P T

; Copyright (C) 2013 by Michael Gogins.
; This software is licensed under the terms of the
; Lesser (or Library) GNU Public License.

; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

; This file assumes that you are Michael Gogins,
; but comments indicate what you should change if you are not me.
; All of these changes SHOULD be in the #defines immediately following this.
; Also, this installer assumes LuaJIT and CsoundAC are part of Csound core.
; At this time the following features are not included in the installer:
; Cabbage, CsoundVST.
; I hope to change this soon.

#define MyAppName "Csound6"
#define MyAppVersion "6"
#define MyAppMinVersion "6.01.0"
#define MyAppPublisher "Csound"
#define MyAppURL "http://sourceforge.net/projects/csound"
; If you are not Michael Gogins, change this to your MinGW dll directory.
#define MyMinGwBinDir "D:\mingw32-4.8.1\bin\"
; If you are not Michael Gogins, change this to your MSys /bin/ directory.
#define MyMSysBinDir "D:\msys\bin\"
; If you are not Michael Gogins, change this to your MSys /usr/local/ directory.
#define MyMSysUsrLocalDir "D:\msys\local\"
; If you are not Michael Gogins, change this to your Csound build directory.
#define MySourceDir "C:\Users\mkg.sorabji\csound-csound6-git\"
; If you are not Michael Gogins, change this to your Csound reference manual build directory.
#define MyManualSourceDir "C:\Users\mkg.sorabji\csound-manual6-git\"
; If you are not Michael Gogins, change this to your Csound tutorial directory.
#define MyCsoundTutorialSourceDir "D:\Dropbox\tutorial\"
; If you are not Michael Gogins, change this to your CsoundAC tutorial directory.
#define MyCsoundAcTutorialSourceDir "D:\Dropbox\tutorial\"
; If you are not Michael Gogins, change this to your libsndfile install directory.
#define MyLibSndfileSourceDir "D:\msys\local\opt\libsndfile\"
; If you are not Michael Gogins, change this to your PortAudio lib directory.
#define MyPortAudioSourceDir "D:\msys\local\src\portaudio\"
; If you are not Michael Gogins, change this to your PortMidi build directory.
#define MyPortMidiSourceDir "D:\msys\local\src\portmidi\"
; If you are not Michael Gogins, change this to your LuaJIT bin directory.
#define MyLuaJitSourceDir "D:\msys\local\src\luajit-2.0\src\"
; If you are not Michael Gogins, change this to your FLTK dll directory.
#define MyFltkSourceDir "D:\msys\local\src\fltk-1.3.2\src\"
; If you are not Michael Gogins, change this to your libmusicxml dll directory.
#define MyLibMusicXmlSourceDir "D:\msys\local\src\libmusicxml\"
; If you are not Michael Gogins, change this to your FluidSynth dll directory.
#define MyFluidSynthSourceDir "D:\msys\local\src\fluidsynth\src\.libs\"
; If you are not Michael Gogins, change this to your OSC library dll directory.
#define MyLibLoSourceDir "D:\msys\local\src\liblo-0.26\"
; If you are not Michael Gogins, change this to your STK dll directory.
#define MyLibStkSourceDir "D:\msys\local\src\stk-4.4.4\"
; If you are not Michael Gogins, change this to your CsoundQt bin directory.
#define MyCsoundQtBinDir "C:\Users\mkg.sorabji\qutecsound-code\bin\"
; If you are not Michael Gogins, change this to your Qt SDK DLL directory.
#define MyQtSdkBinDir "D:\qt-everywhere-opensource-src-5.1.0\qtbase\bin\"

[Components]
Name: "core"; Description: "Core Csound"; Types: full custom; Flags: fixed
Name: "python"; Description: "Python features (requires Python 2.7)"; Types: full;

[Dirs]
; ALL programs and shared libraries (including opcodes and other modules) go here.
Name: "{app}\bin"; Permissions: users-modify
#define APP_BIN "{app}\bin\"
; All C or C++ include files for Csound and other components used by Csound go here.
; This is a convenience for people like me who program in C or C++ and might use
; features of these third party components.
Name: "{app}\include"
#define APP_INCLUDE "{app}\include\"
; The Csound reference manual goes here.
Name: "{app}\doc\manual"
#define APP_MANUAL "{app}\doc\manual\"
; The Csound API reference manuals go here.
Name: "{app}\doc\apiref"
#define APP_APIREF "{app}\doc\apiref\"
; All Csound examples go here.
Name: "{app}\examples"; Permissions: users-modify
#define APP_EXAMPLES "{app}\examples\"
; Any SoundFonts or sound samples used by Csound examples go here.
Name: "{app}\samples"
#define APP_SAMPLES "{app}\samples\"
; Tutorials go here.
Name: "{app}\doc\tutorial"
#define APP_TUTORIAL "{app}\doc\tutorial\"

; These are the Csound environment variables related to directories.

#define SFDIR
#define SSDIR
#define SADIR
#define INCDIR
#define OPCODE6DIR64
#define SNAPDIR
#define RAWWAVE_PATH
#define MFDIR
#define PYTHONPATH

[Setup]
ChangesEnvironment=true
; 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={{4BCEDC5F-C6D2-4869-9097-3F1753739F35}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName} {#MyAppMinVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName=Csound 6
AllowNoIcons=yes
LicenseFile=readme-csound6.txt
;InfoBeforeFile=readme-csound6.txt
OutputDir=installer\windows
OutputBaseFilename=Setup_{#MyAppName}_{#MyAppMinVersion}
Compression=lzma
SolidCompression=yes
SourceDir={#MySourceDir}

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

[Files]
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
Source: "{#MyMinGwBinDir}*.dll"; DestDir: "{#APP_BIN}"; Components: core;
; No idea why this other name is needed.
Source: "{#MyMSysBinDir}libiconv-2.dll"; DestDir: "{#APP_BIN}"; DestName: "iconv.dll"; Components: core;
Source: "{#MyMSysUsrLocalDir}bin/*.dll"; DestDir: "{#APP_BIN}"; Components: core;
Source: "*.exe"; DestDir: "{#APP_BIN}"; Flags: ignoreversion; Components: core;
Source: "*.jar"; DestDir: "{#APP_BIN}"; Flags: ignoreversion; Components: core;
Source: "*.dll*"; DestDir: "{#APP_BIN}"; Flags: ignoreversion; Excludes: "py.dll"; Components: core;
Source: "py.dll"; DestDir: "{#APP_BIN}"; Flags: ignoreversion; Components: python;
Source: "*.pyd"; DestDir: "{#APP_BIN}"; Flags: ignoreversion; Components: python;
Source: "*.py";  DestDir: "{#APP_BIN}"; Flags: ignoreversion; Components: python;

Source: "{#MyCsoundQtBinDir}CsoundQt-d-cs6.exe"; DestDir: "{#APP_BIN}"; Components: core;
Source: "{#MyQtSdkBinDir}Qt5PrintSupport.dll"; DestDir: "{#APP_BIN}"; Components: core;
Source: "{#MyQtSdkBinDir}Qt5Widgets.dll"; DestDir: "{#APP_BIN}"; Components: core;
Source: "{#MyQtSdkBinDir}Qt5Xml.dll"; DestDir: "{#APP_BIN}"; Components: core;
Source: "{#MyQtSdkBinDir}Qt5Gui.dll"; DestDir: "{#APP_BIN}"; Components: core;
Source: "{#MyQtSdkBinDir}Qt5Core.dll"; DestDir: "{#APP_BIN}"; Components: core;
Source: "{#MyQtSdkBinDir}..\plugins\platforms\qwindows.dll"; DestDir: "{#APP_BIN}\platforms"; Components: core;
Source: "{#MyQtSdkBinDir}..\plugins\accessible\qtaccessiblewidgets.dll"; DestDir: "{#APP_BIN}\plugins\accessible"; Components: core;
Source: "{#MyQtSdkBinDir}..\plugins\imageformats\*.dll"; DestDir: "{#APP_BIN}\plugins\imageformats"; Components: core;
Source: "{#MyQtSdkBinDir}..\plugins\printsupport\windowsprintersupport.dll"; DestDir: "{#APP_BIN}\plugins\printsupport"; Components: core;

Source: {#MyLibSndfileSourceDir}\bin\*.*; DestDir: "{#APP_BIN}"; Flags: ignoreversion; Components: core;
Source: {#MyLibSndfileSourceDir}\include\*.*; DestDir: "{#APP_INCLUDE}\sndfile"; Flags: ignoreversion; Components: core;

; Ignore the unspeakably stupid libtool crap.
Source: {#MyPortAudioSourceDir}\lib\.libs\*x86.dll; DestDir: "{#APP_BIN}"; Components: core
Source: {#MyPortAudioSourceDir}\bin\.libs\pa_devs.exe; DestDir: "{#APP_BIN}"; Components: core
Source: {#MyPortAudioSourceDir}\bin\.libs\pa_minlat.exe; DestDir: "{#APP_BIN}"; Components: core

Source: {#MyPortMidiSourceDir}*.dll; DestDir: "{#APP_BIN}"; Flags: ignoreversion; Components: core

Source: {#MyLuaJitSourceDir}luajit.exe; DestDir: "{#APP_BIN}"; Flags: ignoreversion;  Components: core

Source: {#MyLuaJitSourceDir}lua51.dll; DestDir: "{#APP_BIN}"; Flags: ignoreversion;  Components: core
; No idea why this other name is needed.
Source: {#MyLuaJitSourceDir}lua51.dll; DestDir: "{#APP_BIN}"; DestName: "lua5.1.dll"; Flags: ignoreversion;  Components: core
Source: {#MyLuaJitSourceDir}lua51.dll; DestDir: "{#APP_BIN}"; DestName: "luajit.dll"; Flags: ignoreversion;  Components: core
Source: {#MyLuaJitSourceDir}lua*.h; DestDir: "{#APP_INCLUDE}\luajit"; Flags: ignoreversion;  Components: core

Source: {#MyFltkSourceDir}*.dll; DestDir: "{#APP_BIN}"; Flags: ignoreversion;  Components: core

Source: {#MyLibMusicXmlSourceDir}\cmake\*.dll; DestDir: "{#APP_BIN}"; Flags: ignoreversion;  Components: core

; Source: {#MyFluidSynthSourceDir}*.dll; DestDir: "{#APP_BIN}"; Flags: ignoreversion;  Components: core

; Source: {#MyLibLoSourceDir}*.dll; DestDir: "{#APP_BIN}"; Flags: ignoreversion;  Components: core

Source: include/*.h*; DestDir: "{#APP_INCLUDE}\csound"; Flags: ignoreversion;  Components: core
Source: interfaces/*.h*; DestDir: "{#APP_INCLUDE}\csound"; Flags: ignoreversion;  Components: core
Source: frontends/CsoundAC/*.hpp; DestDir: "{#APP_INCLUDE}\csoundac"; Flags: ignoreversion;  Components: core

Source: {#MyManualSourceDir}html\*.*; DestDir: "{#APP_MANUAL}"; Flags: ignoreversion recursesubdirs;  Components: core

Source: "doc\csound\html\*.*"; DestDir: "{#APP_APIREF}/csound"; Flags: ignoreversion recursesubdirs;  Components: core
Source: "doc\csoundac\html\*.*"; DestDir: "{#APP_APIREF}/csoundac"; Flags: ignoreversion recursesubdirs;  Components: core

Source: "examples\*.*"; DestDir: "{#APP_EXAMPLES}"; Excludes: "*.wav"; Flags: ignoreversion recursesubdirs;  Components: core

Source: "samples\*.*"; DestDir: "{#APP_SAMPLES}"; Flags: ignoreversion recursesubdirs;  Components: core
Source: "{#MyLibStkSourceDir}rawwaves\*.*"; DestDir: "{#APP_SAMPLES}"; Flags: ignoreversion recursesubdirs;  Components: core

Source: {#MyCsoundTutorialSourceDir}tutorial.pdf; DestDir: "{#APP_TUTORIAL}"; Flags: ignoreversion recursesubdirs;  Components: core
Source: {#MyCsoundAcTutorialSourceDir}Csound_Algorithmic_Composition_Tutorial.pdf; DestDir: "{#APP_TUTORIAL}"; Flags: ignoreversion recursesubdirs;  Components: core
Source: {#MyCsoundAcTutorialSourceDir}code\*.*; DestDir: "{#APP_TUTORIAL}code\"; Excludes: "*.wav"; Flags: ignoreversion recursesubdirs;  Components: core

[Icons]
Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}";  Components: core;
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{group}\Csound"; Filename: "cmd.exe"; Parameters: "/K csound.exe"; WorkingDir: "{#APP_BIN}"; Flags: dontcloseonexit;  Components: core
Name: "{group}\CsoundQt"; Filename: "{#APP_BIN}CsoundQt-d-cs6.exe"; WorkingDir: "{#APP_BIN}";  Components: core
Name: "{group}\WinSound"; Filename: "{#APP_BIN}winsound.exe"; WorkingDir: "{#APP_BIN}";  Components: core
Name: "{group}\LuaJIT"; Filename: "{#APP_BIN}luajit.exe"; WorkingDir: "{#APP_BIN}";  Components: core
Name: "{group}\Audio device information"; Filename: "cmd"; Parameters: "/K pa_devs.exe"; WorkingDir: "{#APP_BIN}"; Flags: dontcloseonexit;  Components: core
Name: "{group}\Audio device latency"; Filename: "cmd"; Parameters: "/K pa_minlat.exe"; WorkingDir: "{#APP_BIN}"; Flags: dontcloseonexit;  Components: core
Name: "{group}\Csound Reference Manual"; Filename: "{#APP_MANUAL}indexframes.html";  Components: core
Name: "{group}\Csound API Reference Manual"; Filename: "{#APP_APIREF}csound\index.html";  Components: core
Name: "{group}\CsoundAC API Reference Manual"; Filename: "{#APP_APIREF}csoundac\index.html";  Components: core
Name: "{group}\Csound Tutorial"; Filename: "{#APP_TUTORIAL}tutorial.pdf";  Components: core
Name: "{group}\CsoundAC Tutorial"; Filename: "{#APP_TUTORIAL}Csound_Algorithmic_Composition_Tutorial.pdf";  Components: core

[Registry]
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"RAWWAVE_PATH"; ValueData:"{#APP_SAMPLES}"; Flags: preservestringtype uninsdeletekey;  Components: core
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"OPCODE6DIR64"; ValueData:"{#APP_BIN}"; Flags: preservestringtype uninsdeletekey;  Components: core
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"PYTHONPATH"; ValueData:"{#APP_BIN}"; Flags: preservestringtype uninsdeletekey;  Components: python

[Tasks]
Name: modifypath; Description: &Add application directory to your PATH environment variable; Components: core;

[Code]
//	ModPathName defines the name of the task defined above
//	ModPathType defines whether the 'user' or 'system' path will be modified;
//		this will default to user if anything other than system is set
//	setArrayLength must specify the total number of dirs to be added
//	Result[0] contains first directory, Result[1] contains second, etc.
const ModPathName = 'modifypath';
ModPathType = 'system';

function ModPathDir(): TArrayOfString;
begin
	setArrayLength(Result, 1);
	Result[0] := ExpandConstant('{app}\bin');
end;

procedure ModPath();
var
	oldpath:	String;
	newpath:	String;
	updatepath:	Boolean;
	pathArr:	TArrayOfString;
	aExecFile:	String;
	aExecArr:	TArrayOfString;
	i, d:		Integer;
	pathdir:	TArrayOfString;
	regroot:	Integer;
	regpath:	String;
begin
	// Get constants from main script and adjust behavior accordingly
	// ModPathType MUST be 'system' or 'user'; force 'user' if invalid
	if ModPathType = 'system' then begin
		regroot := HKEY_LOCAL_MACHINE;
		regpath := 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
	end else begin
		regroot := HKEY_CURRENT_USER;
		regpath := 'Environment';
	end;

	// Get array of new directories and act on each individually
	pathdir := ModPathDir();
	for d := 0 to GetArrayLength(pathdir)-1 do begin
		updatepath := true;

		// Modify WinNT path
		if UsingWinNT() = true then begin

			// Get current path, split into an array
			RegQueryStringValue(regroot, regpath, 'Path', oldpath);
			oldpath := oldpath + ';';
			i := 0;

			while (Pos(';', oldpath) > 0) do begin
				SetArrayLength(pathArr, i+1);
				pathArr[i] := Copy(oldpath, 0, Pos(';', oldpath)-1);
				oldpath := Copy(oldpath, Pos(';', oldpath)+1, Length(oldpath));
				i := i + 1;

				// Check if current directory matches app dir
				if pathdir[d] = pathArr[i-1] then begin
					// if uninstalling, remove dir from path
					if IsUninstaller() = true then begin
						continue;
					// if installing, flag that dir already exists in path
					end else begin
						updatepath := false;
					end;
				end;

				// Add current directory to new path
				if i = 1 then begin
					newpath := pathArr[i-1];
				end else begin
					newpath := newpath + ';' + pathArr[i-1];
				end;
			end;

			// Append app dir to path if not already included
			if (IsUninstaller() = false) AND (updatepath = true) then
				newpath := newpath + ';' + pathdir[d];

			// Write new path
			RegWriteStringValue(regroot, regpath, 'Path', newpath);

		// Modify Win9x path
		end else begin

			// Convert to shortened dirname
			pathdir[d] := GetShortName(pathdir[d]);

			// If autoexec.bat exists, check if app dir already exists in path
			aExecFile := 'C:\AUTOEXEC.BAT';
			if FileExists(aExecFile) then begin
				LoadStringsFromFile(aExecFile, aExecArr);
				for i := 0 to GetArrayLength(aExecArr)-1 do begin
					if IsUninstaller() = false then begin
						// If app dir already exists while installing, skip add
						if (Pos(pathdir[d], aExecArr[i]) > 0) then
							updatepath := false;
							break;
					end else begin
						// If app dir exists and = what we originally set, then delete at uninstall
						if aExecArr[i] = 'SET PATH=%PATH%;' + pathdir[d] then
							aExecArr[i] := '';
					end;
				end;
			end;

			// If app dir not found, or autoexec.bat didn't exist, then (create and) append to current path
			if (IsUninstaller() = false) AND (updatepath = true) then begin
				SaveStringToFile(aExecFile, #13#10 + 'SET PATH=%PATH%;' + pathdir[d], True);

			// If uninstalling, write the full autoexec out
			end else begin
				SaveStringsToFile(aExecFile, aExecArr, False);
			end;
		end;
	end;
end;

// Split a string into an array using passed delimeter
procedure MPExplode(var Dest: TArrayOfString; Text: String; Separator: String);
var
	i: Integer;
begin
	i := 0;
	repeat
		SetArrayLength(Dest, i+1);
		if Pos(Separator,Text) > 0 then	begin
			Dest[i] := Copy(Text, 1, Pos(Separator, Text)-1);
			Text := Copy(Text, Pos(Separator,Text) + Length(Separator), Length(Text));
			i := i + 1;
		end else begin
			 Dest[i] := Text;
			 Text := '';
		end;
	until Length(Text)=0;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
	taskname:	String;
begin
	taskname := ModPathName;
	if CurStep = ssPostInstall then
		if IsTaskSelected(taskname) then
			ModPath();
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
	aSelectedTasks:	TArrayOfString;
	i:				Integer;
	taskname:		String;
	regpath:		String;
	regstring:		String;
	appid:			String;
begin
	// only run during actual uninstall
	if CurUninstallStep = usUninstall then begin
		// get list of selected tasks saved in registry at install time
		appid := '{#emit SetupSetting("AppId")}';
		if appid = '' then appid := '{#emit SetupSetting("AppName")}';
		regpath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\'+appid+'_is1');
		RegQueryStringValue(HKLM, regpath, 'Inno Setup: Selected Tasks', regstring);
		if regstring = '' then RegQueryStringValue(HKCU, regpath, 'Inno Setup: Selected Tasks', regstring);

		// check each task; if matches modpath taskname, trigger patch removal
		if regstring <> '' then begin
			taskname := ModPathName;
			MPExplode(aSelectedTasks, regstring, ',');
			if GetArrayLength(aSelectedTasks) > 0 then begin
				for i := 0 to GetArrayLength(aSelectedTasks)-1 do begin
					if comparetext(aSelectedTasks[i], taskname) = 0 then
						ModPath();
				end;
			end;
		end;
	end;
end;

function NeedRestart(): Boolean;
var
	taskname:	String;
begin
	taskname := ModPathName;
	if IsTaskSelected(taskname) and not UsingWinNT() then begin
		Result := True;
	end else begin
		Result := False;
	end;
end;

  ; C S O U N D   6   I N N O   S E T U P   S C R I P T

; Copyright (C) 2013 by Michael Gogins.
; This software is licensed under the terms of the
; Lesser (or Library) GNU Public License.

; SEE THE DOCUMENTATION FOR DETAILS ON CREATING INNO SETUP SCRIPT FILES!

; This file assumes that you are Michael Gogins,
; but comments indicate what you should change if you are not me.
; All of these changes SHOULD be in the #defines immediately following this.
; Also, this installer assumes LuaJIT and CsoundAC are part of Csound core.
; At this time the following features are not included in the installer:
; Cabbage, CsoundVST.
; I hope to change this soon.

#define MyAppName "Csound6"
#define MyAppVersion "6"
#define MyAppMinVersion "6.00.1"
#define MyAppPublisher "Csound"
#define MyAppURL "http://sourceforge.net/projects/csound"
; If you are not Michael Gogins, change this to your MinGW dll directory.
#define MyMinGwBinDir "D:\mingw32-4.8.1\bin\"
; If you are not Michael Gogins, change this to your MSys /bin/ directory.
#define MyMSysBinDir "D:\msys\bin\"
; If you are not Michael Gogins, change this to your MSys /usr/local/ directory.
#define MyMSysUsrLocalDir "D:\msys\local\"
; If you are not Michael Gogins, change this to your Csound build directory.
#define MySourceDir "C:\Users\mkg.sorabji\csound-csound6-git\"
; If you are not Michael Gogins, change this to your Csound reference manual build directory.
#define MyManualSourceDir "C:\Users\mkg.sorabji\csound-manual6-git\"
; If you are not Michael Gogins, change this to your Csound tutorial directory.
#define MyCsoundTutorialSourceDir "D:\Dropbox\tutorial\"
; If you are not Michael Gogins, change this to your CsoundAC tutorial directory.
#define MyCsoundAcTutorialSourceDir "D:\Dropbox\tutorial\"
; If you are not Michael Gogins, change this to your libsndfile install directory.
#define MyLibSndfileSourceDir "D:\msys\local\opt\libsndfile\"
; If you are not Michael Gogins, change this to your PortAudio lib directory.
#define MyPortAudioSourceDir "D:\msys\local\src\portaudio\"
; If you are not Michael Gogins, change this to your PortMidi build directory.
#define MyPortMidiSourceDir "D:\msys\local\src\portmidi\"
; If you are not Michael Gogins, change this to your LuaJIT bin directory.
#define MyLuaJitSourceDir "D:\msys\local\src\luajit-2.0\src\"
; If you are not Michael Gogins, change this to your FLTK dll directory.
#define MyFltkSourceDir "D:\msys\local\src\fltk-1.3.2\src\"
; If you are not Michael Gogins, change this to your libmusicxml dll directory.
#define MyLibMusicXmlSourceDir "D:\msys\local\src\libmusicxml\"
; If you are not Michael Gogins, change this to your FluidSynth dll directory.
#define MyFluidSynthSourceDir "D:\msys\local\src\fluidsynth\src\.libs\"
; If you are not Michael Gogins, change this to your OSC library dll directory.
#define MyLibLoSourceDir "D:\msys\local\src\liblo-0.26\"
; If you are not Michael Gogins, change this to your STK dll directory.
#define MyLibStkSourceDir "D:\msys\local\src\stk-4.4.4\"
; If you are not Michael Gogins, change this to your CsoundQt bin directory.
#define MyCsoundQtBinDir "C:\Users\mkg.sorabji\qutecsound-code\bin\"
; If you are not Michael Gogins, change this to your Qt SDK DLL directory.
#define MyQtSdkBinDir "D:\qt-everywhere-opensource-src-5.1.0\qtbase\bin\"

[Components]
Name: "core"; Description: "Core Csound"; Types: full custom; Flags: fixed
Name: "python"; Description: "Python features (requires Python 2.7)"; Types: full;

[Dirs]
; ALL programs and shared libraries (including opcodes and other modules) go here.
Name: "{app}\bin"; Permissions: users-modify
#define APP_BIN "{app}\bin\"
; All C or C++ include files for Csound and other components used by Csound go here.
; This is a convenience for people like me who program in C or C++ and might use
; features of these third party components.
Name: "{app}\include"
#define APP_INCLUDE "{app}\include\"
; The Csound reference manual goes here.
Name: "{app}\doc\manual"
#define APP_MANUAL "{app}\doc\manual\"
; The Csound API reference manuals go here.
Name: "{app}\doc\apiref"
#define APP_APIREF "{app}\doc\apiref\"
; All Csound examples go here.
Name: "{app}\examples"; Permissions: users-modify
#define APP_EXAMPLES "{app}\examples\"
; Any SoundFonts or sound samples used by Csound examples go here.
Name: "{app}\samples"
#define APP_SAMPLES "{app}\samples\"
; Tutorials go here.
Name: "{app}\doc\tutorial"
#define APP_TUTORIAL "{app}\doc\tutorial\"

; These are the Csound environment variables related to directories.

#define SFDIR
#define SSDIR
#define SADIR
#define INCDIR
#define OPCODE6DIR64
#define SNAPDIR
#define RAWWAVE_PATH
#define MFDIR
#define PYTHONPATH

[Setup]
ChangesEnvironment=true
; 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={{4BCEDC5F-C6D2-4869-9097-3F1753739F35}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
AppVerName={#MyAppName} {#MyAppMinVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={pf}\{#MyAppName}
DefaultGroupName=Csound 6
AllowNoIcons=yes
LicenseFile=readme-csound6.txt
;InfoBeforeFile=readme-csound6.txt
OutputDir=installer\windows
OutputBaseFilename=Setup_{#MyAppName}_{#MyAppMinVersion}
Compression=lzma
SolidCompression=yes
SourceDir={#MySourceDir}

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

[Files]
; NOTE: Don't use "Flags: ignoreversion" on any shared system files
Source: "{#MyMinGwBinDir}*.dll"; DestDir: "{#APP_BIN}"; Components: core;
; No idea why this other name is needed.
Source: "{#MyMSysBinDir}libiconv-2.dll"; DestDir: "{#APP_BIN}"; DestName: "iconv.dll"; Components: core;
Source: "{#MyMSysUsrLocalDir}bin/*.dll"; DestDir: "{#APP_BIN}"; Components: core;
Source: "*.exe"; DestDir: "{#APP_BIN}"; Flags: ignoreversion; Components: core;
Source: "*.jar"; DestDir: "{#APP_BIN}"; Flags: ignoreversion; Components: core;
Source: "*.dll*"; DestDir: "{#APP_BIN}"; Flags: ignoreversion; Excludes: "py.dll"; Components: core;
Source: "py.dll"; DestDir: "{#APP_BIN}"; Flags: ignoreversion; Components: python;
Source: "*.pyd"; DestDir: "{#APP_BIN}"; Flags: ignoreversion; Components: python;
Source: "*.py";  DestDir: "{#APP_BIN}"; Flags: ignoreversion; Components: python;

Source: "{#MyCsoundQtBinDir}CsoundQt-d-cs6.exe"; DestDir: "{#APP_BIN}"; Components: core;
Source: "{#MyQtSdkBinDir}Qt5PrintSupport.dll"; DestDir: "{#APP_BIN}"; Components: core;
Source: "{#MyQtSdkBinDir}Qt5Widgets.dll"; DestDir: "{#APP_BIN}"; Components: core;
Source: "{#MyQtSdkBinDir}Qt5Xml.dll"; DestDir: "{#APP_BIN}"; Components: core;
Source: "{#MyQtSdkBinDir}Qt5Gui.dll"; DestDir: "{#APP_BIN}"; Components: core;
Source: "{#MyQtSdkBinDir}Qt5Core.dll"; DestDir: "{#APP_BIN}"; Components: core;
Source: "{#MyQtSdkBinDir}..\plugins\platforms\qwindows.dll"; DestDir: "{#APP_BIN}\platforms"; Components: core;
Source: "{#MyQtSdkBinDir}..\plugins\accessible\qtaccessiblewidgets.dll"; DestDir: "{#APP_BIN}\plugins\accessible"; Components: core;
Source: "{#MyQtSdkBinDir}..\plugins\imageformats\*.dll"; DestDir: "{#APP_BIN}\plugins\imageformats"; Components: core;
Source: "{#MyQtSdkBinDir}..\plugins\printsupport\windowsprintersupport.dll"; DestDir: "{#APP_BIN}\plugins\printsupport"; Components: core;

Source: {#MyLibSndfileSourceDir}\bin\*.*; DestDir: "{#APP_BIN}"; Flags: ignoreversion; Components: core;
Source: {#MyLibSndfileSourceDir}\include\*.*; DestDir: "{#APP_INCLUDE}\sndfile"; Flags: ignoreversion; Components: core;

; Ignore the unspeakably stupid libtool crap.
Source: {#MyPortAudioSourceDir}\lib\.libs\*x86.dll; DestDir: "{#APP_BIN}"; Components: core
Source: {#MyPortAudioSourceDir}\bin\.libs\pa_devs.exe; DestDir: "{#APP_BIN}"; Components: core
Source: {#MyPortAudioSourceDir}\bin\.libs\pa_minlat.exe; DestDir: "{#APP_BIN}"; Components: core

Source: {#MyPortMidiSourceDir}*.dll; DestDir: "{#APP_BIN}"; Flags: ignoreversion; Components: core

Source: {#MyLuaJitSourceDir}luajit.exe; DestDir: "{#APP_BIN}"; Flags: ignoreversion;  Components: core

Source: {#MyLuaJitSourceDir}lua51.dll; DestDir: "{#APP_BIN}"; Flags: ignoreversion;  Components: core
; No idea why this other name is needed.
Source: {#MyLuaJitSourceDir}lua51.dll; DestDir: "{#APP_BIN}"; DestName: "lua5.1.dll"; Flags: ignoreversion;  Components: core
Source: {#MyLuaJitSourceDir}lua51.dll; DestDir: "{#APP_BIN}"; DestName: "luajit.dll"; Flags: ignoreversion;  Components: core
Source: {#MyLuaJitSourceDir}lua*.h; DestDir: "{#APP_INCLUDE}\luajit"; Flags: ignoreversion;  Components: core

Source: {#MyFltkSourceDir}*.dll; DestDir: "{#APP_BIN}"; Flags: ignoreversion;  Components: core

Source: {#MyLibMusicXmlSourceDir}\cmake\*.dll; DestDir: "{#APP_BIN}"; Flags: ignoreversion;  Components: core

; Source: {#MyFluidSynthSourceDir}*.dll; DestDir: "{#APP_BIN}"; Flags: ignoreversion;  Components: core

; Source: {#MyLibLoSourceDir}*.dll; DestDir: "{#APP_BIN}"; Flags: ignoreversion;  Components: core

Source: include/*.h*; DestDir: "{#APP_INCLUDE}\csound"; Flags: ignoreversion;  Components: core
Source: interfaces/*.h*; DestDir: "{#APP_INCLUDE}\csound"; Flags: ignoreversion;  Components: core
Source: frontends/CsoundAC/*.hpp; DestDir: "{#APP_INCLUDE}\csoundac"; Flags: ignoreversion;  Components: core

Source: {#MyManualSourceDir}html\*.*; DestDir: "{#APP_MANUAL}"; Flags: ignoreversion recursesubdirs;  Components: core

Source: "doc\csound\html\*.*"; DestDir: "{#APP_APIREF}/csound"; Flags: ignoreversion recursesubdirs;  Components: core
Source: "doc\csoundac\html\*.*"; DestDir: "{#APP_APIREF}/csoundac"; Flags: ignoreversion recursesubdirs;  Components: core

Source: "examples\*.*"; DestDir: "{#APP_EXAMPLES}"; Excludes: "*.wav"; Flags: ignoreversion recursesubdirs;  Components: core

Source: "samples\*.*"; DestDir: "{#APP_SAMPLES}"; Flags: ignoreversion recursesubdirs;  Components: core
Source: "{#MyLibStkSourceDir}rawwaves\*.*"; DestDir: "{#APP_SAMPLES}"; Flags: ignoreversion recursesubdirs;  Components: core

Source: {#MyCsoundTutorialSourceDir}tutorial.pdf; DestDir: "{#APP_TUTORIAL}"; Flags: ignoreversion recursesubdirs;  Components: core
Source: {#MyCsoundAcTutorialSourceDir}Csound_Algorithmic_Composition_Tutorial.pdf; DestDir: "{#APP_TUTORIAL}"; Flags: ignoreversion recursesubdirs;  Components: core
Source: {#MyCsoundAcTutorialSourceDir}code\*.*; DestDir: "{#APP_TUTORIAL}code\"; Excludes: "*.wav"; Flags: ignoreversion recursesubdirs;  Components: core

[Icons]
Name: "{group}\{cm:ProgramOnTheWeb,{#MyAppName}}"; Filename: "{#MyAppURL}";  Components: core;
Name: "{group}\{cm:UninstallProgram,{#MyAppName}}"; Filename: "{uninstallexe}"
Name: "{group}\Csound"; Filename: "cmd.exe"; Parameters: "/K csound.exe"; WorkingDir: "{#APP_BIN}"; Flags: dontcloseonexit;  Components: core
Name: "{group}\CsoundQt"; Filename: "{#APP_BIN}CsoundQt-d-cs6.exe"; WorkingDir: "{#APP_BIN}";  Components: core
Name: "{group}\WinSound"; Filename: "{#APP_BIN}winsound.exe"; WorkingDir: "{#APP_BIN}";  Components: core
Name: "{group}\LuaJIT"; Filename: "{#APP_BIN}luajit.exe"; WorkingDir: "{#APP_BIN}";  Components: core
Name: "{group}\Audio device information"; Filename: "cmd"; Parameters: "/K pa_devs.exe"; WorkingDir: "{#APP_BIN}"; Flags: dontcloseonexit;  Components: core
Name: "{group}\Audio device latency"; Filename: "cmd"; Parameters: "/K pa_minlat.exe"; WorkingDir: "{#APP_BIN}"; Flags: dontcloseonexit;  Components: core
Name: "{group}\Csound Reference Manual"; Filename: "{#APP_MANUAL}indexframes.html";  Components: core
Name: "{group}\Csound API Reference Manual"; Filename: "{#APP_APIREF}csound\index.html";  Components: core
Name: "{group}\CsoundAC API Reference Manual"; Filename: "{#APP_APIREF}csoundac\index.html";  Components: core
Name: "{group}\Csound Tutorial"; Filename: "{#APP_TUTORIAL}tutorial.pdf";  Components: core
Name: "{group}\CsoundAC Tutorial"; Filename: "{#APP_TUTORIAL}Csound_Algorithmic_Composition_Tutorial.pdf";  Components: core

[Registry]
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"RAWWAVE_PATH"; ValueData:"{#APP_SAMPLES}"; Flags: preservestringtype uninsdeletekey;  Components: core
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"OPCODE6DIR64"; ValueData:"{#APP_BIN}"; Flags: preservestringtype uninsdeletekey;  Components: core
Root: HKCU; Subkey: "Environment"; ValueType:string; ValueName:"PYTHONPATH"; ValueData:"{#APP_BIN}"; Flags: preservestringtype uninsdeletekey;  Components: python

[Tasks]
Name: modifypath; Description: &Add application directory to your PATH environment variable; Components: core;

[Code]
//	ModPathName defines the name of the task defined above
//	ModPathType defines whether the 'user' or 'system' path will be modified;
//		this will default to user if anything other than system is set
//	setArrayLength must specify the total number of dirs to be added
//	Result[0] contains first directory, Result[1] contains second, etc.
const ModPathName = 'modifypath';
ModPathType = 'system';

function ModPathDir(): TArrayOfString;
begin
	setArrayLength(Result, 1);
	Result[0] := ExpandConstant('{app}\bin');
end;

procedure ModPath();
var
	oldpath:	String;
	newpath:	String;
	updatepath:	Boolean;
	pathArr:	TArrayOfString;
	aExecFile:	String;
	aExecArr:	TArrayOfString;
	i, d:		Integer;
	pathdir:	TArrayOfString;
	regroot:	Integer;
	regpath:	String;
begin
	// Get constants from main script and adjust behavior accordingly
	// ModPathType MUST be 'system' or 'user'; force 'user' if invalid
	if ModPathType = 'system' then begin
		regroot := HKEY_LOCAL_MACHINE;
		regpath := 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment';
	end else begin
		regroot := HKEY_CURRENT_USER;
		regpath := 'Environment';
	end;

	// Get array of new directories and act on each individually
	pathdir := ModPathDir();
	for d := 0 to GetArrayLength(pathdir)-1 do begin
		updatepath := true;

		// Modify WinNT path
		if UsingWinNT() = true then begin

			// Get current path, split into an array
			RegQueryStringValue(regroot, regpath, 'Path', oldpath);
			oldpath := oldpath + ';';
			i := 0;

			while (Pos(';', oldpath) > 0) do begin
				SetArrayLength(pathArr, i+1);
				pathArr[i] := Copy(oldpath, 0, Pos(';', oldpath)-1);
				oldpath := Copy(oldpath, Pos(';', oldpath)+1, Length(oldpath));
				i := i + 1;

				// Check if current directory matches app dir
				if pathdir[d] = pathArr[i-1] then begin
					// if uninstalling, remove dir from path
					if IsUninstaller() = true then begin
						continue;
					// if installing, flag that dir already exists in path
					end else begin
						updatepath := false;
					end;
				end;

				// Add current directory to new path
				if i = 1 then begin
					newpath := pathArr[i-1];
				end else begin
					newpath := newpath + ';' + pathArr[i-1];
				end;
			end;

			// Append app dir to path if not already included
			if (IsUninstaller() = false) AND (updatepath = true) then
				newpath := newpath + ';' + pathdir[d];

			// Write new path
			RegWriteStringValue(regroot, regpath, 'Path', newpath);

		// Modify Win9x path
		end else begin

			// Convert to shortened dirname
			pathdir[d] := GetShortName(pathdir[d]);

			// If autoexec.bat exists, check if app dir already exists in path
			aExecFile := 'C:\AUTOEXEC.BAT';
			if FileExists(aExecFile) then begin
				LoadStringsFromFile(aExecFile, aExecArr);
				for i := 0 to GetArrayLength(aExecArr)-1 do begin
					if IsUninstaller() = false then begin
						// If app dir already exists while installing, skip add
						if (Pos(pathdir[d], aExecArr[i]) > 0) then
							updatepath := false;
							break;
					end else begin
						// If app dir exists and = what we originally set, then delete at uninstall
						if aExecArr[i] = 'SET PATH=%PATH%;' + pathdir[d] then
							aExecArr[i] := '';
					end;
				end;
			end;

			// If app dir not found, or autoexec.bat didn't exist, then (create and) append to current path
			if (IsUninstaller() = false) AND (updatepath = true) then begin
				SaveStringToFile(aExecFile, #13#10 + 'SET PATH=%PATH%;' + pathdir[d], True);

			// If uninstalling, write the full autoexec out
			end else begin
				SaveStringsToFile(aExecFile, aExecArr, False);
			end;
		end;
	end;
end;

// Split a string into an array using passed delimeter
procedure MPExplode(var Dest: TArrayOfString; Text: String; Separator: String);
var
	i: Integer;
begin
	i := 0;
	repeat
		SetArrayLength(Dest, i+1);
		if Pos(Separator,Text) > 0 then	begin
			Dest[i] := Copy(Text, 1, Pos(Separator, Text)-1);
			Text := Copy(Text, Pos(Separator,Text) + Length(Separator), Length(Text));
			i := i + 1;
		end else begin
			 Dest[i] := Text;
			 Text := '';
		end;
	until Length(Text)=0;
end;

procedure CurStepChanged(CurStep: TSetupStep);
var
	taskname:	String;
begin
	taskname := ModPathName;
	if CurStep = ssPostInstall then
		if IsTaskSelected(taskname) then
			ModPath();
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
var
	aSelectedTasks:	TArrayOfString;
	i:				Integer;
	taskname:		String;
	regpath:		String;
	regstring:		String;
	appid:			String;
begin
	// only run during actual uninstall
	if CurUninstallStep = usUninstall then begin
		// get list of selected tasks saved in registry at install time
		appid := '{#emit SetupSetting("AppId")}';
		if appid = '' then appid := '{#emit SetupSetting("AppName")}';
		regpath := ExpandConstant('Software\Microsoft\Windows\CurrentVersion\Uninstall\'+appid+'_is1');
		RegQueryStringValue(HKLM, regpath, 'Inno Setup: Selected Tasks', regstring);
		if regstring = '' then RegQueryStringValue(HKCU, regpath, 'Inno Setup: Selected Tasks', regstring);

		// check each task; if matches modpath taskname, trigger patch removal
		if regstring <> '' then begin
			taskname := ModPathName;
			MPExplode(aSelectedTasks, regstring, ',');
			if GetArrayLength(aSelectedTasks) > 0 then begin
				for i := 0 to GetArrayLength(aSelectedTasks)-1 do begin
					if comparetext(aSelectedTasks[i], taskname) = 0 then
						ModPath();
				end;
			end;
		end;
	end;
end;

function NeedRestart(): Boolean;
var
	taskname:	String;
begin
	taskname := ModPathName;
	if IsTaskSelected(taskname) and not UsingWinNT() then begin
		Result := True;
	end else begin
		Result := False;
	end;
end;


Supressible msgboxes in setup with cmdline /silent /suppressmsgboxes

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

#define MyAppName "Visual Leak Detector"
#define MyAppVersion "2.5.1"
#define MyAppPublisher "VLD Team"
#define MyAppURL "http://vld.codeplex.com/"
#define MyAppRegKey "Software\Visual Leak Detector"

[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={{851FBFF7-5148-40A2-A654-942BE80F5B90}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={reg:HKLM\{#MyAppRegKey},InstallPath|{pf}\{#MyAppName}}
DefaultGroupName={#MyAppName}
LicenseFile=license-free.txt
OutputBaseFilename=vld-{#MyAppVersion}-setup
Compression=lzma
SolidCompression=True
MinVersion=0,5.01
; Tell Windows Explorer to reload the environment
ChangesEnvironment=yes
AllowNoIcons=yes
DisableDirPage=auto
DirExistsWarning=no
WizardImageFile=compiler:WizModernImage-IS.bmp
WizardSmallImageFile=WizSmallImage.bmp

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

[Icons]
Name: "{group}\View Documentation"; Filename: "http://vld.codeplex.com/documentation"

[Files]
Source: "dbghelp\x64\dbghelp.dll"; DestDir: "{app}\bin\Win64"; Flags: ignoreversion
Source: "dbghelp\x64\Microsoft.DTfW.DHL.manifest"; DestDir: "{app}\bin\Win64"; Flags: ignoreversion
Source: "dbghelp\x86\dbghelp.dll"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
Source: "dbghelp\x86\Microsoft.DTfW.DHL.manifest"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
Source: "..\src\bin\Win32\Release-v140\vld.lib"; DestDir: "{app}\lib\Win32"; Flags: ignoreversion
Source: "..\src\bin\Win32\Release-v140\vld_x86.dll"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
Source: "..\src\bin\Win32\Release-v140\vld_x86.pdb"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
Source: "..\src\bin\x64\Release-v140\vld.lib"; DestDir: "{app}\lib\Win64"; Flags: ignoreversion
Source: "..\src\bin\x64\Release-v140\vld_x64.dll"; DestDir: "{app}\bin\Win64"; Flags: ignoreversion
Source: "..\src\bin\x64\Release-v140\vld_x64.pdb"; DestDir: "{app}\bin\Win64"; Flags: ignoreversion
Source: "..\src\vld.h"; DestDir: "{app}\include"; Flags: ignoreversion
Source: "..\src\vld_def.h"; DestDir: "{app}\include"; Flags: ignoreversion
Source: "..\vld.ini"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\AUTHORS.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\CHANGES.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\COPYING.txt"; DestDir: "{app}"; Flags: ignoreversion

[Tasks]
Name: "modifypath"; Description: "Add VLD directory to your environmental path"
Name: "modifyVS2008Props"; Description: "Add VLD directory to VS 2008"
Name: "modifyVS2010Props"; Description: "Add VLD directory to VS 2010 - VS 2015"

[ThirdParty]
UseRelativePaths=True

[Registry]
Root: "HKLM32"; Subkey: "{#MyAppRegKey}"; Flags: uninsdeletekeyifempty
Root: "HKLM32"; Subkey: "{#MyAppRegKey}"; ValueType: string; ValueName: "InstalledVersion"; ValueData: "{#MyAppVersion}"
Root: "HKLM32"; Subkey: "{#MyAppRegKey}"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
Root: "HKLM32"; Subkey: "{#MyAppRegKey}"; ValueType: string; ValueName: "IniFile"; ValueData: "{app}\vld.ini"

Root: "HKLM64"; Subkey: "{#MyAppRegKey}"; Flags: uninsdeletekeyifempty
Root: "HKLM64"; Subkey: "{#MyAppRegKey}"; ValueType: string; ValueName: "InstalledVersion"; ValueData: "{#MyAppVersion}"
Root: "HKLM64"; Subkey: "{#MyAppRegKey}"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
Root: "HKLM64"; Subkey: "{#MyAppRegKey}"; ValueType: string; ValueName: "IniFile"; ValueData: "{app}\vld.ini"

[Code]
type
  TKey = string;
  TValue = string;
  TKeyValue = record
    Key: TKey;
    Value: TValue;
  end;
  TKeyValueList = array of TKeyValue;

const
    ModPathName = 'modifypath';
    ModPathType = 'system';

function ModPathDir(): TArrayOfString;
begin
    setArrayLength(Result, 2);
    Result[0] := ExpandConstant('{app}\bin\Win32');
    Result[1] := ExpandConstant('{app}\bin\Win64');
end;

#include "modpath.iss"

function GetUninstallString(regPath: string): String;
var
  sUnInstPath: String;
  sUnInstString: String;
begin
  sUnInstPath := ExpandConstant(regPath);
  sUnInstString := '';
  if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstString) then
    RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstString);
  Result := sUnInstString;
end;

function UninstallOldVersion(regPath: string; params: string): Boolean;
var
  iResultCode: Integer;
begin
  // default return value
  Result := False;

  if SuppressibleMsgBox('VLD is already installed. Uninstall the current version?',
    mbConfirmation, MB_YESNO, IDYES) = IDYES then
  begin
    regPath := RemoveQuotes(regPath);
    if Exec(regPath, params,'', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
      Result := True;
  end
end;

function UninstallOldVersions(): Boolean;
var
  nsisUnInstallString: String;
  isUnInstallString: String;
begin
  nsisUnInstallString := GetUninstallString('Software\Microsoft\Windows\CurrentVersion\Uninstall\Visual Leak Detector');
  isUnInstallString := GetUninstallString('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1');
  Result := True;
  if (nsisUnInstallString <> '') then
  begin
    Result := UninstallOldVersion(nsisUnInstallString, '/S');
  end
  else if (isUnInstallString <> '') then
  begin
    Result := UninstallOldVersion(isUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES');
  end;
end;

function Count(What, Where: String): Integer;
begin
  Result := 0;
  if Length(What) = 0 then
    exit;
  while Pos(What,Where)>0 do
  begin
    Where := Copy(Where,Pos(What,Where)+Length(What),Length(Where));
    Result := Result + 1;
  end;
end;

procedure Explode(var ADest: TKeyValueList; aText, aSeparator: String);
var tmp: Integer;
  item: TKeyValue;
begin
  SetArrayLength(ADest, (Count(aSeparator,aText) / 2) + 1);
  tmp := 0;
  repeat
    item.Key := '';
    item.Value := '';
    if Pos(aSeparator,aText)>0 then
    begin
      item.Key := Copy(aText,1,Pos(aSeparator,aText)-1);
      aText := Copy(aText,Pos(aSeparator,aText)+Length(aSeparator),Length(aText));
    end else
    begin
      item.Key := aText;
      aText := '';
    end;
    if Pos(aSeparator,aText)>0 then
    begin
      item.Value := Copy(aText,1,Pos(aSeparator,aText)-1);
      aText := Copy(aText,Pos(aSeparator,aText)+Length(aSeparator),Length(aText));
    end else
    begin
      item.Value := aText;
      aText := '';
    end;
    ADest[tmp] := item;
    tmp := tmp + 1;
  until Length(aText)=0;
end;

function Merge(ADest: TKeyValueList; aSeparator: String): String;
var i, n, l: Integer;
  str: String;
begin
  n := GetArrayLength(ADest);
  l := n + (n - 1);
  if l < 0 then l := 0;
  Result := '';
  for i := 0 to n - 1 do
  begin
    str := ADest[i].Key + aSeparator + ADest[i].Value;
    Result := Result + str;
    if i < n - 1 then Result := Result + aSeparator;
  end;
end;

function UpdatePath(dirList: String; path: String): String;
begin
  if dirList = '' then
    Result := path
  else if Pos(path, dirList) = 0 then
    Result := path + ';' + dirList
  else
    Result := dirList;
end;

procedure UpdatePaths(var dirList: string; path32: string; path64: string);
var map: TKeyValueList;
  i: Integer;
begin
  Explode(map, dirList, '|');
  for i := 0 to GetArrayLength(map) - 1 do
  begin
    if map[i].Key = 'Win32' then map[i].Value := UpdatePath(map[i].Value, path32)
    else if map[i].Key = 'x64' then map[i].Value := UpdatePath(map[i].Value, path64);
  end;
  dirList := Merge(map, '|');
  Log(dirList);
end;

procedure ModifySettings(filename: string);
var
  XMLDocument: Variant;
  XMLParent, XMLNode, XMLNodes: Variant;
  IncludeDirectoriesNode: Variant;
  AdditionalIncludeDirectories: string;
  LibraryDirectoriesNode: Variant;
  AdditionalLibraryDirectories: string;
  libfolder: string;
begin
  XMLDocument := CreateOleObject('Msxml2.DOMDocument.3.0');
  try
    XMLDocument.async := False;
    XMLDocument.load(filename);
    if (XMLDocument.parseError.errorCode = 0) then
    begin
      XMLDocument.setProperty('SelectionLanguage', 'XPath');
      XMLNodes := XMLDocument.SelectNodes('//UserSettings/ToolsOptions/ToolsOptionsCategory[@name="Projects"]/ToolsOptionsSubCategory[@name="VCDirectories"]');
      if XMLNodes.Length = 0 then
        Exit;
      XMLParent := XMLNodes.Item[0];
      XMLNodes := XMLParent.SelectNodes('//PropertyValue[@name="LibraryDirectories"]');
      if XMLNodes.Length > 0 then
        LibraryDirectoriesNode := XMLNodes.Item[0];
      XMLNodes := XMLParent.SelectNodes('//PropertyValue[@name="IncludeDirectories"]');
      if XMLNodes.Length > 0 then
        IncludeDirectoriesNode := XMLNodes.Item[0];
      AdditionalIncludeDirectories := '';
      if not VarIsNull(IncludeDirectoriesNode) then
        AdditionalIncludeDirectories := IncludeDirectoriesNode.Text;
      AdditionalLibraryDirectories := '';
      if not VarIsNull(LibraryDirectoriesNode) then
        AdditionalLibraryDirectories := LibraryDirectoriesNode.Text;
      UpdatePaths(AdditionalIncludeDirectories, ExpandConstant('{app}\include'), ExpandConstant('{app}\include'));
      UpdatePaths(AdditionalLibraryDirectories, ExpandConstant('{app}\lib\Win32'), ExpandConstant('{app}\lib\Win64'));
      IncludeDirectoriesNode.Text := AdditionalIncludeDirectories;
      LibraryDirectoriesNode.Text := AdditionalLibraryDirectories;
      XMLDocument.save(filename);
    end;
  except
    ShowExceptionMessage;
  end;
end;

procedure ModifyVS2008Settings();
var
  Path, CurSettings: string;
begin
  if RegQueryStringValue(HKEY_CURRENT_USER, 'Software\Microsoft\VisualStudio\9.0',
     'VisualStudioLocation', Path) then
  begin
    StringChangeEx(Path, '%USERPROFILE%', GetEnv('USERPROFILE'), True);
    if RegQueryStringValue(HKEY_CURRENT_USER, 'Software\Microsoft\VisualStudio\9.0\Profile',
       'AutoSaveFile', CurSettings) then
    begin
      StringChangeEx(CurSettings, '%vsspv_visualstudio_dir%', Path, True);
      ModifySettings(CurSettings);
    end;
  end;
end;

function EncodeString(str: string): string;
begin
  Result := str;
  StringChangeEx(Result, '(', '%28', True);
  StringChangeEx(Result, ')', '%29', True);
end;

procedure UpdateString(var dirList: string; path: string; suffix: string);
begin
  if dirList = '' then
    dirList := path + suffix
  else if (Pos(path, dirList) = 0) and (Pos(EncodeString(path), dirList) = 0) then
    dirList := path + dirList;
  Log(dirList);
end;

procedure ModifyProps(filename: string; libfolder: string);
var
  XMLDocument: Variant;
  XMLParent, IdgNode, XMLNode, XMLNodes: Variant;
  IncludeDirectoriesNode: Variant;
  AdditionalIncludeDirectories: string;
  DynamicLibraryDirectoriesNode: Variant;
  AdditionalDynamicLibraryDirectories: string;
  StaticLibraryDirectoriesNode: Variant;
  AdditionalStaticLibraryDirectories: string;
begin
  if not FileExists(filename) then
    Exit;
  XMLDocument := CreateOleObject('Msxml2.DOMDocument.3.0');
  try
    XMLDocument.async := False;
    XMLDocument.load(filename);
    if (XMLDocument.parseError.errorCode = 0) then
    begin
      XMLDocument.setProperty('SelectionLanguage', 'XPath');
      XMLDocument.setProperty('SelectionNamespaces', 'xmlns:b=''http://schemas.microsoft.com/developer/msbuild/2003''');
      XMLNodes := XMLDocument.SelectNodes('//b:Project');
      if XMLNodes.Length = 0 then
        Exit;
      IdgNode := XMLNodes.Item[0];
      XMLNodes := IdgNode.SelectNodes('//b:ItemDefinitionGroup');
      if XMLNodes.Length > 0 then
        IdgNode := XMLNodes.Item[0]
      else
      begin
        XMLNode := XMLDocument.CreateNode(1, 'ItemDefinitionGroup',
                    'http://schemas.microsoft.com/developer/msbuild/2003');
        IdgNode := IdgNode.AppendChild(XMLNode);
      end;

      XMLNodes := IdgNode.SelectNodes('//b:ClCompile');
      if XMLNodes.Length > 0 then
        XMLParent := XMLNodes.Item[0]
      else
      begin
        XMLNode := XMLDocument.CreateNode(1, 'ClCompile',
                    'http://schemas.microsoft.com/developer/msbuild/2003');
        XMLParent := IdgNode.AppendChild(XMLNode);
      end;
      XMLNodes := XMLParent.SelectNodes('//b:ClCompile/b:AdditionalIncludeDirectories');
      if XMLNodes.Length > 0 then
        IncludeDirectoriesNode := XMLNodes.Item[0]
      else
      begin
        XMLNode := XMLDocument.CreateNode(1, 'AdditionalIncludeDirectories',
                    'http://schemas.microsoft.com/developer/msbuild/2003');
        IncludeDirectoriesNode := XMLParent.AppendChild(XMLNode);
      end;

      XMLNodes := IdgNode.SelectNodes('//b:Link');
      if XMLNodes.Length > 0 then
        XMLParent := XMLNodes.Item[0]
      else
      begin
        XMLNode := XMLDocument.CreateNode(1, 'Link',
                    'http://schemas.microsoft.com/developer/msbuild/2003');
        XMLParent := IdgNode.AppendChild(XMLNode);
      end;
      XMLNodes := XMLParent.SelectNodes('//b:Link/b:AdditionalLibraryDirectories');
      if XMLNodes.Length > 0 then
        DynamicLibraryDirectoriesNode := XMLNodes.Item[0]
      else
      begin
        XMLNode := XMLDocument.CreateNode(1, 'AdditionalLibraryDirectories',
                    'http://schemas.microsoft.com/developer/msbuild/2003');
        DynamicLibraryDirectoriesNode := XMLParent.AppendChild(XMLNode);
      end;

      XMLNodes := IdgNode.SelectNodes('//b:Lib');
      if XMLNodes.Length > 0 then
        XMLParent := XMLNodes.Item[0]
      else
      begin
        XMLNode := XMLDocument.CreateNode(1, 'Lib',
                    'http://schemas.microsoft.com/developer/msbuild/2003');
        XMLParent := IdgNode.AppendChild(XMLNode);
      end;
      XMLNodes := XMLParent.SelectNodes('//b:Lib/b:AdditionalLibraryDirectories');
      if XMLNodes.Length > 0 then
        StaticLibraryDirectoriesNode := XMLNodes.Item[0]
      else
      begin
        XMLNode := XMLDocument.CreateNode(1, 'AdditionalLibraryDirectories',
                    'http://schemas.microsoft.com/developer/msbuild/2003');
        StaticLibraryDirectoriesNode := XMLParent.AppendChild(XMLNode);
      end;

      AdditionalIncludeDirectories := '';
      if not VarIsNull(IncludeDirectoriesNode) then
        AdditionalIncludeDirectories := IncludeDirectoriesNode.Text;
      AdditionalDynamicLibraryDirectories := '';;
      if not VarIsNull(DynamicLibraryDirectoriesNode) then
        AdditionalDynamicLibraryDirectories := DynamicLibraryDirectoriesNode.Text;
      AdditionalStaticLibraryDirectories := '';;
      if not VarIsNull(StaticLibraryDirectoriesNode) then
        AdditionalStaticLibraryDirectories := StaticLibraryDirectoriesNode.Text;
      UpdateString(AdditionalIncludeDirectories, ExpandConstant('{app}\include;'), '%(AdditionalIncludeDirectories)');
      UpdateString(AdditionalDynamicLibraryDirectories, ExpandConstant('{app}\lib\' + libfolder + ';'), '%(AdditionalLibraryDirectories)');
      UpdateString(AdditionalStaticLibraryDirectories, ExpandConstant('{app}\lib\' + libfolder + ';'), '%(AdditionalLibraryDirectories)');
      IncludeDirectoriesNode.Text := AdditionalIncludeDirectories;
      DynamicLibraryDirectoriesNode.Text := AdditionalDynamicLibraryDirectories;
      StaticLibraryDirectoriesNode.Text := AdditionalStaticLibraryDirectories;
      XMLDocument.save(filename);
    end;
  except
    ShowExceptionMessage;
  end;
end;

procedure ModifyAllProps();
var
  Path: string;
begin
  Path := GetEnv('LOCALAPPDATA')+'\Microsoft\MSBuild\v4.0\';
  if DirExists(Path) then
  begin
    ModifyProps(Path + 'Microsoft.Cpp.Win32.user.props', 'Win32');
    ModifyProps(Path + 'Microsoft.Cpp.x64.user.props', 'Win64');
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
  begin
    if not UninstallOldVersions() then
      Abort();
    if IsTaskSelected('modifyVS2008Props') then
      ModifyVS2008Settings();
    if IsTaskSelected('modifyVS2010Props') then
      ModifyAllProps();
  end;
  CurStepChangedModPath(CurStep);
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  CurUninstallStepChangedModPath(CurUninstallStep);
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Result := True;

  if CurPageID = wpReady then
    SuppressibleMsgBox('Please close Visual Studio before starting the installation.', mbInformation, MB_OK, IDOK);
end;

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

#define MyAppName "Visual Leak Detector"
#define MyAppVersion "2.5"
#define MyAppPublisher "VLD Team"
#define MyAppURL "http://vld.codeplex.com/"
#define MyAppRegKey "Software\Visual Leak Detector"

[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={{851FBFF7-5148-40A2-A654-942BE80F5B90}
AppName={#MyAppName}
AppVersion={#MyAppVersion}
;AppVerName={#MyAppName} {#MyAppVersion}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={reg:HKLM\{#MyAppRegKey},InstallPath|{pf}\{#MyAppName}}
DefaultGroupName={#MyAppName}
LicenseFile=license-free.txt
OutputBaseFilename=vld-{#MyAppVersion}-setup
Compression=lzma
SolidCompression=True
MinVersion=0,5.01
; Tell Windows Explorer to reload the environment
ChangesEnvironment=yes
AllowNoIcons=yes
DisableDirPage=auto
DirExistsWarning=no
WizardImageFile=compiler:WizModernImage-IS.bmp
WizardSmallImageFile=WizSmallImage.bmp

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

[Icons]
Name: "{group}\View Documentation"; Filename: "http://vld.codeplex.com/documentation"

[Files]
Source: "dbghelp\x64\dbghelp.dll"; DestDir: "{app}\bin\Win64"; Flags: ignoreversion
Source: "dbghelp\x64\Microsoft.DTfW.DHL.manifest"; DestDir: "{app}\bin\Win64"; Flags: ignoreversion
Source: "dbghelp\x86\dbghelp.dll"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
Source: "dbghelp\x86\Microsoft.DTfW.DHL.manifest"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
Source: "..\src\bin\Win32\Release-v140\vld.lib"; DestDir: "{app}\lib\Win32"; Flags: ignoreversion
Source: "..\src\bin\Win32\Release-v140\vld_x86.dll"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
Source: "..\src\bin\Win32\Release-v140\vld_x86.pdb"; DestDir: "{app}\bin\Win32"; Flags: ignoreversion
Source: "..\src\bin\x64\Release-v140\vld.lib"; DestDir: "{app}\lib\Win64"; Flags: ignoreversion
Source: "..\src\bin\x64\Release-v140\vld_x64.dll"; DestDir: "{app}\bin\Win64"; Flags: ignoreversion
Source: "..\src\bin\x64\Release-v140\vld_x64.pdb"; DestDir: "{app}\bin\Win64"; Flags: ignoreversion
Source: "..\src\vld.h"; DestDir: "{app}\include"; Flags: ignoreversion
Source: "..\src\vld_def.h"; DestDir: "{app}\include"; Flags: ignoreversion
Source: "..\vld.ini"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\AUTHORS.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\CHANGES.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "..\COPYING.txt"; DestDir: "{app}"; Flags: ignoreversion

[Tasks]
Name: "modifypath"; Description: "Add VLD directory to your environmental path"
Name: "modifyVS2008Props"; Description: "Add VLD directory to VS 2008"
Name: "modifyVS2010Props"; Description: "Add VLD directory to VS 2010 - VS 2015"

[ThirdParty]
UseRelativePaths=True

[Registry]
Root: "HKLM32"; Subkey: "{#MyAppRegKey}"; Flags: uninsdeletekeyifempty
Root: "HKLM32"; Subkey: "{#MyAppRegKey}"; ValueType: string; ValueName: "InstalledVersion"; ValueData: "{#MyAppVersion}"
Root: "HKLM32"; Subkey: "{#MyAppRegKey}"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
Root: "HKLM32"; Subkey: "{#MyAppRegKey}"; ValueType: string; ValueName: "IniFile"; ValueData: "{app}\vld.ini"

Root: "HKLM64"; Subkey: "{#MyAppRegKey}"; Flags: uninsdeletekeyifempty
Root: "HKLM64"; Subkey: "{#MyAppRegKey}"; ValueType: string; ValueName: "InstalledVersion"; ValueData: "{#MyAppVersion}"
Root: "HKLM64"; Subkey: "{#MyAppRegKey}"; ValueType: string; ValueName: "InstallPath"; ValueData: "{app}"
Root: "HKLM64"; Subkey: "{#MyAppRegKey}"; ValueType: string; ValueName: "IniFile"; ValueData: "{app}\vld.ini"

[Code]
type
  TKey = string;
  TValue = string;
  TKeyValue = record
    Key: TKey;
    Value: TValue;
  end;
  TKeyValueList = array of TKeyValue;

const
    ModPathName = 'modifypath';
    ModPathType = 'system';

function ModPathDir(): TArrayOfString;
begin
    setArrayLength(Result, 2);
    Result[0] := ExpandConstant('{app}\bin\Win32');
    Result[1] := ExpandConstant('{app}\bin\Win64');
end;

#include "modpath.iss"

function GetUninstallString(regPath: string): String;
var
  sUnInstPath: String;
  sUnInstString: String;
begin
  sUnInstPath := ExpandConstant(regPath);
  sUnInstString := '';
  if not RegQueryStringValue(HKLM, sUnInstPath, 'UninstallString', sUnInstString) then
    RegQueryStringValue(HKCU, sUnInstPath, 'UninstallString', sUnInstString);
  Result := sUnInstString;
end;

function UninstallOldVersion(regPath: string; params: string): Boolean;
var
  iResultCode: Integer;
begin
  // default return value
  Result := False;

  if MsgBox('VLD is already installed. Uninstall the current version?',
    mbConfirmation, MB_YESNO) = IDYES then
  begin
    regPath := RemoveQuotes(regPath);
    if Exec(regPath, params,'', SW_HIDE, ewWaitUntilTerminated, iResultCode) then
      Result := True;
  end
end;

function UninstallOldVersions(): Boolean;
var
  nsisUnInstallString: String;
  isUnInstallString: String;
begin
  nsisUnInstallString := GetUninstallString('Software\Microsoft\Windows\CurrentVersion\Uninstall\Visual Leak Detector');
  isUnInstallString := GetUninstallString('Software\Microsoft\Windows\CurrentVersion\Uninstall\{#emit SetupSetting("AppId")}_is1');
  Result := True;
  if (nsisUnInstallString <> '') then
  begin
    Result := UninstallOldVersion(nsisUnInstallString, '/S');
  end
  else if (isUnInstallString <> '') then
  begin
    Result := UninstallOldVersion(isUnInstallString, '/SILENT /NORESTART /SUPPRESSMSGBOXES');
  end;
end;

function Count(What, Where: String): Integer;
begin
  Result := 0;
  if Length(What) = 0 then
    exit;
  while Pos(What,Where)>0 do
  begin
    Where := Copy(Where,Pos(What,Where)+Length(What),Length(Where));
    Result := Result + 1;
  end;
end;

procedure Explode(var ADest: TKeyValueList; aText, aSeparator: String);
var tmp: Integer;
  item: TKeyValue;
begin
  SetArrayLength(ADest, (Count(aSeparator,aText) / 2) + 1);
  tmp := 0;
  repeat
    item.Key := '';
    item.Value := '';
    if Pos(aSeparator,aText)>0 then
    begin
      item.Key := Copy(aText,1,Pos(aSeparator,aText)-1);
      aText := Copy(aText,Pos(aSeparator,aText)+Length(aSeparator),Length(aText));
    end else
    begin
      item.Key := aText;
      aText := '';
    end;
    if Pos(aSeparator,aText)>0 then
    begin
      item.Value := Copy(aText,1,Pos(aSeparator,aText)-1);
      aText := Copy(aText,Pos(aSeparator,aText)+Length(aSeparator),Length(aText));
    end else
    begin
      item.Value := aText;
      aText := '';
    end;
    ADest[tmp] := item;
    tmp := tmp + 1;
  until Length(aText)=0;
end;

function Merge(ADest: TKeyValueList; aSeparator: String): String;
var i, n, l: Integer;
  str: String;
begin
  n := GetArrayLength(ADest);
  l := n + (n - 1);
  if l < 0 then l := 0;
  Result := '';
  for i := 0 to n - 1 do
  begin
    str := ADest[i].Key + aSeparator + ADest[i].Value;
    Result := Result + str;
    if i < n - 1 then Result := Result + aSeparator;
  end;
end;

function UpdatePath(dirList: String; path: String): String;
begin
  if dirList = '' then
    Result := path
  else if Pos(path, dirList) = 0 then
    Result := path + ';' + dirList
  else
    Result := dirList;
end;

procedure UpdatePaths(var dirList: string; path32: string; path64: string);
var map: TKeyValueList;
  i: Integer;
begin
  Explode(map, dirList, '|');
  for i := 0 to GetArrayLength(map) - 1 do
  begin
    if map[i].Key = 'Win32' then map[i].Value := UpdatePath(map[i].Value, path32)
    else if map[i].Key = 'x64' then map[i].Value := UpdatePath(map[i].Value, path64);
  end;
  dirList := Merge(map, '|');
  Log(dirList);
end;

procedure ModifySettings(filename: string);
var
  XMLDocument: Variant;
  XMLParent, XMLNode, XMLNodes: Variant;
  IncludeDirectoriesNode: Variant;
  AdditionalIncludeDirectories: string;
  LibraryDirectoriesNode: Variant;
  AdditionalLibraryDirectories: string;
  libfolder: string;
begin
  XMLDocument := CreateOleObject('Msxml2.DOMDocument.3.0');
  try
    XMLDocument.async := False;
    XMLDocument.load(filename);
    if (XMLDocument.parseError.errorCode = 0) then
    begin
      XMLDocument.setProperty('SelectionLanguage', 'XPath');
      XMLNodes := XMLDocument.SelectNodes('//UserSettings/ToolsOptions/ToolsOptionsCategory[@name="Projects"]/ToolsOptionsSubCategory[@name="VCDirectories"]');
      if XMLNodes.Length = 0 then
        Exit;
      XMLParent := XMLNodes.Item[0];
      XMLNodes := XMLParent.SelectNodes('//PropertyValue[@name="LibraryDirectories"]');
      if XMLNodes.Length > 0 then
        LibraryDirectoriesNode := XMLNodes.Item[0];
      XMLNodes := XMLParent.SelectNodes('//PropertyValue[@name="IncludeDirectories"]');
      if XMLNodes.Length > 0 then
        IncludeDirectoriesNode := XMLNodes.Item[0];
      AdditionalIncludeDirectories := '';
      if not VarIsNull(IncludeDirectoriesNode) then
        AdditionalIncludeDirectories := IncludeDirectoriesNode.Text;
      AdditionalLibraryDirectories := '';
      if not VarIsNull(LibraryDirectoriesNode) then
        AdditionalLibraryDirectories := LibraryDirectoriesNode.Text;
      UpdatePaths(AdditionalIncludeDirectories, ExpandConstant('{app}\include'), ExpandConstant('{app}\include'));
      UpdatePaths(AdditionalLibraryDirectories, ExpandConstant('{app}\lib\Win32'), ExpandConstant('{app}\lib\Win64'));
      IncludeDirectoriesNode.Text := AdditionalIncludeDirectories;
      LibraryDirectoriesNode.Text := AdditionalLibraryDirectories;
      XMLDocument.save(filename);
    end;
  except
    ShowExceptionMessage;
  end;
end;

procedure ModifyVS2008Settings();
var
  Path, CurSettings: string;
begin
  if RegQueryStringValue(HKEY_CURRENT_USER, 'Software\Microsoft\VisualStudio\9.0',
     'VisualStudioLocation', Path) then
  begin
    StringChangeEx(Path, '%USERPROFILE%', GetEnv('USERPROFILE'), True);
    if RegQueryStringValue(HKEY_CURRENT_USER, 'Software\Microsoft\VisualStudio\9.0\Profile',
       'AutoSaveFile', CurSettings) then
    begin
      StringChangeEx(CurSettings, '%vsspv_visualstudio_dir%', Path, True);
      ModifySettings(CurSettings);
    end;
  end;
end;

function EncodeString(str: string): string;
begin
  Result := str;
  StringChangeEx(Result, '(', '%28', True);
  StringChangeEx(Result, ')', '%29', True);
end;

procedure UpdateString(var dirList: string; path: string; suffix: string);
begin
  if dirList = '' then
    dirList := path + suffix
  else if (Pos(path, dirList) = 0) and (Pos(EncodeString(path), dirList) = 0) then
    dirList := path + dirList;
  Log(dirList);
end;

procedure ModifyProps(filename: string; libfolder: string);
var
  XMLDocument: Variant;
  XMLParent, IdgNode, XMLNode, XMLNodes: Variant;
  IncludeDirectoriesNode: Variant;
  AdditionalIncludeDirectories: string;
  DynamicLibraryDirectoriesNode: Variant;
  AdditionalDynamicLibraryDirectories: string;
  StaticLibraryDirectoriesNode: Variant;
  AdditionalStaticLibraryDirectories: string;
begin
  if not FileExists(filename) then
    Exit;
  XMLDocument := CreateOleObject('Msxml2.DOMDocument.3.0');
  try
    XMLDocument.async := False;
    XMLDocument.load(filename);
    if (XMLDocument.parseError.errorCode = 0) then
    begin
      XMLDocument.setProperty('SelectionLanguage', 'XPath');
      XMLDocument.setProperty('SelectionNamespaces', 'xmlns:b=''http://schemas.microsoft.com/developer/msbuild/2003''');
      XMLNodes := XMLDocument.SelectNodes('//b:Project');
      if XMLNodes.Length = 0 then
        Exit;
      IdgNode := XMLNodes.Item[0];
      XMLNodes := IdgNode.SelectNodes('//b:ItemDefinitionGroup');
      if XMLNodes.Length > 0 then
        IdgNode := XMLNodes.Item[0]
      else
      begin
        XMLNode := XMLDocument.CreateNode(1, 'ItemDefinitionGroup',
                    'http://schemas.microsoft.com/developer/msbuild/2003');
        IdgNode := IdgNode.AppendChild(XMLNode);
      end;

      XMLNodes := IdgNode.SelectNodes('//b:ClCompile');
      if XMLNodes.Length > 0 then
        XMLParent := XMLNodes.Item[0]
      else
      begin
        XMLNode := XMLDocument.CreateNode(1, 'ClCompile',
                    'http://schemas.microsoft.com/developer/msbuild/2003');
        XMLParent := IdgNode.AppendChild(XMLNode);
      end;
      XMLNodes := XMLParent.SelectNodes('//b:ClCompile/b:AdditionalIncludeDirectories');
      if XMLNodes.Length > 0 then
        IncludeDirectoriesNode := XMLNodes.Item[0]
      else
      begin
        XMLNode := XMLDocument.CreateNode(1, 'AdditionalIncludeDirectories',
                    'http://schemas.microsoft.com/developer/msbuild/2003');
        IncludeDirectoriesNode := XMLParent.AppendChild(XMLNode);
      end;

      XMLNodes := IdgNode.SelectNodes('//b:Link');
      if XMLNodes.Length > 0 then
        XMLParent := XMLNodes.Item[0]
      else
      begin
        XMLNode := XMLDocument.CreateNode(1, 'Link',
                    'http://schemas.microsoft.com/developer/msbuild/2003');
        XMLParent := IdgNode.AppendChild(XMLNode);
      end;
      XMLNodes := XMLParent.SelectNodes('//b:Link/b:AdditionalLibraryDirectories');
      if XMLNodes.Length > 0 then
        DynamicLibraryDirectoriesNode := XMLNodes.Item[0]
      else
      begin
        XMLNode := XMLDocument.CreateNode(1, 'AdditionalLibraryDirectories',
                    'http://schemas.microsoft.com/developer/msbuild/2003');
        DynamicLibraryDirectoriesNode := XMLParent.AppendChild(XMLNode);
      end;

      XMLNodes := IdgNode.SelectNodes('//b:Lib');
      if XMLNodes.Length > 0 then
        XMLParent := XMLNodes.Item[0]
      else
      begin
        XMLNode := XMLDocument.CreateNode(1, 'Lib',
                    'http://schemas.microsoft.com/developer/msbuild/2003');
        XMLParent := IdgNode.AppendChild(XMLNode);
      end;
      XMLNodes := XMLParent.SelectNodes('//b:Lib/b:AdditionalLibraryDirectories');
      if XMLNodes.Length > 0 then
        StaticLibraryDirectoriesNode := XMLNodes.Item[0]
      else
      begin
        XMLNode := XMLDocument.CreateNode(1, 'AdditionalLibraryDirectories',
                    'http://schemas.microsoft.com/developer/msbuild/2003');
        StaticLibraryDirectoriesNode := XMLParent.AppendChild(XMLNode);
      end;

      AdditionalIncludeDirectories := '';
      if not VarIsNull(IncludeDirectoriesNode) then
        AdditionalIncludeDirectories := IncludeDirectoriesNode.Text;
      AdditionalDynamicLibraryDirectories := '';;
      if not VarIsNull(DynamicLibraryDirectoriesNode) then
        AdditionalDynamicLibraryDirectories := DynamicLibraryDirectoriesNode.Text;
      AdditionalStaticLibraryDirectories := '';;
      if not VarIsNull(StaticLibraryDirectoriesNode) then
        AdditionalStaticLibraryDirectories := StaticLibraryDirectoriesNode.Text;
      UpdateString(AdditionalIncludeDirectories, ExpandConstant('{app}\include;'), '%(AdditionalIncludeDirectories)');
      UpdateString(AdditionalDynamicLibraryDirectories, ExpandConstant('{app}\lib\' + libfolder + ';'), '%(AdditionalLibraryDirectories)');
      UpdateString(AdditionalStaticLibraryDirectories, ExpandConstant('{app}\lib\' + libfolder + ';'), '%(AdditionalLibraryDirectories)');
      IncludeDirectoriesNode.Text := AdditionalIncludeDirectories;
      DynamicLibraryDirectoriesNode.Text := AdditionalDynamicLibraryDirectories;
      StaticLibraryDirectoriesNode.Text := AdditionalStaticLibraryDirectories;
      XMLDocument.save(filename);
    end;
  except
    ShowExceptionMessage;
  end;
end;

procedure ModifyAllProps();
var
  Path: string;
begin
  Path := GetEnv('LOCALAPPDATA')+'\Microsoft\MSBuild\v4.0\';
  if DirExists(Path) then
  begin
    ModifyProps(Path + 'Microsoft.Cpp.Win32.user.props', 'Win32');
    ModifyProps(Path + 'Microsoft.Cpp.x64.user.props', 'Win64');
  end;
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
  if CurStep = ssInstall then
  begin
    if not UninstallOldVersions() then
      Abort();
    if IsTaskSelected('modifyVS2008Props') then
      ModifyVS2008Settings();
    if IsTaskSelected('modifyVS2010Props') then
      ModifyAllProps();
  end;
  CurStepChangedModPath(CurStep);
end;

procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin
  CurUninstallStepChangedModPath(CurUninstallStep);
end;

function NextButtonClick(CurPageID: Integer): Boolean;
begin
  Result := True;

  if CurPageID = wpReady then
    Msgbox('Please close Visual Studio before starting the installation.', mbInformation, MB_OK);
end;


Incerased installer version.

Incerased installer version.

[Setup]
AppName=SQFLint
AppPublisher=Kamen
AppPublisherURL=http://sqflint.zipek.cz
AppVersion=0.5.1
DefaultDirName={pf}\SQFLint
UninstallDisplayIcon={app}\sqflint.exe
OutputDir=dist\packages
OutputBaseFilename=sqflint-install
ChangesEnvironment=yes
SetupIconFile=dist-src\sqflint.ico

[CustomMessages]
AppAddPath=Add application directory to your environmental path

[Tasks]
Name: modifypath; Description:{cm:AppAddPath};

[Files]
Source: "dist\*"; DestDir: "{app}"; Flags: recursesubdirs

[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
    ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}"; \
    Check: NeedsAddPath('{app}'); Tasks: modifypath

[Code]

function NeedsAddPath(Param: string): boolean;
var
  OrigPath: string;
begin
  if not RegQueryStringValue(HKEY_LOCAL_MACHINE,
    'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
    'Path', OrigPath)
  then begin
    Result := True;
    exit;
  end;
  // look for the path with leading and trailing semicolon
  // Pos() returns 0 if not found
  Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0;
end;

[Setup]
AppName=SQFLint
AppPublisher=Kamen
AppPublisherURL=http://sqflint.zipek.cz
AppVersion=0.5
DefaultDirName={pf}\SQFLint
UninstallDisplayIcon={app}\sqflint.exe
OutputDir=dist\packages
OutputBaseFilename=sqflint-install
ChangesEnvironment=yes
SetupIconFile=dist-src\sqflint.ico

[CustomMessages]
AppAddPath=Add application directory to your environmental path

[Tasks]
Name: modifypath; Description:{cm:AppAddPath};

[Files]
Source: "dist\*"; DestDir: "{app}"; Flags: recursesubdirs

[Registry]
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; \
    ValueType: expandsz; ValueName: "Path"; ValueData: "{olddata};{app}"; \
    Check: NeedsAddPath('{app}'); Tasks: modifypath

[Code]

function NeedsAddPath(Param: string): boolean;
var
  OrigPath: string;
begin
  if not RegQueryStringValue(HKEY_LOCAL_MACHINE,
    'SYSTEM\CurrentControlSet\Control\Session Manager\Environment',
    'Path', OrigPath)
  then begin
    Result := True;
    exit;
  end;
  // look for the path with leading and trailing semicolon
  // Pos() returns 0 if not found
  Result := Pos(';' + Param + ';', ';' + OrigPath + ';') = 0;
end;