Skip to content

Commit

Permalink
improve handling if entry does not exist
Browse files Browse the repository at this point in the history
- add DefaultState property
- add handler for DefaultState in Get-WinUtilToggleStatus
  • Loading branch information
MyDrift-user committed Dec 9, 2024
1 parent 6b1a914 commit a2c3100
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 1 deletion.
18 changes: 18 additions & 0 deletions config/tweaks.json
Original file line number Diff line number Diff line change
Expand Up @@ -3349,6 +3349,7 @@
"Name": "BingSearchEnabled",
"Value": "1",
"OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord"
}
],
Expand Down Expand Up @@ -3392,6 +3393,7 @@
"Name": "VerboseStatus",
"Value": "1",
"OriginalValue": "0",
"DefaultState": "false",
"Type": "DWord"
}
],
Expand All @@ -3410,20 +3412,23 @@
"Name": "HideRecommendedSection",
"Value": "0",
"OriginalValue": "1",
"DefaultState": "true",
"Type": "DWord"
},
{
"Path": "HKLM:\\SOFTWARE\\Microsoft\\PolicyManager\\current\\device\\Education",
"Name": "IsEducationEnvironment",
"Value": "0",
"OriginalValue": "1",
"DefaultState": "true",
"Type": "DWord"
},
{
"Path": "HKLM:\\SOFTWARE\\Policies\\Microsoft\\Windows\\Explorer",
"Name": "HideRecommendedSection",
"Value": "0",
"OriginalValue": "1",
"DefaultState": "true",
"Type": "DWord"
}
],
Expand All @@ -3442,6 +3447,7 @@
"Name": "WindowArrangementActive",
"Value": "1",
"OriginalValue": "0",
"DefaultState": "true",
"Type": "String"
}
],
Expand All @@ -3460,6 +3466,7 @@
"Name": "EnableSnapAssistFlyout",
"Value": "1",
"OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord"
}
],
Expand Down Expand Up @@ -3488,6 +3495,7 @@
"Name": "SnapAssist",
"Value": "1",
"OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord"
}
],
Expand Down Expand Up @@ -3516,20 +3524,23 @@
"Name": "MouseSpeed",
"Value": "1",
"OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord"
},
{
"Path": "HKCU:\\Control Panel\\Mouse",
"Name": "MouseThreshold1",
"Value": "6",
"OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord"
},
{
"Path": "HKCU:\\Control Panel\\Mouse",
"Name": "MouseThreshold2",
"Value": "10",
"OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord"
}
],
Expand All @@ -3548,6 +3559,7 @@
"Name": "Flags",
"Value": "510",
"OriginalValue": "58",
"DefaultState": "true",
"Type": "DWord"
}
],
Expand Down Expand Up @@ -3622,6 +3634,7 @@
"Name": "SearchboxTaskbarMode",
"Value": "1",
"OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord"
}
],
Expand All @@ -3640,6 +3653,7 @@
"Name": "ShowTaskViewButton",
"Value": "1",
"OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord"
}
],
Expand All @@ -3658,6 +3672,7 @@
"Name": "TaskbarDa",
"Value": "1",
"OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord"
}
],
Expand All @@ -3676,6 +3691,7 @@
"Name": "TaskbarAl",
"Value": "1",
"OriginalValue": "0",
"DefaultState": "true",
"Type": "DWord"
}
],
Expand All @@ -3694,13 +3710,15 @@
"Name": "DisplayParameters",
"Value": "1",
"OriginalValue": "0",
"DefaultState": "false",
"Type": "DWord"
},
{
"Path": "HKLM:\\SYSTEM\\CurrentControlSet\\Control\\CrashControl",
"Name": "DisableEmoticon",
"Value": "1",
"OriginalValue": "0",
"DefaultState": "false",
"Type": "DWord"
}
],
Expand Down
24 changes: 23 additions & 1 deletion functions/private/Get-WinUtilToggleStatus.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,37 @@ Function Get-WinUtilToggleStatus {

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 (!$regstate) {
write-host "missing $($regentry.Name)"
switch ($regentry.DefaultState) {
"true" {
write-host "true"
$regstate = $regentry.Value
$count += 1
}
"false" {
write-host "false"
$regstate = $regentry.OriginalValue
}
default {
write-host "default"
Write-Error "Entry for $($regentry.Name) does not exist and no DefaultState is defined."
$regstate = $regentry.OriginalValue
}
}
}
} catch {
Write-Error "An error occurred while accessing registry entry $($regentry.Path): $_"
Write-Error "An unexpected error occurred: $_"
}
}

Expand Down

0 comments on commit a2c3100

Please sign in to comment.