param( [string]$Bundle, [string]$Iscc, [string]$Version, [Parameter(Mandatory = $true)][string]$VCRedist ) $ErrorActionPreference = 'Stop' $root = (Resolve-Path (Join-Path $PSScriptRoot '../..')).Path if (-not $Version) { $Version = ([regex]::Match((Get-Content "$root/flutter_sender/pubspec.yaml" -Raw), '(?m)^version:\s*(\d+\.\d+\.\d+)')).Groups[1].Value } if ($Version -notmatch '^\d+\.\d+\.\d+$') { throw 'Version must be major.minor.patch' } if (-not $Iscc) { $command = Get-Command ISCC.exe -ErrorAction SilentlyContinue if ($command) { $Iscc = $command.Source } else { foreach ($base in @(${env:ProgramFiles(x86)}, $env:ProgramFiles)) { if ($base -and (Test-Path "$base/Inno Setup 6/ISCC.exe")) { $Iscc = "$base/Inno Setup 6/ISCC.exe"; break } } } } if (-not $Iscc -or -not (Test-Path -LiteralPath $Iscc)) { throw 'Install Inno Setup 6 or supply -Iscc path/to/ISCC.exe' } $VCRedist = (Resolve-Path -LiteralPath $VCRedist).Path function Invoke-Step([string]$Directory, [string]$Command, [string[]]$Arguments) { Push-Location $Directory try { & $Command @Arguments if ($LASTEXITCODE -ne 0) { throw "$Command failed: $LASTEXITCODE" } } finally { Pop-Location } } $output = "$root/dist/windows" New-Item -ItemType Directory -Force -Path $output | Out-Null if (-not $Bundle) { Invoke-Step "$root/rust_core" cargo @('check', '--offline') Invoke-Step "$root/rust_core" cargo @('test', '--offline', '--lib') Invoke-Step "$root/rust_core" cargo @('build', '--release', '--offline', '--target', 'x86_64-pc-windows-msvc', '--target-dir', "$root/rust_core/target") Invoke-Step "$root/flutter_sender" flutter @('pub', 'get') Invoke-Step "$root/flutter_sender" dart @('analyze', 'lib') Invoke-Step "$root/flutter_sender" flutter @('build', 'windows', '--debug') Invoke-Step "$root/flutter_sender" flutter @('build', 'windows', '--release') $Bundle = Join-Path $output ('stage-' + [guid]::NewGuid().ToString('N')) New-Item -ItemType Directory -Path $Bundle | Out-Null Get-ChildItem "$root/flutter_sender/build/windows/x64/runner/Release" -File | Where-Object { $_.Extension -in '.exe', '.dll' } | Copy-Item -Destination $Bundle Copy-Item "$root/flutter_sender/build/windows/x64/runner/Release/data" $Bundle -Recurse Copy-Item "$root/rust_core/target/x86_64-pc-windows-msvc/release/ttstdconnect_core.dll" $Bundle Invoke-Step "$root/signaling_server" go @('build', '-o', "$Bundle/signaling_server.exe", '.') } $Bundle = (Resolve-Path -LiteralPath $Bundle).Path foreach ($file in @('ttstd_sender.exe', 'flutter_windows.dll', 'ttstdconnect_core.dll', 'signaling_server.exe', 'data/app.so', 'data/flutter_assets')) { if (-not (Test-Path -LiteralPath (Join-Path $Bundle $file))) { throw "Incomplete Release bundle: $file" } } & $Iscc "/DAppVersion=$Version" "/DBundleDir=$Bundle" "/DOutputDir=$output" "/DVCRedist=$VCRedist" "$PSScriptRoot/setup.iss" if ($LASTEXITCODE -ne 0) { throw "Inno Setup failed: $LASTEXITCODE" } Write-Host "Installer: $output/TTSTDConnect-$Version-windows-x64-setup.exe"