Win installer: Add functions that can detect installed version

No functional changes.
InitializeSetup() (currently commented out) can inform the user
about the version differences and uninstall the old version before
installing the new one.

Signed-off-by: Dan Nechita <2f664a27dbc3ee2034ed9e950b3808890cb5416a@analog.com>

#define AppName "Pixelpulse2"
#define AppVersion "0.90"
#define AppPublisher "Analog Devices, Inc."
#define AppURL "http://www.analog.com"
#define AppExeName "Pixelpulse2.exe"

[Setup]
AppId={{258C031E-98C7-4609-9122-65A4D36274AF}
AppName={#AppName}
AppVersion={#AppVersion}
AppPublisher={#AppPublisher}
AppPublisherURL={#AppURL}
AppSupportURL={#AppURL}
AppUpdatesURL={#AppURL}
DefaultDirName={pf}\Analog Devices\{#AppName}
DefaultGroupName=Analog Devices\{#AppName}
OutputDir="C:\"
OutputBaseFilename=Pixelpulse2_win_setup
UninstallDisplayIcon={app}\{#AppExeName}
Compression=lzma
SolidCompression=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "brazilianportuguese"; MessagesFile: "compiler:Languages\BrazilianPortuguese.isl"
Name: "catalan"; MessagesFile: "compiler:Languages\Catalan.isl"
Name: "corsican"; MessagesFile: "compiler:Languages\Corsican.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: "greek"; MessagesFile: "compiler:Languages\Greek.isl"
Name: "hebrew"; MessagesFile: "compiler:Languages\Hebrew.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: "scottishgaelic"; MessagesFile: "compiler:Languages\ScottishGaelic.isl"
Name: "serbiancyrillic"; MessagesFile: "compiler:Languages\SerbianCyrillic.isl"
Name: "serbianlatin"; MessagesFile: "compiler:Languages\SerbianLatin.isl"
Name: "slovenian"; MessagesFile: "compiler:Languages\Slovenian.isl"
Name: "spanish"; MessagesFile: "compiler:Languages\Spanish.isl"
Name: "turkish"; MessagesFile: "compiler:Languages\Turkish.isl"
Name: "ukrainian"; MessagesFile: "compiler:Languages\Ukrainian.isl"

[Tasks]
Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"
; Only allow driver installs for Windows 7 (version 6.2 maps to Windows 8).
Name: drivers; Description: Install WinUSB drivers for the M1K; OnlyBelowVersion: 6.2

[Files]
Source: "c:\projects\pixelpulse2\release\pixelpulse2.exe"; DestDir: "{app}"
Source: "c:\projects\pixelpulse2\distrib\*"; DestDir: "{app}"; Flags: recursesubdirs createallsubdirs
Source: "C:\WinDDK\7600.16385.1\redist\DIFx\dpinst\EngMui\x86\dpinst.exe"; DestDir: "{app}\drivers"; Tasks: drivers; Check: not IsWin64
Source: "C:\WinDDK\7600.16385.1\redist\DIFx\dpinst\EngMui\amd64\dpinst.exe"; DestDir: "{app}\drivers"; Tasks: drivers; Check: IsWin64

[Icons]
Name: "{group}\{#AppName}"; Filename: "{app}\{#AppExeName}"
Name: "{group}\{cm:UninstallProgram,{#AppName}}"; Filename: "{uninstallexe}"
Name: "{commondesktop}\{#AppName}"; Filename: "{app}\{#AppExeName}"; Tasks: desktopicon

[Run]
Filename: "{app}\{#AppExeName}"; Description: "{cm:LaunchProgram,{#StringChange(AppName, '&', '&&')}}"; Flags: nowait postinstall skipifsilent unchecked
Filename: {app}\pp2trayer.exe; Description: "Launch Pixelpulse2 Trayer"; Flags: nowait postinstall skipifsilent
Filename: "{app}\drivers\dpinst.exe"; Parameters: "/path ""{app}\drivers"""; Flags: waituntilterminated; Tasks: drivers

[UninstallRun]
Filename: "{cmd}"; Parameters: "/C""taskkill /im pp2trayer.exe /f /t"; Flags: runhidden

[Registry]
; Make Pixelpulse2 Trayer run every time Windows boots
Root: HKLM; Subkey: "SOFTWARE\Microsoft\Windows\CurrentVersion\Run"; ValueType: string; ValueName: "Pixelpulse2Trayer"; ValueData: """{app}\pp2trayer.exe"""; Flags: uninsdeletevalue

; Functions GetNumber(), CompareInner(), CompareVersion() and InitializeSetup() can be used to detect
; differences between the version being installed and the version that might be already installed.
[Code]
function GetNumber(var temp: String): Integer;
var
  part: String;
  pos1: Integer;
begin
  if Length(temp) = 0 then
  begin
    Result := -1;
    Exit;
  end;
    pos1 := Pos('.', temp);
    if (pos1 = 0) then
    begin
      Result := StrToInt(temp);
    temp := '';
    end
    else
    begin
    part := Copy(temp, 1, pos1 - 1);
      temp := Copy(temp, pos1 + 1, Length(temp));
      Result := StrToInt(part);
    end;
end;

function CompareInner(var temp1, temp2: String): Integer;
var
  num1, num2: Integer;
begin
    num1 := GetNumber(temp1);
  num2 := GetNumber(temp2);
  if (num1 = -1) or (num2 = -1) then
  begin
    Result := 0;
    Exit;
  end;
      if (num1 > num2) then
      begin
        Result := 1;
      end
      else if (num1 < num2) then
      begin
        Result := -1;
      end
      else
      begin
        Result := CompareInner(temp1, temp2);
      end;
end;

function CompareVersion(str1, str2: String): Integer;
var
  temp1, temp2: String;
begin
    temp1 := str1;
    temp2 := str2;
    Result := CompareInner(temp1, temp2);
end;

// function InitializeSetup(): Boolean;
// var
  // oldVersion: String;
  // uninstaller: String;
  // ErrorCode: Integer;
  // vCurID      :String;
  // vCurAppName :String;
// begin
  // vCurID:= '{#SetupSetting("AppName")}';
  // vCurAppName:= '{#SetupSetting("AppName")}';

  // if RegKeyExists(HKLM,
    // 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + vCurID + '_is1') then
  // begin
    // RegQueryStringValue(HKLM,
      // 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + vCurID + '_is1',
      // 'DisplayVersion', oldVersion);
    // if (not (CompareVersion(oldVersion, '{#SetupSetting("AppVersion")}') = 0)) then
    // begin
      // if MsgBox('An older version ' + oldVersion + ' of ' + vCurAppName + ' is already installed. Continue to use this version?',
        // mbConfirmation, MB_YESNO) = IDYES then
      // begin
        // Result := False;
      // end
      // else
      // begin
          // RegQueryStringValue(HKLM,
            // 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + vCurID + '_is1',
            // 'UninstallString', uninstaller);
          // ShellExec('runas', uninstaller, '/SILENT', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
          // Result := True;
      // end;
    // end
    // else
    // begin
      // if MsgBox('Version ' + oldVersion + ' of ' + vCurAppName + ' is already installed. Continue with the install?',
        // mbConfirmation, MB_YESNO) = IDNO then
      // begin
        // Result := False;
      // end
      // else
      // begin
          // RegQueryStringValue(HKLM,
            // 'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\' + vCurID + '_is1',
            // 'UninstallString', uninstaller);
          // ShellExec('runas', uninstaller, '/SILENT', '', SW_HIDE, ewWaitUntilTerminated, ErrorCode);
          // Result := True;
      // end;
    // end
  // end
  // else
  // begin
    // Result := True;
  // end;
// end;


update to match new SDL2.dll version

update to match new SDL2.dll version

update to match files

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

#define MyAppName "SyncTERM"
#define MyAppVerName "SyncTERM #{VERSION}#"
#define MyAppSetupName "SyncTERM-#{VERSION}#-Setup"
#define MyAppPublisher "SyncTERM.Net"
#define MyAppURL "http://syncterm.net/"
#define MyAppURLName "syncterm-website.url"
#define MyAppExeName "syncterm.exe"

[Setup]
AppName={#MyAppName}
AppVerName={#MyAppVerName}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={localappdata}\Programs\{#MyAppName}
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
OutputDir=..\output
OutputBaseFilename={#MyAppSetupName}
Compression=lzma
SolidCompression=yes
PrivilegesRequired=lowest

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

[Tasks]
Name: desktopicon; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm:AdditionalIcons}; Flags: unchecked
Name: telnethandler; Description: Make Default Telnet Handler (recommended); Languages: ; GroupDescription: Protocol Handlers:
Name: rloginhandler; Description: Make Default RLogin Handler (recommended); GroupDescription: Protocol Handlers:
Name: sshhandler; Description: Make Default SSH Handler; GroupDescription: Protocol Handlers:

[Files]
Source: syncterm\syncterm.exe; DestDir: {app}; Flags: ignoreversion
Source: syncterm\SDL2.dll; DestDir: {app}; Flags: ignoreversion
Source: syncterm\fonts\*; DestDir: {app}\fonts\; Flags: ignoreversion recursesubdirs createallsubdirs
Source: synchronet\syncterm.lst; DestDir: {userappdata}\SyncTERM\; Flags: confirmoverwrite comparetimestamp uninsneveruninstall

[INI]
Filename: {app}\{#MyAppUrlName}; Section: InternetShortcut; Key: URL; String: {#MyAppURL}; Tasks: ; Languages:

[Icons]
Name: {group}\{#MyAppName}; Filename: {app}\{#MyAppExeName}
Name: {userdesktop}\{#MyAppName}; Filename: {app}\{#MyAppExeName}; Tasks: desktopicon

;Website Shortcuts
Name: {group}\{cm:ProgramOnTheWeb,{#MyAppName}}; Filename: {app}\{#MyAppUrlName}; IconFilename: {app}\syncterm.exe; IconIndex: 0

[UninstallDelete]
Type: files; Name: {app}\{#MyAppUrlName}

[Code]
//set telnet handler to syncterm
procedure TelnetSet();
var
	OriginalTelnetHandler: String;
begin

	//check for telnet
	if WizardIsTaskSelected('telnethandler') then
	begin

		if not RegValueExists(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'telnet') then
		begin
			//save original telnet handler
			if RegQueryStringValue(HKEY_CLASSES_ROOT, 'telnet\shell\open\command', '', OriginalTelnetHandler) then
			begin
				RegWriteStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'telnet', OriginalTelnetHandler);
			end
			else
			begin
				//set to win32 default
				RegWriteStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'telnet', 'rundll32.exe url.dll,TelnetProtocolHandler %l');
			end;
		end;

		//set telnet handler
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'telnet', 'URL:Custom Protocol', '');
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'telnet', 'URL Protocol', '');
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'telnet\DefaultIcon', 'URL Protocol', ExpandConstant('{app}\syncterm.exe,0'));
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'telnet\shell\open\command', '', ExpandConstant('"{app}\syncterm.exe" %1'));
	end;

end;

//restore telnet handler
procedure TelnetRestore();
var
	OriginalTelnetHandler: String;
begin

	//check for telnet
	if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'telnet', OriginalTelnetHandler) then
	begin
		//restore telnet handler
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'telnet\shell\open\command', '', OriginalTelnetHandler);
	end

end;

//set rlogin handler to syncterm
procedure RloginSet();
var
	OriginalRloginHandler: String;
begin

	//check for rlogin
	if WizardIsTaskSelected('rloginhandler') then
	begin

		if not RegValueExists(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'rlogin') then
		begin
			//save original rlogin handler
			if RegQueryStringValue(HKEY_CLASSES_ROOT, 'rlogin\shell\open\command', '', OriginalRloginHandler) then
			begin
				//set to current value
				RegWriteStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'rlogin', OriginalRloginHandler);
			end
			else
			begin
				//set to win32 default
				RegWriteStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'rlogin', 'rundll32.exe url.dll,TelnetProtocolHandler %l');
			end;
		end;

		//set rlogin handler
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'rlogin', 'URL:Custom Protocol', '');
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'rlogin', 'URL Protocol', '');
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'rlogin\DefaultIcon', 'URL Protocol', ExpandConstant('{app}\syncterm.exe,0'));
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'rlogin\shell\open\command', '', ExpandConstant('"{app}\syncterm.exe" %1'));
	end;

end;

//restore rlogin handler
procedure RloginRestore();
var
	OriginalRloginHandler: String;
begin

	if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'rlogin', OriginalRloginHandler) then
	begin
		//restore rlogin handler
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'rlogin\shell\open\command', '', OriginalRloginHandler);
	end;

end;

// ****** SSH *****************************************************
//set rlogin handler to syncterm
procedure SshSet();
var
	OriginalSshHandler: String;
begin

	//check for rlogin
	if WizardIsTaskSelected('sshhandler') then
	begin
		if not RegValueExists(HKEY_CLASSES_ROOT, 'ssh', '') then
		begin
			RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh', '', 'URL:SSH Protocol');
			RegWriteDWordValue(HKEY_CLASSES_ROOT, 'ssh', 'EditFlags', 2);
			RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh', 'FriendlyTypeName', 'ieframe.dll,-907');
			RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh', 'URL Protocol', '');
		end;

		if not RegValueExists(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'ssh') then
		begin
			//save original rlogin handler
			if RegQueryStringValue(HKEY_CLASSES_ROOT, 'rlogin\shell\open\command', '', OriginalSshHandler) then
			begin
				//set to current value
				RegWriteStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'ssh', OriginalSshHandler);
			end
			else
			begin
				//set to win32 default
				RegWriteStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'ssh', 'rundll32.exe url.dll,TelnetProtocolHandler %l');
			end
		end;

		//set ssh handler
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh', 'URL:Custom Protocol', '');
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh', 'URL Protocol', '');
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh\DefaultIcon', 'URL Protocol', ExpandConstant('{app}\syncterm.exe,0'));
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh\shell\open\command', '', ExpandConstant('"{app}\syncterm.exe" -h %1'));
	end

end;

//restore ssh handler
procedure SshRestore();
var
	OriginalSshHandler: String;
begin

	if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'ssh', OriginalSshHandler) then
	begin
		//restore rlogin handler
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh\shell\open\command', '', OriginalSshHandler);
	end

end;
// ****** SSH *****************************************************

//fix NT Colors
procedure FixColors();
begin

	if (UsingWinNT() = true) then
	begin
		if WizardIsTaskSelected('ntcolorfix') then
		begin
			//Ansi colors for current user
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ScreenColors', 7);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'PopupColors', 31);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable00', 0);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable01', 11010048);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable02', 43008);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable03', 11053056);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable04', 168);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable05', 11010216);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable06', 21672);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable07', 11053224);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable08', 5526612);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable09', 16536660);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable10', 5569620);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable11', 16579668);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable12', 5526780);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable13', 16536828);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable14', 5569788);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable15', 16579836);
		end

	end

end;
// ****** NT Colors *****************************************************

//run during install process
procedure CurStepChanged(CurStep: TSetupStep);
begin

	if (CurStep = ssPostInstall) then
	begin

		RegWriteDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_DISABLE_TELNET_PROTOCOL', 'iexplore.exe', 0);
		TelnetSet();
		RLoginSet();
		SshSet();

	end

end;

//run during uninstall process
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin

	if (CurUninstallStep = usPostUninstall) then
	begin

		//check for telnet
		TelnetRestore()

		//check for rlogin
		RloginRestore()

		//check for ssh
		SshRestore()

		//delete key for future
		RegDeleteKeyIncludingSubkeys(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm');

	end

end;

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

#define MyAppName "SyncTERM"
#define MyAppVerName "SyncTERM #{VERSION}#"
#define MyAppSetupName "SyncTERM-#{VERSION}#-Setup"
#define MyAppPublisher "SyncTERM.Net"
#define MyAppURL "http://syncterm.net/"
#define MyAppURLName "syncterm-website.url"
#define MyAppExeName "syncterm.exe"

[Setup]
AppName={#MyAppName}
AppVerName={#MyAppVerName}
AppPublisher={#MyAppPublisher}
AppPublisherURL={#MyAppURL}
AppSupportURL={#MyAppURL}
AppUpdatesURL={#MyAppURL}
DefaultDirName={localappdata}\Programs\{#MyAppName}
DefaultGroupName={#MyAppName}
AllowNoIcons=yes
OutputDir=..\output
OutputBaseFilename={#MyAppSetupName}
Compression=lzma
SolidCompression=yes
PrivilegesRequired=lowest

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

[Tasks]
Name: desktopicon; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm:AdditionalIcons}; Flags: unchecked
Name: telnethandler; Description: Make Default Telnet Handler (recommended); Languages: ; GroupDescription: Protocol Handlers:
Name: rloginhandler; Description: Make Default RLogin Handler (recommended); GroupDescription: Protocol Handlers:
Name: sshhandler; Description: Make Default SSH Handler; GroupDescription: Protocol Handlers:

[Files]
Source: syncterm\syncterm.exe; DestDir: {app}; Flags: ignoreversion
Source: syncterm\SDL.dll; DestDir: {app}; Flags: ignoreversion
Source: syncterm\fonts\*; DestDir: {app}\fonts\; Flags: ignoreversion recursesubdirs createallsubdirs
Source: synchronet\syncterm.lst; DestDir: {userappdata}\SyncTERM\; Flags: confirmoverwrite comparetimestamp uninsneveruninstall

[INI]
Filename: {app}\{#MyAppUrlName}; Section: InternetShortcut; Key: URL; String: {#MyAppURL}; Tasks: ; Languages:

[Icons]
Name: {group}\{#MyAppName}; Filename: {app}\{#MyAppExeName}
Name: {userdesktop}\{#MyAppName}; Filename: {app}\{#MyAppExeName}; Tasks: desktopicon

;Website Shortcuts
Name: {group}\{cm:ProgramOnTheWeb,{#MyAppName}}; Filename: {app}\{#MyAppUrlName}; IconFilename: {app}\syncterm.exe; IconIndex: 0

[UninstallDelete]
Type: files; Name: {app}\{#MyAppUrlName}

[Code]
//set telnet handler to syncterm
procedure TelnetSet();
var
	OriginalTelnetHandler: String;
begin

	//check for telnet
	if WizardIsTaskSelected('telnethandler') then
	begin

		if not RegValueExists(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'telnet') then
		begin
			//save original telnet handler
			if RegQueryStringValue(HKEY_CLASSES_ROOT, 'telnet\shell\open\command', '', OriginalTelnetHandler) then
			begin
				RegWriteStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'telnet', OriginalTelnetHandler);
			end
			else
			begin
				//set to win32 default
				RegWriteStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'telnet', 'rundll32.exe url.dll,TelnetProtocolHandler %l');
			end;
		end;

		//set telnet handler
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'telnet', 'URL:Custom Protocol', '');
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'telnet', 'URL Protocol', '');
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'telnet\DefaultIcon', 'URL Protocol', ExpandConstant('{app}\syncterm.exe,0'));
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'telnet\shell\open\command', '', ExpandConstant('"{app}\syncterm.exe" %1'));
	end;

end;

//restore telnet handler
procedure TelnetRestore();
var
	OriginalTelnetHandler: String;
begin

	//check for telnet
	if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'telnet', OriginalTelnetHandler) then
	begin
		//restore telnet handler
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'telnet\shell\open\command', '', OriginalTelnetHandler);
	end

end;

//set rlogin handler to syncterm
procedure RloginSet();
var
	OriginalRloginHandler: String;
begin

	//check for rlogin
	if WizardIsTaskSelected('rloginhandler') then
	begin

		if not RegValueExists(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'rlogin') then
		begin
			//save original rlogin handler
			if RegQueryStringValue(HKEY_CLASSES_ROOT, 'rlogin\shell\open\command', '', OriginalRloginHandler) then
			begin
				//set to current value
				RegWriteStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'rlogin', OriginalRloginHandler);
			end
			else
			begin
				//set to win32 default
				RegWriteStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'rlogin', 'rundll32.exe url.dll,TelnetProtocolHandler %l');
			end;
		end;

		//set rlogin handler
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'rlogin', 'URL:Custom Protocol', '');
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'rlogin', 'URL Protocol', '');
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'rlogin\DefaultIcon', 'URL Protocol', ExpandConstant('{app}\syncterm.exe,0'));
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'rlogin\shell\open\command', '', ExpandConstant('"{app}\syncterm.exe" %1'));
	end;

end;

//restore rlogin handler
procedure RloginRestore();
var
	OriginalRloginHandler: String;
begin

	if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'rlogin', OriginalRloginHandler) then
	begin
		//restore rlogin handler
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'rlogin\shell\open\command', '', OriginalRloginHandler);
	end;

end;

// ****** SSH *****************************************************
//set rlogin handler to syncterm
procedure SshSet();
var
	OriginalSshHandler: String;
begin

	//check for rlogin
	if WizardIsTaskSelected('sshhandler') then
	begin
		if not RegValueExists(HKEY_CLASSES_ROOT, 'ssh', '') then
		begin
			RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh', '', 'URL:SSH Protocol');
			RegWriteDWordValue(HKEY_CLASSES_ROOT, 'ssh', 'EditFlags', 2);
			RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh', 'FriendlyTypeName', 'ieframe.dll,-907');
			RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh', 'URL Protocol', '');
		end;

		if not RegValueExists(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'ssh') then
		begin
			//save original rlogin handler
			if RegQueryStringValue(HKEY_CLASSES_ROOT, 'rlogin\shell\open\command', '', OriginalSshHandler) then
			begin
				//set to current value
				RegWriteStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'ssh', OriginalSshHandler);
			end
			else
			begin
				//set to win32 default
				RegWriteStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'ssh', 'rundll32.exe url.dll,TelnetProtocolHandler %l');
			end
		end;

		//set ssh handler
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh', 'URL:Custom Protocol', '');
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh', 'URL Protocol', '');
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh\DefaultIcon', 'URL Protocol', ExpandConstant('{app}\syncterm.exe,0'));
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh\shell\open\command', '', ExpandConstant('"{app}\syncterm.exe" -h %1'));
	end

end;

//restore ssh handler
procedure SshRestore();
var
	OriginalSshHandler: String;
begin

	if RegQueryStringValue(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm\install', 'ssh', OriginalSshHandler) then
	begin
		//restore rlogin handler
		RegWriteStringValue(HKEY_CLASSES_ROOT, 'ssh\shell\open\command', '', OriginalSshHandler);
	end

end;
// ****** SSH *****************************************************

//fix NT Colors
procedure FixColors();
begin

	if (UsingWinNT() = true) then
	begin
		if WizardIsTaskSelected('ntcolorfix') then
		begin
			//Ansi colors for current user
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ScreenColors', 7);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'PopupColors', 31);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable00', 0);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable01', 11010048);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable02', 43008);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable03', 11053056);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable04', 168);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable05', 11010216);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable06', 21672);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable07', 11053224);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable08', 5526612);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable09', 16536660);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable10', 5569620);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable11', 16579668);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable12', 5526780);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable13', 16536828);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable14', 5569788);
			RegWriteDWordValue(HKEY_CURRENT_USER, 'Console', 'ColorTable15', 16579836);
		end

	end

end;
// ****** NT Colors *****************************************************

//run during install process
procedure CurStepChanged(CurStep: TSetupStep);
begin

	if (CurStep = ssPostInstall) then
	begin

		RegWriteDWordValue(HKEY_LOCAL_MACHINE, 'SOFTWARE\Microsoft\Internet Explorer\Main\FeatureControl\FEATURE_DISABLE_TELNET_PROTOCOL', 'iexplore.exe', 0);
		TelnetSet();
		RLoginSet();
		SshSet();

	end

end;

//run during uninstall process
procedure CurUninstallStepChanged(CurUninstallStep: TUninstallStep);
begin

	if (CurUninstallStep = usPostUninstall) then
	begin

		//check for telnet
		TelnetRestore()

		//check for rlogin
		RloginRestore()

		//check for ssh
		SshRestore()

		//delete key for future
		RegDeleteKeyIncludingSubkeys(HKEY_CURRENT_USER, 'SOFTWARE\bbsdev.net\syncterm');

	end

end;


Updated the install to remove SamplePlugin.amp.amp just in case, to prevent lib clashes/issues, (as it happned to me already).

#define APP_NAME "Myoddweb Action Monitor (Piger)";
#define APP_PUBLISHER "myoddweb.com";
#define APP_URL "http://www.myoddweb.com";
#define APP_DIR "{pf}\myoddweb\piger";
#define APP_INCLUDE "..\includes\";

; The source files.
#define APP_SOURCE86 "..\Output\Release\x86\";
#define APP_SOURCE64 "..\Output\Release\x64\";

; set the version number based on the classifier version number.
#define APP_VERSION GetFileVersion( APP_SOURCE86 + 'ActionMonitor.exe' );

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

[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={{E0B5F430-234F-47AE-912F-089E79259B3D}
AppVersion={#APP_VERSION}
VersionInfoVersion={#APP_VERSION}
AppName=Piger
AppVerName=Piger Alpha {#APP_VERSION}
AppPublisher={#APP_PUBLISHER}
AppPublisherURL={#APP_URL}
AppSupportURL={#APP_URL}
AppUpdatesURL={#APP_URL}
DefaultDirName={pf}\myoddweb\Piger
DefaultGroupName=Piger
OutputDir=/
OutputBaseFilename=piger-{#APP_VERSION}
Compression=lzma
SolidCompression=true

; "ArchitecturesInstallIn64BitMode=x64" requests that the install be
; done in "64-bit mode" on x64, meaning it should use the native
; 64-bit Program Files directory and the 64-bit view of the registry.
ArchitecturesInstallIn64BitMode=x64
ArchitecturesAllowed=x86 x64

; for now make sure that only admins can install this
; this is for the registry entry.
PrivilegesRequired=admin
AppMutex=MyOddweb_com_ActionMonitor

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

[Registry]
Root: HKLM; Subkey: SOFTWARE\Microsoft\Windows\CurrentVersion\Run; ValueType: string; ValueName: Piger; ValueData: """{app}\ActionMonitor.exe"""; Flags: uninsdeletevalue

[Tasks]
Name: pluginloader; Description: "Create a 'Learn/Unlearn' action to learn new simple actions."; GroupDescription: "Plugins";
Name: pluginapppaths; Description: "Parse all the common applications on your system and create actions on the fly."; GroupDescription: "Plugins";
Name: pluginontop; Description: "Create 'OnTop' command to keep any window as the topmost window, (like vlc/winamp etc...)."; GroupDescription: "Plugins";
Name: plugindolly; Description: "Hello Dolly sample plugin"; GroupDescription: "Plugins"; Flags: unchecked

[InstallDelete]
; remove old files that the user might no longer want
; we remove them to make sure that they don't cause some weird conflict
; and that they are not present if the user does not want them.
Type: files; Name: "{userappdata}\myoddweb\ActionMonitor\RootCommands\__in\LoaderPlugin.amp"
Type: files; Name: "{userappdata}\myoddweb\ActionMonitor\RootCommands\__in\AppPaths.amp"
Type: files; Name: "{userappdata}\myoddweb\ActionMonitor\RootCommands\__in\Dolly.amp"
Type: files; Name: "{userappdata}\myoddweb\ActionMonitor\RootCommands\__in\OnTop.amp"
Type: files; Name: "{userappdata}\myoddweb\ActionMonitor\RootCommands\__in\SamplePlugin.amp"

; remove old python file as things are now moved to {app}\python\ folder.
Type: files; Name: "{app}\python35.zip"
Type: files; Name: "{app}\python6435.dll"

[Files]
;
; All the plugins
; Remember to update the task list as well as the InstallDelete above!
;
; x86 plugins
Source: {#APP_SOURCE86}LoaderPlugin.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: not IsWin64 and IsTaskSelected('pluginloader')
Source: {#APP_SOURCE86}AppPaths.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: not IsWin64 and IsTaskSelected('pluginapppaths')
Source: {#APP_SOURCE86}Dolly.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: not IsWin64 and IsTaskSelected('plugindolly')
Source: {#APP_SOURCE86}OnTop.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: not IsWin64 and IsTaskSelected('pluginontop')

; x64 plugins
Source: {#APP_SOURCE64}LoaderPlugin64.amp; DestName:LoaderPlugin.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: IsWin64 and IsTaskSelected('pluginloader')
Source: {#APP_SOURCE64}AppPaths64.amp; DestName:AppPaths.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: IsWin64 and IsTaskSelected('pluginapppaths')
Source: {#APP_SOURCE64}Dolly64.amp; DestName:Dolly.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: IsWin64 and IsTaskSelected('plugindolly')
Source: {#APP_SOURCE64}OnTop64.amp; DestName:OnTop.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: IsWin64 and IsTaskSelected('pluginontop')

; any commands we might want to add.
Source: .\RootCommands\*; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\; Flags: recursesubdirs createallsubdirs
;
; All the plugins
;

Source: {#APP_INCLUDE}vc_redist.x86.exe; DestDir: {tmp}; Flags: deleteafterinstall; Check: "not IsWin64"
Source: {#APP_INCLUDE}vc_redist.x64.exe; DestDir: {tmp}; Flags: deleteafterinstall; Check: IsWin64
;
; be sure to build the latest exe.
; select "Release Any CPU" to ensure that both x64 and x86 are built.
;
; x86 App
Source: {#APP_SOURCE86}ActionMonitor.exe; DestDir: {app}; Flags: ignoreversion; Check: "not IsWin64"
Source: {#APP_SOURCE86}hook.dll; DestDir: {app}; Flags: ignoreversion; Check: "not IsWin64"
Source: {#APP_SOURCE86}python35.dll; DestDir: {app}; Flags: ignoreversion; Check: "not IsWin64"

; x64 App
Source: {#APP_SOURCE64}ActionMonitor64.exe; DestName:ActionMonitor.exe; DestDir: {app}; Flags: ignoreversion; Check: IsWin64
Source: {#APP_SOURCE64}hook64.dll; DestDir: {app}; Flags: ignoreversion; Check: IsWin64
Source: {#APP_SOURCE64}python35.dll; DestDir: {app}; Flags: ignoreversion; Check: IsWin64

; common
Source: {#APP_INCLUDE}python86\*.*; DestDir: {app}\python\; Flags: recursesubdirs createallsubdirs; Check: "not IsWin64"
Source: {#APP_INCLUDE}python64\*.*; DestDir: {app}\python\; Flags: recursesubdirs createallsubdirs; Check: IsWin64

; default config
Source: profile.xml; DestDir: {userappdata}\myoddweb\ActionMonitor\; Flags: onlyifdoesntexist

[Run]
Filename: {tmp}\vc_redist.x86.exe; Parameters: "/install /passive /quiet /norestart"; StatusMsg: Installing VC++ 2015 Redistributables...(Please wait a few minutes); Check: "not IsWin64"
Filename: {tmp}\vc_redist.x64.exe; Parameters: "/install /passive /quiet /norestart"; StatusMsg: Installing VC++ 2015 Redistributables...(Please wait a few minutes); Check: IsWin64

Filename: {app}\ActionMonitor.exe; Description: {cm:LaunchProgram,Piger}; Flags: nowait postinstall skipifsilent

[Icons]
Name: {group}\Piger; Filename: {app}\ActionMonitor.exe
Name: {group}\{cm:ProgramOnTheWeb,Piger}; Filename: {#APP_URL}
Name: {group}\{cm:UninstallProgram,Piger}; Filename: {uninstallexe}
Name: {group}\{cm:UninstallProgram, Piger}; Filename: {uninstallexe}

#define APP_NAME "Myoddweb Action Monitor (Piger)";
#define APP_PUBLISHER "myoddweb.com";
#define APP_URL "http://www.myoddweb.com";
#define APP_DIR "{pf}\myoddweb\piger";
#define APP_INCLUDE "..\includes\";

; The source files.
#define APP_SOURCE86 "..\Output\Release\x86\";
#define APP_SOURCE64 "..\Output\Release\x64\";

; set the version number based on the classifier version number.
#define APP_VERSION GetFileVersion( APP_SOURCE86 + 'ActionMonitor.exe' );

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

[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={{E0B5F430-234F-47AE-912F-089E79259B3D}
AppVersion={#APP_VERSION}
VersionInfoVersion={#APP_VERSION}
AppName=Piger
AppVerName=Piger Alpha {#APP_VERSION}
AppPublisher={#APP_PUBLISHER}
AppPublisherURL={#APP_URL}
AppSupportURL={#APP_URL}
AppUpdatesURL={#APP_URL}
DefaultDirName={pf}\myoddweb\Piger
DefaultGroupName=Piger
OutputDir=/
OutputBaseFilename=piger-{#APP_VERSION}
Compression=lzma
SolidCompression=true

; "ArchitecturesInstallIn64BitMode=x64" requests that the install be
; done in "64-bit mode" on x64, meaning it should use the native
; 64-bit Program Files directory and the 64-bit view of the registry.
ArchitecturesInstallIn64BitMode=x64
ArchitecturesAllowed=x86 x64

; for now make sure that only admins can install this
; this is for the registry entry.
PrivilegesRequired=admin
AppMutex=MyOddweb_com_ActionMonitor

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

[Registry]
Root: HKLM; Subkey: SOFTWARE\Microsoft\Windows\CurrentVersion\Run; ValueType: string; ValueName: Piger; ValueData: """{app}\ActionMonitor.exe"""; Flags: uninsdeletevalue

[Tasks]
Name: pluginloader; Description: "Create a 'Learn/Unlearn' action to learn new simple actions."; GroupDescription: "Plugins";
Name: pluginapppaths; Description: "Parse all the common applications on your system and create actions on the fly."; GroupDescription: "Plugins";
Name: pluginontop; Description: "Create 'OnTop' command to keep any window as the topmost window, (like vlc/winamp etc...)."; GroupDescription: "Plugins";
Name: plugindolly; Description: "Hello Dolly sample plugin"; GroupDescription: "Plugins"; Flags: unchecked

[InstallDelete]
; remove old files that the user might no longer want
; we remove them to make sure that they don't cause some weird conflict
; and that they are not present if the user does not want them.
Type: files; Name: "{userappdata}\myoddweb\ActionMonitor\RootCommands\__in\LoaderPlugin.amp"
Type: files; Name: "{userappdata}\myoddweb\ActionMonitor\RootCommands\__in\AppPaths.amp"
Type: files; Name: "{userappdata}\myoddweb\ActionMonitor\RootCommands\__in\Dolly.amp"
Type: files; Name: "{userappdata}\myoddweb\ActionMonitor\RootCommands\__in\OnTop.amp"

; remove old python file as things are now moved to {app}\python\ folder.
Type: files; Name: "{app}\python35.zip"
Type: files; Name: "{app}\python6435.dll"

[Files]
;
; All the plugins
; Remember to update the task list as well as the InstallDelete above!
;
; x86 plugins
Source: {#APP_SOURCE86}LoaderPlugin.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: not IsWin64 and IsTaskSelected('pluginloader')
Source: {#APP_SOURCE86}AppPaths.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: not IsWin64 and IsTaskSelected('pluginapppaths')
Source: {#APP_SOURCE86}Dolly.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: not IsWin64 and IsTaskSelected('plugindolly')
Source: {#APP_SOURCE86}OnTop.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: not IsWin64 and IsTaskSelected('pluginontop')

; x64 plugins
Source: {#APP_SOURCE64}LoaderPlugin64.amp; DestName:LoaderPlugin.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: IsWin64 and IsTaskSelected('pluginloader')
Source: {#APP_SOURCE64}AppPaths64.amp; DestName:AppPaths.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: IsWin64 and IsTaskSelected('pluginapppaths')
Source: {#APP_SOURCE64}Dolly64.amp; DestName:Dolly.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: IsWin64 and IsTaskSelected('plugindolly')
Source: {#APP_SOURCE64}OnTop64.amp; DestName:OnTop.amp; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\__in\; Flags: ignoreversion; Check: IsWin64 and IsTaskSelected('pluginontop')

; any commands we might want to add.
Source: .\RootCommands\*; DestDir: {userappdata}\myoddweb\ActionMonitor\RootCommands\; Flags: recursesubdirs createallsubdirs
;
; All the plugins
;

Source: {#APP_INCLUDE}vc_redist.x86.exe; DestDir: {tmp}; Flags: deleteafterinstall; Check: "not IsWin64"
Source: {#APP_INCLUDE}vc_redist.x64.exe; DestDir: {tmp}; Flags: deleteafterinstall; Check: IsWin64
;
; be sure to build the latest exe.
; select "Release Any CPU" to ensure that both x64 and x86 are built.
;
; x86 App
Source: {#APP_SOURCE86}ActionMonitor.exe; DestDir: {app}; Flags: ignoreversion; Check: "not IsWin64"
Source: {#APP_SOURCE86}hook.dll; DestDir: {app}; Flags: ignoreversion; Check: "not IsWin64"
Source: {#APP_SOURCE86}python35.dll; DestDir: {app}; Flags: ignoreversion; Check: "not IsWin64"

; x64 App
Source: {#APP_SOURCE64}ActionMonitor64.exe; DestName:ActionMonitor.exe; DestDir: {app}; Flags: ignoreversion; Check: IsWin64
Source: {#APP_SOURCE64}hook64.dll; DestDir: {app}; Flags: ignoreversion; Check: IsWin64
Source: {#APP_SOURCE64}python35.dll; DestDir: {app}; Flags: ignoreversion; Check: IsWin64

; common
Source: {#APP_INCLUDE}python86\*.*; DestDir: {app}\python\; Flags: recursesubdirs createallsubdirs; Check: "not IsWin64"
Source: {#APP_INCLUDE}python64\*.*; DestDir: {app}\python\; Flags: recursesubdirs createallsubdirs; Check: IsWin64

; default config
Source: profile.xml; DestDir: {userappdata}\myoddweb\ActionMonitor\; Flags: onlyifdoesntexist

[Run]
Filename: {tmp}\vc_redist.x86.exe; Parameters: "/install /passive /quiet /norestart"; StatusMsg: Installing VC++ 2015 Redistributables...(Please wait a few minutes); Check: "not IsWin64"
Filename: {tmp}\vc_redist.x64.exe; Parameters: "/install /passive /quiet /norestart"; StatusMsg: Installing VC++ 2015 Redistributables...(Please wait a few minutes); Check: IsWin64

Filename: {app}\ActionMonitor.exe; Description: {cm:LaunchProgram,Piger}; Flags: nowait postinstall skipifsilent

[Icons]
Name: {group}\Piger; Filename: {app}\ActionMonitor.exe
Name: {group}\{cm:ProgramOnTheWeb,Piger}; Filename: {#APP_URL}
Name: {group}\{cm:UninstallProgram,Piger}; Filename: {uninstallexe}
Name: {group}\{cm:UninstallProgram, Piger}; Filename: {uninstallexe}


Its still SubKey

Its still SubKey

;
;          _\|/_
;          (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.2"
#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={{797B9070-BD1B-4DD9-8434-3A02697F9984}

; 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}
UninstallDisplayIcon={app}\unknown-horizons\content\gfx\uh.ico
UninstallDisplayName={#APP_NAME}

; 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.2-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

; Logging
SetupLogging=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "german";  MessagesFile: "compiler:Languages\German.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 and engine)"
Name: "custom";        Description: "Custom installation"; Flags: iscustom

; Define components to install
[Components]
Name: "unknown_horizons"; Description: "[unknown-horizons] Unknown-Horizons";              Types: full
Name: vcredist2015;       Description: "[dep libs] VCRedist2015";                          Types: full

[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: unknown_horizons
Source: "..\repackage\vc_redist.x86.exe";       DestDir: "{tmp}";                       Flags: deleteafterinstall;           Components: unknown_horizons

[Tasks]
Name: add_startmenu;       Description: Create Startmenu entries;                         Components: unknown_horizons
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}\Start Unknown-Horizons Debug; Filename: {app}\unknown-horizons\run_uh.bat; Parameters: "--debug"; IconFilename: "{app}\unknown-horizons\content\gfx\uh.ico"; Tasks: add_startmenu
Name: {group}\Uninstall Unknown-Horizons; Filename: "{uninstallexe}"; 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]
; add the Parameters, WorkingDir and StatusMsg as you wish, just keep here
; the conditional installation Check
Filename: "{tmp}\vc_redist.x86.exe"; Parameters: "/q /norestart"; Check: VCRedistNeedsInstall; StatusMsg: "Installing VC++ redistributables..."

[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 fife (because libpng16-16.dll and other dependencies needs to be found)
Root: HKLM; Subkey: "SYSTEM\CurrentControlSet\Control\Session Manager\Environment"; ValueType:string; ValueName:"PATH"; ValueData:"{olddata};{app}\python\Lib\site-packages\fife"; Flags: preservestringtype; Check: NeedsAddPathLocalMachine(ExpandConstant('{app}\python\Lib\site-packages\fife')); Components: unknown_horizons

[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
    SaveOldPathLocalMachine();
  end;
  // 2. remove paths from the env var PATH
  if (CurUninstallStep = usPostUninstall) then
  begin
    RemovePathLocalMachine(ExpandConstant('{app}') + '\python\Lib\site-packages\fife');
    // 3. refresh environment, so that the modified PATH var is activated
    RefreshEnvironment();
  end;
end;

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

  // Visual C++ 2015 Redistributable 14.0.24215.1
  VC_2015_REDIST_X86 = '{e2803110-78b3-4664-a479-3611a381656a}';
//  VC_2015_REDIST_X64 = '{d992c12e-cab2-426f-bde3-fb8c53950b0d}';

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

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

function VCRedistNeedsInstall: Boolean;
begin
  Result := not (VCVersionInstalled(VC_2015_REDIST_X86));
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.2"
#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={{797B9070-BD1B-4DD9-8434-3A02697F9984}

; 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}
UninstallDisplayIcon={app}\unknown-horizons\content\gfx\uh.ico
UninstallDisplayName={#APP_NAME}

; 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.2-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

; Logging
SetupLogging=yes

[Languages]
Name: "english"; MessagesFile: "compiler:Default.isl"
Name: "german";  MessagesFile: "compiler:Languages\German.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 and engine)"
Name: "custom";        Description: "Custom installation"; Flags: iscustom

; Define components to install
[Components]
Name: "unknown_horizons"; Description: "[unknown-horizons] Unknown-Horizons";              Types: full
Name: vcredist2015;       Description: "[dep libs] VCRedist2015";                          Types: full

[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: unknown_horizons
Source: "..\repackage\vc_redist.x86.exe";       DestDir: "{tmp}";                       Flags: deleteafterinstall;           Components: unknown_horizons

[Tasks]
Name: add_startmenu;       Description: Create Startmenu entries;                         Components: unknown_horizons
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}\Start Unknown-Horizons Debug; Filename: {app}\unknown-horizons\run_uh.bat; Parameters: "--debug"; IconFilename: "{app}\unknown-horizons\content\gfx\uh.ico"; Tasks: add_startmenu
Name: {group}\Uninstall Unknown-Horizons; Filename: "{uninstallexe}"; 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]
; add the Parameters, WorkingDir and StatusMsg as you wish, just keep here
; the conditional installation Check
Filename: "{tmp}\vc_redist.x86.exe"; Parameters: "/q /norestart"; Check: VCRedistNeedsInstall; StatusMsg: "Installing VC++ redistributables..."

[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 fife (because libpng16-16.dll and other dependencies needs to be found)
Root: HKLM; EnvironmentKey = 'SYSTEM\CurrentControlSet\Control\Session Manager\Environment'; ValueType:string; ValueName:"PATH"; ValueData:"{olddata};{app}\python\Lib\site-packages\fife"; Flags: preservestringtype; Check: NeedsAddPathLocalMachine(ExpandConstant('{app}\python\Lib\site-packages\fife')); Components: unknown_horizons

[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
    SaveOldPathLocalMachine();
  end;
  // 2. remove paths from the env var PATH
  if (CurUninstallStep = usPostUninstall) then
  begin
    RemovePathLocalMachine(ExpandConstant('{app}') + '\python\Lib\site-packages\fife');
    // 3. refresh environment, so that the modified PATH var is activated
    RefreshEnvironment();
  end;
end;

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

  // Visual C++ 2015 Redistributable 14.0.24215.1
  VC_2015_REDIST_X86 = '{e2803110-78b3-4664-a479-3611a381656a}';
//  VC_2015_REDIST_X64 = '{d992c12e-cab2-426f-bde3-fb8c53950b0d}';

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

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

function VCRedistNeedsInstall: Boolean;
begin
  Result := not (VCVersionInstalled(VC_2015_REDIST_X86));
end;