Files
Void-Bastion/packaging/windows/build.ps1
T

88 lines
3.7 KiB
PowerShell

param(
[Parameter(Mandatory = $true)]
[string]$GodotExe,
[string]$MakeNsisExe
)
$ErrorActionPreference = "Stop"
$nsisCandidates = @()
if (-not [string]::IsNullOrWhiteSpace($MakeNsisExe)) {
$nsisCandidates += $MakeNsisExe
} else {
$pathNsis = Get-Command "makensis.exe" -ErrorAction SilentlyContinue
if ($pathNsis) {
$nsisCandidates += $pathNsis.Source
}
$nsisCandidates += @(
(Join-Path $env:LOCALAPPDATA "Programs\NSIS-3.13\Bin\makensis.exe"),
(Join-Path $env:LOCALAPPDATA "Programs\NSIS-3.13\makensis.exe"),
"C:\Program Files (x86)\NSIS\makensis.exe",
"C:\Program Files\NSIS\makensis.exe"
)
$MakeNsisExe = $nsisCandidates | Where-Object { Test-Path -LiteralPath $_ -PathType Leaf } | Select-Object -First 1
}
if ([string]::IsNullOrWhiteSpace($MakeNsisExe)) {
throw "NSIS wurde nicht gefunden. Installiere NSIS oder übergib -MakeNsisExe mit dem Pfad zu makensis.exe."
}
$projectRoot = (Resolve-Path (Join-Path $PSScriptRoot "..\..")).Path
$gameExe = Join-Path $projectRoot "build\windows\Void-Bastion.exe"
$installer = Join-Path $projectRoot "dist\Void-Bastion-Setup-x64.exe"
$installerScript = Join-Path $PSScriptRoot "installer.nsi"
$projectFile = Join-Path $projectRoot "project.godot"
foreach ($requiredFile in @($GodotExe, $MakeNsisExe, $installerScript)) {
if (-not (Test-Path -LiteralPath $requiredFile -PathType Leaf)) {
throw "Benötigte Datei fehlt: $requiredFile"
}
}
New-Item -ItemType Directory -Force -Path (Split-Path $gameExe), (Split-Path $installer) | Out-Null
$projectConfiguration = Get-Content -LiteralPath $projectFile -Raw
$releaseConfiguration = $projectConfiguration -replace '(?m)^_MCPGameBridge=.*\r?\n?', ''
$releaseConfiguration = $releaseConfiguration -replace '"res://addons/agent_tools/plugin\.cfg",\s*', ''
try {
# Die lokale MCP-Laufzeit ist ein Entwicklungswerkzeug und wird vom
# Exportfilter ausgeschlossen. Deshalb dürfen weder ihr Autoload-Verweis
# noch das Editor-Plugin in der veröffentlichten project.binary verbleiben.
Set-Content -LiteralPath $projectFile -Value $releaseConfiguration -NoNewline
& $GodotExe --headless --path $projectRoot --export-release "Windows x64" $gameExe
if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath $gameExe)) {
throw "Der Godot-Windows-Export ist fehlgeschlagen."
}
# Prüft, dass Godot die eingebetteten Projektdaten tatsächlich laden kann,
# bevor NSIS daraus einen Installer erstellt. Ein bloß vorhandenes EXE reicht
# nicht: ein defektes project.binary würde erst beim Start des Spiels auffallen.
$launchOutput = & $gameExe --headless --quit 2>&1 | Out-String
$launchExitCode = $LASTEXITCODE
if (($null -ne $launchExitCode -and $launchExitCode -ne 0) -or $launchOutput -match "Corrupted header in binary project\.binary|Couldn't load project data|Is the \.pck file missing") {
throw "Der exportierte Windows-Build kann seine Projektdaten nicht laden. NSIS-Installer wurde nicht erstellt. Ausgabe: $launchOutput"
}
}
finally {
Set-Content -LiteralPath $projectFile -Value $projectConfiguration -NoNewline
}
Push-Location $PSScriptRoot
try {
& $MakeNsisExe $installerScript
if ($LASTEXITCODE -ne 0 -or -not (Test-Path -LiteralPath $installer)) {
throw "Die Installer-Erstellung mit NSIS ist fehlgeschlagen."
}
}
finally {
Pop-Location
}
$installerFile = Get-Item -LiteralPath $installer
$hash = Get-FileHash -Algorithm SHA256 -LiteralPath $installer
Write-Host "Windows-Installer erfolgreich erstellt:"
Write-Host " Datei: $($installerFile.FullName)"
Write-Host " Größe: $([math]::Round($installerFile.Length / 1MB, 1)) MiB"
Write-Host " SHA256: $($hash.Hash)"