Free, open-source Windows optimization tool for performance, privacy, and simplicity.
C# csharpdebloatdotnetgamingopen-sourceoptimizationoptimizeroptimizerduckperformanceprivacytweakertweakswindowswinui
fix(ui): report packages Windows refuses to remove
fatDuck417db7ac3061
diff --git a/optimizerDuck.Test/Services/UI/BloatwareRemovalParsingTests.cs b/optimizerDuck.Test/Services/UI/BloatwareRemovalParsingTests.csnew file mode 100644index 0000000..79759d4--- /dev/null+++ b/optimizerDuck.Test/Services/UI/BloatwareRemovalParsingTests.cs@@ -0,0 +1,64 @@+using optimizerDuck.Services.UI;++namespace optimizerDuck.Test.Services.UI;++public class BloatwareRemovalParsingTests+{+ [Fact]+ public void ParseRemovalOutput_RemovedPackage_ReportsSuccess()+ {+ var result = BloatwareService.ParseRemovalOutput(+ "Removed: Test.Package_1.0.0.0_x64__abc\nRemoved provisioned package: Test.Package\n"+ );++ Assert.True(result.Succeeded);+ Assert.Empty(result.Failures);+ }++ [Fact]+ public void ParseRemovalOutput_RefusedPackage_CarriesTheLine()+ {+ var result = BloatwareService.ParseRemovalOutput(+ "Failed: Test.Package_1.0.0.0_x64__abc. Error: the package is in use\n"+ );++ Assert.False(result.Succeeded);+ Assert.Contains(result.Failures, f => f.Contains("in use"));+ }++ [Fact]+ public void ParseRemovalOutput_RefusedProvisionedPackage_IsAFailure()+ {+ var result = BloatwareService.ParseRemovalOutput(+ "Failed removing provisioned package: Test.Package. Error: access denied\n"+ );++ Assert.False(result.Succeeded);+ Assert.Single(result.Failures);+ }++ [Fact]+ public void ParseRemovalOutput_NothingInstalled_IsNotAFailure()+ {+ var result = BloatwareService.ParseRemovalOutput("No installed package found for Test\n");++ Assert.True(result.Succeeded);+ }++ [Fact]+ public void ParseRemovalOutput_SkippedProvisionedRemoval_IsNotAFailure()+ {+ var result = BloatwareService.ParseRemovalOutput(+ "Removed: Test.Package_1.0.0.0_x64__abc\nSkipping provisioned package removal (disabled by user)\n"+ );++ Assert.True(result.Succeeded);+ }++ [Fact]+ public void ParseRemovalOutput_EmptyOutput_ReportsNoFailureOnItsOwn()+ {+ // The shell exit code decides that case, not the parser.+ Assert.True(BloatwareService.ParseRemovalOutput(string.Empty).Succeeded);+ }+}diff --git a/optimizerDuck/Resources/Languages/Translations.ar-SA.resx b/optimizerDuck/Resources/Languages/Translations.ar-SA.resxindex 2a988ad..ce39ceb 100644--- a/optimizerDuck/Resources/Languages/Translations.ar-SA.resx+++ b/optimizerDuck/Resources/Languages/Translations.ar-SA.resx@@ -2270,5 +2270,11 @@<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>كانت حالة الإسبات غير معروفة عند تطبيق هذا، لذلك لا شيء يُستعاد</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>لم تتم إزالة بعض الحزم</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>لم يقم Windows بإزالة هذه الحزم: {0}</value>+ </data></root>diff --git a/optimizerDuck/Resources/Languages/Translations.de-DE.resx b/optimizerDuck/Resources/Languages/Translations.de-DE.resxindex 0a119b3..f0b09a9 100644--- a/optimizerDuck/Resources/Languages/Translations.de-DE.resx+++ b/optimizerDuck/Resources/Languages/Translations.de-DE.resx@@ -2280,4 +2280,10 @@ Aktualisiere jetzt, um die neuesten Funktionen, Verbesserungen und Fehlerbehebun<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>Der Ruhezustand war beim Anwenden unbekannt, es wird also nichts wiederhergestellt</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>Einige Pakete wurden nicht entfernt</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows hat diese Pakete nicht entfernt: {0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Resources/Languages/Translations.es-ES.resx b/optimizerDuck/Resources/Languages/Translations.es-ES.resxindex 39f99ed..4ff4f6f 100644--- a/optimizerDuck/Resources/Languages/Translations.es-ES.resx+++ b/optimizerDuck/Resources/Languages/Translations.es-ES.resx@@ -4033,4 +4033,10 @@ Actualiza ahora para disfrutar de las nuevas funciones y mejoras.</value><data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>El estado de hibernación era desconocido al aplicar esto, así que no se restaura nada</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>Algunos paquetes no se eliminaron</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows no eliminó estos paquetes: {0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Resources/Languages/Translations.fr-FR.resx b/optimizerDuck/Resources/Languages/Translations.fr-FR.resxindex ca72256..d237c0d 100644--- a/optimizerDuck/Resources/Languages/Translations.fr-FR.resx+++ b/optimizerDuck/Resources/Languages/Translations.fr-FR.resx@@ -2228,4 +2228,10 @@ Mettez à jour maintenant pour profiter des dernières fonctionnalités, amélio<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>L'état de veille prolongée était inconnu lors de l'application, rien n'est donc restauré</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>Certains paquets n'ont pas été supprimés</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows n'a pas supprimé ces paquets : {0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Resources/Languages/Translations.he-IL.resx b/optimizerDuck/Resources/Languages/Translations.he-IL.resxindex 4c80925..cf37374 100644--- a/optimizerDuck/Resources/Languages/Translations.he-IL.resx+++ b/optimizerDuck/Resources/Languages/Translations.he-IL.resx@@ -2285,4 +2285,10 @@<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>מצב השינה היה לא ידוע בעת ההחלה, ולכן דבר לא משוחזר</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>חלק מהחבילות לא הוסרו</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows לא הסיר את החבילות האלה: {0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Resources/Languages/Translations.id-ID.resx b/optimizerDuck/Resources/Languages/Translations.id-ID.resxindex a5fb056..dd86aaa 100644--- a/optimizerDuck/Resources/Languages/Translations.id-ID.resx+++ b/optimizerDuck/Resources/Languages/Translations.id-ID.resx@@ -2285,4 +2285,10 @@ Perbarui sekarang untuk menikmati fitur terbaru, peningkatan, dan perbaikan bug.<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>Status hibernasi tidak diketahui saat ini diterapkan, jadi tidak ada yang dipulihkan</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>Beberapa paket tidak dihapus</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows tidak menghapus paket berikut: {0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Resources/Languages/Translations.it-IT.resx b/optimizerDuck/Resources/Languages/Translations.it-IT.resxindex ad0a061..6b7a5b8 100644--- a/optimizerDuck/Resources/Languages/Translations.it-IT.resx+++ b/optimizerDuck/Resources/Languages/Translations.it-IT.resx@@ -2236,4 +2236,10 @@ Aggiorna ora per godere delle ultime funzionalità, miglioramenti e correzioni.<<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>Lo stato di ibernazione era sconosciuto al momento dell'applicazione, quindi non viene ripristinato nulla</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>Alcuni pacchetti non sono stati rimossi</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows non ha rimosso questi pacchetti: {0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Resources/Languages/Translations.ja-JP.resx b/optimizerDuck/Resources/Languages/Translations.ja-JP.resxindex 8c5a37c..9f4f7c5 100644--- a/optimizerDuck/Resources/Languages/Translations.ja-JP.resx+++ b/optimizerDuck/Resources/Languages/Translations.ja-JP.resx@@ -2220,4 +2220,10 @@<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>適用時の休止状態が不明だったため、復元する内容はありません</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>一部のパッケージを削除できませんでした</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows は次のパッケージを削除しませんでした: {0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Resources/Languages/Translations.ko-KR.resx b/optimizerDuck/Resources/Languages/Translations.ko-KR.resxindex e90311b..ec28a5a 100644--- a/optimizerDuck/Resources/Languages/Translations.ko-KR.resx+++ b/optimizerDuck/Resources/Languages/Translations.ko-KR.resx@@ -2219,4 +2219,10 @@<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>적용할 때 최대 절전 상태를 알 수 없었으므로 복원할 내용이 없습니다</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>일부 패키지가 제거되지 않았습니다</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows에서 다음 패키지를 제거하지 않았습니다: {0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Resources/Languages/Translations.pl-PL.resx b/optimizerDuck/Resources/Languages/Translations.pl-PL.resxindex 449f4a9..37848df 100644--- a/optimizerDuck/Resources/Languages/Translations.pl-PL.resx+++ b/optimizerDuck/Resources/Languages/Translations.pl-PL.resx@@ -2228,4 +2228,10 @@ Zaktualizuj teraz, aby korzystać z najnowszych funkcji, ulepszeń i poprawek b<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>Stan hibernacji był nieznany w momencie zastosowania, więc nic nie zostanie przywrócone</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>Niektóre pakiety nie zostały usunięte</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows nie usunął tych pakietów: {0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Resources/Languages/Translations.pt-BR.resx b/optimizerDuck/Resources/Languages/Translations.pt-BR.resxindex 3db2b69..00eeb02 100644--- a/optimizerDuck/Resources/Languages/Translations.pt-BR.resx+++ b/optimizerDuck/Resources/Languages/Translations.pt-BR.resx@@ -2228,4 +2228,10 @@ Atualize agora para desfrutar das últimas funcionalidades, melhorias e correç<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>O estado de hibernação era desconhecido quando isto foi aplicado, então nada é restaurado</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>Alguns pacotes não foram removidos</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>O Windows não removeu estes pacotes: {0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Resources/Languages/Translations.resx b/optimizerDuck/Resources/Languages/Translations.resxindex 224730e..b3260ca 100644--- a/optimizerDuck/Resources/Languages/Translations.resx+++ b/optimizerDuck/Resources/Languages/Translations.resx@@ -2286,4 +2286,10 @@ Update now to enjoy the latest features, improvements, and bug fixes.</value><data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>Hibernation state was unknown when this was applied, so nothing is restored</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>Some packages were not removed</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows did not remove these packages: {0}</value>+ </data></root>diff --git a/optimizerDuck/Resources/Languages/Translations.ru-RU.resx b/optimizerDuck/Resources/Languages/Translations.ru-RU.resxindex 09eda27..2b5c902 100644--- a/optimizerDuck/Resources/Languages/Translations.ru-RU.resx+++ b/optimizerDuck/Resources/Languages/Translations.ru-RU.resx@@ -2228,4 +2228,10 @@<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>Состояние спящего режима было неизвестно при применении, поэтому ничего не восстанавливается</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>Некоторые пакеты не были удалены</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows не удалил эти пакеты: {0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Resources/Languages/Translations.tr-TR.resx b/optimizerDuck/Resources/Languages/Translations.tr-TR.resxindex 1629545..38ee0cd 100644--- a/optimizerDuck/Resources/Languages/Translations.tr-TR.resx+++ b/optimizerDuck/Resources/Languages/Translations.tr-TR.resx@@ -2219,4 +2219,10 @@ En son özelliklerden, iyileştirmelerden ve hata düzeltmelerinden yararlanmak<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>Bu uygulandığında hazırda bekletme durumu bilinmiyordu, bu nedenle hiçbir şey geri yüklenmez</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>Bazı paketler kaldırılamadı</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows şu paketleri kaldırmadı: {0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Resources/Languages/Translations.vi-VN.resx b/optimizerDuck/Resources/Languages/Translations.vi-VN.resxindex e2a53af..e67d85a 100644--- a/optimizerDuck/Resources/Languages/Translations.vi-VN.resx+++ b/optimizerDuck/Resources/Languages/Translations.vi-VN.resx@@ -2220,4 +2220,10 @@ Cập nhật ngay để trải nghiệm các tính năng mới, cải tiến và<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>Không xác định được trạng thái hibernation khi áp dụng, nên không có gì để khôi phục</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>Một số gói chưa được gỡ</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows chưa gỡ các gói sau: {0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Resources/Languages/Translations.zh-CN.resx b/optimizerDuck/Resources/Languages/Translations.zh-CN.resxindex 13907cd..2bfc16e 100644--- a/optimizerDuck/Resources/Languages/Translations.zh-CN.resx+++ b/optimizerDuck/Resources/Languages/Translations.zh-CN.resx@@ -2236,4 +2236,10 @@<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>应用时 hibernation 状态未知,因此不会还原任何内容</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>部分包未能移除</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows 未能移除此包:{0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Resources/Languages/Translations.zh-TW.resx b/optimizerDuck/Resources/Languages/Translations.zh-TW.resxindex b006e49..d72f974 100644--- a/optimizerDuck/Resources/Languages/Translations.zh-TW.resx+++ b/optimizerDuck/Resources/Languages/Translations.zh-TW.resx@@ -2223,4 +2223,10 @@<data name="Revert.Hibernation.Description.Unknown" xml:space="preserve"><value>套用時 hibernation 狀態未知,因此不會還原任何內容</value></data>+ <data name="Bloatware.Remove.Failed.Title" xml:space="preserve">+ <value>部分套件未能移除</value>+ </data>+ <data name="Bloatware.Remove.Failed.Message" xml:space="preserve">+ <value>Windows 未能移除這些套件:{0}</value>+ </data></root>\ No newline at end of filediff --git a/optimizerDuck/Services/UI/BloatwareService.cs b/optimizerDuck/Services/UI/BloatwareService.csindex 2c527dc..76a477d 100644--- a/optimizerDuck/Services/UI/BloatwareService.cs+++ b/optimizerDuck/Services/UI/BloatwareService.cs@@ -1,4 +1,4 @@-using System.Collections.Concurrent;+using System.Collections.Concurrent;using System.IO;using System.Text.Json;using System.Text.Json.Serialization;@@ -142,6 +142,42 @@ public class BloatwareService(/// accepted; deserialising only as a list silently yielded an empty result for the/// single-package case./// </summary>+ /// <summary>Outcome of one package removal, derived from what the removal script reported.</summary>+ /// <param name="Failures">+ /// One entry per refusal, empty when Windows removed the package or reported that nothing+ /// was installed.+ /// </param>+ public sealed record AppXRemovalResult(IReadOnlyList<string> Failures)+ {+ /// <summary>Whether Windows reported nothing as refused.</summary>+ public bool Succeeded => Failures.Count == 0;+ }++ /// <summary>+ /// Reads the per package lines the removal script prints. Pure, so the mapping from the+ /// script's output to a result is testable without running PowerShell. The markers are+ /// printed by the script itself rather than by Windows, so a localized PowerShell cannot+ /// change them; a script edit has to move with this parser.+ /// </summary>+ internal static AppXRemovalResult ParseRemovalOutput(string stdout)+ {+ var failures = new List<string>();+ foreach (var line in stdout.Split('\n'))+ {+ var trimmed = line.Trim();+ if (+ trimmed.StartsWith("Failed:", StringComparison.Ordinal)+ || trimmed.StartsWith(+ "Failed removing provisioned package:",+ StringComparison.Ordinal+ )+ )+ failures.Add(trimmed);+ }++ return new AppXRemovalResult(failures);+ }+internal static List<AppXPackage> ParsePackages(string stdout){var json = stdout.TrimStart();@@ -197,7 +233,7 @@ public class BloatwareService(/// <summary>/// Removes an AppX package from the system./// </summary>- public async Task RemoveAppXPackage(AppXPackage appXPackage)+ public async Task<AppXRemovalResult> RemoveAppXPackage(AppXPackage appXPackage){try{@@ -207,7 +243,7 @@ public class BloatwareService("Skip removing app because PackageFullName is empty: {Name}",appXPackage.Name);- return;+ return new AppXRemovalResult([]);}// Safe string literal escaping for PowerShell@@ -288,11 +324,33 @@ public class BloatwareService(if (!string.IsNullOrWhiteSpace(result.Stderr))logger.LogWarning("Remove AppX stderr: {Error}", result.Stderr);- logger.LogInformation("Remove AppX finished for {Name}", appXPackage.Name);+ var outcome = ParseRemovalOutput(result.Stdout);++ // A shell that exited non zero without printing a per package line never reported a+ // removal, so the captured error text stands in for it.+ if (outcome.Succeeded && result.ExitCode != 0)+ outcome = new AppXRemovalResult([result.Stderr]);++ if (outcome.Succeeded)+ {+ logger.LogInformation("Remove AppX finished for {Name}", appXPackage.Name);+ }+ else+ {+ foreach (var failure in outcome.Failures)+ logger.LogError(+ "[APPX][FAIL] {Name}: {Failure}",+ appXPackage.Name,+ failure+ );+ }++ return outcome;}catch (Exception ex){logger.LogError(ex, "Failed removing AppX package {Name}", appXPackage.Name);+ return new AppXRemovalResult([ex.Message]);}}diff --git a/optimizerDuck/UI/ViewModels/Pages/BloatwareViewModel.cs b/optimizerDuck/UI/ViewModels/Pages/BloatwareViewModel.csindex 7c9d40e..ad251ef 100644--- a/optimizerDuck/UI/ViewModels/Pages/BloatwareViewModel.cs+++ b/optimizerDuck/UI/ViewModels/Pages/BloatwareViewModel.cs@@ -1,4 +1,4 @@-using System.Collections.ObjectModel;+using System.Collections.ObjectModel;using System.ComponentModel;using CommunityToolkit.Mvvm.ComponentModel;using CommunityToolkit.Mvvm.Input;@@ -12,6 +12,7 @@ using optimizerDuck.Services.UI;using optimizerDuck.UI.Dialogs;using optimizerDuck.UI.ViewModels.Dialogs;using Wpf.Ui;+using Wpf.Ui.Extensions;using Wpf.Ui.Controls;using AppXPackage = optimizerDuck.Domain.Optimizations.Models.Bloatware.AppXPackage;@@ -242,6 +243,8 @@ public partial class BloatwareViewModel : ViewModelIsFooterVisible = false,};+ var failed = new List<string>();+try{_logger.LogInformation(@@ -267,8 +270,9 @@ public partial class BloatwareViewModel : ViewModelValue = i,});- await _bloatwareService.RemoveAppXPackage(item);- //await Task.Delay(500); // Simulate work+ var removal = await _bloatwareService.RemoveAppXPackage(item);+ if (!removal.Succeeded)+ failed.Add(item.Name ?? item.PackageFullName ?? string.Empty);}}finally@@ -281,6 +285,22 @@ public partial class BloatwareViewModel : ViewModelawait Refresh();CrossPageEventBus.NotifyDataChanged<BloatwareChanged>();}++ // The refreshed list is what shows a package is still installed; this names it, because a+ // package that came back looks like a quirk of Windows otherwise.+ if (failed.Count > 0)+ await _contentDialogService.ShowSimpleDialogAsync(+ new SimpleContentDialogCreateOptions+ {+ Title = Loc.Instance["Bloatware.Remove.Failed.Title"],+ Content = Loc.Instance[+ "Bloatware.Remove.Failed.Message",+ string.Join(", ", failed)+ ],+ CloseButtonText = Loc.Instance["Button.Ok"],+ },+ CancellationToken.None+ );}private bool CanRemoveSelected()