Free, open-source Windows optimization tool for performance, privacy, and simplicity.
C# csharpdebloatdotnetgamingopen-sourceoptimizationoptimizeroptimizerduckperformanceprivacytweakertweakswindowswinui
fix: fail-open customize toggle on registry read failure
fatDuck98a58be58e64
diff --git a/optimizerDuck/Domain/Customize/Models/BaseCustomizeSetting.cs b/optimizerDuck/Domain/Customize/Models/BaseCustomizeSetting.csindex 103bdb2..005641c 100644--- a/optimizerDuck/Domain/Customize/Models/BaseCustomizeSetting.cs+++ b/optimizerDuck/Domain/Customize/Models/BaseCustomizeSetting.cs@@ -198,13 +198,23 @@ public abstract partial class BaseCustomizeSetting : LocalizedObject, ICustomizepublic async Task<bool> GetStateWithRetryAsync(int maxRetries = 3, int delayMs = 80){bool? previous = null;+ Exception? lastError = null;for (var i = 0; i < maxRetries; i++){if (i > 0)await Task.Delay(delayMs);- var state = await GetStateAsync();+ bool state;+ try+ {+ state = await GetStateAsync();+ }+ catch (Exception ex)+ {+ lastError = ex;+ continue;+ }if (previous.HasValue && previous.Value == state)return state;@@ -212,7 +222,10 @@ public abstract partial class BaseCustomizeSetting : LocalizedObject, ICustomizeprevious = state;}- return previous ?? await GetStateAsync();+ if (previous.HasValue)+ return previous.Value;++ throw lastError ?? new InvalidOperationException("Failed to read setting state.");}/// <summary>diff --git a/optimizerDuck/Domain/Customize/Models/RegistryToggle.cs b/optimizerDuck/Domain/Customize/Models/RegistryToggle.csindex b29fd82..44f0c4a 100644--- a/optimizerDuck/Domain/Customize/Models/RegistryToggle.cs+++ b/optimizerDuck/Domain/Customize/Models/RegistryToggle.cs@@ -1,3 +1,4 @@+using System.IO;using Microsoft.Win32;using optimizerDuck.Domain.Execution;using optimizerDuck.Domain.Optimizations.Models.Services;@@ -92,7 +93,10 @@ public class RegistryToggleprivate object? GetRawValue(){- return RegistryService.Read<object?>(new RegistryItem(Path, Name));+ if (!RegistryService.TryReadValue(new RegistryItem(Path, Name), out var value))+ throw new IOException($"Failed to read registry value {Path}\\{Name}.");++ return value;}private static bool IsValueInList(object? value, IReadOnlyList<object?> values)diff --git a/optimizerDuck/UI/ViewModels/Customize/CustomizeItemViewModel.cs b/optimizerDuck/UI/ViewModels/Customize/CustomizeItemViewModel.csindex 7edb3a0..b0c3cb7 100644--- a/optimizerDuck/UI/ViewModels/Customize/CustomizeItemViewModel.cs+++ b/optimizerDuck/UI/ViewModels/Customize/CustomizeItemViewModel.cs@@ -120,7 +120,9 @@ public partial class CustomizeItemViewModel({// Registry I/O (state query, options, current value) runs on the thread pool// so page load never blocks the UI thread.- IsEnabled = await Task.Run(() => setting.GetStateAsync());+ IsEnabled = await Task.Run(() =>+ setting.GetStateWithRetryAsync(maxRetries: 4, delayMs: 80)+ );// Publish the effective options before the selection value so the ComboBox// item list already contains the value when the SelectedValue binding resolves.