# xetup installer - downloads and launches the latest release
# Usage: irm xetup.x9.cz/get.ps1 | iex

$api = 'https://xetup.x9.cz/forgejo-api/repos/x9/xetup/releases?limit=1'

try {
    $rel   = (Invoke-RestMethod -Uri $api -UseBasicParsing)[0]
    $asset = $rel.assets | Where-Object { $_.name -eq 'xetup.exe' } | Select-Object -First 1
    if (-not $asset) { Write-Error "xetup.exe not found in latest release"; exit 1 }

    $out = "$env:TEMP\xetup.exe"
    Write-Host "Downloading xetup $($rel.tag_name)..."
    Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $out -UseBasicParsing
    Write-Host "Launching..."
    Start-Process -FilePath $out -Verb RunAs
} catch {
    Write-Error "Failed: $_"
}
