From 8034e855218727cedc976db93b63c1dd05a707b4 Mon Sep 17 00:00:00 2001 From: Gabi <218829269+GabiNun2@users.noreply.github.com> Date: Tue, 19 May 2026 21:16:06 +0300 Subject: [PATCH] Remove Write-Debug (#4498) * Update Invoke-WinUtilCurrentSystem.ps1 * Update Invoke-WinUtilFontScaling.ps1 * Update Invoke-WinUtilTweaks.ps1 * Update Reset-WPFCheckBoxes.ps1 * Update Set-Preferences.ps1 * Update Update-WinUtilSelections.ps1 * Update Invoke-WPFSelectedCheckboxesUpdate.ps1 * Update Invoke-WPFtweaksbutton.ps1 * Update main.ps1 * Update main.ps1 * Update main.ps1 * Update main.ps1 * Update main.ps1 * Merge branch 'main' into Remove-Write-Debug --- .../private/Invoke-WinUtilCurrentSystem.ps1 | 4 --- .../private/Invoke-WinUtilFontScaling.ps1 | 5 --- functions/private/Invoke-WinUtilTweaks.ps1 | 30 ++++------------ functions/private/Reset-WPFCheckBoxes.ps1 | 11 ------ functions/private/Set-Preferences.ps1 | 2 -- .../private/Update-WinUtilSelections.ps1 | 9 ----- .../Invoke-WPFSelectedCheckboxesUpdate.ps1 | 7 ---- functions/public/Invoke-WPFtweaksbutton.ps1 | 3 -- scripts/main.ps1 | 34 ------------------- 9 files changed, 7 insertions(+), 98 deletions(-) diff --git a/functions/private/Invoke-WinUtilCurrentSystem.ps1 b/functions/private/Invoke-WinUtilCurrentSystem.ps1 index 2d2bf894..23fa7a14 100644 --- a/functions/private/Invoke-WinUtilCurrentSystem.ps1 +++ b/functions/private/Invoke-WinUtilCurrentSystem.ps1 @@ -117,10 +117,6 @@ Function Invoke-WinUtilCurrentSystem { if ($values -notcontains $false) { Write-Output $Config } - } else { - if ($invokeScript -or $appxKeys) { - Write-Debug "Skipping $Config in Get Installed: no detectable registry, scheduled task, or service state." - } } } } diff --git a/functions/private/Invoke-WinUtilFontScaling.ps1 b/functions/private/Invoke-WinUtilFontScaling.ps1 index e57e8d8c..1a88094e 100644 --- a/functions/private/Invoke-WinUtilFontScaling.ps1 +++ b/functions/private/Invoke-WinUtilFontScaling.ps1 @@ -67,7 +67,6 @@ function Invoke-WinUtilFontScaling { # Calculates and applies the new font size $newValue = [math]::Round($originalValue * $ScaleFactor, 1) $sync.Form.Resources[$resourceName] = $newValue - Write-Debug "Scaled $resourceName from original $originalValue to $newValue (factor: $ScaleFactor)" } } catch { @@ -80,8 +79,4 @@ function Invoke-WinUtilFontScaling { $percentage = [math]::Round($ScaleFactor * 100) $sync.FontScalingValue.Text = "$percentage%" } - - Write-Debug "Font scaling applied with factor: $ScaleFactor" } - - diff --git a/functions/private/Invoke-WinUtilTweaks.ps1 b/functions/private/Invoke-WinUtilTweaks.ps1 index bb5a755c..f3812c88 100644 --- a/functions/private/Invoke-WinUtilTweaks.ps1 +++ b/functions/private/Invoke-WinUtilTweaks.ps1 @@ -21,8 +21,7 @@ function Invoke-WinUtilTweaks { $KeepServiceStartup = $true ) - Write-Debug "Tweaks: $($CheckBox)" - if($undo) { + if ($undo) { $Values = @{ Registry = "OriginalValue" Service = "OriginalType" @@ -37,18 +36,16 @@ function Invoke-WinUtilTweaks { ScriptType = "InvokeScript" } } - if($sync.configs.tweaks.$CheckBox.service) { - Write-Debug "KeepServiceStartup is $KeepServiceStartup" + if ($sync.configs.tweaks.$CheckBox.service) { $sync.configs.tweaks.$CheckBox.service | ForEach-Object { $changeservice = $true # The check for !($undo) is required, without it the script will throw an error for accessing unavailable member, which's the 'OriginalService' Property - if($KeepServiceStartup -AND !($undo)) { + if ($KeepServiceStartup -AND !($undo)) { try { # Check if the service exists $service = Get-Service -Name $psitem.Name -ErrorAction Stop if(!($service.StartType.ToString() -eq $psitem.$($values.OriginalService))) { - Write-Debug "Service $($service.Name) was changed in the past to $($service.StartType.ToString()) from it's original type of $($psitem.$($values.OriginalService)), will not change it to $($psitem.$($values.service))" $changeservice = $false } } catch [System.ServiceProcess.ServiceNotFoundException] { @@ -56,41 +53,28 @@ function Invoke-WinUtilTweaks { } } - if($changeservice) { - Write-Debug "$($psitem.Name) and state is $($psitem.$($values.service))" + if ($changeservice) { Set-WinUtilService -Name $psitem.Name -StartupType $psitem.$($values.Service) } } } - if($sync.configs.tweaks.$CheckBox.registry) { + if ($sync.configs.tweaks.$CheckBox.registry) { $sync.configs.tweaks.$CheckBox.registry | ForEach-Object { - Write-Debug "$($psitem.Name) and state is $($psitem.$($values.registry))" - if (($psitem.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." - } - } Set-WinUtilRegistry -Name $psitem.Name -Path $psitem.Path -Type $psitem.Type -Value $psitem.$($values.registry) } } - if($sync.configs.tweaks.$CheckBox.$($values.ScriptType)) { + if ($sync.configs.tweaks.$CheckBox.$($values.ScriptType)) { $sync.configs.tweaks.$CheckBox.$($values.ScriptType) | ForEach-Object { - Write-Debug "$($psitem) and state is $($psitem.$($values.ScriptType))" $Scriptblock = [scriptblock]::Create($psitem) Invoke-WinUtilScript -ScriptBlock $scriptblock -Name $CheckBox } } - if(!$undo) { + if (!$undo) { if($sync.configs.tweaks.$CheckBox.appx) { $sync.configs.tweaks.$CheckBox.appx | ForEach-Object { - Write-Debug "UNDO $($psitem.Name)" Remove-WinUtilAPPX -Name $psitem } } - } } diff --git a/functions/private/Reset-WPFCheckBoxes.ps1 b/functions/private/Reset-WPFCheckBoxes.ps1 index 59ae6533..17536eaf 100644 --- a/functions/private/Reset-WPFCheckBoxes.ps1 +++ b/functions/private/Reset-WPFCheckBoxes.ps1 @@ -23,14 +23,6 @@ function Reset-WPFCheckBoxes { $CheckBoxesToCheck = $sync.selectedApps + $sync.selectedTweaks + $sync.selectedFeatures $CheckBoxes = ($sync.GetEnumerator()).where{ $_.Value -is [System.Windows.Controls.CheckBox] -and $_.Name -notlike "WPFToggle*" -and $_.Name -like "$checkboxfilterpattern"} - Write-Debug "Getting checkboxes to set, number of checkboxes: $($CheckBoxes.Count)" - - if ($CheckBoxesToCheck -ne "") { - $debugMsg = "CheckBoxes to Check are: " - $CheckBoxesToCheck | ForEach-Object { $debugMsg += "$_, " } - $debugMsg = $debugMsg -replace (',\s*$', '') - Write-Debug "$debugMsg" - } foreach ($CheckBox in $CheckBoxes) { $checkboxName = $CheckBox.Key @@ -43,11 +35,9 @@ function Reset-WPFCheckBoxes { if ($CheckBoxesToCheck -contains $checkboxName) { # If it exists, set IsChecked to true $sync.$checkboxName.IsChecked = $true - Write-Debug "$checkboxName is checked" } else { # If it doesn't exist, set IsChecked to false $sync.$checkboxName.IsChecked = $false - Write-Debug "$checkboxName is not checked" } } @@ -68,7 +58,6 @@ function Reset-WPFCheckBoxes { foreach ($toggle in $allToggles) { if ($importedToggles -contains $toggle.Key) { $sync[$toggle.Key].IsChecked = $true - Write-Debug "Restoring toggle: $($toggle.Key) = checked" } # Toggles not present in the import are intentionally left untouched; # their current UI state already reflects the real system state. diff --git a/functions/private/Set-Preferences.ps1 b/functions/private/Set-Preferences.ps1 index 56338c53..1b411ec7 100644 --- a/functions/private/Set-Preferences.ps1 +++ b/functions/private/Set-Preferences.ps1 @@ -34,7 +34,6 @@ function Set-Preferences{ $ini = "" foreach($key in $sync.preferences.Keys) { $pref = "$($key)=$($sync.preferences.$key)" - Write-Debug "Saving pref: $($pref)" $ini = $ini + $pref + "`r`n" } $ini | Out-File $iniPath @@ -49,7 +48,6 @@ function Set-Preferences{ $arr = $line -split "=",-2 $key = $arr[0] -replace "\s","" $value = $arr[1] -replace "\s","" - Write-Debug "Preference: Key = '$($key)' Value ='$($value)'" $sync.preferences.$key = $value } } diff --git a/functions/private/Update-WinUtilSelections.ps1 b/functions/private/Update-WinUtilSelections.ps1 index a4d65f0e..e1c5e99a 100644 --- a/functions/private/Update-WinUtilSelections.ps1 +++ b/functions/private/Update-WinUtilSelections.ps1 @@ -12,8 +12,6 @@ function Update-WinUtilSelections { $flatJson ) - Write-Debug "JSON to import: $($flatJson)" - foreach ($item in $flatJson) { # Ensure each item is treated as a string to handle PSCustomObject from JSON deserialization $cbkey = [string]$item @@ -51,11 +49,4 @@ function Update-WinUtilSelections { } } } - - Write-Debug "-------------------------------------" - Write-Debug "Selected Apps: $($sync.selectedApps)" - Write-Debug "Selected Tweaks: $($sync.selectedTweaks)" - Write-Debug "Selected Toggles: $($sync.selectedToggles)" - Write-Debug "Selected Features: $($sync.selectedFeatures)" - Write-Debug "--------------------------------------" } diff --git a/functions/public/Invoke-WPFSelectedCheckboxesUpdate.ps1 b/functions/public/Invoke-WPFSelectedCheckboxesUpdate.ps1 index 6bdee481..653efad6 100644 --- a/functions/public/Invoke-WPFSelectedCheckboxesUpdate.ps1 +++ b/functions/public/Invoke-WPFSelectedCheckboxesUpdate.ps1 @@ -85,11 +85,4 @@ function Invoke-WPFSelectedCheckboxesUpdate{ Write-Host "Unknown group for checkbox: $($appKey)" } } - - Write-Debug "-------------------------------------" - Write-Debug "Selected Apps: $($sync.selectedApps)" - Write-Debug "Selected Tweaks: $($sync.selectedTweaks)" - Write-Debug "Selected Toggles: $($sync.selectedToggles)" - Write-Debug "Selected Features: $($sync.selectedFeatures)" - Write-Debug "--------------------------------------" } diff --git a/functions/public/Invoke-WPFtweaksbutton.ps1 b/functions/public/Invoke-WPFtweaksbutton.ps1 index a0f9accc..1c413a66 100644 --- a/functions/public/Invoke-WPFtweaksbutton.ps1 +++ b/functions/public/Invoke-WPFtweaksbutton.ps1 @@ -29,8 +29,6 @@ function Invoke-WPFtweaksbutton { return } - Write-Debug "Number of tweaks to process: $($Tweaks.Count)" - if ($restorePointSelected) { $sync.ProcessRunning = $true @@ -58,7 +56,6 @@ function Invoke-WPFtweaksbutton { # The leading "," in the ParameterList is necessary because we only provide one argument and powershell cannot be convinced that we want a nested loop with only one argument otherwise $handle = Invoke-WPFRunspace -ParameterList @(("tweaks", $tweaksToRun), ("dnsProvider", $dnsProvider), ("completedSteps", $completedSteps), ("totalSteps", $totalSteps)) -ScriptBlock { param($tweaks, $dnsProvider, $completedSteps, $totalSteps) - Write-Debug "Inside Number of tweaks to process: $($Tweaks.Count)" $sync.ProcessRunning = $true diff --git a/scripts/main.ps1 b/scripts/main.ps1 index d678f810..d6d3cf85 100644 --- a/scripts/main.ps1 +++ b/scripts/main.ps1 @@ -13,14 +13,12 @@ $maxthreads = [int]$env:NUMBER_OF_PROCESSORS # Create a new session state for parsing variables into our runspace $hashVars = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'sync',$sync,$Null -$debugVar = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'DebugPreference',$DebugPreference,$Null $uiVar = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'PARAM_NOUI',$PARAM_NOUI,$Null $offlineVar = New-object System.Management.Automation.Runspaces.SessionStateVariableEntry -ArgumentList 'PARAM_OFFLINE',$PARAM_OFFLINE,$Null $InitialSessionState = [System.Management.Automation.Runspaces.InitialSessionState]::CreateDefault() # Add the variable to the session state $InitialSessionState.Variables.Add($hashVars) -$InitialSessionState.Variables.Add($debugVar) $InitialSessionState.Variables.Add($uiVar) $InitialSessionState.Variables.Add($offlineVar) @@ -210,7 +208,6 @@ $sync.keys | ForEach-Object { $sync["$psitem"].Add_MouseUp({ [System.Object]$Sender = $args[0] Start-Process $Sender.ToolTip -ErrorAction Stop - Write-Debug "Opening: $($Sender.ToolTip)" }) } @@ -316,7 +313,6 @@ $sync["Form"].Add_MouseDoubleClick({ }) $sync["Form"].Add_Deactivated({ - Write-Debug "WinUtil lost focus" Invoke-WPFPopup -Action "Hide" -Popups @("Settings", "Theme", "FontScaling") }) @@ -330,10 +326,6 @@ $sync["Form"].Add_ContentRendered({ $screenWidth = $primaryScreen.Bounds.Width $screenHeight = $primaryScreen.Bounds.Height - # Print the screen size - Write-Debug "Primary Monitor Width: $screenWidth pixels" - Write-Debug "Primary Monitor Height: $screenHeight pixels" - # Compare with the primary monitor size if ($sync.Form.ActualWidth -gt $screenWidth -or $sync.Form.ActualHeight -gt $screenHeight) { Write-Debug "The specified width and/or height is greater than the primary monitor size." @@ -341,11 +333,7 @@ $sync["Form"].Add_ContentRendered({ $sync.Form.Top = 0 $sync.Form.Width = $screenWidth $sync.Form.Height = $screenHeight - } else { - Write-Debug "The specified width and height are within the primary monitor size limits." } - } else { - Write-Debug "Unable to retrieve information about the primary monitor." } if ($PARAM_OFFLINE) { @@ -445,41 +433,33 @@ $sync["Form"].Add_Activated({ }) $sync["ThemeButton"].Add_Click({ - Write-Debug "ThemeButton clicked" Invoke-WPFPopup -PopupActionTable @{ "Settings" = "Hide"; "Theme" = "Toggle"; "FontScaling" = "Hide" } }) $sync["AutoThemeMenuItem"].Add_Click({ - Write-Debug "About clicked" Invoke-WPFPopup -Action "Hide" -Popups @("Theme") Invoke-WinutilThemeChange -theme "Auto" }) $sync["DarkThemeMenuItem"].Add_Click({ - Write-Debug "Dark Theme clicked" Invoke-WPFPopup -Action "Hide" -Popups @("Theme") Invoke-WinutilThemeChange -theme "Dark" }) $sync["LightThemeMenuItem"].Add_Click({ - Write-Debug "Light Theme clicked" Invoke-WPFPopup -Action "Hide" -Popups @("Theme") Invoke-WinutilThemeChange -theme "Light" }) $sync["SettingsButton"].Add_Click({ - Write-Debug "SettingsButton clicked" Invoke-WPFPopup -PopupActionTable @{ "Settings" = "Toggle"; "Theme" = "Hide"; "FontScaling" = "Hide" } }) $sync["ImportMenuItem"].Add_Click({ - Write-Debug "Import clicked" Invoke-WPFPopup -Action "Hide" -Popups @("Settings") Invoke-WPFImpex -type "import" }) $sync["ExportMenuItem"].Add_Click({ - Write-Debug "Export clicked" Invoke-WPFPopup -Action "Hide" -Popups @("Settings") Invoke-WPFImpex -type "export" }) $sync["AboutMenuItem"].Add_Click({ - Write-Debug "About clicked" Invoke-WPFPopup -Action "Hide" -Popups @("Settings") $authorInfo = @" @@ -492,12 +472,10 @@ Version :