Skip to content

Free, open-source Windows optimization tool for performance, privacy, and simplicity.

Refactor registry value conversions for better type handling

itsfatduck60ad8b07b6de
diff --git a/README.md b/README.md
index 7c4b7b5..cf3a00f 100644
--- a/README.md
+++ b/README.md
@@ -18,6 +18,22 @@
---
+# Table of Contents
+
+1. [Download](#download)
+2. [What It Actually Does](#what-it-actually-does)
+3. [Safety First](#safety-first)
+4. [Mindset Matters](#mindset-matters)
+5. [Why I Built optimizerDuck](#why-i-built-optimizerduck)
+6. [Community & Support](#community--support)
+7. [Contributing](#contributing)
+8. [Acknowledgments](#acknowledgments)
+9. [Disclaimer](#disclaimer)
+10. [License](#license)
+11. [Star History](#star-history)
+
+---
+
## Download
<img src="./.github/assets/app_screenshot.png" alt="optimizerDuck App Screenshot" title="optimizerDuck App Screenshot" width="1000" />
@@ -75,6 +91,14 @@
---
+## Why I Built optimizerDuck
+
+I run games on a **low-spec PC**, so smooth play is always a struggle. I spent hours digging through forums and community threads, trying everything I could find: **editing configs**, **applying `.reg` tweaks**, **running shell commands**, and **using third-party tools**. Those tweaks helped, but I never found a "**tweaker**" that felt right. Some **cost money**, some **looked fake**, and many **didn't** let me choose the exact changes I wanted.
+
+I made this tool because I enjoy tweaking my system and wanted something simple and honest I could control. **Every tweak** here has been **tested** by me and carefully chosen to improve gameplay without surprises.
+
+---
+
## Community & Support
- Got questions? Found a bug? Want to suggest a feature?
diff --git a/optimizerDuck/src/Core/Services/RegistryService.cs b/optimizerDuck/src/Core/Services/RegistryService.cs
index 8fdd09c..d30329d 100644
--- a/optimizerDuck/src/Core/Services/RegistryService.cs
+++ b/optimizerDuck/src/Core/Services/RegistryService.cs
@@ -136,25 +136,34 @@ public static class RegistryService
{
var value = key.GetValue(item.Name);
if (value is null) return default;
+
if (value is T tValue) return tValue;
- if (typeof(T) == typeof(byte[]) && value is byte[] bytes) return (T)(object)bytes;
- if (typeof(T) == typeof(string[]) && value is string[] arr) return (T)(object)arr;
+ var targetType = typeof(T);
- if (typeof(T) == typeof(int) && value is int i) return (T)(object)i;
- if (typeof(T) == typeof(bool) && value is int i2) return (T)(object)(i2 != 0);
+ if (targetType == typeof(byte[]) && value is byte[] bytes) return (T)(object)bytes;
+ if (targetType == typeof(string[]) && value is string[] arr) return (T)(object)arr;
- return (T)Convert.ChangeType(value, typeof(T));
+ if (targetType == typeof(int) && value is int i) return (T)(object)i;
+ if (targetType == typeof(bool))
+ {
+ if (value is int i2) return (T)(object)(i2 != 0);
+ if (value is string s && bool.TryParse(s, out var b)) return (T)(object)b;
+ }
+
+ return (T)Convert.ChangeType(value, targetType);
}
catch (Exception ex)
{
- ServiceTracker.Current?.Log.LogError(ex, "Failed to read or convert registry value {Path}:{Name}",
- item.Path, item.Name);
+ ServiceTracker.Current?.Log.LogError(ex,
+ "Failed to read registry value {Path}:{Name} as {TargetType}",
+ item.Path, item.Name, typeof(T).FullName);
return default;
}
});
}
+
public static bool Write(RegistryItem registryItem)
{
if (registryItem.Value == null)