Skip to content

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

fix(optimization): remove cache for bloatware choices and move EnsureDirectoriesExists to requirementchecker

itsfatduck964146a80dff
diff --git a/optimizerDuck/Program.cs b/optimizerDuck/Program.cs
index 7463ae4..24e817d 100644
--- a/optimizerDuck/Program.cs
+++ b/optimizerDuck/Program.cs
@@ -90,7 +90,7 @@ internal class Program
ctx.Status("Checking and creating necessary paths...");
Log.LogInformation("Checking and creating necessary paths...");
- SystemHelper.EnsureDirectoriesExists();
+ RequirementChecker.EnsureDirectoriesExists();
ctx.Status("Checking system requirements...");
Log.LogInformation("Checking system requirements...");
diff --git a/optimizerDuck/src/Core/Helpers/OptimizationHelper.cs b/optimizerDuck/src/Core/Helpers/OptimizationHelper.cs
index bcaab88..fa7d693 100644
--- a/optimizerDuck/src/Core/Helpers/OptimizationHelper.cs
+++ b/optimizerDuck/src/Core/Helpers/OptimizationHelper.cs
@@ -78,11 +78,7 @@ public static class OptimizationHelper
public static AppxClassification GetBloatwareChoices()
{
- return CacheManager.GetOrCreate("bloatware_choices", entry =>
- {
- entry.SlidingExpiration = TimeSpan.FromMinutes(5);
-
- var result = ShellService.PowerShell($$"""
+ var result = ShellService.PowerShell($$"""
# list the SAFE_APPS
$safeApps = @({{string.Join(", ", Defaults.SAFE_APPS.Keys.Select(x => $"\"{x}\""))}})
@@ -130,96 +126,89 @@ public static class OptimizationHelper
""");
- var raw = JsonConvert.DeserializeObject<AppxClassificationRaw>(result.Stdout);
+ var raw = JsonConvert.DeserializeObject<AppxClassificationRaw>(result.Stdout);
- var allSafe = raw.SafeApps.SelectMany(x => x).ToList();
- var allCaution = raw.CautionApps.SelectMany(x => x).ToList();
+ var allSafe = raw.SafeApps.SelectMany(x => x).ToList();
+ var allCaution = raw.CautionApps.SelectMany(x => x).ToList();
- // Display Length
- var safeDisplayLength = allSafe.Count != 0
- ? allSafe.Max(x => Defaults.SAFE_APPS.TryGetValue(x.Name, out var dn) ? dn.Length : x.Name.Length)
- : 0;
+ // Display Length
+ var safeDisplayLength = allSafe.Count != 0
+ ? allSafe.Max(x => Defaults.SAFE_APPS.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)
- : 0;
+ var cautionDisplayLength = allCaution.Count != 0
+ ? allCaution.Max(x => Defaults.CAUTION_APPS.TryGetValue(x.Name, out var dn) ? dn.Length : x.Name.Length)
+ : 0;
- // Version Length
- var safeVersionLength = allSafe.Count != 0
- ? allSafe.Max(x => x.Version.Length)
- : 0;
+ // Version Length
+ var safeVersionLength = allSafe.Count != 0
+ ? allSafe.Max(x => x.Version.Length)
+ : 0;
- var cautionVersionLength = allCaution.Count != 0
- ? allCaution.Max(x => x.Version.Length)
- : 0;
+ var cautionVersionLength = allCaution.Count != 0
+ ? allCaution.Max(x => x.Version.Length)
+ : 0;
- var maxDisplayNameLength = Math.Max(safeDisplayLength, cautionDisplayLength) + 1;
+ var maxDisplayNameLength = Math.Max(safeDisplayLength, cautionDisplayLength) + 1;
- var maxVersionLength = Math.Max(safeVersionLength, cautionVersionLength) + 1;
+ var maxVersionLength = Math.Max(safeVersionLength, cautionVersionLength) + 1;
- var classification = new AppxClassification(
- allSafe
- .Select(app =>
+ var classification = new AppxClassification(
+ allSafe
+ .Select(app =>
+ {
+ return app with
{
- var key = app.Name;
- var display = Defaults.SAFE_APPS.TryGetValue(key, out var dn) ? dn : app.Name;
- return app with
- {
- DisplayName = display,
- Version = app.Version
- };
- })
- .OrderBy(x => x.DisplayName)
- .Select(app => app with
- {
- DisplayName = app.DisplayName.PadRight(maxDisplayNameLength),
- Version = app.Version.PadRight(maxVersionLength)
- })
- .ToList(),
- allCaution
- .Select(app =>
- {
- var key = app.Name;
- var display = Defaults.CAUTION_APPS.TryGetValue(key, out var dn) ? dn : app.Name;
- return app with
- {
- DisplayName = display,
- Version = app.Version
- };
- })
- .OrderBy(x => x.DisplayName)
- .Select(app => app with
+ DisplayName = Defaults.SAFE_APPS.TryGetValue(app.Name, out var dn) ? dn : app.Name // get display name or fallback to app name
+ };
+ })
+ .OrderBy(x => x.DisplayName)
+ .Select(app => app with
+ {
+ DisplayName = app.DisplayName.PadRight(maxDisplayNameLength),
+ Version = app.Version.PadRight(maxVersionLength)
+ })
+ .ToList(),
+ allCaution
+ .Select(app =>
+ {
+ return app with
{
- DisplayName = app.DisplayName.PadRight(maxDisplayNameLength),
- Version = app.Version.PadRight(maxVersionLength)
- })
- .ToList()
- );
-
- var parts = new List<string>();
-
- if (classification.SafeApps.Count > 0)
- {
- parts.Add($"[{Theme.Success}]{classification.SafeApps.Count}[/] safe apps");
- Log.LogDebug("Found {TotalSafeApps} safe apps: {SafeApps}", classification.SafeApps.Count,
- string.Join(", ", classification.SafeApps.Select(x => x.Name).ToList()));
- }
+ DisplayName = Defaults.CAUTION_APPS.TryGetValue(app.Name, out var dn) ? dn : app.Name
+ };
+ })
+ .OrderBy(x => x.DisplayName)
+ .Select(app => app with
+ {
+ DisplayName = app.DisplayName.PadRight(maxDisplayNameLength),
+ Version = app.Version.PadRight(maxVersionLength)
+ })
+ .ToList()
+ );
+
+ var parts = new List<string>();
+
+ if (classification.SafeApps.Count > 0)
+ {
+ parts.Add($"[{Theme.Success}]{classification.SafeApps.Count}[/] safe apps");
+ Log.LogDebug("Found {TotalSafeApps} safe apps: {SafeApps}", classification.SafeApps.Count,
+ string.Join(", ", classification.SafeApps.Select(x => x.Name).ToList()));
+ }
- if (classification.CautionApps.Count > 0)
- {
- parts.Add($"[{Theme.Error}]{classification.CautionApps.Count}[/] caution apps");
- Log.LogDebug("Found {TotalCautionApps} caution apps: {CautionApps}", classification.CautionApps.Count,
- string.Join(", ", classification.CautionApps.Select(x => x.Name).ToList()));
- }
+ if (classification.CautionApps.Count > 0)
+ {
+ parts.Add($"[{Theme.Error}]{classification.CautionApps.Count}[/] caution apps");
+ Log.LogDebug("Found {TotalCautionApps} caution apps: {CautionApps}", classification.CautionApps.Count,
+ string.Join(", ", classification.CautionApps.Select(x => x.Name).ToList()));
+ }
- if (parts.Count != 0)
- Log.LogInformation($"Found {string.Join(" and ", parts)}.");
- else
- Log.LogWarning("No apps found.");
+ if (parts.Count != 0)
+ Log.LogInformation($"Found {string.Join(" and ", parts)}.");
+ else
+ Log.LogWarning("No apps found.");
- return classification;
- });
+ return classification;
}
}
\ No newline at end of file
diff --git a/optimizerDuck/src/Core/Helpers/RequirementChecker.cs b/optimizerDuck/src/Core/Helpers/RequirementChecker.cs
index 7b62f47..a6eef42 100644
--- a/optimizerDuck/src/Core/Helpers/RequirementChecker.cs
+++ b/optimizerDuck/src/Core/Helpers/RequirementChecker.cs
@@ -70,6 +70,23 @@ public static class RequirementChecker
}
}
+ public static void EnsureDirectoriesExists()
+ {
+ if (!Directory.Exists(Defaults.RootPath))
+ {
+ Log.LogInformation(@"AppData\optimizerDuck directory does not exist. Creating directory at: {Path}",
+ Defaults.RootPath);
+ Directory.CreateDirectory(Defaults.RootPath);
+ }
+
+ if (!Directory.Exists(Defaults.ResourcesPath))
+ {
+ Log.LogInformation("Resources directory does not exist. Creating directory at: {Path}",
+ Defaults.ResourcesPath);
+ Directory.CreateDirectory(Defaults.ResourcesPath);
+ }
+ }
+
public static void Restart(bool force = false)
{
var args = Environment.GetCommandLineArgs();
diff --git a/optimizerDuck/src/Core/Helpers/SystemHelper.cs b/optimizerDuck/src/Core/Helpers/SystemHelper.cs
index af723fa..1c56bf1 100644
--- a/optimizerDuck/src/Core/Helpers/SystemHelper.cs
+++ b/optimizerDuck/src/Core/Helpers/SystemHelper.cs
@@ -11,23 +11,6 @@ public static class SystemHelper
{
private static readonly ILogger Log = Logger.CreateLogger(typeof(SystemHelper));
- public static void EnsureDirectoriesExists()
- {
- if (!Directory.Exists(Defaults.RootPath))
- {
- Log.LogInformation(@"AppData\optimizerDuck directory does not exist. Creating directory at: {Path}",
- Defaults.RootPath);
- Directory.CreateDirectory(Defaults.RootPath);
- }
-
- if (!Directory.Exists(Defaults.ResourcesPath))
- {
- Log.LogInformation("Resources directory does not exist. Creating directory at: {Path}",
- Defaults.ResourcesPath);
- Directory.CreateDirectory(Defaults.ResourcesPath);
- }
- }
-
public static void OpenLogFile()
{
Process.Start(new ProcessStartInfo
diff --git a/optimizerDuck/src/Core/Managers/OptimizationManager.cs b/optimizerDuck/src/Core/Managers/OptimizationManager.cs
index 1132629..fd11103 100644
--- a/optimizerDuck/src/Core/Managers/OptimizationManager.cs
+++ b/optimizerDuck/src/Core/Managers/OptimizationManager.cs
@@ -53,7 +53,7 @@ public class OptimizationManager(SystemSnapshot systemSnapshot)
g.Tweaks
);
- if (_selectedTweaks.Count == 0) // only select enabled by default if no tweaks are selected (first time)
+ if (_selectedTweaks.Count == 0)
foreach (var tweak in optimizationGroups.SelectMany(g => g.Tweaks).Where(t => t.EnabledByDefault))
promptTweakChoice.Select(tweak);
else
@@ -68,7 +68,6 @@ public class OptimizationManager(SystemSnapshot systemSnapshot)
if (_selectedTweaks.Any(t => t.Instance is BloatwareAndServices.RemoveBloatwareApps)) // if Bloatware selection is selected
{
SystemHelper.Title("Select the bloatware you want to remove");
- Log.LogDebug("Bloatware selection detected, prompting for bloatware apps...");
Log.LogInformation("Loading installed bloatware apps...");
var appxClassification = OptimizationHelper.GetBloatwareChoices();
@@ -121,7 +120,7 @@ public class OptimizationManager(SystemSnapshot systemSnapshot)
appxClassification.CautionApps);
- if (SelectedBloatware.Count == 0) // default selected safe apps first time only
+ if (SelectedBloatware.Count == 0)
foreach (var app in appxClassification.SafeApps)
promptBloatware.Select(app);
else
@@ -167,13 +166,14 @@ public class OptimizationManager(SystemSnapshot systemSnapshot)
{
AnsiConsole.Clear();
AnsiConsole.Write(Defaults.Logo);
- SystemHelper.Title("Initializing Optimizer");
+ SystemHelper.Title("Starting Optimization");
Log.LogInformation("Refreshing system information...");
_systemSnapshot = await SystemInfoService.RefreshAsync().ConfigureAwait(false);
Log.LogDebug("Selected tweaks ({TweakAmount}): {Tweaks}", _selectedTweaks.Count,
string.Join(", ", _selectedTweaks.Select(t => t.Name)));
+
if (_selectedTweaks.Any(t => t.Instance is BloatwareAndServices.RemoveBloatwareApps)) // if Bloatware selection is selected
Log.LogDebug("Selected bloatware apps ({BloatwareAmount}): {Bloatware}", SelectedBloatware.Count,
string.Join(", ", SelectedBloatware.Select(app => $"{app.DisplayName} ({app.Version})")));
@@ -221,6 +221,7 @@ public class OptimizationManager(SystemSnapshot systemSnapshot)
});
Rule("Optimization completed!", Theme.Success);
+ SystemHelper.Title("Optimization completed!");
Log.LogInformation($"[{Theme.Success}]Optimization completed![/]");