Respect updateOverride when updating plugins

This commit is contained in:
Archi
2024-03-20 11:36:14 +01:00
parent 437dfd5f02
commit 533fbe0c2f
5 changed files with 26 additions and 10 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, false, updateChannel, forced).ConfigureAwait(false);
updated = await PluginsCore.UpdatePlugins(SharedInfo.Version, false, updateChannel, updateOverride, forced).ConfigureAwait(false);
}
return (updated, newVersion);
@@ -929,7 +929,7 @@ public static class ASF {
await using (memoryStream.ConfigureAwait(false)) {
using ZipArchive zipArchive = new(memoryStream);
if (!await UpdateFromArchive(newVersion, channel.Value, forced, zipArchive).ConfigureAwait(false)) {
if (!await UpdateFromArchive(newVersion, channel.Value, updateOverride, forced, zipArchive).ConfigureAwait(false)) {
ArchiLogger.LogGenericError(Strings.WarningFailed);
}
}
@@ -965,7 +965,7 @@ public static class ASF {
}
}
private static async Task<bool> UpdateFromArchive(Version newVersion, GlobalConfig.EUpdateChannel updateChannel, bool forced, ZipArchive zipArchive) {
private static async Task<bool> UpdateFromArchive(Version newVersion, GlobalConfig.EUpdateChannel updateChannel, bool updateOverride, bool forced, ZipArchive zipArchive) {
ArgumentNullException.ThrowIfNull(newVersion);
if (!Enum.IsDefined(updateChannel)) {
@@ -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, true, updateChannel, forced).ConfigureAwait(false);
await PluginsCore.UpdatePlugins(newVersion, true, updateChannel, updateOverride, forced).ConfigureAwait(false);
return Utilities.UpdateFromArchive(zipArchive, SharedInfo.HomeDirectory);
}

View File

@@ -1263,6 +1263,12 @@ namespace ArchiSteamFarm.Localization {
}
}
public static string PluginUpdateNewVersionAvailable {
get {
return ResourceManager.GetString("PluginUpdateNewVersionAvailable", resourceCulture);
}
}
public static string PluginUpdateFound {
get {
return ResourceManager.GetString("PluginUpdateFound", resourceCulture);

View File

@@ -779,6 +779,10 @@ Process uptime: {1}</value>
<value>No update available for {0} plugin: {1} ≥ {2}.</value>
<comment>{0} will be replaced by plugin name (string), {1} will be replaced by current plugin's version, {2} will be replaced by remote plugin's version.</comment>
</data>
<data name="PluginUpdateNewVersionAvailable" xml:space="preserve">
<value>New {0} plugin version is available! Consider updating yourself!</value>
<comment>{0} will be replaced by plugin name (string).</comment>
</data>
<data name="PluginUpdateFound" xml:space="preserve">
<value>Found {0} plugin update from version {1} to {2}...</value>
<comment>{0} will be replaced by plugin name (string), {1} will be replaced by current plugin's version, {2} will be replaced by remote plugin's version.</comment>

View File

@@ -709,7 +709,7 @@ public static class PluginsCore {
}
}
internal static async Task<bool> UpdatePlugins(Version asfVersion, bool asfUpdate, GlobalConfig.EUpdateChannel? updateChannel = null, bool forced = false) {
internal static async Task<bool> UpdatePlugins(Version asfVersion, bool asfUpdate, GlobalConfig.EUpdateChannel? updateChannel = null, bool updateOverride = false, 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, forced).ConfigureAwait(false);
return await UpdatePlugins(asfVersion, asfUpdate, ActivePluginUpdates, updateChannel, updateOverride, forced).ConfigureAwait(false);
}
internal static async Task<bool> UpdatePlugins(Version asfVersion, bool asfUpdate, IReadOnlyCollection<IPluginUpdates> plugins, GlobalConfig.EUpdateChannel? updateChannel = null, bool forced = false) {
internal static async Task<bool> UpdatePlugins(Version asfVersion, bool asfUpdate, IReadOnlyCollection<IPluginUpdates> plugins, GlobalConfig.EUpdateChannel? updateChannel = null, bool updateOverride = false, bool forced = false) {
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, asfUpdate, plugin, updateChannel.Value, forced))).ConfigureAwait(false);
IList<bool> pluginUpdates = await Utilities.InParallel(plugins.Select(plugin => UpdatePlugin(asfVersion, asfUpdate, plugin, updateChannel.Value, updateOverride, forced))).ConfigureAwait(false);
return pluginUpdates.Any(static updated => updated);
}
@@ -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, bool forced) {
private static async Task<bool> UpdatePlugin(Version asfVersion, bool asfUpdate, IPluginUpdates plugin, GlobalConfig.EUpdateChannel updateChannel, bool updateOverride, bool forced) {
ArgumentNullException.ThrowIfNull(asfVersion);
ArgumentNullException.ThrowIfNull(plugin);
@@ -833,6 +833,12 @@ public static class PluginsCore {
return false;
}
if (!updateOverride && ((ASF.GlobalConfig?.UpdatePeriod ?? GlobalConfig.DefaultUpdatePeriod) == 0)) {
ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateNewVersionAvailable, pluginName));
return false;
}
ASF.ArchiLogger.LogGenericInfo(string.Format(CultureInfo.CurrentCulture, Strings.PluginUpdateInProgress, pluginName));
Progress<byte> progressReporter = new();

View File

@@ -504,7 +504,7 @@ public sealed class Actions : IAsyncDisposable, IDisposable {
return (false, Strings.NothingFound);
}
bool updated = await PluginsCore.UpdatePlugins(SharedInfo.Version, false, pluginsForUpdate, channel, forced).ConfigureAwait(false);
bool updated = await PluginsCore.UpdatePlugins(SharedInfo.Version, false, pluginsForUpdate, channel, true, forced).ConfigureAwait(false);
if (updated) {
Utilities.InBackground(ASF.RestartOrExit);