mirror of
https://github.com/ChrisTitusTech/winutil
synced 2026-04-05 22:28:31 +00:00
* cleaned up typo, fixes, grammatical and other related fixes (#2) * typo in Lightshot app name * remove trailing comma in applications.json * consistent capitalization of Windows, WinGet - only user-facing text - includes update to devdocs-generator.ps1, so docs for tweaks modifying registry will have `Windows settings` rather than `windows settings` * various fixes for typos, style, punctuation and capitalization * capitalize 'AM' * Update README.md change formatting for GitHub UI interaction form code format (` `) to bold md Co-authored-by: Jay <65828559+Jay-o-Way@users.noreply.github.com> * typos and wording in docs --------- Co-authored-by: Jay <65828559+Jay-o-Way@users.noreply.github.com>
79 lines
2.7 KiB
PowerShell
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
|
|
}
|
|
}
|