From f04daa1998790c6fc8fec792930f2e88779ca86f Mon Sep 17 00:00:00 2001 From: Tom Butcher Date: Sat, 1 Aug 2026 23:59:59 +0100 Subject: [PATCH] Update NSIS installer and build script for improved file handling and icon management - Changed the application source directory definition in the NSIS installer script to point to "app" for better clarity. - Updated the file inclusion pattern to ensure all files are correctly packaged in the installer. - Enhanced the build script to define a local installer name and manage the icon file more effectively, ensuring it is copied to the working directory if present. - Improved error handling to provide clearer messages regarding the installer creation process. --- packaging/windows/farmcontrol-server.nsi | 4 ++-- scripts/build-windows-nsis.ps1 | 29 +++++++++++++----------- scripts/embed-windows-exe-icon.mjs | 11 +++++++++ 3 files changed, 29 insertions(+), 15 deletions(-) diff --git a/packaging/windows/farmcontrol-server.nsi b/packaging/windows/farmcontrol-server.nsi index 76f1d0f..5d9a36c 100644 --- a/packaging/windows/farmcontrol-server.nsi +++ b/packaging/windows/farmcontrol-server.nsi @@ -11,7 +11,7 @@ !endif !ifndef APP_SOURCE_DIR - !define APP_SOURCE_DIR "." + !define APP_SOURCE_DIR "app" !endif Name "Farm Control Server" @@ -48,7 +48,7 @@ FunctionEnd Section "Farm Control Server" SecMain SectionIn RO SetOutPath $INSTDIR - File /r "${APP_SOURCE_DIR}\*" + File /r "${APP_SOURCE_DIR}\*.*" !insertmacro customInstall diff --git a/scripts/build-windows-nsis.ps1 b/scripts/build-windows-nsis.ps1 index a660c89..0f21449 100644 --- a/scripts/build-windows-nsis.ps1 +++ b/scripts/build-windows-nsis.ps1 @@ -47,6 +47,7 @@ $rootDir = Split-Path -Parent $PSScriptRoot $nsiPath = Join-Path $rootDir "packaging/windows/farmcontrol-server.nsi" $installerInclude = Join-Path $rootDir "packaging/windows/installer.nsh" $workDir = Join-Path $env:TEMP "farmcontrol-server-nsis" +$localInstallerName = "farmcontrol-server-installer.exe" if (Test-Path $workDir) { Remove-Item $workDir -Recurse -Force @@ -74,6 +75,11 @@ if (-not (Test-Path $requiredExe)) { Copy-Item -LiteralPath $nsiPath -Destination (Join-Path $workDir "farmcontrol-server.nsi") Copy-Item -LiteralPath $installerInclude -Destination (Join-Path $workDir "installer.nsh") +$iconPath = Join-Path $rootDir "assets\icon.ico" +if (Test-Path $iconPath) { + Copy-Item -LiteralPath $iconPath -Destination (Join-Path $workDir "icon.ico") -Force +} + $makensis = Find-Makensis $outputExePath = $ExecutionContext.SessionState.Path.GetUnresolvedProviderPathFromPSPath($OutputExe) $outputDir = Split-Path $outputExePath -Parent @@ -81,17 +87,16 @@ if (-not (Test-Path $outputDir)) { New-Item -ItemType Directory -Path $outputDir | Out-Null } -$iconPath = Join-Path $rootDir "assets\icon.ico" $makensisArgs = @( + "/V3" "/NOCD" - "/DOUTFILE=$outputExePath" + "/DOUTFILE=$localInstallerName" "/DVERSION=$Version" "/DAPP_SOURCE_DIR=app" ) -if (Test-Path $iconPath) { - $iconPathForNsis = $iconPath.Replace("\", "/") - $makensisArgs += "/DINSTALLER_ICON=$iconPathForNsis" +if (Test-Path (Join-Path $workDir "icon.ico")) { + $makensisArgs += "/DINSTALLER_ICON=icon.ico" } $makensisArgs += (Join-Path $workDir "farmcontrol-server.nsi") @@ -106,20 +111,18 @@ try { Pop-Location } -if (-not (Test-Path $outputExePath)) { - throw "NSIS installer was not created at $outputExePath" +$localInstallerPath = Join-Path $workDir $localInstallerName +if (-not (Test-Path $localInstallerPath)) { + throw "NSIS installer was not created at $localInstallerPath" } -$installerBytes = (Get-Item -LiteralPath $outputExePath).Length +$installerBytes = (Get-Item -LiteralPath $localInstallerPath).Length Write-Host "NSIS installer size: $([math]::Round($installerBytes / 1MB, 2)) MB" if ($installerBytes -lt $MinInstallerBytes) { - throw "NSIS installer is only $([math]::Round($installerBytes / 1KB, 1)) KiB at $outputExePath. The application files were not packaged. Check APP_SOURCE_DIR staging and NSIS logs." + throw "NSIS installer is only $([math]::Round($installerBytes / 1KB, 1)) KiB at $localInstallerPath. The application files were not packaged. Check NSIS logs above." } -if (Test-Path $iconPath) { - $embedIconScript = Join-Path $rootDir "scripts/embed-windows-exe-icon.mjs" - & bun $embedIconScript $outputExePath --icon $iconPath -} +Move-Item -LiteralPath $localInstallerPath -Destination $outputExePath -Force Write-Host "Created NSIS installer at $outputExePath" diff --git a/scripts/embed-windows-exe-icon.mjs b/scripts/embed-windows-exe-icon.mjs index 7e5e752..1ecfe9d 100644 --- a/scripts/embed-windows-exe-icon.mjs +++ b/scripts/embed-windows-exe-icon.mjs @@ -99,6 +99,17 @@ export async function embedWindowsExeIcon(exePath, options = {}) { throw new Error(`embed-windows-exe-icon: executable not found: ${exePath}`); } + const basename = path.basename(exePath).toLowerCase(); + if ( + basename.includes("farmcontrol-server-") && + basename.endsWith(".exe") && + !basename.endsWith("-setup.exe") + ) { + throw new Error( + `embed-windows-exe-icon: refusing to patch NSIS installer ${basename}; use NSIS Icon/MUI_ICON instead`, + ); + } + const iconSourcePath = resolveWindowsIconSource(options.icon); const workDir = options.workDir || path.join(rootDir, "build", ".windows-icon-work");