diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/BundledWinGetHelper.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/BundledWinGetHelper.cs index bf55777f4..1c38c5ed5 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/BundledWinGetHelper.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/BundledWinGetHelper.cs @@ -106,7 +106,15 @@ public IEnumerable GetAvailableUpdates_UnSafe() source = Manager.SourcesHelper.Factory.GetSourceOrDefault(sourceName); } - Packages.Add(new Package(name, id, version, newVersion, source, Manager)); + var package = new Package(name, id, version, newVersion, source, Manager); + if (!WinGetPkgOperationHelper.UpdateAlreadyInstalled(package)) + { + Packages.Add(package); + } + else + { + Logger.Warn($"WinGet package {package.Id} not being shown as an updated as this version has already been marked as installed"); + } } OldLine = line; } diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/NativeWinGetHelper.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/NativeWinGetHelper.cs index a5b79673b..dd87ceac2 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/NativeWinGetHelper.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/ClientHelpers/NativeWinGetHelper.cs @@ -159,7 +159,8 @@ public IEnumerable GetAvailableUpdates_UnSafe() if (nativePackage.IsUpdateAvailable) { IManagerSource source; - source = Manager.SourcesHelper.Factory.GetSourceOrDefault(nativePackage.DefaultInstallVersion.PackageCatalog.Info.Name); + source = Manager.SourcesHelper.Factory.GetSourceOrDefault(nativePackage.DefaultInstallVersion + .PackageCatalog.Info.Name); var UniGetUIPackage = new Package( nativePackage.Name, @@ -168,9 +169,18 @@ public IEnumerable GetAvailableUpdates_UnSafe() nativePackage.DefaultInstallVersion.Version, source, Manager); - NativePackageHandler.AddPackage(UniGetUIPackage, nativePackage); - packages.Add(UniGetUIPackage); - logger.Log($"Found package {nativePackage.Name} {nativePackage.Id} on source {source.Name}, from version {nativePackage.InstalledVersion.Version} to version {nativePackage.DefaultInstallVersion.Version}"); + + if (!WinGetPkgOperationHelper.UpdateAlreadyInstalled(UniGetUIPackage)) + { + NativePackageHandler.AddPackage(UniGetUIPackage, nativePackage); + packages.Add(UniGetUIPackage); + logger.Log( + $"Found package {nativePackage.Name} {nativePackage.Id} on source {source.Name}, from version {nativePackage.InstalledVersion.Version} to version {nativePackage.DefaultInstallVersion.Version}"); + } + else + { + Logger.Warn($"WinGet package {nativePackage.Id} not being shown as an updated as this version has already been marked as installed"); + } } } diff --git a/src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetPkgOperationHelper.cs b/src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetPkgOperationHelper.cs index 121b510f6..38830c5d0 100644 --- a/src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetPkgOperationHelper.cs +++ b/src/UniGetUI.PackageEngine.Managers.WinGet/Helpers/WinGetPkgOperationHelper.cs @@ -1,5 +1,6 @@ using System.Runtime.InteropServices; using Microsoft.Management.Deployment; +using UniGetUI.Core.SettingsEngine; using UniGetUI.Core.Tools; using UniGetUI.PackageEngine.Classes.Manager.BaseProviders; using UniGetUI.PackageEngine.Enums; @@ -120,6 +121,7 @@ protected override OperationVeredict _getOperationResult( if (uintCode == 0x8A150109) { // If the user is required to restart the system to complete the installation + if(operation is OperationType.Update) MarkUpgradeAsDone(package); return OperationVeredict.RestartRequired; } @@ -142,6 +144,14 @@ protected override OperationVeredict _getOperationResult( if (uintCode == 0x8A15010D || uintCode == 0x8A15004F || uintCode == 0x8A15010E) { // Application is already installed + if(operation is OperationType.Update) MarkUpgradeAsDone(package); + return OperationVeredict.Succeeded; + } + + if (returnCode == 0) + { + // Operation succeeded + if(operation is OperationType.Update) MarkUpgradeAsDone(package); return OperationVeredict.Succeeded; } @@ -159,6 +169,16 @@ protected override OperationVeredict _getOperationResult( return OperationVeredict.AutoRetry; } - return returnCode == 0 ? OperationVeredict.Succeeded : OperationVeredict.Failed; + return OperationVeredict.Failed; + } + + private static void MarkUpgradeAsDone(IPackage package) + { + Settings.SetDictionaryItem("WinGetAlreadyUpgradedPackages", package.Id, package.NewVersion); + } + + public static bool UpdateAlreadyInstalled(IPackage package) + { + return Settings.GetDictionaryItem("WinGetAlreadyUpgradedPackages", package.Id) == package.NewVersion; } } diff --git a/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes/IgnoredUpdatesDatabase.cs b/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes/IgnoredUpdatesDatabase.cs index 2e6f43e94..892aa4f0c 100644 --- a/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes/IgnoredUpdatesDatabase.cs +++ b/src/UniGetUI.PackageEngine.PackageManagerClasses/Packages/Classes/IgnoredUpdatesDatabase.cs @@ -82,21 +82,4 @@ public static bool HasUpdatesIgnored(string ignoredId, string version = "*") { return Settings.GetDictionaryItem("IgnoredPackageUpdates", ignoredId); } - - /// - /// Transfers the old ignored updates format (IgnoredPackageUpdates.json) to the new one - /// - public static void TransferOldFormat() - { - string OldFile = Path.Join(CoreData.UniGetUIDataDirectory, "IgnoredPackageUpdates.json"); - if (File.Exists(OldFile)) - { - Dictionary? OldDB = JsonSerializer.Deserialize>(File.ReadAllText(CoreData.IgnoredUpdatesDatabaseFile), options: CoreData.SerializingOptions); - if (OldDB != null) - { - Settings.SetDictionary("IgnoredPackageUpdates", OldDB); - File.Delete(OldFile); - } - } - } } diff --git a/src/UniGetUI/Controls/OperationWidgets/PackageOperations.cs b/src/UniGetUI/Controls/OperationWidgets/PackageOperations.cs index 19eb431e3..932636d73 100644 --- a/src/UniGetUI/Controls/OperationWidgets/PackageOperations.cs +++ b/src/UniGetUI/Controls/OperationWidgets/PackageOperations.cs @@ -357,11 +357,6 @@ protected override async Task HandleSuccess() new Dictionary { { "package", Package.Name } }) ); - if (Package.Version == "Unknown") - { - await Package.AddToIgnoredUpdatesAsync(Package.NewVersion); - } - return AfterFinshAction.TimeoutClose; } diff --git a/src/UniGetUI/MainWindow.xaml.cs b/src/UniGetUI/MainWindow.xaml.cs index f5ab5708e..16797ef1a 100644 --- a/src/UniGetUI/MainWindow.xaml.cs +++ b/src/UniGetUI/MainWindow.xaml.cs @@ -120,8 +120,6 @@ public MainWindow() private static void TransferOldSettingsFormats() { - IgnoredUpdatesDatabase.TransferOldFormat(); - foreach (IPackageManager Manager in PEInterface.Managers) { string SettingName = "Disable" + Manager.Name;