Free, open-source Windows optimization tool for performance, privacy, and simplicity.
C# csharpdebloatdotnetgamingopen-sourceoptimizationoptimizeroptimizerduckperformanceprivacytweakertweakswindowswinui
Fix naming inconsistencies and static field usage
itsfatduckc40543c60e5e
diff --git a/optimizerDuck/Program.cs b/optimizerDuck/Program.csindex 17277bf..1030390 100644--- a/optimizerDuck/Program.cs+++ b/optimizerDuck/Program.cs@@ -4,7 +4,6 @@ using optimizerDuck.Core;using optimizerDuck.Core.Extensions;using optimizerDuck.Core.Helpers;using optimizerDuck.Core.Services;-using optimizerDuck.src.UI;using optimizerDuck.UI;using optimizerDuck.UI.Components;using optimizerDuck.UI.Logger;diff --git a/optimizerDuck/src/Core/Defaults.cs b/optimizerDuck/src/Core/Defaults.csindex b5e826f..cc975c6 100644--- a/optimizerDuck/src/Core/Defaults.cs+++ b/optimizerDuck/src/Core/Defaults.cs@@ -37,7 +37,7 @@ public static class Defaultspublic const string RestorePointName = "optimizerDuck Restore Point";public const string PowerPlanGUID = "946c0ca5-6ee0-4f2a-9dd7-7addbb8e60f5";- public static bool IsDebug = Environment.GetCommandLineArgs().Contains("--debug");+ public static readonly bool IsDebug = Environment.GetCommandLineArgs().Contains("--debug");public static readonly Panel Logo = new(new Align(@@ -69,7 +69,7 @@ public static class Defaultspublic static readonly string ResourcesPath =Path.Combine(RootPath, "Resources");- public static readonly Dictionary<string, string> SAFE_APPS = new()+ public static readonly Dictionary<string, string> SafeApps = new(){// bing["Microsoft.BingWeather"] = "Weather",@@ -108,7 +108,7 @@ public static class Defaults};- public static readonly Dictionary<string, string> CAUTION_APPS = new()+ public static readonly Dictionary<string, string> CautionApps = new(){["Microsoft.WindowsCalculator"] = "Calculator",["Microsoft.Windows.Photos"] = "Photos",diff --git a/optimizerDuck/src/Core/Extensions/EnumExtensions.cs b/optimizerDuck/src/Core/Extensions/EnumExtensions.csindex 396f0b7..29ee7a6 100644--- a/optimizerDuck/src/Core/Extensions/EnumExtensions.cs+++ b/optimizerDuck/src/Core/Extensions/EnumExtensions.cs@@ -5,7 +5,7 @@ namespace optimizerDuck.Core.Extensions;public static class EnumExtensions{- public static string GetDescription(this Enum value)+ public static string GetDescription(this Enum? value){if (value == null) return string.Empty;diff --git a/optimizerDuck/src/Core/Extensions/StatusExtensions.cs b/optimizerDuck/src/Core/Extensions/StatusExtensions.csindex 5b370de..53721c5 100644--- a/optimizerDuck/src/Core/Extensions/StatusExtensions.cs+++ b/optimizerDuck/src/Core/Extensions/StatusExtensions.cs@@ -5,59 +5,55 @@ namespace optimizerDuck.Core.Extensions;public static class StatusExtensions{- public static void StartGlobal(this Status status,- string message,- Action<StatusContext> action)+ extension(Status status){- var task = status.StartAsync(message, ctx =>+ public void StartGlobal(string message,+ Action<StatusContext> action){- GlobalStatus.Current = ctx;- action(ctx);- return Task.CompletedTask;- });-- task.GetAwaiter().GetResult();- }-- public static T StartGlobal<T>(- this Status status,- string message,- Func<StatusContext, T> func)- {- return status.Start(message, ctx =>+ var task = status.StartAsync(message, ctx =>+ {+ GlobalStatus.Current = ctx;+ action(ctx);+ return Task.CompletedTask;+ });++ task.GetAwaiter().GetResult();+ }++ public T StartGlobal<T>(string message,+ Func<StatusContext, T> func){- GlobalStatus.Current = ctx;- return func(ctx);- });- }-- public static async Task StartAsyncGlobal(- this Status status,- string message,- Func<StatusContext, Task> action)- {- ArgumentNullException.ThrowIfNull(status);-- _ = await status.StartAsync<object?>(message, async ctx =>+ return status.Start(message, ctx =>+ {+ GlobalStatus.Current = ctx;+ return func(ctx);+ });+ }++ public async Task StartAsyncGlobal(string message,+ Func<StatusContext, Task> action){- GlobalStatus.Current = ctx;- await action(ctx).ConfigureAwait(false);- return null;- }).ConfigureAwait(false);- }-- public static async Task<T> StartAsyncGlobal<T>(- this Status status,- string message,- Func<StatusContext, Task<T>> func)- {- ArgumentNullException.ThrowIfNull(status);- ArgumentNullException.ThrowIfNull(func);-- return await status.StartAsync<T>(message, async ctx =>+ ArgumentNullException.ThrowIfNull(status);++ _ = await status.StartAsync<object?>(message, async ctx =>+ {+ GlobalStatus.Current = ctx;+ await action(ctx).ConfigureAwait(false);+ return null;+ }).ConfigureAwait(false);+ }++ public async Task<T> StartAsyncGlobal<T>(string message,+ Func<StatusContext, Task<T>> func){- GlobalStatus.Current = ctx;- return await func(ctx).ConfigureAwait(false);- }).ConfigureAwait(false);+ ArgumentNullException.ThrowIfNull(status);+ ArgumentNullException.ThrowIfNull(func);++ return await status.StartAsync<T>(message, async ctx =>+ {+ GlobalStatus.Current = ctx;+ return await func(ctx).ConfigureAwait(false);+ }).ConfigureAwait(false);+ }}}\ No newline at end of filediff --git a/optimizerDuck/src/Core/Helpers/OptimizationHelper.cs b/optimizerDuck/src/Core/Helpers/OptimizationHelper.csindex 6699b39..d4c5730 100644--- a/optimizerDuck/src/Core/Helpers/OptimizationHelper.cs+++ b/optimizerDuck/src/Core/Helpers/OptimizationHelper.cs@@ -84,10 +84,10 @@ public static class OptimizationHelper{var result = ShellService.PowerShell($$"""# list the SAFE_APPS- $safeApps = @({{string.Join(", ", Defaults.SAFE_APPS.Keys.Select(x => $"\"{x}\""))}})+ $safeApps = @({{string.Join(", ", Defaults.SafeApps.Keys.Select(x => $"\"{x}\""))}})# list the CAUTION_APPS- $cautionApps = @({{string.Join(", ", Defaults.CAUTION_APPS.Keys.Select(x => $"\"{x}\""))}})+ $cautionApps = @({{string.Join(", ", Defaults.CautionApps.Keys.Select(x => $"\"{x}\""))}})# get the installed apps$installedApps = Get-AppxPackage -AllUsers | Where-Object { $_.NonRemovable -eq 0 } # NonRemovable = 0 means the app can be removed@@ -137,11 +137,11 @@ public static class OptimizationHelper// Display Lengthvar safeDisplayLength = allSafe.Count != 0- ? allSafe.Max(x => Defaults.SAFE_APPS.TryGetValue(x.Name, out var dn) ? dn.Length : x.Name.Length)+ ? allSafe.Max(x => Defaults.SafeApps.TryGetValue(x.Name, out var dn) ? dn.Length : x.Name.Length): 0;var cautionDisplayLength = allCaution.Count != 0- ? allCaution.Max(x => Defaults.CAUTION_APPS.TryGetValue(x.Name, out var dn) ? dn.Length : x.Name.Length)+ ? allCaution.Max(x => Defaults.CautionApps.TryGetValue(x.Name, out var dn) ? dn.Length : x.Name.Length): 0;// Version Length@@ -166,7 +166,7 @@ public static class OptimizationHelperreturn app with{DisplayName =- Defaults.SAFE_APPS.TryGetValue(app.Name, out var dn)+ Defaults.SafeApps.TryGetValue(app.Name, out var dn)? dn: app.Name // get display name or fallback to app name};@@ -183,7 +183,7 @@ public static class OptimizationHelper{return app with{- DisplayName = Defaults.CAUTION_APPS.TryGetValue(app.Name, out var dn) ? dn : app.Name+ DisplayName = Defaults.CautionApps.TryGetValue(app.Name, out var dn) ? dn : app.Name};}).OrderBy(x => x.DisplayName)diff --git a/optimizerDuck/src/Core/Managers/CacheManager.cs b/optimizerDuck/src/Core/Managers/CacheManager.csindex 878caac..f0f9264 100644--- a/optimizerDuck/src/Core/Managers/CacheManager.cs+++ b/optimizerDuck/src/Core/Managers/CacheManager.cs@@ -4,10 +4,10 @@ namespace optimizerDuck.Core.Managers;public static class CacheManager{- private static readonly MemoryCache _cache = new(new MemoryCacheOptions());+ private static readonly MemoryCache Cache = new(new MemoryCacheOptions());public static T GetOrCreate<T>(string key, Func<ICacheEntry, T> factory){- return _cache.GetOrCreate(key, factory)!;+ return Cache.GetOrCreate(key, factory)!;}}\ No newline at end of filediff --git a/optimizerDuck/src/UI/Logger/Logger.cs b/optimizerDuck/src/UI/Logger/Logger.csindex 1a2c585..c91f05a 100644--- a/optimizerDuck/src/UI/Logger/Logger.cs+++ b/optimizerDuck/src/UI/Logger/Logger.cs@@ -41,19 +41,28 @@ public class PlainTextFormatter : ITextFormatter// [Scope1] [Scope2] ...if (logEvent.Properties.TryGetValue("Scope", out var scopeValue)){- if (scopeValue is SequenceValue seq)- foreach (var scope in seq.Elements)+ switch (scopeValue)+ {+ case SequenceValue seq:{- var text = scope switch+ foreach (var scope in seq.Elements){- ScalarValue s => s.Value?.ToString(),- _ => scope.ToString()- };+ var text = scope switch+ {+ ScalarValue s => s.Value?.ToString(),+ _ => scope.ToString()+ };++ if (!string.IsNullOrWhiteSpace(text))+ output.Write($" [{text}]");+ }- if (!string.IsNullOrWhiteSpace(text))- output.Write($" [{text}]");+ break;}- else if (scopeValue is ScalarValue single) output.Write($" [{single.Value}]");+ case ScalarValue single:+ output.Write($" [{single.Value}]");+ break;+ }}@@ -126,7 +135,7 @@ public class ShortSourceContextEnricher : ILogEventEnricherpublic static class Logger{public static readonly string LogFilePath = Path.Combine(Defaults.RootPath, "optimizerDuck.log");- private static readonly ILoggerFactory _loggerFactory;+ private static readonly ILoggerFactory LoggerFactory;static Logger(){@@ -139,7 +148,7 @@ public static class Logger// add a header to the log fileLog.Logger.Information("\n\n{Logo}\nVersion: {Version}\n\n", Defaults.RawLogo, Defaults.FileVersion);- _loggerFactory = LoggerFactory.Create(builder =>+ LoggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(builder =>{builder.AddSpectreConsole(config =>{@@ -189,11 +198,11 @@ public static class Loggerpublic static ILogger CreateLogger<T>(){- return _loggerFactory.CreateLogger<T>();+ return LoggerFactory.CreateLogger<T>();}public static ILogger CreateLogger(Type type){- return _loggerFactory.CreateLogger(type);+ return LoggerFactory.CreateLogger(type);}}\ No newline at end of filediff --git a/optimizerDuck/src/UI/MainMenu.cs b/optimizerDuck/src/UI/MainMenu.csindex f70423e..2b0cd7f 100644--- a/optimizerDuck/src/UI/MainMenu.cs+++ b/optimizerDuck/src/UI/MainMenu.cs@@ -1,11 +1,10 @@using optimizerDuck.Core;using optimizerDuck.Core.Helpers;using optimizerDuck.Core.Services;-using optimizerDuck.UI;using optimizerDuck.UI.Components;using Spectre.Console;-namespace optimizerDuck.src.UI;+namespace optimizerDuck.UI;internal static class MainMenu{diff --git a/optimizerDuck/src/UI/MenuHandler.cs b/optimizerDuck/src/UI/MenuHandler.csindex 0b0e422..7d1022b 100644--- a/optimizerDuck/src/UI/MenuHandler.cs+++ b/optimizerDuck/src/UI/MenuHandler.cs@@ -3,14 +3,13 @@ using optimizerDuck.Core;using optimizerDuck.Core.Helpers;using optimizerDuck.Core.Managers;using optimizerDuck.Core.Services;-using optimizerDuck.UI.Logger;using Spectre.Console;-namespace optimizerDuck.src.UI;+namespace optimizerDuck.UI;internal class MenuHandler{- private readonly ILogger _log = Logger.CreateLogger<MenuHandler>();+ private static readonly ILogger Log = Logger.Logger.CreateLogger<MenuHandler>();private readonly Dictionary<char, Func<Task>> _menuActions;private OptimizationManager? _optimizer;@@ -58,13 +57,13 @@ internal class MenuHandler}}- private Task HandleDiscordLinkAsync()+ private static Task HandleDiscordLinkAsync(){SystemHelper.OpenWebsite(Defaults.DiscordInvite);return Task.CompletedTask;}- private Task HandleGitHubLinkAsync()+ private static Task HandleGitHubLinkAsync(){SystemHelper.OpenWebsite(Defaults.GitHubRepo);return Task.CompletedTask;@@ -72,13 +71,13 @@ internal class MenuHandlerprivate async Task HandleSystemInfoAsync(){- _log.LogInformation("Refreshing System Information...");+ Log.LogInformation("Refreshing System Information...");_systemSnapshot = await SystemInfoService.RefreshAsync().ConfigureAwait(false);AnsiConsole.Clear();AnsiConsole.Write(Defaults.Logo);- var detailedPanel = SystemInfoService.GetDetailedPanel(_systemSnapshot, _log);+ var detailedPanel = SystemInfoService.GetDetailedPanel(_systemSnapshot, Log);if (detailedPanel is not null){AnsiConsole.Write(detailedPanel);