Free, open-source Windows optimization tool for performance, privacy, and simplicity.
C# csharpdebloatdotnetgamingopen-sourceoptimizationoptimizeroptimizerduckperformanceprivacytweakertweakswindowswinui
fix: add logging to DisableUSBPowerSaving
fatDucke007115e25b7
diff --git a/optimizerDuck/Core/Optimizers/PowerManagement.cs b/optimizerDuck/Core/Optimizers/PowerManagement.csindex 0e37b89..9be854a 100644--- a/optimizerDuck/Core/Optimizers/PowerManagement.cs+++ b/optimizerDuck/Core/Optimizers/PowerManagement.cs@@ -50,11 +50,11 @@ public class PowerManagement : IOptimizationCategory{context.Logger.LogInformation("Saving current USB power state");var usbStates = ShellService.PowerShell("""- $states = Get-CimInstance -Namespace root\wmi -ClassName MSPower_DeviceEnable |- Where-Object { $_.InstanceName -match 'USB\\ROOT' } |- Select-Object InstanceName, Enable+ $states = Get-CimInstance -Namespace root\wmi -ClassName MSPower_DeviceEnable -ErrorAction SilentlyContinue |+ Where-Object { $_.InstanceName -match 'USB\\ROOT' } |+ Select-Object InstanceName, Enable- $states | ConvertTo-Json -Compress+ $states | ConvertTo-Json -Compress""");if (string.IsNullOrWhiteSpace(usbStates.Stdout))@@ -65,7 +65,7 @@ public class PowerManagement : IOptimizationCategorycontext.Logger.LogInformation("Disabling USB power saving");ShellService.PowerShell("""- $devices = Get-CimInstance -Namespace root\wmi -ClassName MSPower_DeviceEnable |+ $devices = Get-CimInstance -Namespace root\wmi -ClassName MSPower_DeviceEnable -ErrorAction SilentlyContinue |Where-Object { $_.InstanceName -match 'USB\\ROOT' }foreach ($d in $devices) {@@ -75,13 +75,14 @@ public class PowerManagement : IOptimizationCategory}""",$$"""- $states = '{{usbStates.Stdout}}' | ConvertFrom-Json+ $states = @('{{usbStates.Stdout}}' | ConvertFrom-Json)foreach ($s in $states) {- $obj = Get-CimInstance -Namespace root\wmi -ClassName MSPower_DeviceEnable |+ $obj = Get-CimInstance -Namespace root\wmi -ClassName MSPower_DeviceEnable -ErrorAction SilentlyContinue |Where-Object { $_.InstanceName -eq $s.InstanceName }if ($obj -and $obj.Enable -ne [bool]$s.Enable) {+ Write-Host "Reverting $($s.InstanceName) to $([bool]$s.Enable)"Set-CimInstance -CimInstance $obj -Property @{ Enable = [bool]$s.Enable } | Out-Null}}diff --git a/optimizerDuck/Services/OptimizationServices/ShellService.cs b/optimizerDuck/Services/OptimizationServices/ShellService.csindex 344ee48..20c0f9f 100644--- a/optimizerDuck/Services/OptimizationServices/ShellService.cs+++ b/optimizerDuck/Services/OptimizationServices/ShellService.cs@@ -189,8 +189,10 @@ public static class ShellServiceerror,success? null- : () => Task.FromResult(- Run(fileName, arguments, command, serviceName, revertStep, policy).ExitCode == 0));+ : () => Task.Run(() =>+ policy.IsSuccess(Run(fileName, arguments, command, serviceName, revertStep, policy))+ )+ );return result;}@@ -215,8 +217,10 @@ public static class ShellServicefalse,revertStep,ex.Message,- () => Task.FromResult(Run(fileName, arguments, command, serviceName, revertStep, policy).ExitCode ==- 0));+ () => Task.Run(() =>+ policy.IsSuccess(Run(fileName, arguments, command, serviceName, revertStep, policy))+ )+ );return result;}@@ -338,9 +342,8 @@ public static class ShellServiceerror,success? null- : async () =>- (await RunAsync(fileName, arguments, command, serviceName, revertStep, policy, ct)).ExitCode ==- 0);+ : async () => policy.IsSuccess(await RunAsync(fileName, arguments, command, serviceName, revertStep, policy, ct))+ );return result;}@@ -365,8 +368,7 @@ public static class ShellServicefalse,revertStep,ex.Message,- async () =>- (await RunAsync(fileName, arguments, command, serviceName, revertStep, policy, ct)).ExitCode == 0);+ async () => policy.IsSuccess(await RunAsync(fileName, arguments, command, serviceName, revertStep, policy, ct)));return result;}diff --git a/optimizerDuck/optimizerDuck.csproj b/optimizerDuck/optimizerDuck.csprojindex 7703950..6d5a23a 100644--- a/optimizerDuck/optimizerDuck.csproj+++ b/optimizerDuck/optimizerDuck.csproj@@ -10,7 +10,7 @@<Authors>fatDuck</Authors><ApplicationIcon>Logo.ico</ApplicationIcon><Company>fatDuck</Company>- <FileVersion>2.6.0</FileVersion>+ <FileVersion>2.6.4</FileVersion><Version>1.0.0</Version><Product>optimizerDuck</Product><Copyright>Copyright fatDuck 2026</Copyright>