From 997e7f04202536f532bbebeecc1b63442ac19471 Mon Sep 17 00:00:00 2001 From: Archi Date: Wed, 20 Mar 2024 04:42:18 +0100 Subject: [PATCH] Add bool asfUpdate to IPluginUpdates --- ArchiSteamFarm/Core/ASF.cs | 4 ++-- .../Plugins/Interfaces/IGitHubPluginUpdates.cs | 2 +- ArchiSteamFarm/Plugins/Interfaces/IPluginUpdates.cs | 5 +++-- ArchiSteamFarm/Plugins/PluginsCore.cs | 12 ++++++------ ArchiSteamFarm/Steam/Interaction/Actions.cs | 2 +- 5 files changed, 13 insertions(+), 12 deletions(-) diff --git a/ArchiSteamFarm/Core/ASF.cs b/ArchiSteamFarm/Core/ASF.cs index f5d0481d0..f112e47a3 100644 --- a/ArchiSteamFarm/Core/ASF.cs +++ b/ArchiSteamFarm/Core/ASF.cs @@ -202,7 +202,7 @@ public static class ASF { if (!updated) { // ASF wasn't updated as part of the process, update the plugins alone - updated = await PluginsCore.UpdatePlugins(SharedInfo.Version, updateChannel).ConfigureAwait(false); + updated = await PluginsCore.UpdatePlugins(SharedInfo.Version, false, updateChannel).ConfigureAwait(false); } return (updated, newVersion); @@ -986,7 +986,7 @@ public static class ASF { } // We're ready to start update process, handle any plugin updates ready for new version - await PluginsCore.UpdatePlugins(newVersion, updateChannel).ConfigureAwait(false); + await PluginsCore.UpdatePlugins(newVersion, true, updateChannel).ConfigureAwait(false); return Utilities.UpdateFromArchive(zipArchive, SharedInfo.HomeDirectory); } diff --git a/ArchiSteamFarm/Plugins/Interfaces/IGitHubPluginUpdates.cs b/ArchiSteamFarm/Plugins/Interfaces/IGitHubPluginUpdates.cs index 6dcbaf246..7bafb637c 100644 --- a/ArchiSteamFarm/Plugins/Interfaces/IGitHubPluginUpdates.cs +++ b/ArchiSteamFarm/Plugins/Interfaces/IGitHubPluginUpdates.cs @@ -58,7 +58,7 @@ public interface IGitHubPluginUpdates : IPluginUpdates { /// JustArchiNET/ArchiSteamFarm string RepositoryName { get; } - Task IPluginUpdates.GetTargetReleaseURL(Version asfVersion, string asfVariant, GlobalConfig.EUpdateChannel updateChannel) { + Task IPluginUpdates.GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, GlobalConfig.EUpdateChannel updateChannel) { ArgumentNullException.ThrowIfNull(asfVersion); ArgumentException.ThrowIfNullOrEmpty(asfVariant); diff --git a/ArchiSteamFarm/Plugins/Interfaces/IPluginUpdates.cs b/ArchiSteamFarm/Plugins/Interfaces/IPluginUpdates.cs index c9fcf7782..5741b70d5 100644 --- a/ArchiSteamFarm/Plugins/Interfaces/IPluginUpdates.cs +++ b/ArchiSteamFarm/Plugins/Interfaces/IPluginUpdates.cs @@ -38,11 +38,12 @@ public interface IPluginUpdates : IPlugin { /// /// ASF will call this function for determining the target release asset URL to update to. /// - /// Target ASF version that plugin update should be compatible with. In rare cases, this might not match currently running ASF version, in particular when updating to newer release and checking if any plugins are compatible with it. + /// Target ASF version that plugin update should be compatible with. In rare cases, this might not match currently running ASF version, in particular when updating to newer release and checking if any plugins are compatible with it - see . /// ASF variant of current instance, which may be useful if you're providing different versions for different ASF variants. + /// Boolean value specifying whether ASF is being updated right now to given /// ASF update channel specified for this request. This might be different from the one specified in , as user might've specified other one for this request. /// Target release asset URL that should be used for auto-update. It's permitted to return null if you want to skip update, e.g. because no new version is available. - Task GetTargetReleaseURL(Version asfVersion, string asfVariant, GlobalConfig.EUpdateChannel updateChannel); + Task GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, GlobalConfig.EUpdateChannel updateChannel); /// /// ASF will call this method after update to the new plugin version has been finished, just before restart of the process. diff --git a/ArchiSteamFarm/Plugins/PluginsCore.cs b/ArchiSteamFarm/Plugins/PluginsCore.cs index 52d957611..a2d382508 100644 --- a/ArchiSteamFarm/Plugins/PluginsCore.cs +++ b/ArchiSteamFarm/Plugins/PluginsCore.cs @@ -709,7 +709,7 @@ public static class PluginsCore { } } - internal static async Task UpdatePlugins(Version asfVersion, GlobalConfig.EUpdateChannel? updateChannel = null) { + internal static async Task UpdatePlugins(Version asfVersion, bool asfUpdate, GlobalConfig.EUpdateChannel? updateChannel = null) { ArgumentNullException.ThrowIfNull(asfVersion); if (updateChannel.HasValue && !Enum.IsDefined(updateChannel.Value)) { @@ -720,10 +720,10 @@ public static class PluginsCore { return false; } - return await UpdatePlugins(asfVersion, ActivePluginUpdates, updateChannel).ConfigureAwait(false); + return await UpdatePlugins(asfVersion, asfUpdate, ActivePluginUpdates, updateChannel).ConfigureAwait(false); } - internal static async Task UpdatePlugins(Version asfVersion, IReadOnlyCollection plugins, GlobalConfig.EUpdateChannel? updateChannel = null) { + internal static async Task UpdatePlugins(Version asfVersion, bool asfUpdate, IReadOnlyCollection plugins, GlobalConfig.EUpdateChannel? updateChannel = null) { ArgumentNullException.ThrowIfNull(asfVersion); if ((plugins == null) || (plugins.Count == 0)) { @@ -746,7 +746,7 @@ public static class PluginsCore { ASF.ArchiLogger.LogGenericInfo(Strings.PluginUpdatesChecking); - IList pluginUpdates = await Utilities.InParallel(plugins.Select(plugin => UpdatePlugin(asfVersion, plugin, updateChannel.Value))).ConfigureAwait(false); + IList pluginUpdates = await Utilities.InParallel(plugins.Select(plugin => UpdatePlugin(asfVersion, asfUpdate, plugin, updateChannel.Value))).ConfigureAwait(false); return pluginUpdates.Any(static restartNeeded => restartNeeded); } @@ -794,7 +794,7 @@ public static class PluginsCore { } [UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL3000", Justification = "We don't care about trimmed assemblies, as we need it to work only with the known (used) ones")] - private static async Task UpdatePlugin(Version asfVersion, IPluginUpdates plugin, GlobalConfig.EUpdateChannel updateChannel) { + private static async Task UpdatePlugin(Version asfVersion, bool asfUpdate, IPluginUpdates plugin, GlobalConfig.EUpdateChannel updateChannel) { ArgumentNullException.ThrowIfNull(asfVersion); ArgumentNullException.ThrowIfNull(plugin); @@ -827,7 +827,7 @@ public static class PluginsCore { Directory.Delete(backupDirectory, true); } - Uri? releaseURL = await plugin.GetTargetReleaseURL(asfVersion, SharedInfo.BuildInfo.Variant, updateChannel).ConfigureAwait(false); + Uri? releaseURL = await plugin.GetTargetReleaseURL(asfVersion, SharedInfo.BuildInfo.Variant, asfUpdate, updateChannel).ConfigureAwait(false); if (releaseURL == null) { return false; diff --git a/ArchiSteamFarm/Steam/Interaction/Actions.cs b/ArchiSteamFarm/Steam/Interaction/Actions.cs index 8457296bd..3c75e0d2e 100644 --- a/ArchiSteamFarm/Steam/Interaction/Actions.cs +++ b/ArchiSteamFarm/Steam/Interaction/Actions.cs @@ -504,7 +504,7 @@ public sealed class Actions : IAsyncDisposable, IDisposable { return (false, Strings.NothingFound); } - bool restartNeeded = await PluginsCore.UpdatePlugins(SharedInfo.Version, pluginsForUpdate, channel).ConfigureAwait(false); + bool restartNeeded = await PluginsCore.UpdatePlugins(SharedInfo.Version, false, pluginsForUpdate, channel).ConfigureAwait(false); if (restartNeeded) { Utilities.InBackground(ASF.RestartOrExit);