-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Make MPO tweak a three-state control #4897
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
78dc3e7
refactor: make MPO tweak a three-state control
mewclouds 64fc478
docs: explain MPO tweak states
mewclouds 715e830
docs: address code review comments
mewclouds dff85e4
refactor: make Multiplane Overlay config-driven
mewclouds a9bb80a
Merge remote-tracking branch 'upstream/main'
mewclouds File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| function Get-WinUtilRegistryComboState { | ||
| <# | ||
| .SYNOPSIS | ||
| Finds the configured combo-box state matching the current registry values. | ||
|
|
||
| .PARAMETER Registry | ||
| Registry settings containing a value mapping for each supported state. | ||
|
|
||
| .OUTPUTS | ||
| The name of the matching state. | ||
| #> | ||
| param( | ||
| [Parameter(Mandatory)] | ||
| $Registry | ||
| ) | ||
|
|
||
| foreach ($state in $Registry[0].Values.PSObject.Properties) { | ||
| $stateMatches = $true | ||
| foreach ($setting in @($Registry)) { | ||
| $currentValue = Get-WinUtilRegistryComboValue -Setting $setting | ||
| $actualValue = if ($currentValue.Exists -and $null -ne $currentValue.Value) { $currentValue.Value } else { $setting.DefaultValue } | ||
| $configuredValue = $setting.Values.PSObject.Properties[$state.Name].Value | ||
| # Removal represents the effective Windows default when matching the current state. | ||
| $expectedValue = if ($configuredValue -eq "<RemoveEntry>") { $setting.DefaultValue } else { $configuredValue } | ||
| if ([string]$actualValue -ne [string]$expectedValue) { | ||
| $stateMatches = $false | ||
| break | ||
| } | ||
| } | ||
| if ($stateMatches) { | ||
| return $state.Name | ||
| } | ||
| } | ||
|
|
||
| throw "Registry values do not match a supported state." | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| function Get-WinUtilRegistryComboValue { | ||
| <# | ||
| .SYNOPSIS | ||
| Reads one registry value for a registry-backed combo-box state. | ||
|
|
||
| .PARAMETER Setting | ||
| The registry setting from the combo-box configuration. | ||
| #> | ||
| param( | ||
| [Parameter(Mandatory)] | ||
| $Setting | ||
| ) | ||
|
|
||
| try { | ||
| $item = Get-ItemProperty -Path $Setting.Path -Name $Setting.Name -ErrorAction Stop | ||
| $property = $item.PSObject.Properties[$Setting.Name] | ||
| return [pscustomobject]@{ Exists = $null -ne $property; Value = $property.Value } | ||
| } catch [System.Management.Automation.PSArgumentException] { | ||
| # The registry provider uses PSArgumentException when a named value is absent. | ||
| return [pscustomobject]@{ Exists = $false; Value = $null } | ||
| } catch [System.Management.Automation.ItemNotFoundException] { | ||
| return [pscustomobject]@{ Exists = $false; Value = $null } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,78 @@ | ||
| function Set-WinUtilRegistryComboState { | ||
| <# | ||
| .SYNOPSIS | ||
| Applies and verifies a config-defined registry combo-box state. | ||
|
|
||
| .PARAMETER Registry | ||
| Registry settings containing a value mapping for each supported state. | ||
|
|
||
| .PARAMETER State | ||
| The state name to apply. | ||
| #> | ||
| param( | ||
| [Parameter(Mandatory)] | ||
| $Registry, | ||
|
|
||
| [Parameter(Mandatory)] | ||
| [string]$State | ||
| ) | ||
|
|
||
| if ($Registry[0].Values.PSObject.Properties.Name -notcontains $State) { | ||
| throw "Unknown registry state '$State'." | ||
| } | ||
|
|
||
| # Preserve exact prior values so a partial update can be rolled back. | ||
| $previousValues = foreach ($setting in @($Registry)) { | ||
| $currentValue = Get-WinUtilRegistryComboValue -Setting $setting | ||
| [pscustomobject]@{ Setting = $setting; Exists = $currentValue.Exists; Value = $currentValue.Value } | ||
| } | ||
|
|
||
| try { | ||
| foreach ($setting in @($Registry)) { | ||
| $configuredValue = $setting.Values.PSObject.Properties[$State].Value | ||
| $previousValue = $previousValues | Where-Object Setting -EQ $setting | ||
| if ($configuredValue -ne "<RemoveEntry>" -or $previousValue.Exists) { | ||
| Set-WinUtilRegistry -Name $setting.Name -Path $setting.Path -Type $setting.Type -Value $configuredValue | ||
| } | ||
| } | ||
|
|
||
| # Set-WinUtilRegistry reports write errors without throwing, so verify each result explicitly. | ||
| foreach ($setting in @($Registry)) { | ||
| $configuredValue = $setting.Values.PSObject.Properties[$State].Value | ||
| $currentValue = Get-WinUtilRegistryComboValue -Setting $setting | ||
| $writeMatches = if ($configuredValue -eq "<RemoveEntry>") { | ||
| -not $currentValue.Exists | ||
| } else { | ||
| $currentValue.Exists -and [string]$currentValue.Value -eq [string]$configuredValue | ||
| } | ||
| if (-not $writeMatches) { | ||
| throw "The registry values did not match the requested state." | ||
| } | ||
| } | ||
| } catch { | ||
| $applyError = $_.Exception.Message | ||
| if ([string]::IsNullOrWhiteSpace($applyError)) { | ||
| $applyError = "The registry values did not match the requested state." | ||
| } | ||
| $rollbackFailed = $false | ||
| foreach ($previousValue in $previousValues) { | ||
| try { | ||
| $currentValue = Get-WinUtilRegistryComboValue -Setting $previousValue.Setting | ||
| if ($previousValue.Exists -or $currentValue.Exists) { | ||
| $rollbackValue = if ($previousValue.Exists) { $previousValue.Value } else { "<RemoveEntry>" } | ||
| Set-WinUtilRegistry -Name $previousValue.Setting.Name -Path $previousValue.Setting.Path -Type $previousValue.Setting.Type -Value $rollbackValue | ||
| } | ||
| $restoredValue = Get-WinUtilRegistryComboValue -Setting $previousValue.Setting | ||
| if ($restoredValue.Exists -ne $previousValue.Exists -or ($restoredValue.Exists -and [string]$restoredValue.Value -ne [string]$previousValue.Value)) { | ||
| $rollbackFailed = $true | ||
| } | ||
| } catch { | ||
| $rollbackFailed = $true | ||
| } | ||
| } | ||
| if ($rollbackFailed) { | ||
| throw "Unable to apply registry state '$State': $applyError. The previous registry state could not be restored." | ||
| } | ||
| throw "Unable to apply registry state '$State': $applyError" | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.