diff --git a/ArchiSteamFarm/Plugins/Interfaces/IGitHubPluginUpdates.cs b/ArchiSteamFarm/Plugins/Interfaces/IGitHubPluginUpdates.cs index 170f27108..88f54acc8 100644 --- a/ArchiSteamFarm/Plugins/Interfaces/IGitHubPluginUpdates.cs +++ b/ArchiSteamFarm/Plugins/Interfaces/IGitHubPluginUpdates.cs @@ -125,24 +125,31 @@ public interface IGitHubPluginUpdates : IPluginUpdates { throw new ArgumentNullException(nameof(releaseAssets)); } - Dictionary assetsByName = releaseAssets.ToDictionary(static asset => asset.Name, StringComparer.OrdinalIgnoreCase); + // Since we only find assets from available .zip files, we can filter out other assets right away + Dictionary assetsByName = releaseAssets.Where(static asset => asset.Name.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)).ToDictionary(static asset => asset.Name, StringComparer.OrdinalIgnoreCase); - foreach (string possibleMatch in GetPossibleMatches(asfVersion)) { - if (assetsByName.TryGetValue(possibleMatch, out ReleaseAsset? targetAsset)) { - return targetAsset; - } + switch (assetsByName.Count) { + case 0: + // Release does not have a single zip file, so the matching has failed + ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateNoAssetFound, Name, Version, newPluginVersion)); + + return null; + case 1: + // If exactly one match is found, we can return it right away, as it'd be used as a fallback regardless of our matching + return assetsByName.Values.First(); + default: + // Otherwise, we have 2+ zip files, so either we match one of those, or fail + foreach (string possibleMatch in GetPossibleMatches(asfVersion)) { + if (assetsByName.TryGetValue(possibleMatch, out ReleaseAsset? targetAsset)) { + return targetAsset; + } + } + + // We can't possibly determine which zip file to use, the plugin author should either fix the release, or provide custom GetTargetReleaseAsset() implementation + ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateConflictingAssetsFound, Name, Version, newPluginVersion)); + + return null; } - - // The very last fallback in case user uses different naming scheme - HashSet zipAssets = releaseAssets.Where(static asset => asset.Name.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)).ToHashSet(); - - if (zipAssets.Count == 1) { - return zipAssets.First(); - } - - ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateConflictingAssetsFound, Name, Version, newPluginVersion)); - - return null; } protected async Task GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, bool stable, bool forced) {