deploy/ builds a single zip for TeslaConsole: the self-contained tray app and the signed ViGEmBus installer under a riojoy\ folder, with postinstall.bat at the root. postinstall elevates and runs riojoy\install-rio.ps1, which installs ViGEmBus silently (if absent) and registers RIOJoy to start at logon — no cert trust, test signing, Secure Boot change, or reboot. Also guard against two instances fighting over the COM port (machine-wide + per-user autostart both firing): a per-session named mutex makes a second launch exit immediately. Built zips (dist/) and the bundled installer (deploy/vendor/) are git-ignored. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
104 lines
5.2 KiB
PowerShell
104 lines
5.2 KiB
PowerShell
<#
|
|
.SYNOPSIS
|
|
Build the RIOJoy cockpit deployment zip: publish the tray app self-contained,
|
|
bundle the signed ViGEmBus installer + the post-install scripts, and zip it for
|
|
TeslaConsole. The zip extracts directly into a single directory (C:\games\RIOJOY).
|
|
|
|
.PARAMETER VigemInstaller
|
|
Path to the signed ViGEmBus installer to bundle. If omitted, looks in
|
|
deploy\vendor\ViGEmBus*.exe.
|
|
.PARAMETER OutDir
|
|
Where to write the zip (default: dist, relative to the repo root).
|
|
.PARAMETER Configuration
|
|
Build configuration (default: Release).
|
|
#>
|
|
param(
|
|
[string]$VigemInstaller,
|
|
[string]$OutDir = 'dist',
|
|
[string]$Configuration = 'Release'
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
$repo = Split-Path $PSScriptRoot -Parent # deploy\ -> repo root
|
|
$staging = Join-Path ([IO.Path]::GetTempPath()) "riojoy-pkg-$([Guid]::NewGuid().ToString('N'))"
|
|
|
|
Write-Host '== RIOJoy deployment package ==' -ForegroundColor Cyan
|
|
|
|
# --- version stamp --------------------------------------------------------
|
|
$sha = (& git -C $repo rev-parse --short HEAD 2>$null)
|
|
if (-not $sha) { $sha = 'nogit' }
|
|
$version = "{0}-{1}" -f (Get-Date -Format 'yyyyMMdd'), $sha
|
|
|
|
# --- locate the ViGEmBus installer ----------------------------------------
|
|
if (-not $VigemInstaller) {
|
|
$VigemInstaller = Get-ChildItem -Path (Join-Path $PSScriptRoot 'vendor') -Filter 'ViGEmBus*.exe' `
|
|
-ErrorAction SilentlyContinue | Select-Object -First 1 -ExpandProperty FullName
|
|
}
|
|
if (-not $VigemInstaller -or -not (Test-Path $VigemInstaller)) {
|
|
throw "ViGEmBus installer not found. Pass -VigemInstaller <path>, or drop ViGEmBus_*.exe into deploy\vendor\. Get it from https://github.com/nefarius/ViGEmBus/releases."
|
|
}
|
|
$sig = Get-AuthenticodeSignature $VigemInstaller
|
|
if ($sig.Status -ne 'Valid') { throw "ViGEmBus installer is not validly signed ($($sig.Status)): $VigemInstaller" }
|
|
Write-Host "ViGEmBus installer: $(Split-Path $VigemInstaller -Leaf) (signature $($sig.Status))"
|
|
|
|
try {
|
|
# The payload lives in a 'riojoy' folder; postinstall.bat sits beside it at the
|
|
# zip root (TeslaConsole runs it; it calls riojoy\install-rio.ps1).
|
|
$pkgDir = Join-Path $staging 'riojoy'
|
|
New-Item -ItemType Directory -Force -Path $pkgDir | Out-Null
|
|
|
|
# 1. Publish the tray app into riojoy\app (self-contained win-x64 — no .NET on target).
|
|
$appOut = Join-Path $pkgDir 'app'
|
|
Write-Host "Publishing RioJoy.Tray ($Configuration, self-contained win-x64)..."
|
|
& dotnet publish (Join-Path $repo 'src\RioJoy.Tray\RioJoy.Tray.csproj') `
|
|
-c $Configuration -r win-x64 --self-contained true `
|
|
-p:PublishSingleFile=false -p:DebugType=none `
|
|
-o $appOut | Out-Null
|
|
if ($LASTEXITCODE -ne 0) { throw 'dotnet publish failed.' }
|
|
|
|
# 2. Bundle the signed ViGEmBus installer into riojoy\vendor.
|
|
$vendorOut = Join-Path $pkgDir 'vendor'
|
|
New-Item -ItemType Directory -Force -Path $vendorOut | Out-Null
|
|
Copy-Item $VigemInstaller $vendorOut
|
|
|
|
# 3. Install script + readme + version stamp inside riojoy\; postinstall.bat at root.
|
|
Copy-Item (Join-Path $PSScriptRoot 'install-rio.ps1') $pkgDir
|
|
Copy-Item (Join-Path $PSScriptRoot 'README-DEPLOY.txt') $pkgDir
|
|
Set-Content -Path (Join-Path $pkgDir 'VERSION.txt') -Value "RIOJoy $version" -Encoding utf8
|
|
Copy-Item (Join-Path $PSScriptRoot 'postinstall.bat') $staging
|
|
|
|
# 4. Zip the package contents (so it extracts straight into C:\games\RIOJOY).
|
|
$outDirFull = if ([IO.Path]::IsPathRooted($OutDir)) { $OutDir } else { Join-Path $repo $OutDir }
|
|
New-Item -ItemType Directory -Force -Path $outDirFull | Out-Null
|
|
$zip = Join-Path $outDirFull "RIOJoy-$version.zip"
|
|
if (Test-Path $zip) { Remove-Item $zip -Force }
|
|
Write-Host "Zipping -> $zip"
|
|
# Build entries by hand with forward-slash names: both Compress-Archive and
|
|
# ZipFile.CreateFromDirectory write BACKSLASH separators under Windows PowerShell
|
|
# (.NET Framework), which some extractors mishandle. Entries are relative to the
|
|
# staging root, so the zip extracts straight into the target (C:\games\RIOJOY\...).
|
|
Add-Type -AssemblyName System.IO.Compression
|
|
Add-Type -AssemblyName System.IO.Compression.FileSystem
|
|
$base = (Resolve-Path $staging).Path.TrimEnd('\') + '\'
|
|
$fs = [System.IO.File]::Open($zip, [System.IO.FileMode]::CreateNew)
|
|
try {
|
|
$archive = New-Object System.IO.Compression.ZipArchive($fs, [System.IO.Compression.ZipArchiveMode]::Create)
|
|
try {
|
|
foreach ($file in Get-ChildItem -Path $staging -Recurse -File) {
|
|
$entryName = $file.FullName.Substring($base.Length) -replace '\\', '/'
|
|
[System.IO.Compression.ZipFileExtensions]::CreateEntryFromFile(
|
|
$archive, $file.FullName, $entryName,
|
|
[System.IO.Compression.CompressionLevel]::Optimal) | Out-Null
|
|
}
|
|
} finally { $archive.Dispose() }
|
|
} finally { $fs.Dispose() }
|
|
|
|
$size = '{0:N1} MB' -f ((Get-Item $zip).Length / 1MB)
|
|
Write-Host ''
|
|
Write-Host "Package built: $zip ($size)" -ForegroundColor Green
|
|
Write-Host 'Deploy: extract (postinstall.bat + riojoy\), then run postinstall.bat (elevated).'
|
|
}
|
|
finally {
|
|
if (Test-Path $staging) { Remove-Item $staging -Recurse -Force }
|
|
}
|