diff --git a/ArchiSteamFarm.OfficialPlugins.Monitoring/MonitoringPlugin.cs b/ArchiSteamFarm.OfficialPlugins.Monitoring/MonitoringPlugin.cs index 4666b67db..dafb948d6 100644 --- a/ArchiSteamFarm.OfficialPlugins.Monitoring/MonitoringPlugin.cs +++ b/ArchiSteamFarm.OfficialPlugins.Monitoring/MonitoringPlugin.cs @@ -45,7 +45,7 @@ namespace ArchiSteamFarm.OfficialPlugins.Monitoring; [Export(typeof(IPlugin))] [SuppressMessage("ReSharper", "MemberCanBeFileLocal")] -internal sealed class MonitoringPlugin : OfficialPlugin, IDisposable, IGitHubPluginUpdates, IWebInterface, IWebServiceProvider { +internal sealed class MonitoringPlugin : OfficialPlugin, IDisposable, IOfficialGitHubPluginUpdates, IWebInterface, IWebServiceProvider { private const string MeterName = SharedInfo.AssemblyName; private const string MetricNamePrefix = "asf"; diff --git a/ArchiSteamFarm/Plugins/Interfaces/IGitHubPluginUpdates.cs b/ArchiSteamFarm/Plugins/Interfaces/IGitHubPluginUpdates.cs index 227fa63f6..170f27108 100644 --- a/ArchiSteamFarm/Plugins/Interfaces/IGitHubPluginUpdates.cs +++ b/ArchiSteamFarm/Plugins/Interfaces/IGitHubPluginUpdates.cs @@ -114,11 +114,22 @@ public interface IGitHubPluginUpdates : IPluginUpdates { throw new ArgumentNullException(nameof(releaseAssets)); } + return Task.FromResult(FindPossibleMatch(asfVersion, newPluginVersion, releaseAssets)); + } + + protected ReleaseAsset? FindPossibleMatch(Version asfVersion, Version newPluginVersion, IReadOnlyCollection releaseAssets) { + ArgumentNullException.ThrowIfNull(asfVersion); + ArgumentNullException.ThrowIfNull(newPluginVersion); + + if ((releaseAssets == null) || (releaseAssets.Count == 0)) { + throw new ArgumentNullException(nameof(releaseAssets)); + } + Dictionary assetsByName = releaseAssets.ToDictionary(static asset => asset.Name, StringComparer.OrdinalIgnoreCase); foreach (string possibleMatch in GetPossibleMatches(asfVersion)) { if (assetsByName.TryGetValue(possibleMatch, out ReleaseAsset? targetAsset)) { - return Task.FromResult(targetAsset); + return targetAsset; } } @@ -126,12 +137,12 @@ public interface IGitHubPluginUpdates : IPluginUpdates { HashSet zipAssets = releaseAssets.Where(static asset => asset.Name.EndsWith(".zip", StringComparison.OrdinalIgnoreCase)).ToHashSet(); if (zipAssets.Count == 1) { - return Task.FromResult(zipAssets.First()); + return zipAssets.First(); } ASF.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateConflictingAssetsFound, Name, Version, newPluginVersion)); - return Task.FromResult(null); + return null; } protected async Task GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, bool stable, bool forced) { diff --git a/ArchiSteamFarm/Plugins/Interfaces/IOfficialGitHubPluginUpdates.cs b/ArchiSteamFarm/Plugins/Interfaces/IOfficialGitHubPluginUpdates.cs new file mode 100644 index 000000000..92ee7fef1 --- /dev/null +++ b/ArchiSteamFarm/Plugins/Interfaces/IOfficialGitHubPluginUpdates.cs @@ -0,0 +1,45 @@ +// ---------------------------------------------------------------------------------------------- +// _ _ _ ____ _ _____ +// / \ _ __ ___ | |__ (_)/ ___| | |_ ___ __ _ _ __ ___ | ___|__ _ _ __ _ __ ___ +// / _ \ | '__|/ __|| '_ \ | |\___ \ | __|/ _ \ / _` || '_ ` _ \ | |_ / _` || '__|| '_ ` _ \ +// / ___ \ | | | (__ | | | || | ___) || |_| __/| (_| || | | | | || _|| (_| || | | | | | | | +// /_/ \_\|_| \___||_| |_||_||____/ \__|\___| \__,_||_| |_| |_||_| \__,_||_| |_| |_| |_| +// ---------------------------------------------------------------------------------------------- +// | +// Copyright 2015-2024 Ɓukasz "JustArchi" Domeradzki +// Contact: JustArchi@JustArchi.net +// | +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// | +// http://www.apache.org/licenses/LICENSE-2.0 +// | +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using ArchiSteamFarm.Web.GitHub.Data; + +namespace ArchiSteamFarm.Plugins.Interfaces; + +internal interface IOfficialGitHubPluginUpdates : IGitHubPluginUpdates { + Task IGitHubPluginUpdates.GetTargetReleaseAsset(Version asfVersion, string asfVariant, Version newPluginVersion, IReadOnlyCollection releaseAssets) { + ArgumentNullException.ThrowIfNull(asfVersion); + ArgumentException.ThrowIfNullOrEmpty(asfVariant); + ArgumentNullException.ThrowIfNull(newPluginVersion); + + if ((releaseAssets == null) || (releaseAssets.Count == 0)) { + throw new ArgumentNullException(nameof(releaseAssets)); + } + + // For official plugins, the ASF version must match the plugin version + // Refuse to find the match if that's not the case, otherwise fallback to default implementation + return Task.FromResult(asfVersion == newPluginVersion ? FindPossibleMatch(asfVersion, newPluginVersion, releaseAssets) : null); + } +}