PrintToVeraeTimeStamp/platform/windows/installer-netprint.nsi
Cursor Agent 17bb067010
Keep one IPP advertisement and accept link-local IPv6.
DnsServiceRegister stays the only owner of the _ipp._tcp instance. The shared UDP responder answers subtype PTRs only, so mDNS no longer renames a second copy to Name(1). The IPP port listens on IPv4 and on [::] with IPV6_V6ONLY, and the firewall rules allow fe80::/10, so a Mac connect to the host's link-local address completes.

Co-authored-by: George Lambert <marchon@gmail.com>
2026-10-05 00:34:34 +00:00

252 lines
8 KiB
NSIS

; Verae Network Printer — standalone Windows installer (NSIS).
; Installs into its own folder (C:\Program Files\Verae\NetPrint) so it does not
; overwrite the driver's C:\Program Files\Verae\PrintStamp\bin\verae-print.exe.
; The service name (VeraeNetPrint) and %ProgramData% config are shared. Installing
; one product when the other is present points the service at the same or newer
; binary and leaves the other product's files in place.
!ifndef VERSION
!define VERSION "0.3.4"
!endif
!ifndef ARCH
!define ARCH "amd64"
!endif
!ifndef SRCDIR
!define SRCDIR "."
!endif
!ifndef OUTDIR
!define OUTDIR "."
!endif
!define PRODUCT_NAME "Verae Network Printer"
!define UNINST_KEY "Software\Microsoft\Windows\CurrentVersion\Uninstall\VeraeNetPrint"
Name "${PRODUCT_NAME} ${VERSION}"
OutFile "${OUTDIR}\VeraeNetPrint-windows-${ARCH}-${VERSION}-setup.exe"
InstallDir "$PROGRAMFILES64\Verae\NetPrint"
RequestExecutionLevel admin
Unicode true
SetCompressor /SOLID lzma
ShowInstDetails show
!include "MUI2.nsh"
!include "nsDialogs.nsh"
!include "x64.nsh"
!include "LogicLib.nsh"
!include "FileFunc.nsh"
!include "WinMessages.nsh"
!include "netprint-upgrade.nsh"
!insertmacro GetParameters
!insertmacro GetOptions
!define MUI_ABORTWARNING
!insertmacro MUI_PAGE_WELCOME
!insertmacro MUI_PAGE_LICENSE "${SRCDIR}\LICENSE.txt"
!insertmacro MUI_PAGE_DIRECTORY
Page custom NetOptionsCreate NetOptionsLeave
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Var LogFile
Var LogDir
Var AllowPublic
Var LocalQueue
Var hPublic
Var hQueue
Var FwProfile
Function .onInit
${IfNot} ${RunningX64}
MessageBox MB_ICONSTOP "This build targets 64-bit Windows." /SD IDOK
Abort
${EndIf}
SetRegView 64
SetShellVarContext all
AllowSkipFiles off
Call SetupLogPath
StrCpy $AllowPublic "0"
StrCpy $LocalQueue "0"
${GetParameters} $R0
ClearErrors
${GetOptions} $R0 "/PUBLIC=" $R1
${IfNot} ${Errors}
${If} $R1 == "1"
StrCpy $AllowPublic "1"
${EndIf}
${EndIf}
ClearErrors
${GetOptions} $R0 "/QUEUE=" $R1
${IfNot} ${Errors}
${If} $R1 == "1"
StrCpy $LocalQueue "1"
${EndIf}
${EndIf}
FunctionEnd
Function un.onInit
SetRegView 64
SetShellVarContext all
AllowSkipFiles off
Call un.SetupLogPath
FunctionEnd
Function SetupLogPath
ReadEnvStr $LogDir "ProgramData"
${If} $LogDir == ""
StrCpy $LogDir "C:\ProgramData"
${EndIf}
StrCpy $LogDir "$LogDir\Verae\logs"
StrCpy $LogFile "$LogDir\netprint-installer.log"
FunctionEnd
Function un.SetupLogPath
ReadEnvStr $LogDir "ProgramData"
${If} $LogDir == ""
StrCpy $LogDir "C:\ProgramData"
${EndIf}
StrCpy $LogDir "$LogDir\Verae\logs"
StrCpy $LogFile "$LogDir\netprint-installer.log"
FunctionEnd
; Inbound TCP 631 (IPP), TCP 8632 (fallback; 8631 is the driver helper), UDP 5353 (mDNS).
; $FwProfile is private,domain unless the installer opted into Public.
; remoteip=any includes IPv4, global IPv6, and link-local fe80::/10.
; A macro so the uninstaller can run the same commands.
!macro NETPRINT_FIREWALL_ADD
nsExec::Exec 'netsh advfirewall firewall delete rule name="Verae NetPrint IPP"'
Pop $0
nsExec::Exec 'netsh advfirewall firewall add rule name="Verae NetPrint IPP" dir=in action=allow protocol=TCP localport=631 remoteip=any profile=$FwProfile'
Pop $0
nsExec::Exec 'netsh advfirewall firewall delete rule name="Verae NetPrint IPP Fallback"'
Pop $0
nsExec::Exec 'netsh advfirewall firewall add rule name="Verae NetPrint IPP Fallback" dir=in action=allow protocol=TCP localport=8632 remoteip=any profile=$FwProfile'
Pop $0
nsExec::Exec 'netsh advfirewall firewall delete rule name="Verae NetPrint mDNS"'
Pop $0
nsExec::Exec 'netsh advfirewall firewall add rule name="Verae NetPrint mDNS" dir=in action=allow protocol=UDP localport=5353 remoteip=any profile=$FwProfile'
Pop $0
!macroend
Function NetOptionsCreate
!insertmacro MUI_HEADER_TEXT "Network options" "Both stay off unless you turn them on."
nsDialogs::Create 1018
Pop $0
${NSD_CreateCheckbox} 0 0 100% 28u "Allow connections from &Public networks (off by default).$\r$\nPrivate and Domain networks are always allowed."
Pop $hPublic
${NSD_CreateCheckbox} 0 36u 100% 28u "Add a local Windows printer named &Verae Timestamp (off by default).$\r$\nPrints to this computer through http://127.0.0.1 on the port the service binds."
Pop $hQueue
${If} $AllowPublic == "1"
${NSD_Check} $hPublic
${EndIf}
${If} $LocalQueue == "1"
${NSD_Check} $hQueue
${EndIf}
nsDialogs::Show
FunctionEnd
Function NetOptionsLeave
${NSD_GetState} $hPublic $0
${If} $0 == ${BST_CHECKED}
StrCpy $AllowPublic "1"
${Else}
StrCpy $AllowPublic "0"
${EndIf}
${NSD_GetState} $hQueue $0
${If} $0 == ${BST_CHECKED}
StrCpy $LocalQueue "1"
${Else}
StrCpy $LocalQueue "0"
${EndIf}
FunctionEnd
!macro NETPRINT_FIREWALL_REMOVE
nsExec::Exec 'netsh advfirewall firewall delete rule name="Verae NetPrint IPP"'
Pop $0
nsExec::Exec 'netsh advfirewall firewall delete rule name="Verae NetPrint IPP Fallback"'
Pop $0
nsExec::Exec 'netsh advfirewall firewall delete rule name="Verae NetPrint mDNS"'
Pop $0
!macroend
Section "Verae Network Printer" SecMain
SectionIn RO
; The service and tray keep the installed exes locked. Copying first
; skips those files under /S and leaves the old binary in place.
!insertmacro NETPRINT_STOP_SERVICE
!insertmacro NETPRINT_KILL_TRAY
SetOverwrite on
AllowSkipFiles off
SetOutPath "$INSTDIR\bin"
!insertmacro NETPRINT_COPY_CHECKED "${SRCDIR}\verae-print.exe" "verae-print.exe"
!insertmacro NETPRINT_COPY_CHECKED "${SRCDIR}\verae-netprint-tray.exe" "verae-netprint-tray.exe"
SetOutPath "$INSTDIR"
!insertmacro NETPRINT_COPY_CHECKED "${SRCDIR}\LICENSE.txt" "LICENSE.txt"
WriteUninstaller "$INSTDIR\Uninstall-NetPrint.exe"
WriteRegStr HKLM "${UNINST_KEY}" "DisplayName" "${PRODUCT_NAME} ${VERSION}"
WriteRegStr HKLM "${UNINST_KEY}" "UninstallString" '"$INSTDIR\Uninstall-NetPrint.exe"'
WriteRegStr HKLM "${UNINST_KEY}" "DisplayVersion" "${VERSION}"
WriteRegStr HKLM "${UNINST_KEY}" "Publisher" "Verae"
CreateDirectory "$SMPROGRAMS\Verae"
CreateShortCut "$SMPROGRAMS\Verae\Verae Network Printer.lnk" "$INSTDIR\bin\verae-netprint-tray.exe"
StrCpy $FwProfile "private,domain"
StrCpy $R8 "false"
${If} $AllowPublic == "1"
StrCpy $FwProfile "private,domain,public"
StrCpy $R8 "true"
${EndIf}
!insertmacro NETPRINT_FIREWALL_ADD
CreateDirectory "$LogDir"
StrCpy $R9 '"$INSTDIR\bin\verae-print.exe" netprint install --owner standalone --allow-public=$R8'
${If} $LocalQueue == "1"
StrCpy $R9 '$R9 --local-queue'
${EndIf}
nsExec::ExecToStack $R9
Pop $0
Pop $1
ClearErrors
FileOpen $2 "$LogFile" a
${IfNot} ${Errors}
FileSeek $2 0 END
FileWrite $2 "netprint install allow-public=$R8 local-queue=$LocalQueue exit $0$\r$\n$1$\r$\n"
FileClose $2
${EndIf}
${If} $0 != 0
MessageBox MB_ICONEXCLAMATION "The service did not start (exit $0).$\r$\nDetails were written to $LogFile$\r$\nYou can start it from the tray icon after signing in." /SD IDOK
${EndIf}
SectionEnd
Section "Uninstall"
!insertmacro NETPRINT_STOP_SERVICE
!insertmacro NETPRINT_KILL_TRAY
nsExec::ExecToStack '"$INSTDIR\bin\verae-print.exe" netprint uninstall --owner standalone'
Pop $0
Pop $1
CreateDirectory "$LogDir"
ClearErrors
FileOpen $2 "$LogFile" a
${IfNot} ${Errors}
FileSeek $2 0 END
FileWrite $2 "netprint uninstall exit $0$\r$\n$1$\r$\n"
FileClose $2
${EndIf}
ClearErrors
ReadRegDWORD $R1 HKLM "Software\Verae\NetPrint" "Driver"
${If} ${Errors}
StrCpy $R1 0
${EndIf}
ClearErrors
${If} $R1 != 1
!insertmacro NETPRINT_FIREWALL_REMOVE
${EndIf}
!insertmacro NETPRINT_DELETE_CHECKED "$INSTDIR\bin\verae-print.exe"
!insertmacro NETPRINT_DELETE_CHECKED "$INSTDIR\bin\verae-netprint-tray.exe"
RMDir "$INSTDIR\bin"
Delete "$INSTDIR\LICENSE.txt"
Delete "$INSTDIR\Uninstall-NetPrint.exe"
RMDir "$INSTDIR"
Delete "$SMPROGRAMS\Verae\Verae Network Printer.lnk"
RMDir "$SMPROGRAMS\Verae"
DeleteRegKey HKLM "${UNINST_KEY}"
SectionEnd