|
1 | 1 | #!/usr/bin/env pwsh |
2 | 2 |
|
3 | 3 | param( |
4 | | - [string]$DestinationPath = "C:\Program Files (x86)\Steam\steamapps\common\VoiceAttack 2\Apps\EliteAPI", |
5 | | - [switch]$SkipVoiceAttackRestart |
| 4 | + [ValidateSet("VA1", "VA2", "Both")] |
| 5 | + [string]$Version = "Both", |
| 6 | + |
| 7 | + [string]$VA1Path = "C:\Program Files (x86)\Steam\steamapps\common\VoiceAttack\Apps\EliteAPI", |
| 8 | + [string]$VA2Path = "C:\Program Files (x86)\Steam\steamapps\common\VoiceAttack 2\Apps\EliteAPI", |
| 9 | + |
| 10 | + [switch]$SkipRestart, |
| 11 | + [switch]$NoTest |
6 | 12 | ) |
7 | 13 |
|
8 | 14 | # Detect if running on Windows |
9 | 15 | $IsWindowsOS = ($PSVersionTable.PSVersion.Major -lt 6) -or ($IsWindows -eq $true) |
10 | 16 |
|
11 | | -Write-Host "Stopping VoiceAttack..." -ForegroundColor Cyan |
| 17 | +function Stop-VoiceAttackProcess { |
| 18 | + param([string]$ProcessName) |
| 19 | + |
| 20 | + if ($IsWindowsOS) { |
| 21 | + try { |
| 22 | + $process = Get-Process -Name $ProcessName -ErrorAction SilentlyContinue |
| 23 | + if ($process) { |
| 24 | + Stop-Process -Name $ProcessName -Force -ErrorAction SilentlyContinue |
| 25 | + Write-Host "Stopped $ProcessName." -ForegroundColor Green |
| 26 | + Start-Sleep -Seconds 2 |
| 27 | + } |
| 28 | + } |
| 29 | + catch { |
| 30 | + Write-Host "$ProcessName was not running." -ForegroundColor Yellow |
| 31 | + } |
| 32 | + } |
| 33 | +} |
| 34 | + |
| 35 | +function Start-VoiceAttackProcess { |
| 36 | + param([string]$ExePath, [string]$Name) |
| 37 | + |
| 38 | + if ($IsWindowsOS -and (Test-Path $ExePath)) { |
| 39 | + Write-Host "Starting $Name..." -ForegroundColor Cyan |
| 40 | + Start-Process $ExePath |
| 41 | + Write-Host "$Name started." -ForegroundColor Green |
| 42 | + } |
| 43 | + else { |
| 44 | + Write-Warning "$Name not found at: $ExePath" |
| 45 | + } |
| 46 | +} |
| 47 | + |
| 48 | +function Deploy-Plugin { |
| 49 | + param( |
| 50 | + [string]$TargetFramework, |
| 51 | + [string]$DestinationPath, |
| 52 | + [string]$Name |
| 53 | + ) |
12 | 54 |
|
13 | | -if (-not $SkipVoiceAttackRestart -and $IsWindowsOS) { |
14 | | - try { |
15 | | - Stop-Process -Name "VoiceAttack" -Force -ErrorAction SilentlyContinue |
16 | | - Write-Host "VoiceAttack stopped." -ForegroundColor Green |
| 55 | + Write-Host "`nDeploying to $Name ($TargetFramework)..." -ForegroundColor Cyan |
| 56 | + |
| 57 | + # Create destination directory if it doesn't exist |
| 58 | + if (-not (Test-Path $DestinationPath)) { |
| 59 | + New-Item -ItemType Directory -Path $DestinationPath -Force | Out-Null |
| 60 | + } |
| 61 | + |
| 62 | + # Copy all items from build output to destination |
| 63 | + $buildOutputPath = "EliteVA/bin/Debug/$TargetFramework/" |
| 64 | + if (Test-Path $buildOutputPath) { |
| 65 | + Get-ChildItem -Path $buildOutputPath -Filter *.dll | ForEach-Object { |
| 66 | + Copy-Item $_.FullName -Destination $DestinationPath -Force |
| 67 | + Write-Host " Copied $($_.Name)" -ForegroundColor Gray |
| 68 | + } |
| 69 | + Write-Host "$Name deployment complete." -ForegroundColor Green |
17 | 70 | } |
18 | | - catch { |
19 | | - Write-Host "VoiceAttack was not running." -ForegroundColor Yellow |
| 71 | + else { |
| 72 | + Write-Error "Build output not found at: $buildOutputPath" |
| 73 | + return $false |
20 | 74 | } |
21 | 75 |
|
22 | | - Start-Sleep -Seconds 2 |
| 76 | + return $true |
23 | 77 | } |
24 | 78 |
|
| 79 | +# Stop VoiceAttack instances |
| 80 | +if (-not $SkipRestart) { |
| 81 | + Write-Host "Stopping VoiceAttack instances..." -ForegroundColor Cyan |
| 82 | + |
| 83 | + if ($Version -eq "VA1" -or $Version -eq "Both") { |
| 84 | + Stop-VoiceAttackProcess -ProcessName "VoiceAttack" |
| 85 | + } |
| 86 | + |
| 87 | + if ($Version -eq "VA2" -or $Version -eq "Both") { |
| 88 | + Stop-VoiceAttackProcess -ProcessName "VoiceAttack" |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +# Build plugin |
25 | 93 | Write-Host "`nBuilding plugin..." -ForegroundColor Cyan |
26 | | -dotnet clean "EliteVA/EliteVA.csproj" -c Debug |
| 94 | +dotnet clean "EliteVA/EliteVA.csproj" -c Debug | Out-Null |
27 | 95 | dotnet build "EliteVA/EliteVA.csproj" -c Debug |
28 | 96 |
|
29 | 97 | if ($LASTEXITCODE -ne 0) { |
30 | 98 | Write-Error "Build failed!" |
31 | 99 | exit 1 |
32 | 100 | } |
33 | 101 |
|
34 | | -Write-Host "`nCopying plugin files..." -ForegroundColor Cyan |
| 102 | +Write-Host "Build successful." -ForegroundColor Green |
35 | 103 |
|
36 | | -# Create destination directory if it doesn't exist |
37 | | -if (-not (Test-Path $DestinationPath)) { |
38 | | - New-Item -ItemType Directory -Path $DestinationPath -Force | Out-Null |
| 104 | +# Deploy to selected version(s) |
| 105 | +$deploySuccess = $true |
| 106 | + |
| 107 | +if ($Version -eq "VA1" -or $Version -eq "Both") { |
| 108 | + if (-not (Deploy-Plugin -TargetFramework "net48" -DestinationPath $VA1Path -Name "VoiceAttack 1")) { |
| 109 | + $deploySuccess = $false |
| 110 | + } |
39 | 111 | } |
40 | 112 |
|
41 | | -# Copy all items from build output to destination |
42 | | -$buildOutputPath = "EliteVA/bin/Debug/net8.0/" |
43 | | -Get-ChildItem -Path $buildOutputPath -Filter *.dll | ForEach-Object { |
44 | | - Copy-Item $_.FullName -Destination $DestinationPath -Force |
| 113 | +if ($Version -eq "VA2" -or $Version -eq "Both") { |
| 114 | + if (-not (Deploy-Plugin -TargetFramework "net8.0" -DestinationPath $VA2Path -Name "VoiceAttack 2")) { |
| 115 | + $deploySuccess = $false |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +if (-not $deploySuccess) { |
| 120 | + Write-Error "Deployment failed for one or more versions!" |
| 121 | + exit 1 |
45 | 122 | } |
46 | 123 |
|
47 | | -Write-Host "Plugin deployed successfully." -ForegroundColor Green |
| 124 | +# Start VoiceAttack for testing |
| 125 | +if (-not $SkipRestart -and -not $NoTest) { |
| 126 | + Write-Host "`nStarting VoiceAttack for testing..." -ForegroundColor Cyan |
48 | 127 |
|
49 | | -if (-not $SkipVoiceAttackRestart -and $IsWindowsOS) { |
50 | | - Write-Host "`nStarting VoiceAttack..." -ForegroundColor Cyan |
51 | | - $voiceAttackExe = "C:\Program Files (x86)\Steam\steamapps\common\VoiceAttack 2\VoiceAttack.exe" |
52 | | - if (Test-Path $voiceAttackExe) { |
53 | | - Start-Process $voiceAttackExe |
54 | | - Write-Host "Done!" -ForegroundColor Green |
| 128 | + if ($Version -eq "VA1") { |
| 129 | + $va1Exe = "C:\Program Files (x86)\Steam\steamapps\common\VoiceAttack\VoiceAttack.exe" |
| 130 | + Start-VoiceAttackProcess -ExePath $va1Exe -Name "VoiceAttack 1" |
55 | 131 | } |
56 | | - else { |
57 | | - Write-Warning "VoiceAttack.exe not found at: $voiceAttackExe" |
| 132 | + elseif ($Version -eq "VA2") { |
| 133 | + $va2Exe = "C:\Program Files (x86)\Steam\steamapps\common\VoiceAttack 2\VoiceAttack.exe" |
| 134 | + Start-VoiceAttackProcess -ExePath $va2Exe -Name "VoiceAttack 2" |
| 135 | + } |
| 136 | + elseif ($Version -eq "Both") { |
| 137 | + Write-Host "`nBoth versions deployed. Start manually to test:" -ForegroundColor Yellow |
| 138 | + Write-Host " VA1: $(Join-Path (Split-Path $VA1Path -Parent) 'VoiceAttack.exe')" -ForegroundColor Gray |
| 139 | + Write-Host " VA2: C:\Program Files (x86)\Steam\steamapps\common\VoiceAttack 2\VoiceAttack.exe" -ForegroundColor Gray |
58 | 140 | } |
59 | 141 | } |
| 142 | + |
| 143 | +Write-Host "`nDone!" -ForegroundColor Green |
0 commit comments