Update NSIS installer and build script for improved file handling and icon management
All checks were successful
farmcontrol/farmcontrol-server/pipeline/head This commit looks good

- 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.
This commit is contained in:
Tom Butcher 2026-08-01 23:59:59 +01:00
parent d572688370
commit f04daa1998
3 changed files with 29 additions and 15 deletions

View File

@ -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

View File

@ -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"

View File

@ -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");