Allow forced plugin updates as well

This commit is contained in:
Archi
2024-03-20 11:13:10 +01:00
parent 5f4962ddcc
commit 437dfd5f02
6 changed files with 28 additions and 21 deletions

View File

@@ -58,7 +58,7 @@ public interface IGitHubPluginUpdates : IPluginUpdates {
/// <example>JustArchiNET/ArchiSteamFarm</example>
string RepositoryName { get; }
Task<Uri?> IPluginUpdates.GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, GlobalConfig.EUpdateChannel updateChannel) {
Task<Uri?> IPluginUpdates.GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, GlobalConfig.EUpdateChannel updateChannel, bool forced) {
ArgumentNullException.ThrowIfNull(asfVersion);
ArgumentException.ThrowIfNullOrEmpty(asfVariant);
@@ -66,7 +66,7 @@ public interface IGitHubPluginUpdates : IPluginUpdates {
throw new InvalidEnumArgumentException(nameof(updateChannel), (int) updateChannel, typeof(GlobalConfig.EUpdateChannel));
}
return GetTargetReleaseURL(asfVersion, asfVariant, asfUpdate, updateChannel == GlobalConfig.EUpdateChannel.Stable);
return GetTargetReleaseURL(asfVersion, asfVariant, asfUpdate, updateChannel == GlobalConfig.EUpdateChannel.Stable, forced);
}
/// <summary>
@@ -137,7 +137,7 @@ public interface IGitHubPluginUpdates : IPluginUpdates {
return Task.FromResult<ReleaseAsset?>(null);
}
protected async Task<Uri?> GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, bool stable) {
protected async Task<Uri?> GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, bool stable, bool forced) {
ArgumentNullException.ThrowIfNull(asfVersion);
ArgumentException.ThrowIfNullOrEmpty(asfVariant);
@@ -159,7 +159,7 @@ public interface IGitHubPluginUpdates : IPluginUpdates {
Version newVersion = new(releaseResponse.Tag);
if (Version >= newVersion) {
if (!forced && (Version >= newVersion)) {
ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateNotFound, Name, Version, newVersion));
return null;

View File

@@ -42,8 +42,9 @@ public interface IPluginUpdates : IPlugin {
/// <param name="asfVariant">ASF variant of current instance, which may be useful if you're providing different versions for different ASF variants.</param>
/// <param name="asfUpdate">Boolean value specifying whether ASF is being updated right now to given version.</param>
/// <param name="updateChannel">ASF update channel specified for this request. This might be different from the one specified in <see cref="GlobalConfig" />, as user might've specified other one for this request.</param>
/// <param name="forced">Boolean value specifying whether user has requested forced plugin update, that is, one that should always execute if possible - even with the same and lower version (downgrade).</param>
/// <returns>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.</returns>
Task<Uri?> GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, GlobalConfig.EUpdateChannel updateChannel);
Task<Uri?> GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, GlobalConfig.EUpdateChannel updateChannel, bool forced);
/// <summary>
/// ASF will call this method after update to the new plugin version has been finished, just before restart of the process.

View File

@@ -709,7 +709,7 @@ public static class PluginsCore {
}
}
internal static async Task<bool> UpdatePlugins(Version asfVersion, bool asfUpdate, GlobalConfig.EUpdateChannel? updateChannel = null) {
internal static async Task<bool> UpdatePlugins(Version asfVersion, bool asfUpdate, GlobalConfig.EUpdateChannel? updateChannel = null, bool forced = false) {
ArgumentNullException.ThrowIfNull(asfVersion);
if (updateChannel.HasValue && !Enum.IsDefined(updateChannel.Value)) {
@@ -720,10 +720,10 @@ public static class PluginsCore {
return false;
}
return await UpdatePlugins(asfVersion, asfUpdate, ActivePluginUpdates, updateChannel).ConfigureAwait(false);
return await UpdatePlugins(asfVersion, asfUpdate, ActivePluginUpdates, updateChannel, forced).ConfigureAwait(false);
}
internal static async Task<bool> UpdatePlugins(Version asfVersion, bool asfUpdate, IReadOnlyCollection<IPluginUpdates> plugins, GlobalConfig.EUpdateChannel? updateChannel = null) {
internal static async Task<bool> UpdatePlugins(Version asfVersion, bool asfUpdate, IReadOnlyCollection<IPluginUpdates> plugins, GlobalConfig.EUpdateChannel? updateChannel = null, bool forced = false) {
ArgumentNullException.ThrowIfNull(asfVersion);
if ((plugins == null) || (plugins.Count == 0)) {
@@ -746,9 +746,9 @@ public static class PluginsCore {
ASF.ArchiLogger.LogGenericInfo(Strings.PluginUpdatesChecking);
IList<bool> pluginUpdates = await Utilities.InParallel(plugins.Select(plugin => UpdatePlugin(asfVersion, asfUpdate, plugin, updateChannel.Value))).ConfigureAwait(false);
IList<bool> pluginUpdates = await Utilities.InParallel(plugins.Select(plugin => UpdatePlugin(asfVersion, asfUpdate, plugin, updateChannel.Value, forced))).ConfigureAwait(false);
return pluginUpdates.Any(static restartNeeded => restartNeeded);
return pluginUpdates.Any(static updated => updated);
}
[UnconditionalSuppressMessage("AssemblyLoadTrimming", "IL2026:RequiresUnreferencedCode", Justification = "We don't care about trimmed assemblies, as we need it to work only with the known (used) ones")]
@@ -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<bool> UpdatePlugin(Version asfVersion, bool asfUpdate, IPluginUpdates plugin, GlobalConfig.EUpdateChannel updateChannel) {
private static async Task<bool> UpdatePlugin(Version asfVersion, bool asfUpdate, IPluginUpdates plugin, GlobalConfig.EUpdateChannel updateChannel, bool forced) {
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, asfUpdate, updateChannel).ConfigureAwait(false);
Uri? releaseURL = await plugin.GetTargetReleaseURL(asfVersion, SharedInfo.BuildInfo.Variant, asfUpdate, updateChannel, forced).ConfigureAwait(false);
if (releaseURL == null) {
return false;