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

[Setup]
#ifdef WIN64
ArchitecturesInstallIn64BitMode=x64compatible
ArchitecturesAllowed=x64compatible
#endif
AppName=@CMAKE_PROJECT_NAME@
AppVerName=@CMAKE_PROJECT_NAME@ v@VERSION@ (@BUILD@)
AppVersion=@VERSION@
AppPublisher=@PKGVENDOR@
AppPublisherURL=@PKGURL@
AppSupportURL=@PKGURL@
AppUpdatesURL=@PKGURL@
DefaultDirName={pf}\@CMAKE_PROJECT_NAME@
DefaultGroupName=@CMAKE_PROJECT_NAME@
AllowNoIcons=yes
InfoBeforeFile=@CMAKE_SOURCE_DIR@\release\InstInfo.rtf
Compression=zip/9
WindowVisible=no
DisableStartupPrompt=yes
BackColor=clBlack
BackColor2=clBlue
DirExistsWarning=no
VersionInfoCompany=@PKGVENDOR@
VersionInfoDescription=A highly-optimized version of VNC that can be used with performance-critical applications
VersionInfoVersion=@VERSION@

ChangesAssociations=yes

[Components]
Name: "viewer"; Description: "@CMAKE_PROJECT_NAME@ Viewer"; Types: full compact custom;
Name: "doc";    Description: "Documentation";   Types: full custom;

[Files]
Source: "@CMAKE_BINARY_DIR@\java\VncViewer.jar"; DestDir: "{app}\java"; Flags: ignoreversion; Components: viewer
Source: "@CMAKE_BINARY_DIR@\vncviewerw.bat"; DestDir: "{app}"; Flags: ignoreversion; Components: viewer
Source: "@CMAKE_BINARY_DIR@\vncviewer.bat"; DestDir: "{app}"; Flags: ignoreversion; Components: viewer
Source: "@CMAKE_SOURCE_DIR@\win\vncviewer\vncviewer.ico"; DestDir: "{app}"; Flags: ignoreversion; Components: viewer
Source: "@CMAKE_SOURCE_DIR@\java\com\turbovnc\vncviewer\README.md"; DestDir: "{app}\java"; Flags: ignoreversion; Components: viewer
Source: "@CMAKE_BINARY_DIR@\java\{#BUILDDIR}turbovnchelper.dll"; DestDir: "{app}\java"; Flags: ignoreversion; Components: viewer
#ifdef INCLUDEJRE
Source: "@CMAKE_BINARY_DIR@\java\jre\*"; DestDir: "{app}\java\jre"; Flags: ignoreVersion recursesubdirs; Components: viewer
#endif
Source: "@CMAKE_SOURCE_DIR@\LICENSE.txt"; DestDir: "{app}"; Flags: ignoreversion
Source: "@CMAKE_SOURCE_DIR@\ChangeLog.md"; DestDir: "{app}"; Flags: ignoreversion
Source: "@CMAKE_SOURCE_DIR@\README.md"; DestDir: "{app}"; Flags: ignoreversion
Source: "@CMAKE_SOURCE_DIR@\win\@CMAKE_PROJECT_NAME@.url"; DestDir: "{app}"; Flags: ignoreversion
Source: "@CMAKE_SOURCE_DIR@\doc\*.png"; DestDir: "{app}\doc"; Flags: ignoreversion; Components: doc
Source: "@CMAKE_SOURCE_DIR@\doc\*.html"; DestDir: "{app}\doc"; Flags: ignoreversion; Components: doc
Source: "@CMAKE_SOURCE_DIR@\doc\LIC*.TXT"; DestDir: "{app}\doc"; Flags: ignoreversion; Components: doc
Source: "@CMAKE_SOURCE_DIR@\doc\LIC*.txt"; DestDir: "{app}\doc"; Flags: ignoreversion; Components: doc
Source: "@CMAKE_SOURCE_DIR@\doc\*.css"; DestDir: "{app}\doc"; Flags: ignoreversion; Components: doc
Source: "@CMAKE_SOURCE_DIR@\doc\viewer_*.txt"; DestDir: "{app}\doc"; Flags: ignoreversion; Components: doc

[Icons]
Name: "{group}\@CMAKE_PROJECT_NAME@ Viewer";                      FileName: "{app}\vncviewerw.bat";                                WorkingDir: "{app}";      Flags: "runminimized";  IconFileName: "{app}\vncviewer.ico"
Name: "{group}\@CMAKE_PROJECT_NAME@ Viewer (Listen Mode)";        FileName: "{app}\vncviewerw.bat";  Parameters: "-listen";        WorkingDir: "{app}";      Flags: "runminimized";  IconFileName: "{app}\vncviewer.ico"
Name: "{group}\Uninstall @CMAKE_PROJECT_NAME@";                   FileName: "{uninstallexe}";                                      WorkingDir: "{app}";
Name: "{group}\Documentation\@CMAKE_PROJECT_NAME@ README";        FileName: "write.exe";           Parameters: "README.md";       WorkingDir: "{app}";      Flags: "useapppaths"
Name: "{group}\Documentation\@CMAKE_PROJECT_NAME@ User's Guide";  FileName: "{app}\doc\index.html";                                WorkingDir: "{app}\doc";  Components: doc;
Name: "{group}\Documentation\Licensing Terms";                    FileName: "write.exe";           Parameters: "LICENSE.txt";      WorkingDir: "{app}\doc";  Flags: "useapppaths"
Name: "{group}\Documentation\@CMAKE_PROJECT_NAME@ Web Site";      FileName: "{app}\@CMAKE_PROJECT_NAME@.url"
Name: "{group}\Documentation\@CMAKE_PROJECT_NAME@ Change Log";    FileName: "write.exe";           Parameters: "ChangeLog.md";     WorkingDir: "{app}";      Flags: "useapppaths"

[Tasks]
Name: associateturbovnc; Description: "&Associate .turbovnc files with @CMAKE_PROJECT_NAME@ Viewer"; GroupDescription: "File associations:"; Components: viewer
Name: associatevnc; Description: "&Associate .vnc files with @CMAKE_PROJECT_NAME@ Viewer"; GroupDescription: "File associations:"; Components: viewer

[Registry]
Root: HKCR; Subkey: ".turbovnc"; ValueType: string; ValueName: ""; ValueData: "TurboVNCViewer.Config"; Flags: uninsdeletevalue; Tasks: associateturbovnc
Root: HKCR; Subkey: "TurboVNCViewer.Config"; ValueType: string; ValueName: ""; ValueData: "TurboVNC Viewer Config File"; Flags: uninsdeletekey; Tasks: associateturbovnc
Root: HKCR; Subkey: "TurboVNCViewer.Config\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\vncviewerw.bat,0"; Tasks: associateturbovnc
Root: HKCR; Subkey: "TurboVNCViewer.Config\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\vncviewerw.bat"" -config ""%1"""; Tasks: associateturbovnc
Root: HKCR; Subkey: ".vnc"; ValueType: string; ValueName: ""; ValueData: "VncViewer.Config"; Flags: uninsdeletevalue; Tasks: associatevnc
Root: HKCR; Subkey: "VncViewer.Config"; ValueType: string; ValueName: ""; ValueData: "VNCviewer Config File"; Flags: uninsdeletekey; Tasks: associatevnc
Root: HKCR; Subkey: "VncViewer.Config\DefaultIcon"; ValueType: string; ValueName: ""; ValueData: "{app}\vncviewerw.bat,0"; Tasks: associatevnc
Root: HKCR; Subkey: "VncViewer.Config\shell\open\command"; ValueType: string; ValueName: ""; ValueData: """{app}\vncviewerw.bat"" -config ""%1"""; Tasks: associatevnc

[Code]
procedure UninstallPreviousVersion(UninstallerKey: String);
var
	resultCode: Integer;
	uninstallerPath: String;
begin
	if not RegQueryStringValue(HKLM, UninstallerKey, 'UninstallString',
		uninstallerPath) then
		RegQueryStringValue(HKCU, UninstallerKey, 'UninstallString',
			uninstallerPath);
	if uninstallerPath <> '' then
		Exec(RemoveQuotes(uninstallerPath),
			'/SILENT /NORESTART /SUPPRESSMSGBOXES', '', SW_HIDE,
			ewWaitUntilTerminated, resultCode);
end;

procedure CurStepChanged(CurStep: TSetupStep);
begin
	if (CurStep = ssInstall) then
	begin
		// 64-bit TurboVNC 3.1.x and prior running on Windows/x64
		UninstallPreviousVersion(
			'SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\TurboVNC 64-bit_is1');
		// 64-bit TurboVNC 3.1.x and prior running on Windows/Arm
		UninstallPreviousVersion(
			'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\TurboVNC 64-bit_is1');
		// 32-bit TurboVNC 3.1.x and prior, or
		// 64-bit TurboVNC 3.2 beta1 or 3.2 running on Windows/Arm
		UninstallPreviousVersion(
			'SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\TurboVNC_is1');
	end;
end;
