pw3270.nsi.in 12.1 KB
# SPDX-License-Identifier: LGPL-3.0-or-later
#
#  Copyright (C) 2021 Perry Werneck <perry.werneck@gmail.com>
#
#  This program is free software: you can redistribute it and/or modify
#  it under the terms of the GNU Lesser General Public License as published
#  by the Free Software Foundation, either version 3 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU Lesser General Public License
#  along with this program.  If not, see <https://www.gnu.org/licenses/>.
#

!include "MUI2.nsh"
!include "x64.nsh"
!include "FileFunc.nsh"
!include "LogicLib.nsh"
!include "winmessages.nsh"

Name "@PRODUCT_NAME@"
Caption "@PRODUCT_NAME@ - @PACKAGE_DESCRIPTION@"
outfile "@PRODUCT_NAME@-@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@-@host_cpu@.exe"

XPStyle on

installDir "$@PROGRAMFILES@\@PRODUCT_NAME@"

#define the installer icon
!define MUI_ICON "bin\@PRODUCT_NAME@.ico"
!define MUI_UNICON "bin\@PRODUCT_NAME@.ico"
icon "bin\@PRODUCT_NAME@.ico"

# Get installation folder from registry if available
InstallDirRegKey HKLM "Software\@PRODUCT_NAME@" "InstallLocation"

RequestExecutionLevel admin

# Properties
VIProductVersion "@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@.@PACKAGE_MAJOR_RELEASE@.@PACKAGE_MINOR_RELEASE@"
VIFileVersion "@WIN32_VERSION@"

# Reference: https://nsis.sourceforge.io/Reference/VIAddVersionKey
VIAddVersionKey "ProductVersion" "@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@.@PACKAGE_MAJOR_RELEASE@.@PACKAGE_MINOR_RELEASE@"
VIAddVersionKey "FileVersion" "@WIN32_VERSION@"

VIAddVersionKey "ProductName" "@PRODUCT_NAME@"
VIAddVersionKey "FileDescription" "@PACKAGE_DESCRIPTION@"
VIAddVersionKey "LegalCopyright" "(C) 2017 Banco do Brasil S/A. All Rights Reserved"
# VIAddVersionKey "PrivateBuild" ""

# Interface

!define MUI_ABORTWARNING
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "share\@PRODUCT_NAME@\LICENSE"
!insertmacro MUI_PAGE_COMPONENTS
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES

!insertmacro MUI_UNPAGE_WELCOME
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_UNPAGE_FINISH

# Languages
!insertmacro MUI_LANGUAGE "English"

# Section scripts
!include Sections.nsh

# default section
SubSection "@PRODUCT_NAME@" SecMain

	Section "@PRODUCT_NAME@" SecCore

		SetRegView @WINARCH@
		${DisableX64FSRedirection}

		# Set SMPROGRAMS and DESKTOP path
		SetShellVarContext all

		# Binary files
		setOutPath "$INSTDIR"
		file /r "bin"
		
		setOutPath "$INSTDIR\share\@PRODUCT_NAME@"
		file /r "share\@PRODUCT_NAME@\*.png"
		file /r "share\@PRODUCT_NAME@\*.svg"
		file /r "share\@PRODUCT_NAME@\*.ui.xml"
		file /r "share\@PRODUCT_NAME@\*.conf"

		setOutPath "$INSTDIR\share\@PRODUCT_NAME@\remap"
		file /r "share\@PRODUCT_NAME@\remap\*"

		setOutPath "$INSTDIR\lib\gdk-pixbuf-2.0"
		file /r "lib\gdk-pixbuf-2.0\*"

		setOutPath "$INSTDIR\etc"
		file /r "etc\*"

		setOutPath "$INSTDIR\share\locale"
		file /r "share\locale\*"

		setOutPath "$INSTDIR\share\themes"
		file /r "share\themes\*"

		setOutPath "$INSTDIR\share\icons"
		file /r "share\icons\*"

		setOutPath "$INSTDIR\share\glib-2.0"
		file /r "share\glib-2.0\*"

		setOutPath "$INSTDIR\share\@PRODUCT_NAME@\icons"
		file /r "share\@PRODUCT_NAME@\icons\*"
		
		# define uninstaller name
		SetRegView 32

		writeUninstaller $INSTDIR\uninstall.exe

		WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@PRODUCT_NAME@" \
			         "DisplayName" "@PRODUCT_NAME@ - @PACKAGE_DESCRIPTION@"
		WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@PRODUCT_NAME@" \
			         "DisplayIcon" "$INSTDIR\@PRODUCT_NAME@.ico"
		WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@PRODUCT_NAME@" \
			         "DisplayVersion" "@PACKAGE_MAJOR_VERSION@.@PACKAGE_MINOR_VERSION@.@PACKAGE_MAJOR_RELEASE@.@PACKAGE_MINOR_RELEASE@"

		WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@PRODUCT_NAME@" \
			         "UninstallString" "$INSTDIR\uninstall.exe"
		WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@PRODUCT_NAME@" \
			         "InstallLocation" "$INSTDIR"
		WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@PRODUCT_NAME@" \
			         "NoModify" "1"
		WriteRegStr HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@PRODUCT_NAME@" \
			         "NoRepair" "1"

		# Default settings
		SetRegView @WINARCH@

		# Setup log file
		# https://docs.microsoft.com/en-us/windows/win32/eventlog/event-sources
		WriteRegStr HKLM "SYSTEM\CurrentControlSet\Services\EventLog\@PRODUCT_NAME@" \
				 "PackageVersion"	"@PACKAGE_VERSION@"

		# Required for IPC Library.
		WriteRegStr 	HKLM	"Software\@PRODUCT_NAME@"				"InstallLocation"	"$INSTDIR"

		# Customized options
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"autoconnect"			0x00000001
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"blankfill"             0x00000000
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"bold"                  0x00000000
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"keepselected"          0x00000001
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"marginedpaste"         0x00000001
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"rectselect"            0x00000000

		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"monocase"              0x00000000
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"cursorblink"           0x00000001
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"showtiming"            0x00000001
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"cursorpos"             0x00000001
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"linewrap"              0x00000000
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"crosshair"             0x00000000
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"fullscreen"            0x00000000
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"autoreconnect"         0x00000001
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"insert"                0x00000000
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"smartpaste"            0x00000001
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"beep"                  0x00000001
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"fieldattr"             0x00000000
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"altscreen"             0x00000001
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"keepalive"             0x00000000

		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"dstrace"               0x00000000
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"screentrace"           0x00000000
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"eventtrace"            0x00000000
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"nettrace"              0x00000000
		WriteRegDWORD	HKLM	"Software\@PRODUCT_NAME@\toggles"		"ssltrace"              0x00000000

		WriteRegStr 	HKLM	"Software\@PRODUCT_NAME@"				"font-family"			"Lucida Console"
		WriteRegStr		HKLM	"Software\@PRODUCT_NAME@"				"colors"				"rgb(24,24,24);rgb(79,156,254);rgb(237,74,70);rgb(235,110,183);rgb(131,199,70);rgb(86,216,201);rgb(239,197,65);rgb(222,222,222);rgb(59,59,59);rgb(54,142,171);rgb(250,145,83);rgb(165,128,226);rgb(112,180,51);rgb(65,199,185);rgb(219,179,45);rgb(119,119,119);rgb(131,199,70);rgb(237,74,70);rgb(65,199,185);rgb(250,145,83);rgb(37,37,37);rgb(222,222,222);rgb(222,222,222);rgb(24,24,24);rgb(222,222,222);rgb(79,156,254);rgb(131,199,70);rgb(239,197,65);rgb(239,197,65)"

		createShortCut "$SMPROGRAMS\@PRODUCT_NAME@.lnk" "$INSTDIR\bin\@PRODUCT_NAME@.exe" "" "$INSTDIR\bin\@PRODUCT_NAME@.ico"
		createShortCut "$DESKTOP\@PRODUCT_NAME@.lnk" "$INSTDIR\bin\@PRODUCT_NAME@.exe" "" "$INSTDIR\bin\@PRODUCT_NAME@.ico"

	sectionEnd

!ifdef WITHSDK
    Section /o "Software Development Kit" SDK

		setOutPath $INSTDIR\sdk\include
		file /r "include\*.*"

		setOutPath $INSTDIR\sdk\lib
		file /r "lib\*.a"

		setOutPath $INSTDIR\sdk\lib\pkgconfig
		file /r "lib\pkgconfig\*.pc"

		setOutPath $INSTDIR\sdk\msvc
		file /r "share\@PRODUCT_NAME@\def\*.def"
		file /r "share\@PRODUCT_NAME@\def\*.mak"

		SetRegView @WINARCH@
		WriteRegExpandStr HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "PW3270_SDK_PATH" "$INSTDIR\sdk"
		SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000

    SectionEnd
!endif

!ifdef WITHCERTS
	Section "SSL Certificates" SSLCerts
		setOutPath $INSTDIR\certs
		file /r "sslcerts\*.*"
	sectionEnd
!endif

	SubSection "Plugins" SecPLugin

		Section "Remote control" IPCPlugin

			${DisableX64FSRedirection}

			CreateDirectory "$INSTDIR\lib\@PRODUCT_NAME@-plugins"
            file "/oname=$INSTDIR\lib\@PRODUCT_NAME@-plugins\ipcserver.dll" "lib\@PRODUCT_NAME@-plugins\ipcserver.dll"
	
		sectionEnd

	SubSectionEnd

SubSectionEnd

Section "Uninstall"

	# Always delete uninstaller first
	delete $INSTDIR\uninstaller.exe

	# Remove association

	# Set SMPROGRAMS and DESKTOP path
	SetShellVarContext all

	# now delete installed files
	delete $INSTDIR\@PRODUCT_NAME@.exe
	delete $SMPROGRAMS\@PRODUCT_NAME@.lnk
	delete $DESKTOP\@PRODUCT_NAME@.lnk

	RMDir /r "$INSTDIR"

	# Remove registry
	SetRegView 32
	DeleteRegKey HKLM "Software\Microsoft\Windows\CurrentVersion\Uninstall\@PRODUCT_NAME@"
	DeleteRegKey HKLM "Software\@PRODUCT_NAME@"
	
	SetRegView @WINARCH@
	DeleteRegKey HKLM "Software\@PRODUCT_NAME@"
	DeleteRegValue HKLM "SYSTEM\CurrentControlSet\Control\Session Manager\Environment" "PW3270_SDK_PATH"
	DeleteRegKey HKLM "SYSTEM\CurrentControlSet\Services\EventLog\@PRODUCT_NAME@"

	SendMessage ${HWND_BROADCAST} ${WM_WININICHANGE} 0 "STR:Environment" /TIMEOUT=5000

	DeleteRegKey HKLM "Software\GSettings\apps\@PACKAGE_NAME@\@PRODUCT_NAME@"

	# Delete System libraries
	${@NSISREDIR@}

	delete $SYSDIR\libipc3270.dll

!ifdef WITHLIBHLLAPI
	delete $SYSDIR\libhllapi.dll
	delete $SYSDIR\hllapi.dll
!endif

!ifdef WITHMONO-TN3270
	delete $SYSDIR\mono-tn3270.dll
!endif

	RMDir /r "$INSTDIR"

SectionEnd

Function .onInit

	#---[ Check if already installed ]--------------------------------------------------------------------

	${If} ${FileExists} "$INSTDIR\@PRODUCT_NAME@.exe"
		MessageBox MB_OK|MB_ICONEXCLAMATION "@PRODUCT_NAME@ is already installed. Please uninstall it first" /SD IDOK
		Abort
	${EndIf}

	#---[ Check SDK Command line option ]-----------------------------------------------------------------

!ifdef WITHSDK

	Push $0

	${GetParameters} $R0
	ClearErrors
	${GetOptions} $R0 /SDK= $0

	${if} $0 == "YES"

		SectionGetFlags ${SDK} $0
		IntOp $0 $0 | ${SF_SELECTED}
		SectionSetFlags ${SDK} $0

	${else}

		SectionGetFlags ${SDK} $0
		IntOp $0 $0 & ${SECTION_OFF}
		SectionSetFlags ${SDK} $0

	${EndIf}

	Pop $0
!endif

	#---[ Check DOTNET Command line option ]--------------------------------------------------------------

!ifdef WITHMONO-TN3270
	Push $0

	${GetParameters} $R0
	ClearErrors
	${GetOptions} $R0 /DOTNET= $0

	# Default = NO
	${if} $0 == "YES"

		SectionGetFlags ${DOTNET} $0
		IntOp $0 $0 | ${SF_SELECTED}
		SectionSetFlags ${DOTNET} $0

		SectionGetFlags ${IPCPlugin} $0
		IntOp $0 $0 | ${SF_SELECTED}
		SectionSetFlags ${IPCPlugin} $0

	${else}

		SectionGetFlags ${DOTNET} $0
		IntOp $0 $0 & ${SECTION_OFF}
		SectionSetFlags ${DOTNET} $0

	${EndIf}

	Pop $0
!endif

	#---[ Check HLLAPI Command line option ]-------------------------------------------------------------

!ifdef WITHLIBHLLAPI

	Push $0

	${GetParameters} $R0
	ClearErrors
	${GetOptions} $R0 /HLLAPI= $0

	# Default = YES
	${if} $0 == "NO"

		SectionGetFlags ${HLLAPIBinding} $0
		IntOp $0 $0 & ${SECTION_OFF}
		SectionSetFlags ${HLLAPIBinding} $0

	${else}

		SectionGetFlags ${HLLAPIBinding} $0
		IntOp $0 $0 | ${SF_SELECTED}
		SectionSetFlags ${HLLAPIBinding} $0

		SectionGetFlags ${IPCPlugin} $0
		IntOp $0 $0 | ${SF_SELECTED}
		SectionSetFlags ${IPCPlugin} $0


	${EndIf}

	Pop $0

!endif

FunctionEnd

Function .onInstSuccess

	# Update GTK Image loaders
	

FunctionEnd