From 665c6806d3797f8329ef8c6fcaa80d469fef5005 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 22 Apr 2021 21:52:09 -0400 Subject: [PATCH] add update alerts for Stardew64Installer (#767) --- docs/release-notes.md | 3 +- src/SMAPI/Constants.cs | 15 ++++++++++ src/SMAPI/Framework/Logging/LogManager.cs | 9 ++---- src/SMAPI/Framework/Models/SConfig.cs | 3 ++ src/SMAPI/Framework/SCore.cs | 35 +++++++++++++++++++++++ src/SMAPI/SMAPI.config.json | 5 ++++ 6 files changed, 62 insertions(+), 8 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index 974c0ef3..748e62c5 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -11,7 +11,7 @@ * For players: * When many mods fail to load, root dependencies are now listed in their own group so it's easier to see which ones you should try updating first. * On macOS, the `StardewModdingAPI.bin.osx` file is no longer overwritten if it's identical to avoid resetting file permissions (thanks to 007wayne!). - * Added SMAPI version and bitness to the console title before startup to simplify troubleshooting. + * Added update checks for Stardew64Installer if it patched the game. * Fixed error for non-English players after returning to title, reloading, and entering town with a completed movie theater. * Fixed `world_clear` console command not removing resource clumps outside the farm and secret woods. * Fixed inconsistent spelling/style for 'macOS'. @@ -19,6 +19,7 @@ * For modders: * Added asset propagation for `Data\Concessions`. + * Added SMAPI version and bitness to the console title before startup to simplify troubleshooting. * Improved error-handling during asset propagation. * Fixed `Context.IsMainPlayer` returning true for a farmhand in split-screen mode before the screen is initialized. * Fixed error when editing bundle data while a split-screen player is joining. diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index b55104c0..161e92b4 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -300,6 +300,21 @@ namespace StardewModdingAPI return new PlatformAssemblyMap(targetPlatform, removeAssemblyReferences.ToArray(), targetAssemblies.ToArray()); } + /// Get whether the game assembly was patched by Stardew64Installer. + /// The version of Stardew64Installer which was applied to the game assembly, if any. + internal static bool IsPatchedByStardew64Installer(out ISemanticVersion version) + { + PropertyInfo property = typeof(Game1).GetProperty("Stardew64InstallerVersion"); + if (property == null) + { + version = null; + return false; + } + + version = new SemanticVersion((string)property.GetValue(null)); + return true; + } + /********* ** Private methods diff --git a/src/SMAPI/Framework/Logging/LogManager.cs b/src/SMAPI/Framework/Logging/LogManager.cs index 804acfb3..a4df3c18 100644 --- a/src/SMAPI/Framework/Logging/LogManager.cs +++ b/src/SMAPI/Framework/Logging/LogManager.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.IO; using System.Linq; -using System.Reflection; using System.Text.RegularExpressions; using System.Threading; using StardewModdingAPI.Framework.Commands; @@ -12,7 +11,6 @@ using StardewModdingAPI.Framework.ModLoading; using StardewModdingAPI.Internal.ConsoleWriting; using StardewModdingAPI.Toolkit.Framework.ModData; using StardewModdingAPI.Toolkit.Utilities; -using StardewValley; namespace StardewModdingAPI.Framework.Logging { @@ -421,11 +419,8 @@ namespace StardewModdingAPI.Framework.Logging yield return $"running {Constants.GameFramework}"; // patched by Stardew64Installer - { - PropertyInfo patcherProperty = typeof(Game1).GetProperty("Stardew64InstallerVersion"); - if (patcherProperty != null) - yield return $"patched by Stardew64Installer {patcherProperty.GetValue(null)}"; - } + if (Constants.IsPatchedByStardew64Installer(out ISemanticVersion patchedByVersion)) + yield return $"patched by Stardew64Installer {patchedByVersion}"; } /// Write a summary of mod warnings to the console and log. diff --git a/src/SMAPI/Framework/Models/SConfig.cs b/src/SMAPI/Framework/Models/SConfig.cs index 4a80e34c..a71bafd9 100644 --- a/src/SMAPI/Framework/Models/SConfig.cs +++ b/src/SMAPI/Framework/Models/SConfig.cs @@ -52,6 +52,9 @@ namespace StardewModdingAPI.Framework.Models /// SMAPI's GitHub project name, used to perform update checks. public string GitHubProjectName { get; set; } + /// Stardew64Installer's GitHub project name, used to perform update checks. + public string Stardew64InstallerGitHubProjectName { get; set; } + /// The base URL for SMAPI's web API, used to perform update checks. public string WebApiBaseUrl { get; set; } diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs index e8c8a8e5..85a2bb8f 100644 --- a/src/SMAPI/Framework/SCore.cs +++ b/src/SMAPI/Framework/SCore.cs @@ -1302,6 +1302,41 @@ namespace StardewModdingAPI.Framework this.LogManager.WriteUpdateMarker(updateFound.ToString(), updateUrl); } + // check Stardew64Installer version + if (Constants.IsPatchedByStardew64Installer(out ISemanticVersion patchedByVersion)) + { + ISemanticVersion updateFound = null; + string updateUrl = null; + try + { + // fetch update check + ModEntryModel response = client.GetModInfo(new[] { new ModSearchEntryModel("Steviegt6.Stardew64Installer", patchedByVersion, new[] { $"GitHub:{this.Settings.Stardew64InstallerGitHubProjectName}" }) }, apiVersion: Constants.ApiVersion, gameVersion: Constants.GameVersion, platform: Constants.Platform).Single().Value; + updateFound = response.SuggestedUpdate?.Version; + updateUrl = response.SuggestedUpdate?.Url ?? Constants.HomePageUrl; + + // log message + if (updateFound != null) + this.Monitor.Log($"You can update Stardew64Installer to {updateFound}: {updateUrl}", LogLevel.Alert); + else + this.Monitor.Log(" Stardew64Installer okay."); + + // show errors + if (response.Errors.Any()) + { + this.Monitor.Log("Couldn't check for a new version of Stardew64Installer. This won't affect your game, but you may not be notified of new versions if this keeps happening.", LogLevel.Warn); + this.Monitor.Log($"Error: {string.Join("\n", response.Errors)}"); + } + } + catch (Exception ex) + { + this.Monitor.Log("Couldn't check for a new version of Stardew64Installer. This won't affect your game, but you won't be notified of new versions if this keeps happening.", LogLevel.Warn); + this.Monitor.Log(ex is WebException && ex.InnerException == null + ? $"Error: {ex.Message}" + : $"Error: {ex.GetLogSummary()}" + ); + } + } + // check mod versions if (mods.Any()) { diff --git a/src/SMAPI/SMAPI.config.json b/src/SMAPI/SMAPI.config.json index b8179207..7b5625d6 100644 --- a/src/SMAPI/SMAPI.config.json +++ b/src/SMAPI/SMAPI.config.json @@ -69,6 +69,11 @@ copy all the settings, or you may cause bugs due to overridden changes in future */ "GitHubProjectName": "Pathoschild/SMAPI", + /** + * Stardew64Installer's GitHub project name, used to perform update checks. + */ + "Stardew64InstallerGitHubProjectName": "Steviegt6/Stardew64Installer", + /** * The base URL for SMAPI's web API, used to perform update checks. * Note: the protocol will be changed to http:// on Linux/macOS due to OpenSSL issues with the