-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.ps1
126 lines (106 loc) · 2.8 KB
/
install.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
param (
[Parameter(Mandatory)]
[ValidateSet('First', 'Last', 'Enable', 'Disable', 'Remove', 'Before', 'After')]
[string] $Mode,
[Parameter(Mandatory = $False)]
[string] $LayerPath,
[Parameter(Mandatory = $False)]
[string] $RelativeTo
)
if ("${LayerPath}" -eq "") {
if (Test-Path out/APILayer.json) {
$LayerPath = "out/APILayer.json"
} elseif (Test-Path APILayer.json) {
$LayerPath = "APILayer.json"
}
}
if ("${LayerPath}" -eq "") {
Write-Host "Could not find APILayer.json"
return 1
}
if (-not (Test-Path $LayerPath)) {
Write-Host "LayerPath '${LayerPath}' does not exist."
return 1
}
$LayerPath = (Get-Item $LayerPath).FullName
if ($Mode -eq "Before" -or $Mode -eq "After") {
if ("${RelativeTo}" -eq "") {
Write-Host "Specify -RelativeTo if specifying -Mode Before or -Mode After."
return 1
}
}
$key = "HKLM:\SOFTWARE\Khronos\OpenXR\1\ApiLayers\Implicit"
$layers = Get-Item $key
if (-not (Test-Path $key)) {
New-Item -ItemPath $key -Frce
}
$have_this_layer = $null -ne $layers.GetValue($LayerPath, $null)
if ("${RelativeTo}" -ne "") {
$have_relative_layer = $null -ne $layers.GetValue($RelativeTo, $null)
if (-not $have_relative_layer) {
Write-Host "-RelativeTo '${RelativeTo}' is not in the registry."
return 1
}
}
switch ($Mode) {
"Disable" {
if (-Not $have_this_layer) {
Write-Host "Layer already not in registry"
return;
}
Set-ItemProperty -Path $key -Name $LayerPath -Value 1
Write-Host "Disabled layer ${LayerPath}."
return;
}
"Enable" {
if (-Not $have_this_layer) {
Write-Host "Layer not in registry; use 'First' or 'Last' to install"
return;
}
Set-ItemProperty -Path $key -Name $LayerPath -Value 0
Write-Host "Enabled layer ${LayerPath}."
return;
}
"Remove" {
if (-Not $have_this_layer) {
Write-Host "Layer already not in registry"
return;
}
Remove-ItemProperty -Path $key -Name $LayerPath
Write-Host "Removed layer ${LayerPath}"
return;
}
}
# Okay, if we get here, we're definitely rebuilding the layer list anyway. Mode is 'First' or 'Last'
$new_layers = @()
$this_layer = @{ Path = $LayerPath; Disabled = 0 }
if ($Mode -eq "First") {
$new_layers += $this_layer
}
foreach ($layer in $layers.Property) {
$disabled = $layers.GetValue($layer, $null)
if ($null -eq $disabled) {
continue;
}
if ($layer -eq $this_layer.Path) {
continue;
}
$relative = $RelativeTo -eq $layer
if ($relative -and $Mode -eq "Before") {
$new_layers += $this_layer
}
$new_layers += @(@{ Path = $layer; Disabled = $disabled })
if ($relative -and $Mode -eq "After") {
$new_layers += $this_layer
}
}
if ($Mode -eq "Last") {
$new_layers += $this_layer
}
Clear-Item -Path $key
foreach ($layer in $new_layers) {
$path = $layer.Path
$disabled = $layer.Disabled
Set-ItemProperty -Path $key -Name $path -Value $disabled
}
Write-Host "Updated OpenXR layer list."