# Build complet : publish + Inno Setup
#
# Pré-requis :
#   - .NET 8 SDK
#   - Inno Setup 6.x  (https://jrsoftware.org/isdl.php)
#
# Lancer depuis la racine du repo :
#   powershell -ExecutionPolicy Bypass -File installer\build-installer.ps1

param(
    [string]$ISCC = "C:\Program Files (x86)\Inno Setup 6\ISCC.exe"
)

$ErrorActionPreference = 'Stop'
$root = Split-Path -Parent $PSScriptRoot

Write-Host "==> dotnet publish PSLauncher.App (Release single-file)" -ForegroundColor Cyan
dotnet publish "$root\src\PSLauncher.App\PSLauncher.App.csproj" -c Release --nologo
if ($LASTEXITCODE -ne 0) { throw "publish PSLauncher.App failed" }

Write-Host "==> dotnet publish PSLauncher.Updater (Release single-file)" -ForegroundColor Cyan
dotnet publish "$root\src\PSLauncher.Updater\PSLauncher.Updater.csproj" -c Release --nologo
if ($LASTEXITCODE -ne 0) { throw "publish PSLauncher.Updater failed" }

if (-not (Test-Path $ISCC)) {
    throw "ISCC.exe introuvable à $ISCC. Installe Inno Setup ou passe -ISCC <chemin>."
}

Write-Host "==> Inno Setup compile" -ForegroundColor Cyan
& $ISCC "$PSScriptRoot\PSLauncher.iss"
if ($LASTEXITCODE -ne 0) { throw "ISCC failed" }

Write-Host ""
Write-Host "OK - installer disponible dans: $PSScriptRoot\output\" -ForegroundColor Green
Get-ChildItem "$PSScriptRoot\output" -Filter "*.exe" | ForEach-Object {
    Write-Host "  $($_.Name)  ($([math]::Round($_.Length / 1MB, 1)) Mo)"
}
