Files
winutil/functions/private/Get-WinUtilToggleStatus.ps1
Chris Titus 27b0a59abb Zeus-toggle-fix (#4017)
* Fix Get Installed toggle detection and multiple config bugs

Fixes the issue where "Get Installed" in the Tweaks tab was not correctly
pulling all toggle states, plus several additional config bugs discovered
during investigation.

Changes:
- Unified toggle detection logic using Get-WinUtilToggleStatus
- Fixed registry value detection (0 values were incorrectly treated as missing)
- Added DefaultState support for missing registry keys
- Fixed WPFTweaksUTC registry type (QWord → DWord)
- Fixed WPFTweaksServices startup types (TermService, VaultSvc: Automatic → Manual)
- Fixed duplicate order collisions in tweaks
- Fixed FFmpeg display name
- Improved OneDrive removal script reliability
- Improved Copilot removal script with wildcard pattern and null check
- Fixed code formatting (added spaces after if/Foreach statements)

Files changed:
- functions/private/Invoke-WinUtilCurrentSystem.ps1
- functions/private/Get-WinUtilToggleStatus.ps1
- config/tweaks.json
- config/applications.json

Fixes #3762
Fixes #3189
Fixes #3876
Potentially fixes #3008
Potentially fixes #3815

* Fix toggles

---------

Co-authored-by: Akhil Achanta <akhilachanta8@gmail.com>
2026-02-10 13:37:37 -06:00

79 lines
2.7 KiB
PowerShell

Function Get-WinUtilToggleStatus {
<#
.SYNOPSIS
Pulls the registry keys for the given toggle switch and checks whether the toggle should be checked or unchecked
.PARAMETER ToggleSwitch
The name of the toggle to check
.OUTPUTS
Boolean to set the toggle's status to
#>
Param($ToggleSwitch)
$ToggleSwitchReg = $sync.configs.tweaks.$ToggleSwitch.registry
try {
if (($ToggleSwitchReg.path -imatch "hku") -and !(Get-PSDrive -Name HKU -ErrorAction SilentlyContinue)) {
$null = (New-PSDrive -PSProvider Registry -Name HKU -Root HKEY_USERS)
if (Get-PSDrive -Name HKU -ErrorAction SilentlyContinue) {
Write-Debug "HKU drive created successfully"
} else {
Write-Debug "Failed to create HKU drive"
}
}
} catch {
Write-Error "An error occurred regarding the HKU Drive: $_"
return $false
}
if ($ToggleSwitchReg) {
$count = 0
foreach ($regentry in $ToggleSwitchReg) {
try {
if (!(Test-Path $regentry.Path)) {
New-Item -Path $regentry.Path -Force | Out-Null
}
$regstate = (Get-ItemProperty -path $regentry.Path).$($regentry.Name)
if ($regstate -eq $regentry.Value) {
$count += 1
Write-Debug "$($regentry.Name) is true (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))"
} else {
Write-Debug "$($regentry.Name) is false (state: $regstate, value: $($regentry.Value), original: $($regentry.OriginalValue))"
}
if ($null -eq $regstate) {
switch ($regentry.DefaultState) {
"true" {
$regstate = $regentry.Value
$count += 1
}
"false" {
$regstate = $regentry.OriginalValue
}
default {
Write-Error "Entry for $($regentry.Name) does not exist and no DefaultState is defined."
$regstate = $regentry.OriginalValue
}
}
}
} catch {
Write-Error "An unexpected error occurred: $_"
}
}
if ($count -eq $ToggleSwitchReg.Count) {
Write-Debug "$($ToggleSwitchReg.Name) is true (count: $count)"
return $true
} else {
Write-Debug "$($ToggleSwitchReg.Name) is false (count: $count)"
return $false
}
} else {
return $false
}
}