Skip to content

Commit

Permalink
Merge pull request #3042 from marticliment/fix-winget-showing-updates…
Browse files Browse the repository at this point in the history
…-repeatedly

Prevent WinGet upgradable packages from showing again and again
  • Loading branch information
marticliment authored Dec 2, 2024
2 parents 82c7853 + b0efa56 commit 1416183
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,15 @@ public IEnumerable<Package> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,8 @@ public IEnumerable<Package> 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,
Expand All @@ -168,9 +169,18 @@ public IEnumerable<Package> 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");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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;
}

Expand All @@ -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;
}

Expand All @@ -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<string, string>("WinGetAlreadyUpgradedPackages", package.Id, package.NewVersion);
}

public static bool UpdateAlreadyInstalled(IPackage package)
{
return Settings.GetDictionaryItem<string, string>("WinGetAlreadyUpgradedPackages", package.Id) == package.NewVersion;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,4 @@ public static bool HasUpdatesIgnored(string ignoredId, string version = "*")
{
return Settings.GetDictionaryItem<string, string>("IgnoredPackageUpdates", ignoredId);
}

/// <summary>
/// Transfers the old ignored updates format (IgnoredPackageUpdates.json) to the new one
/// </summary>
public static void TransferOldFormat()
{
string OldFile = Path.Join(CoreData.UniGetUIDataDirectory, "IgnoredPackageUpdates.json");
if (File.Exists(OldFile))
{
Dictionary<string, string>? OldDB = JsonSerializer.Deserialize<Dictionary<string, string>>(File.ReadAllText(CoreData.IgnoredUpdatesDatabaseFile), options: CoreData.SerializingOptions);
if (OldDB != null)
{
Settings.SetDictionary("IgnoredPackageUpdates", OldDB);
File.Delete(OldFile);
}
}
}
}
5 changes: 0 additions & 5 deletions src/UniGetUI/Controls/OperationWidgets/PackageOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,11 +357,6 @@ protected override async Task<AfterFinshAction> HandleSuccess()
new Dictionary<string, object?> { { "package", Package.Name } })
);

if (Package.Version == "Unknown")
{
await Package.AddToIgnoredUpdatesAsync(Package.NewVersion);
}

return AfterFinshAction.TimeoutClose;
}

Expand Down
2 changes: 0 additions & 2 deletions src/UniGetUI/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ public MainWindow()

private static void TransferOldSettingsFormats()
{
IgnoredUpdatesDatabase.TransferOldFormat();

foreach (IPackageManager Manager in PEInterface.Managers)
{
string SettingName = "Disable" + Manager.Name;
Expand Down

0 comments on commit 1416183

Please sign in to comment.