Skip to content

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

fix(Managers): update SelectedBloatware type to AppxPackage

itsfatduckd727d8381cdd
diff --git a/optimizerDuck/src/Core/Defaults.cs b/optimizerDuck/src/Core/Defaults.cs
index b36d8df..8b4f04a 100644
--- a/optimizerDuck/src/Core/Defaults.cs
+++ b/optimizerDuck/src/Core/Defaults.cs
@@ -32,7 +32,8 @@ public static class Defaults
public const string ZwtDownloadUrl =
"https://github.com/LuSlower/ZwTimerResolution/releases/download/0.0.0.6/ZwTimer.exe";
- public const string PowerPlanUrl = "https://github.com/itsfatduck/optimizerDuck/raw/refs/heads/master/optimizerDuck.Resources/optimizerDuck.pow";
+ public const string PowerPlanUrl =
+ "https://github.com/itsfatduck/optimizerDuck/raw/refs/heads/master/optimizerDuck.Resources/optimizerDuck.pow";
public const string RestorePointName = "optimizerDuck Restore Point";
public const string PowerPlanGUID = "946c0ca5-6ee0-4f2a-9dd7-7addbb8e60f5";
@@ -54,7 +55,7 @@ public static class Defaults
// @formatter:on
HorizontalAlignment.Center
))
- { Border = CustomBoxBorder.UnderlineBorder, Padding = new Padding(0, 1, 0, 1) };
+ { Border = CustomBoxBorder.UnderlineBorder, Padding = new Padding(0, 1, 0, 1) };
public static readonly string ExePath = Environment.ProcessPath!;
public static readonly string ExeDir = Path.GetDirectoryName(ExePath)!;
@@ -69,17 +70,17 @@ public static class Defaults
public static readonly Dictionary<string, string> SAFE_APPS = new()
{
- ["BingWeather"] = "Weather",
- ["GetHelp"] = "Get Help",
- ["Getstarted"] = "Get Started / Tips",
- ["Messaging"] = "Messaging",
- ["Microsoft3DViewer"] = "3D Viewer",
- ["MicrosoftSolitaireCollection"] = "Solitaire Collection",
- ["MicrosoftStickyNotes"] = "Sticky Notes",
- ["MixedReality.Portal"] = "Mixed Reality Portal",
- ["OneConnect"] = "OneConnect (Connect App)",
- ["People"] = "People",
- ["Print3D"] = "Print 3D",
+ ["Microsoft.BingWeather"] = "Weather",
+ ["Microsoft.GetHelp"] = "Get Help",
+ ["Microsoft.GetStarted"] = "Get Started / Tips",
+ ["Microsoft.Messaging"] = "Messaging",
+ ["Microsoft.Microsoft3DViewer"] = "3D Viewer",
+ ["Microsoft.MicrosoftSolitaireCollection"] = "Solitaire Collection",
+ ["Microsoft.MicrosoftStickyNotes"] = "Sticky Notes",
+ ["Microsoft.MixedReality.Portal"] = "Mixed Reality Portal",
+ ["Microsoft.OneConnect"] = "OneConnect (Connect App)",
+ ["Microsoft.People"] = "People",
+ ["Microsoft.Print3D"] = "Print 3D",
["SkypeApp"] = "Skype",
["WindowsAlarms"] = "Alarms & Clock",
["WindowsCamera"] = "Camera",
@@ -87,21 +88,25 @@ public static class Defaults
["WindowsFeedbackHub"] = "Feedback Hub",
["WindowsSoundRecorder"] = "Voice Recorder",
["YourPhone"] = "Phone Link",
- ["ZuneMusic"] = "Media Player / Groove",
- ["Sway"] = "Microsoft Sway",
- ["3dBuilder"] = "3D Builder (legacy)",
- ["bing"] = "Microsoft Bing (everything)",
- ["Drawboard PDF"] = "Drawboard PDF (OEM)",
+ ["Microsoft.ZuneMusic"] = "Media Player / Groove",
+ ["Microsoft.Sway"] = "Microsoft Sway",
+ ["Microsoft.3DBuilder"] = "3D Builder (legacy)",
+ ["Microsoft.DrawboardPDF"] = "Drawboard PDF (OEM)",
["WindowsPhone"] = "Windows Phone (old)",
["CommsPhone"] = "Communications Phone (old)",
["Microsoft.Todos"] = "Microsoft To Do",
- ["windowscommunicationsapps"] = "Mail and Calendar",
- ["MicrosoftCorporationII.QuickAssist"] = "Quick Assist"
+ ["microsoft.windowscommunicationsapps"] = "Mail and Calendar",
+ ["MicrosoftCorporationII.QuickAssist"] = "Quick Assist",
+ ["Microsoft.Office.OneNote"] = "OneNote",
+ ["Microsoft.YourPhone"] = "Phone Link",
+ ["Microsoft.MicrosoftNews"] = "Microsoft News",
+ ["Microsoft.MicrosoftOfficeHub"] = "Office Hub"
};
+
public static readonly Dictionary<string, string> CAUTION_APPS = new()
{
- ["WindowsCalculator"] = "Calculator",
+ ["Microsoft.WindowsCalculator"] = "Calculator",
["Microsoft.Windows.Photos"] = "Photos",
["Microsoft.MSPaint"] = "Paint",
["Microsoft.Paint3D"] = "Paint 3D",
@@ -111,14 +116,24 @@ public static class Defaults
["Microsoft.XboxIdentityProvider"] = "Xbox Identity Provider",
["Microsoft.WindowsTerminal"] = "Windows Terminal",
["Clipchamp.Clipchamp"] = "Clipchamp (Video Editor)",
- ["MicrosoftWindows.Notepad"] = "Notepad",
+ ["Microsoft.WindowsNotepad"] = "Notepad",
+ ["Microsoft.PowerAutomateDesktop"] = "Power Automate",
+ ["MicrosoftTeams"] = "Microsoft Teams",
+ ["MicrosoftCorporationII.MicrosoftFamily"] = "Microsoft Family Safety",
+ ["MicrosoftCorporationII.MicrosoftSupportDiagnosticTool"] = "Support Diagnostic Tool",
+ ["MicrosoftCorporationII.MicrosoftQuickAssist"] = "Quick Assist",
// Extensions
- ["HEIFImageExtension"] = "HEIF Image Extension",
- ["WebMediaExtensions"] = "Web Media Extensions",
- ["WebpImageExtension"] = "WebP Image Extension",
+ ["Microsoft.HEIFImageExtension"] = "HEIF Image Extension",
+ ["Microsoft.WebMediaExtensions"] = "Web Media Extensions",
+ ["Microsoft.WebpImageExtension"] = "WebP Image Extension",
+ ["Microsoft.RawImageExtension"] = "Raw Image Extension",
+ ["Microsoft.VP9VideoExtensions"] = "VP9 Video Extension",
+ ["Microsoft.AV1VideoExtension"] = "AV1 Video Extension",
// Xbox / Game Bar
+ ["Microsoft.XboxSpeechToTextOverlay"] = "Xbox Speech Overlay",
+ ["Microsoft.XboxGameOverlay"] = "Xbox Game Overlay",
["Microsoft.XboxGamingOverlay"] = "Xbox Game Bar",
- ["Microsoft.XboxApp"] = "Xbox App (Console Companion)",
+ ["Microsoft.XboxApp"] = "Xbox Console Companion",
["Microsoft.Xbox.TCUI"] = "Xbox TCUI"
};
}
\ No newline at end of file
diff --git a/optimizerDuck/src/Core/Helpers/OptimizationHelper.cs b/optimizerDuck/src/Core/Helpers/OptimizationHelper.cs
new file mode 100644
index 0000000..1f5a6ed
--- /dev/null
+++ b/optimizerDuck/src/Core/Helpers/OptimizationHelper.cs
@@ -0,0 +1,176 @@
+using System.Reflection;
+using Microsoft.Extensions.Caching.Memory;
+using Microsoft.Extensions.Logging;
+using Newtonsoft.Json;
+using optimizerDuck.Core.Managers;
+using optimizerDuck.Core.Services;
+using optimizerDuck.Interfaces;
+using optimizerDuck.Models;
+using optimizerDuck.UI.Logger;
+using Spectre.Console;
+
+namespace optimizerDuck.Core.Helpers;
+
+public static class OptimizationHelper
+{
+ private static readonly ILogger Log = Logger.CreateLogger(typeof(OptimizationHelper));
+
+ public static List<OptimizationGroupChoice> GetTweakChoices()
+ {
+ return CacheManager.GetOrCreate("optimization_choices", entry =>
+ {
+ entry.Priority = CacheItemPriority.NeverRemove;
+
+ var groups = new List<OptimizationGroupChoice>();
+ var optimizationGroups = ReflectionHelper.FindImplementationsInLoadedAssemblies(typeof(IOptimizationGroup));
+
+ var enumerable = optimizationGroups as Type[] ?? optimizationGroups.ToArray();
+ var allTweaks = enumerable
+ .SelectMany(og => og.GetNestedTypes(BindingFlags.Public)
+ .Where(t => typeof(IOptimizationTweak).IsAssignableFrom(t))
+ .Select(t => (IOptimizationTweak?)Activator.CreateInstance(t)!))
+ .Where(_ => true)
+ .ToList();
+
+ var globalMaxNameLength = allTweaks.Count != 0
+ ? allTweaks.Max(t => t.Name.Length) + 1
+ : 0;
+
+
+ foreach (var optimizationGroup in enumerable)
+ {
+ var groupInstance = (IOptimizationGroup)Activator.CreateInstance(optimizationGroup)!;
+
+ var tweaks = optimizationGroup
+ .GetNestedTypes(BindingFlags.Public)
+ .Where(t => typeof(IOptimizationTweak).IsAssignableFrom(t))
+ .Select(t => (IOptimizationTweak)Activator.CreateInstance(t)!)
+ .OrderByDescending(t => t.EnabledByDefault)
+ .ToList();
+
+ if (tweaks.Count == 0) // skip groups with no tweaks
+ continue;
+
+ var tweakChoices = tweaks
+ .Select(t =>
+ {
+ var paddedName = t.Name.PadRight(globalMaxNameLength);
+ var description = $"[dim]| {t.Description}[/]";
+
+ return new OptimizationTweakChoice(t, paddedName, description, t.EnabledByDefault);
+ })
+ .ToList();
+
+ groups.Add(new OptimizationGroupChoice(groupInstance.Name, groupInstance.Order, tweakChoices));
+ }
+
+ var orderedGroups = groups.OrderBy(g => g.Priority).ToList();
+ foreach (var g in orderedGroups)
+ {
+ Log.LogDebug("Loaded group {Group}:", g.Name);
+ foreach (var t in g.Tweaks)
+ if (t.Description != null)
+ Log.LogDebug(" - {TweakName} {TweakDescription}", t.Name, Markup.Remove(t.Description));
+ }
+
+ return orderedGroups;
+ });
+ }
+
+ public static AppxClassification GetBloatwareChoices()
+ {
+ return CacheManager.GetOrCreate("bloatware_choices", entry =>
+ {
+ entry.SlidingExpiration = TimeSpan.FromMinutes(5);
+
+ var result = ShellService.PowerShell($$"""
+ # list the SAFE_APPS
+ $safeApps = @({{string.Join(", ", Defaults.SAFE_APPS.Keys.Select(x => $"\"{x}\""))}})
+
+ # list the CAUTION_APPS
+ $cautionApps = @({{string.Join(", ", Defaults.CAUTION_APPS.Keys.Select(x => $"\"{x}\""))}})
+
+ # get the installed apps
+ $installedApps = Get-AppxPackage -AllUsers
+
+ # categorize the installed apps
+ $safeInstalled = $installedApps | Where-Object { $safeApps -contains $_.Name.ToLower() } | Select-Object Name, Version, InstallLocation
+ $cautionInstalled = $installedApps | Where-Object { $cautionApps -contains $_.Name.ToLower() } | Select-Object Name, Version, InstallLocation
+
+ # create the JSON object
+ $result = [PSCustomObject]@{
+ SafeApps = @($safeInstalled | ForEach-Object {
+ [PSCustomObject]@{
+ Name = $_.Name
+ Version = $_.Version
+ InstallLocation = $_.InstallLocation
+ }
+ })
+ CautionApps = @($cautionInstalled | ForEach-Object {
+ [PSCustomObject]@{
+ Name = $_.Name
+ Version = $_.Version
+ InstallLocation = $_.InstallLocation
+ }
+ })
+ }
+
+ # output JSON
+ $result | ConvertTo-Json -Depth 4
+ """);
+
+
+ var raw = JsonConvert.DeserializeObject<AppxClassificationRaw>(result.Stdout);
+
+ var allSafe = raw.SafeApps.SelectMany(x => x).ToList();
+ var allCaution = raw.CautionApps.SelectMany(x => x).ToList();
+
+ var maxDisplayNameLength = new[] {
+ allSafe.Max(x => Defaults.SAFE_APPS.TryGetValue(x.Name, out var dn) ? dn.Length : x.Name.Length),
+ allCaution.Max(x => Defaults.CAUTION_APPS.TryGetValue(x.Name, out var dn) ? dn.Length : x.Name.Length)
+ }.Max() + 1;
+
+ var maxVersionLength = new[] {
+ allSafe.Max(x => x.Version?.Length ?? 0),
+ allCaution.Max(x => x.Version?.Length ?? 0)
+ }.Max() + 1;
+
+ var classification = new AppxClassification(
+ allSafe.Select(app =>
+ {
+ var display = Defaults.SAFE_APPS.TryGetValue(app.Name, out var dn) ? dn : app.Name;
+ return app with
+ {
+ DisplayName = display.PadRight(maxDisplayNameLength),
+ Version = (app.Version ?? string.Empty).PadRight(maxVersionLength)
+ };
+ }).ToList(),
+ allCaution.Select(app =>
+ {
+ var display = Defaults.CAUTION_APPS.TryGetValue(app.Name, out var dn) ? dn : app.Name;
+ return app with
+ {
+ DisplayName = display.PadRight(maxDisplayNameLength),
+ Version = (app.Version ?? string.Empty).PadRight(maxVersionLength)
+ };
+ }).ToList()
+ );
+
+ Log.LogDebug("Found {TotalSafeApps} safe apps: {SafeApps}", classification.SafeApps.Count, string.Join(", ", classification.SafeApps.Select(x => x.Name).ToList()));
+ Log.LogDebug("Found {TotalCautionApps} caution apps: {CautionApps}", classification.CautionApps.Count, string.Join(", ", classification.CautionApps.Select(x => x.Name).ToList()));
+
+ return classification;
+ });
+ }
+
+ private static string ResolveDisplayName(string name, Dictionary<string,string> dict)
+ {
+ var lower = name.ToLowerInvariant();
+ if (dict.TryGetValue(lower, out var exact))
+ return exact;
+
+ var suffix = dict.FirstOrDefault(kv => lower.EndsWith(kv.Key.ToLowerInvariant()));
+ return !string.IsNullOrEmpty(suffix.Value) ? suffix.Value : name;
+ }
+
+}
\ No newline at end of file
diff --git a/optimizerDuck/src/Core/Managers/OptimizationManager.cs b/optimizerDuck/src/Core/Managers/OptimizationManager.cs
index a10ac53..10abb06 100644
--- a/optimizerDuck/src/Core/Managers/OptimizationManager.cs
+++ b/optimizerDuck/src/Core/Managers/OptimizationManager.cs
@@ -22,73 +22,10 @@ public class OptimizationManager(SystemSnapshot systemSnapshot)
private Queue<OptimizationTweakChoice> _selectedTweaks = new();
private SystemSnapshot _systemSnapshot = systemSnapshot;
- public static Queue<string> SelectedBloatware { get; private set; } =
+ public static Queue<AppxPackage> SelectedBloatware { get; private set; } =
new(); // public and static for Remove Bloatware Apps tweak
- private static List<OptimizationGroupChoice> GetTweakChoices()
- {
- return CacheManager.GetOrCreate("optimization_choices", entry =>
- {
- entry.Priority = CacheItemPriority.NeverRemove;
-
- var groups = new List<OptimizationGroupChoice>();
- var optimizationGroups = ReflectionHelper.FindImplementationsInLoadedAssemblies(typeof(IOptimizationGroup));
-
- var enumerable = optimizationGroups as Type[] ?? optimizationGroups.ToArray();
- var allTweaks = enumerable
- .SelectMany(og => og.GetNestedTypes(BindingFlags.Public)
- .Where(t => typeof(IOptimizationTweak).IsAssignableFrom(t))
- .Select(t => (IOptimizationTweak?)Activator.CreateInstance(t)!))
- .Where(_ => true)
- .ToList();
-
- var globalMaxNameLength = allTweaks.Count != 0
- ? allTweaks.Max(t => t.Name.Length) + 1
- : 0;
-
-
- foreach (var optimizationGroup in enumerable)
- {
- var groupInstance = (IOptimizationGroup)Activator.CreateInstance(optimizationGroup)!;
-
- var tweaks = optimizationGroup
- .GetNestedTypes(BindingFlags.Public)
- .Where(t => typeof(IOptimizationTweak).IsAssignableFrom(t))
- .Select(t => (IOptimizationTweak)Activator.CreateInstance(t)!)
- .OrderByDescending(t => t.EnabledByDefault)
- .ToList();
-
- if (tweaks.Count == 0) // skip groups with no tweaks
- continue;
-
- var tweakChoices = tweaks
- .Select(t =>
- {
- var paddedName = t.Name.PadRight(globalMaxNameLength);
- var description = $"[dim]| {t.Description}[/]";
-
- return new OptimizationTweakChoice(t, paddedName, description, t.EnabledByDefault);
- })
- .ToList();
-
- groups.Add(new OptimizationGroupChoice(groupInstance.Name, groupInstance.Order, tweakChoices));
- }
-
- var orderedGroups = groups.OrderBy(g => g.Priority).ToList();
- foreach (var g in orderedGroups)
- {
- Log.LogDebug("Loaded group {Group}:", g.Name);
- foreach (var t in g.Tweaks)
- if (t.Description != null)
- Log.LogDebug(" - {TweakName} {TweakDescription}", t.Name, Markup.Remove(t.Description));
- }
-
- return orderedGroups;
- });
- }
-
-
public async Task<bool> Begin()
{
SystemHelper.Title("Select the tweaks you want to apply");
@@ -97,7 +34,7 @@ public class OptimizationManager(SystemSnapshot systemSnapshot)
Log.LogInformation("Loading optimizations...");
- var optimizationGroups = GetTweakChoices();
+ var optimizationGroups = OptimizationHelper.GetTweakChoices();
Log.LogInformation("Loaded {GroupAmount} groups with {TweakAmount} tweaks.", optimizationGroups.Count,
optimizationGroups.Sum(g => g.Tweaks.Count));
@@ -135,29 +72,44 @@ public class OptimizationManager(SystemSnapshot systemSnapshot)
t.Instance?.GetType() ==
typeof(BloatwareAndServices.RemoveBloatwareApps))) // if Bloatware selection is selected
{
- var promptBloatware = new MultiSelectionPrompt<string>()
+ Log.LogDebug("Bloatware selection detected, prompting for bloatware apps...");
+ Log.LogInformation("Loading installed bloatware apps...");
+
+ var appxClassification = OptimizationHelper.GetBloatwareChoices();
+
+ Log.LogInformation("Found {TotalSafeApps} safe apps and {TotalCautionApps} caution apps.",
+ appxClassification.SafeApps.Count, appxClassification.CautionApps.Count);
+
+ var promptBloatware = new MultiSelectionPrompt<AppxPackage>()
.Title("Select the bloatware you want to remove")
.InstructionsText(Defaults.EscapeCancellableConsoleMultiSelectionPromptInstructionsText)
.Required(true)
.HighlightStyle(Theme.Primary)
- .UseConverter(key =>
- $"{(key.Contains("Safe") || key.Contains("Caution") ? key + " " : "")}{Defaults.SAFE_APPS.GetValueOrDefault(key) ?? Defaults.CAUTION_APPS.GetValueOrDefault(key)}")
- .AddChoiceGroup("[bold underline lightgreen]Safe Apps[/] - [lightgreen]Recommended[/]",
- Defaults.SAFE_APPS.Keys)
- .AddChoiceGroup("[bold underline red]Caution Apps[/] - [red]May cause issues[/]",
- Defaults.CAUTION_APPS.Keys)
+ .UseConverter(app =>
+ $"{(app.DisplayName.Contains("Safe Apps") || app.DisplayName.Contains("Caution Apps") ?
+ app.DisplayName :
+ $"[bold]{app.DisplayName}[/] [dim]{app.Version} {app.InstallLocation}[/]")
+ }")
+ .AddChoiceGroup(
+ new AppxPackage("[bold underline lightgreen]Safe Apps[/] - [lightgreen]Recommended[/]",
+ string.Empty, string.Empty, string.Empty),
+ appxClassification.SafeApps)
+ .AddChoiceGroup(
+ new AppxPackage("[bold underline red]Caution Apps[/] - [red]May cause issues[/]", string.Empty,
+ string.Empty, string.Empty),
+ appxClassification.CautionApps)
.PageSize(24);
if (SelectedBloatware is { Count: > 0 })
foreach (var app in SelectedBloatware)
promptBloatware.Select(app);
else
- foreach (var app in Defaults.SAFE_APPS.Keys)
+ foreach (var app in appxClassification.SafeApps)
promptBloatware.Select(app);
SelectedBloatware =
- new Queue<string>(await escapeCancellableConsole.PromptAsync(promptBloatware)
+ new Queue<AppxPackage>(await escapeCancellableConsole.PromptAsync(promptBloatware)
.ConfigureAwait(false));
}
}
diff --git a/optimizerDuck/src/Models/AppxClassification.cs b/optimizerDuck/src/Models/AppxClassification.cs
new file mode 100644
index 0000000..6d805cf
--- /dev/null
+++ b/optimizerDuck/src/Models/AppxClassification.cs
@@ -0,0 +1,6 @@
+namespace optimizerDuck.Models;
+
+public record struct AppxClassification(
+ List<AppxPackage> SafeApps,
+ List<AppxPackage> CautionApps
+);
\ No newline at end of file
diff --git a/optimizerDuck/src/Models/AppxClassificationRaw.cs b/optimizerDuck/src/Models/AppxClassificationRaw.cs
new file mode 100644
index 0000000..b55503d
--- /dev/null
+++ b/optimizerDuck/src/Models/AppxClassificationRaw.cs
@@ -0,0 +1,6 @@
+namespace optimizerDuck.Models;
+
+public record struct AppxClassificationRaw(
+ List<List<AppxPackage>> SafeApps,
+ List<List<AppxPackage>> CautionApps
+);
\ No newline at end of file
diff --git a/optimizerDuck/src/Models/AppxPackage.cs b/optimizerDuck/src/Models/AppxPackage.cs
new file mode 100644
index 0000000..40a8325
--- /dev/null
+++ b/optimizerDuck/src/Models/AppxPackage.cs
@@ -0,0 +1,8 @@
+namespace optimizerDuck.Models;
+
+public record struct AppxPackage(
+ string DisplayName,
+ string Name,
+ string Version,
+ string InstallLocation
+);
\ No newline at end of file
diff --git a/optimizerDuck/src/UI/Components/PromptDialog.cs b/optimizerDuck/src/UI/Components/PromptDialog.cs
index 06b7030..88cc96e 100644
--- a/optimizerDuck/src/UI/Components/PromptDialog.cs
+++ b/optimizerDuck/src/UI/Components/PromptDialog.cs
@@ -174,7 +174,7 @@ public class PromptDialog
[bold {Theme.Error}]Exception:[/]
[italic]{exception.GetType().Name}[/]
- [bold {Theme.Error}]{exception.Message}[/]
+ [bold {Theme.Error}]{Markup.Escape(exception.Message)}[/]
[dim]──────────────────────────────[/]
[grey]Please check the log file for more details.[/]