Files
aza/AzA march 2026 - Kopie (5)/build_installer.ps1

171 lines
5.0 KiB
PowerShell
Raw Normal View History

2026-03-25 13:42:48 +01:00
$projectRoot = $PSScriptRoot
$innoScript = Join-Path $projectRoot "installer\aza_installer.iss"
$setupOutput = Join-Path $projectRoot "dist\installer\aza_desktop_setup.exe"
$versionMetaDir = Join-Path $projectRoot "dist\installer_meta"
$versionMetaFile = Join-Path $versionMetaDir "aza_version_info.txt"
$azaVersionPy = Join-Path $projectRoot "aza_version.py"
function Find-InnoSetup {
$candidates = @(
"${env:ProgramFiles(x86)}\Inno Setup 6\ISCC.exe",
"${env:ProgramFiles}\Inno Setup 6\ISCC.exe",
"C:\Program Files (x86)\Inno Setup 6\ISCC.exe",
"C:\Program Files\Inno Setup 6\ISCC.exe",
"${env:LOCALAPPDATA}\Programs\Inno Setup 6\ISCC.exe"
)
foreach ($path in $candidates) {
if ($path -and (Test-Path $path)) {
return $path
}
}
$regPaths = @(
"HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 6_is1",
"HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 6_is1",
"HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Inno Setup 6_is1"
)
foreach ($regPath in $regPaths) {
try {
$installLocation = (Get-ItemProperty $regPath -ErrorAction SilentlyContinue).InstallLocation
if ($installLocation) {
$iscc = Join-Path $installLocation "ISCC.exe"
if (Test-Path $iscc) {
return $iscc
}
}
} catch {}
}
$isccInPath = Get-Command "ISCC.exe" -ErrorAction SilentlyContinue
if ($isccInPath) {
return $isccInPath.Source
}
return $null
}
function Install-InnoSetup {
$innoUrl = "https://jrsoftware.org/download.php/is.exe"
$installerPath = Join-Path $env:TEMP "innosetup6_installer.exe"
Write-Host ""
Write-Host "Inno Setup 6 wird automatisch heruntergeladen und installiert..."
Write-Host "Quelle: $innoUrl"
try {
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-WebRequest -Uri $innoUrl -OutFile $installerPath -UseBasicParsing
} catch {
Write-Error "Download von Inno Setup fehlgeschlagen: $_"
return $false
}
if (-not (Test-Path $installerPath)) {
Write-Error "Inno Setup Installer wurde nicht heruntergeladen."
return $false
}
Write-Host "Installiere Inno Setup 6 (silent)..."
$process = Start-Process -FilePath $installerPath -ArgumentList "/VERYSILENT", "/SUPPRESSMSGBOXES", "/NORESTART" -Wait -PassThru
if ($process.ExitCode -ne 0) {
Write-Error "Inno Setup Installation fehlgeschlagen (Exit Code: $($process.ExitCode))."
return $false
}
Write-Host "Inno Setup 6 wurde erfolgreich installiert."
return $true
}
# --- Voraussetzungen pruefen ---
if (-not (Test-Path $innoScript)) {
Write-Error "Installer-Script nicht gefunden: $innoScript"
exit 1
}
if (-not (Test-Path $azaVersionPy)) {
Write-Error "aza_version.py nicht gefunden: $azaVersionPy"
exit 1
}
if (-not (Test-Path (Join-Path $projectRoot "dist\aza_desktop\aza_desktop.exe"))) {
Write-Error "Desktop-Build nicht gefunden. Bitte zuerst build_exe.ps1 ausfuehren."
exit 1
}
# --- Inno Setup finden oder automatisch installieren ---
$innoCompiler = Find-InnoSetup
if (-not $innoCompiler) {
$installed = Install-InnoSetup
if ($installed) {
$innoCompiler = Find-InnoSetup
}
if (-not $innoCompiler) {
Write-Host ""
Write-Error "Inno Setup 6 konnte nicht gefunden oder installiert werden."
Write-Host ""
Write-Host "Bitte Inno Setup 6 manuell installieren:"
Write-Host " https://jrsoftware.org/isdl.php"
Write-Host ""
Write-Host "Danach dieses Script erneut ausfuehren."
exit 1
}
}
Write-Host "Inno Setup Compiler: $innoCompiler"
# --- Version lesen ---
if (-not (Test-Path $versionMetaDir)) {
New-Item -ItemType Directory -Path $versionMetaDir | Out-Null
}
Write-Host "Lese zentrale AZA-Version aus aza_version.py..."
$versionContent = Get-Content $azaVersionPy -Raw
if ($versionContent -match 'APP_VERSION\s*=\s*"([^"]+)"') {
$appVersion = $matches[1].Trim()
} else {
$appVersion = $null
}
if (-not $appVersion) {
Write-Error "Konnte APP_VERSION nicht aus aza_version.py lesen."
exit 1
}
Set-Content -Path $versionMetaFile -Value $appVersion -Encoding ASCII
# --- Ausgabe-Ordner sicherstellen ---
$outputDir = Join-Path $projectRoot "dist\installer"
if (-not (Test-Path $outputDir)) {
New-Item -ItemType Directory -Path $outputDir | Out-Null
}
# --- Installer bauen ---
Write-Host "Baue AZA Installer (Version $appVersion)..."
& $innoCompiler "/DMyAppVersion=$appVersion" $innoScript
if ($LASTEXITCODE -ne 0) {
Write-Error "Installer-Build fehlgeschlagen."
exit 1
}
if (-not (Test-Path $setupOutput)) {
Write-Error "Installer wurde nicht gefunden: $setupOutput"
exit 1
}
Write-Host ""
Write-Host "Installer erfolgreich erstellt:"
Write-Host $setupOutput
Write-Host "Verwendete Version:"
Write-Host $appVersion