Skip to content

Commit 82c2abe

Browse files
authored
Merge pull request #16 from deiteris/main
Improve SteamVR settings serialization, fix shortcut checkboxes
2 parents 3bf4d11 + b24338b commit 82c2abe

2 files changed

Lines changed: 22 additions & 15 deletions

File tree

windows/web/slimevr_web_installer.nsi

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -233,8 +233,8 @@ Function endPageLeave
233233

234234
SetOutPath $INSTDIR
235235

236-
${NSD_GetState} $CREATE_DESKTOP_SHORTCUT $0
237-
${NSD_GetState} $CREATE_STARTMENU_SHORTCUTS $1
236+
${NSD_GetState} $CREATE_STARTMENU_SHORTCUTS $0
237+
${NSD_GetState} $CREATE_DESKTOP_SHORTCUT $1
238238
${NSD_GetState} $OPEN_DOCUMENTATION $2
239239

240240
${If} $0 = 1

windows/web/steamvr.ps1

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ param (
55
[parameter(Position=2)][switch]$Uninstall = $false
66
)
77

8+
# Required for System.Web.Script.Serialization.JavaScriptSerializer
9+
[void][System.Reflection.Assembly]::LoadWithPartialName("System.Web.Extensions")
10+
811
# Prune external SlimeVR driver(s)
912
$OpenVrConfigPath = "$env:LOCALAPPDATA\openvr\openvrpaths.vrpath"
1013
$OpenVrConfig = Get-Content -Path $OpenVrConfigPath -Encoding utf8 | ConvertFrom-Json
@@ -36,23 +39,27 @@ if ($ExternalDriverPaths.Length -eq 0) {
3639
if ($Uninstall -eq $true) {
3740
$SteamVrSettingsPath = "$SteamPath\config\steamvr.vrsettings"
3841
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+
4046
# 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
5154
}
55+
$Trackers[$Tracker.Key] = $Tracker.Value
5256
}
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)
5560
}
61+
62+
[System.IO.File]::WriteAllLines($SteamVrSettingsPath, $JsonSerializer.Serialize($SteamVrSettings))
5663
}
5764

5865
$SteamVrPaths = @("$SteamPath\steamapps\common\SteamVR")

0 commit comments

Comments
 (0)