# Windows Installer Build Script
# Requires WiX Toolset 3.x or 4.x

# Variables - update these paths for your build environment
$BuildDir = "..\build\Release"
$Qt6Dir = "C:\Qt\6.x.x\msvc2022_64"
$OpenSSLDir = "C:\OpenSSL-Win64"
$FFmpegDir = "C:\ffmpeg"
$SourceDir = ".."

# Generate GUIDs (run once and replace PUT-GUID-HERE in installer.wxs)
# [guid]::NewGuid()

# Build the installer
Write-Host "Building Scar Chat MSI installer..."

# Set WiX variables
$wixVars = @(
    "-dBuildDir=$BuildDir",
    "-dQt6Dir=$Qt6Dir",
    "-dOpenSSLDir=$OpenSSLDir",
    "-dFFmpegDir=$FFmpegDir",
    "-dSourceDir=$SourceDir"
)

# Compile WiX source
& candle.exe installer.wxs @wixVars -ext WixUIExtension

if ($LASTEXITCODE -ne 0) {
    Write-Error "WiX compilation failed"
    exit 1
}

# Link and create MSI
& light.exe installer.wixobj @wixVars -ext WixUIExtension -out "Scar Chat.msi"

if ($LASTEXITCODE -ne 0) {
    Write-Error "WiX linking failed"
    exit 1
}

Write-Host "Successfully created 'Scar Chat.msi'"

# Clean up intermediate files
Remove-Item installer.wixobj -ErrorAction SilentlyContinue
Remove-Item installer.wixpdb -ErrorAction SilentlyContinue
