farmcontrol-ui/packaging/windows/farmcontrol.nsi
Tom Butcher ee62045416
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good
Add support for automatic restart after successful installation on Windows
- Implemented a new function to restart Farm Control after a successful installation, triggered by the `/RESTARTFC` option.
- Enhanced the installer script to wait for the application to close before relaunching, improving user experience during updates.
- Updated the app update process to conditionally schedule a restart based on the platform, ensuring compatibility with macOS.
2026-08-04 00:45:52 +01:00

124 lines
3.4 KiB
NSIS

!include "MUI2.nsh"
!include "LogicLib.nsh"
!include "installer.nsh"
!ifndef OUTFILE
!define OUTFILE "farmcontrol-installer.exe"
!endif
!ifndef VERSION
!define VERSION "0.1.0"
!endif
!ifndef BUILD_NUMBER
!define BUILD_NUMBER "dev"
!endif
!ifndef APP_SOURCE_DIR
!define APP_SOURCE_DIR "app"
!endif
Name "Farm Control"
OutFile "${OUTFILE}"
InstallDir "$LOCALAPPDATA\Programs\Farm Control"
InstallDirRegKey HKCU "Software\Tom Butcher\Farm Control" "InstallDir"
RequestExecutionLevel user
SilentInstall normal
!define MUI_ABORTWARNING
!ifndef INSTALLER_ICON
!define INSTALLER_ICON "${NSISDIR}\Contrib\Graphics\Icons\modern-install.ico"
!endif
!define MUI_ICON "${INSTALLER_ICON}"
!define MUI_UNICON "${INSTALLER_ICON}"
Icon "${INSTALLER_ICON}"
UninstallIcon "${INSTALLER_ICON}"
BrandingText "Farm Control v${VERSION}-b${BUILD_NUMBER} Installer"
!insertmacro MUI_PAGE_DIRECTORY
!insertmacro MUI_PAGE_INSTFILES
!insertmacro MUI_UNPAGE_CONFIRM
!insertmacro MUI_UNPAGE_INSTFILES
!insertmacro MUI_LANGUAGE "English"
Function .onInit
!insertmacro initProgressLog
${If} ${Silent}
SetAutoClose true
${EndIf}
!insertmacro progressPhase "Starting installation"
!insertmacro progressStatus "Starting Farm Control installation..."
!insertmacro progressPercent 5
; In-app updates keep the running process alive for progress UI.
; Interactive / silent fresh installs still remove the previous version first.
${If} $IsInAppUpdate == "1"
!insertmacro prepareInPlaceUpdate
!insertmacro progressPercent 15
${Else}
!insertmacro uninstallPreviousFarmControl
!insertmacro progressPercent 20
${EndIf}
FunctionEnd
Function .onInstFailed
!insertmacro progressFailure "Installation failed."
FunctionEnd
Function .onInstSuccess
Call restartFarmControlAfterUpdate
FunctionEnd
Section "Farm Control" SecMain
SectionIn RO
!insertmacro progressPhase "Copying application files"
!insertmacro progressStatus "Copying application files..."
!insertmacro progressPercent 35
SetOutPath $INSTDIR
SetOverwrite try
File /r "${APP_SOURCE_DIR}\*.*"
!insertmacro progressPercent 75
!insertmacro customInstall
!insertmacro progressPhase "Finalizing installation"
!insertmacro progressStatus "Writing uninstall information..."
!insertmacro progressPercent 90
WriteRegStr HKCU "Software\Tom Butcher\Farm Control" "InstallDir" $INSTDIR
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Farm Control" \
"DisplayName" "Farm Control"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Farm Control" \
"DisplayVersion" "${VERSION}"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Farm Control" \
"Publisher" "Tom Butcher"
WriteRegStr HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Farm Control" \
"UninstallString" "$INSTDIR\Uninstall.exe"
WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Farm Control" \
"NoModify" 1
WriteRegDWORD HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Farm Control" \
"NoRepair" 1
WriteUninstaller "$INSTDIR\Uninstall.exe"
!insertmacro progressSuccess
SectionEnd
Section "Uninstall"
!insertmacro customUnInstall
Delete "$INSTDIR\Uninstall.exe"
RMDir /r "$INSTDIR"
DeleteRegKey HKCU "Software\Tom Butcher\Farm Control"
DeleteRegKey HKCU "Software\Microsoft\Windows\CurrentVersion\Uninstall\Farm Control"
SectionEnd