Add bool asfUpdate to IPluginUpdates

This commit is contained in:
Archi
2024-03-20 04:42:18 +01:00
parent 96619b9565
commit 997e7f0420
5 changed files with 13 additions and 12 deletions

View File

@@ -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);
}

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, GlobalConfig.EUpdateChannel updateChannel) {
Task<Uri?> IPluginUpdates.GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, GlobalConfig.EUpdateChannel updateChannel) {
ArgumentNullException.ThrowIfNull(asfVersion);
ArgumentException.ThrowIfNullOrEmpty(asfVariant);

View File

@@ -38,11 +38,12 @@ public interface IPluginUpdates : IPlugin {
/// <summary>
/// ASF will call this function for determining the target release asset URL to update to.
/// </summary>
/// <param name="asfVersion">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.</param>
/// <param name="asfVersion">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 <see cref="asfUpdate"/>.</param>
/// <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 <see cref="asfVersion"/></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>
/// <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, GlobalConfig.EUpdateChannel updateChannel);
Task<Uri?> GetTargetReleaseURL(Version asfVersion, string asfVariant, bool asfUpdate, GlobalConfig.EUpdateChannel updateChannel);
/// <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, GlobalConfig.EUpdateChannel? updateChannel = null) {
internal static async Task<bool> 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<bool> UpdatePlugins(Version asfVersion, IReadOnlyCollection<IPluginUpdates> plugins, GlobalConfig.EUpdateChannel? updateChannel = null) {
internal static async Task<bool> UpdatePlugins(Version asfVersion, bool asfUpdate, IReadOnlyCollection<IPluginUpdates> 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<bool> pluginUpdates = await Utilities.InParallel(plugins.Select(plugin => UpdatePlugin(asfVersion, plugin, updateChannel.Value))).ConfigureAwait(false);
IList<bool> 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<bool> UpdatePlugin(Version asfVersion, IPluginUpdates plugin, GlobalConfig.EUpdateChannel updateChannel) {
private static async Task<bool> 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;

View File

@@ -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);