|
5 | 5 | [parameter(Position=2)][switch]$Uninstall = $false |
6 | 6 | ) |
7 | 7 |
|
| 8 | +# Required for System.Web.Script.Serialization.JavaScriptSerializer |
| 9 | +[void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions") |
| 10 | + |
8 | 11 | # Prune external SlimeVR driver(s) |
9 | 12 | $OpenVrConfigPath = "$env:LOCALAPPDATA\openvr\openvrpaths.vrpath" |
10 | 13 | $OpenVrConfig = Get-Content -Path $OpenVrConfigPath -Encoding utf8 | ConvertFrom-Json |
@@ -36,23 +39,27 @@ if ($ExternalDriverPaths.Length -eq 0) { |
36 | 39 | if ($Uninstall -eq $true) { |
37 | 40 | $SteamVrSettingsPath = "$SteamPath\config\steamvr.vrsettings" |
38 | 41 | Write-Host "Removing trackers from `"$SteamVrSettingsPath`"" |
39 | | - $SteamVrSettings = (Get-Content -Path $SteamVrSettingsPath -Encoding utf8) -creplace "/devices/SlimeVR/", "/devices/SlimeVR1/" | ConvertFrom-Json |
| 42 | + $SteamVrSettingsContent = Get-Content -Path $SteamVrSettingsPath -Encoding utf8 |
| 43 | + $JsonSerializer = New-Object -TypeName "System.Web.Script.Serialization.JavaScriptSerializer" -Property @{MaxJsonLength = [System.Int32]::MaxValue} |
| 44 | + $SteamVrSettings = $JsonSerializer.DeserializeObject($SteamVrSettingsContent) |
| 45 | + |
40 | 46 | # Remove "driver_SlimeVR" entry if the driver was disabled manually |
41 | | - $SteamVrSettings.PSObject.Properties.Remove("driver_SlimeVR") |
42 | | - if ($SteamVrSettings.trackers) { |
43 | | - $SettingsTrackers = $SteamVrSettings.trackers.PSObject.Properties |
44 | | - $Trackers = New-Object -TypeName PSCustomObject |
45 | | - if ($SettingsTrackers.Value.Count) { |
46 | | - foreach ($Tracker in $SettingsTrackers) { |
47 | | - if ($Tracker.Name -match "^/devices/slimevr(1)?/") { |
48 | | - continue |
49 | | - } |
50 | | - Add-Member -InputObject $Trackers -MemberType NoteProperty -Name $Tracker.Name -Value $Tracker.Value |
| 47 | + $SteamVrSettings.Remove("driver_SlimeVR") |
| 48 | + |
| 49 | + if ($SteamVrSettings.trackers -and $SteamVrSettings.trackers.Count) { |
| 50 | + $Trackers = New-Object -TypeName "System.Collections.Generic.Dictionary[[string], [object]]" |
| 51 | + foreach ($Tracker in $SteamVrSettings.trackers.GetEnumerator()) { |
| 52 | + if ($Tracker.Key -match "^/devices/slimevr/") { |
| 53 | + continue |
51 | 54 | } |
| 55 | + $Trackers[$Tracker.Key] = $Tracker.Value |
52 | 56 | } |
53 | | - $SteamVrSettings.trackers = $Trackers |
54 | | - [System.IO.File]::WriteAllLines($SteamVrSettingsPath, (ConvertTo-Json -InputObject $SteamVrSettings)) |
| 57 | + # Why? Because you cannot just replace key value without a circular reference error |
| 58 | + $SteamVrSettings.Remove('trackers') |
| 59 | + $SteamVrSettings.Add('trackers', $Trackers) |
55 | 60 | } |
| 61 | + |
| 62 | + [System.IO.File]::WriteAllLines($SteamVrSettingsPath, $JsonSerializer.Serialize($SteamVrSettings)) |
56 | 63 | } |
57 | 64 |
|
58 | 65 | $SteamVrPaths = @("$SteamPath\steamapps\common\SteamVR") |
|
0 commit comments