mirror of
https://github.com/ChrisTitusTech/winutil.git
synced 2026-10-08 11:39:10 +11:00
* feat: add automated environment report export * refactor: address code review comments * fix: refresh toggle state in environment report * fix: surface environment report read failures * test: make registry failure explicit --------- Co-authored-by: Chris Titus <contact@christitus.com>
54 lines
1.5 KiB
PowerShell
54 lines
1.5 KiB
PowerShell
Function Get-WinUtilToggleStatus {
|
|
param(
|
|
$ToggleSwitch,
|
|
[switch]$BypassCache,
|
|
[switch]$StopOnReadError
|
|
)
|
|
|
|
$ToggleSwitchReg = $sync.configs.tweaks.$ToggleSwitch.registry
|
|
|
|
if (-not $BypassCache) {
|
|
if ($null -eq $sync.ToggleStatusCache) {
|
|
$sync.ToggleStatusCache = @{}
|
|
}
|
|
|
|
if ($sync.ToggleStatusCache.ContainsKey($ToggleSwitch)) {
|
|
return [bool]$sync.ToggleStatusCache[$ToggleSwitch]
|
|
}
|
|
}
|
|
|
|
$readErrorAction = if ($StopOnReadError) { "Stop" } else { "Continue" }
|
|
|
|
if (-not (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) {
|
|
New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS -ErrorAction $readErrorAction | Out-Null
|
|
}
|
|
|
|
foreach ($regentry in $ToggleSwitchReg) {
|
|
|
|
if (Test-Path $regentry.Path -ErrorAction $readErrorAction) {
|
|
$regstate = (Get-ItemProperty -Path $regentry.Path -ErrorAction $readErrorAction).$($regentry.Name)
|
|
} else {
|
|
$regstate = $null
|
|
}
|
|
|
|
if ($null -eq $regstate) {
|
|
switch ([string]$regentry.DefaultState) {
|
|
"true" { $regstate = $regentry.Value }
|
|
"false" { $regstate = $regentry.OriginalValue }
|
|
}
|
|
}
|
|
|
|
if ($regstate -ne $regentry.Value) {
|
|
if (-not $BypassCache) {
|
|
$sync.ToggleStatusCache[$ToggleSwitch] = $false
|
|
}
|
|
return $false
|
|
}
|
|
}
|
|
|
|
if (-not $BypassCache) {
|
|
$sync.ToggleStatusCache[$ToggleSwitch] = $true
|
|
}
|
|
return $true
|
|
}
|