mirror of
https://github.com/JustArchiNET/ArchiSteamFarm.git
synced 2026-01-01 14:10:53 +00:00
Make it work
This commit is contained in:
@@ -172,8 +172,7 @@ internal static class ArchiKestrel {
|
||||
string? assemblyDirectory = Path.GetDirectoryName(plugin.GetType().Assembly.Location);
|
||||
|
||||
if (string.IsNullOrEmpty(assemblyDirectory)) {
|
||||
// Invalid path provided
|
||||
continue;
|
||||
throw new InvalidOperationException(nameof(assemblyDirectory));
|
||||
}
|
||||
|
||||
physicalPath = Path.Combine(assemblyDirectory, plugin.PhysicalPath);
|
||||
|
||||
6
ArchiSteamFarm/Localization/Strings.Designer.cs
generated
6
ArchiSteamFarm/Localization/Strings.Designer.cs
generated
@@ -1238,5 +1238,11 @@ namespace ArchiSteamFarm.Localization {
|
||||
return ResourceManager.GetString("IdlingGameNotPossiblePrivate", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
public static string WarningSkipping {
|
||||
get {
|
||||
return ResourceManager.GetString("WarningSkipping", resourceCulture);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -764,4 +764,8 @@ Process uptime: {1}</value>
|
||||
<value>Farming {0} ({1}) is disabled, as that game is currently marked as private. If you intend from ASF to farm that game, then consider changing its privacy settings.</value>
|
||||
<comment>{0} will be replaced by game's ID (number), {1} will be replaced by game's name</comment>
|
||||
</data>
|
||||
<data name="WarningSkipping" xml:space="preserve">
|
||||
<value>Skipping: {0}...</value>
|
||||
<comment>{0} will be replaced by text value (string) of entry being skipped.</comment>
|
||||
</data>
|
||||
</root>
|
||||
|
||||
@@ -47,16 +47,16 @@ public interface IPluginUpdates : IPlugin {
|
||||
Task<ReleaseAsset?> GetTargetReleaseAsset(Version asfVersion, string asfVariant, Version newPluginVersion, IReadOnlyCollection<ReleaseAsset> releaseAssets);
|
||||
|
||||
/// <summary>
|
||||
/// ASF will call this method after update to a particular ASF version has been finished, just before restart of the process.
|
||||
/// ASF will call this method after update to a particular plugin version has been finished, just before restart of the process.
|
||||
/// </summary>
|
||||
/// <param name="currentVersion">The current (old) version of ASF program.</param>
|
||||
/// <param name="newVersion">The target (new) version of ASF program.</param>
|
||||
/// <param name="currentVersion">The current (old) version of plugin assembly.</param>
|
||||
/// <param name="newVersion">The target (new) version of plugin assembly.</param>
|
||||
Task OnUpdateFinished(Version currentVersion, Version newVersion);
|
||||
|
||||
/// <summary>
|
||||
/// ASF will call this method before proceeding with an update to a particular ASF version.
|
||||
/// ASF will call this method before proceeding with an update to a particular plugin version.
|
||||
/// </summary>
|
||||
/// <param name="currentVersion">The current (old) version of ASF program.</param>
|
||||
/// <param name="newVersion">The target (new) version of ASF program.</param>
|
||||
/// <param name="currentVersion">The current (old) version of plugin assembly.</param>
|
||||
/// <param name="newVersion">The target (new) version of plugin assembly.</param>
|
||||
Task OnUpdateProceeding(Version currentVersion, Version newVersion);
|
||||
}
|
||||
|
||||
@@ -673,69 +673,81 @@ public static class PluginsCore {
|
||||
|
||||
// We update plugins one-by-one to limit memory pressure from potentially big release assets
|
||||
foreach (IPluginUpdates plugin in ActivePlugins.OfType<IPluginUpdates>()) {
|
||||
string repoName = plugin.RepositoryName;
|
||||
|
||||
if (string.IsNullOrEmpty(repoName)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ASF.ArchiLogger.LogGenericInfo($"Checking update for {plugin.Name} plugin...");
|
||||
|
||||
ReleaseResponse? releaseResponse = await GitHub.GetLatestRelease(repoName, stable).ConfigureAwait(false);
|
||||
|
||||
if (releaseResponse == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Version newVersion = new(releaseResponse.Tag);
|
||||
|
||||
if (plugin.Version >= newVersion) {
|
||||
ASF.ArchiLogger.LogGenericInfo($"No update available for {plugin.Name} plugin: {plugin.Version} >= {newVersion}.");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
ASF.ArchiLogger.LogGenericInfo($"Updating {plugin.Name} plugin from version {plugin.Version} to {newVersion}...");
|
||||
|
||||
ReleaseAsset? asset = await plugin.GetTargetReleaseAsset(asfVersion, SharedInfo.BuildInfo.Variant, newVersion, releaseResponse.Assets).ConfigureAwait(false);
|
||||
|
||||
if ((asset == null) || !releaseResponse.Assets.Contains(asset)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Progress<byte> progressReporter = new();
|
||||
|
||||
progressReporter.ProgressChanged += Utilities.OnProgressChanged;
|
||||
|
||||
BinaryResponse? response;
|
||||
|
||||
try {
|
||||
response = await ASF.WebBrowser.UrlGetToBinary(asset.DownloadURL, progressReporter: progressReporter).ConfigureAwait(false);
|
||||
} finally {
|
||||
progressReporter.ProgressChanged -= Utilities.OnProgressChanged;
|
||||
}
|
||||
ASF.ArchiLogger.LogGenericInfo($"Checking update for {plugin.Name} plugin...");
|
||||
|
||||
if (response?.Content == null) {
|
||||
continue;
|
||||
}
|
||||
string? assemblyDirectory = Path.GetDirectoryName(plugin.GetType().Assembly.Location);
|
||||
|
||||
ASF.ArchiLogger.LogGenericInfo(Strings.PatchingFiles);
|
||||
if (string.IsNullOrEmpty(assemblyDirectory)) {
|
||||
throw new InvalidOperationException(nameof(assemblyDirectory));
|
||||
}
|
||||
|
||||
string? assemblyDirectory = Path.GetDirectoryName(plugin.GetType().Assembly.Location);
|
||||
string backupDirectory = Path.Combine(assemblyDirectory, SharedInfo.UpdateDirectory);
|
||||
|
||||
if (string.IsNullOrEmpty(assemblyDirectory)) {
|
||||
// Invalid path provided
|
||||
continue;
|
||||
}
|
||||
if (Directory.Exists(backupDirectory)) {
|
||||
ASF.ArchiLogger.LogGenericInfo(Strings.UpdateCleanup);
|
||||
|
||||
byte[] responseBytes = response.Content as byte[] ?? response.Content.ToArray();
|
||||
Directory.Delete(backupDirectory, true);
|
||||
}
|
||||
|
||||
string repoName = plugin.RepositoryName;
|
||||
|
||||
if (string.IsNullOrEmpty(repoName)) {
|
||||
ASF.ArchiLogger.LogGenericTrace(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(plugin.RepositoryName)));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
ReleaseResponse? releaseResponse = await GitHub.GetLatestRelease(repoName, stable).ConfigureAwait(false);
|
||||
|
||||
if (releaseResponse == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Version pluginVersion = plugin.Version;
|
||||
Version newVersion = new(releaseResponse.Tag);
|
||||
|
||||
if (pluginVersion >= newVersion) {
|
||||
ASF.ArchiLogger.LogGenericInfo($"No update available for {plugin.Name} plugin: {pluginVersion} >= {newVersion}.");
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
ASF.ArchiLogger.LogGenericInfo($"Updating {plugin.Name} plugin from version {pluginVersion} to {newVersion}...");
|
||||
|
||||
ReleaseAsset? asset = await plugin.GetTargetReleaseAsset(asfVersion, SharedInfo.BuildInfo.Variant, newVersion, releaseResponse.Assets).ConfigureAwait(false);
|
||||
|
||||
if ((asset == null) || !releaseResponse.Assets.Contains(asset)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Progress<byte> progressReporter = new();
|
||||
|
||||
progressReporter.ProgressChanged += Utilities.OnProgressChanged;
|
||||
|
||||
BinaryResponse? response;
|
||||
|
||||
try {
|
||||
response = await ASF.WebBrowser.UrlGetToBinary(asset.DownloadURL, progressReporter: progressReporter).ConfigureAwait(false);
|
||||
} finally {
|
||||
progressReporter.ProgressChanged -= Utilities.OnProgressChanged;
|
||||
}
|
||||
|
||||
if (response?.Content == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ASF.ArchiLogger.LogGenericInfo(Strings.PatchingFiles);
|
||||
|
||||
byte[] responseBytes = response.Content as byte[] ?? response.Content.ToArray();
|
||||
|
||||
try {
|
||||
MemoryStream memoryStream = new(responseBytes);
|
||||
|
||||
await using (memoryStream.ConfigureAwait(false)) {
|
||||
using ZipArchive zipArchive = new(memoryStream);
|
||||
|
||||
await plugin.OnUpdateProceeding(pluginVersion, newVersion).ConfigureAwait(false);
|
||||
|
||||
if (!Utilities.UpdateFromArchive(zipArchive, assemblyDirectory)) {
|
||||
ASF.ArchiLogger.LogGenericError(Strings.WarningFailed);
|
||||
|
||||
@@ -746,6 +758,8 @@ public static class PluginsCore {
|
||||
restartNeeded = true;
|
||||
|
||||
ASF.ArchiLogger.LogGenericInfo($"Updating {plugin.Name} plugin has succeeded, the changes will be loaded on the next ASF launch.");
|
||||
|
||||
await plugin.OnUpdateFinished(pluginVersion, newVersion).ConfigureAwait(false);
|
||||
} catch (Exception e) {
|
||||
ASF.ArchiLogger.LogGenericException(e);
|
||||
}
|
||||
@@ -766,6 +780,14 @@ public static class PluginsCore {
|
||||
|
||||
try {
|
||||
foreach (string assemblyPath in Directory.EnumerateFiles(path, "*.dll", SearchOption.AllDirectories)) {
|
||||
string? assemblyDirectoryName = Path.GetFileName(Path.GetDirectoryName(assemblyPath));
|
||||
|
||||
if (assemblyDirectoryName == SharedInfo.UpdateDirectory) {
|
||||
ASF.ArchiLogger.LogGenericTrace(string.Format(CultureInfo.CurrentCulture, Strings.WarningSkipping, assemblyPath));
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
Assembly assembly;
|
||||
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user