From 4bee6311c4f6bf654d8b9c54a53597347de65c4f Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Thu, 3 May 2018 00:23:26 -0400 Subject: [PATCH] add prompt when in beta channel and a new version is found --- docs/release-notes.md | 1 + src/SMAPI/Constants.cs | 3 +++ src/SMAPI/Program.cs | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/docs/release-notes.md b/docs/release-notes.md index e913618a..551dd1d5 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -3,6 +3,7 @@ * For players: * Updated for Stardew Valley 1.3 (no longer compatible with earlier versions). * Added beta update channel. + * Added prompt when in beta channel and a new version is found. * Added friendly error when game can't start audio. * Added console warning for mods which don't have update checks configured. * Fixed console color scheme on Mac or in PowerShell, configurable via `StardewModdingAPI.config.json`. diff --git a/src/SMAPI/Constants.cs b/src/SMAPI/Constants.cs index 2ef26704..f87141b2 100644 --- a/src/SMAPI/Constants.cs +++ b/src/SMAPI/Constants.cs @@ -88,6 +88,9 @@ namespace StardewModdingAPI /// The file path which stores a fatal crash message for the next run. internal static string FatalCrashMarker => Path.Combine(Constants.ExecutionPath, "StardewModdingAPI.crash.marker"); + /// The file path which stores the detected update version for the next run. + internal static string UpdateMarker => Path.Combine(Constants.ExecutionPath, "StardewModdingAPI.update.marker"); + /// The full path to the folder containing mods. internal static string ModPath { get; } = Path.Combine(Constants.ExecutionPath, "Mods"); diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 64520ccf..ebe44cf7 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -241,6 +241,23 @@ namespace StardewModdingAPI return; } + // check update marker + if (File.Exists(Constants.UpdateMarker)) + { + string rawUpdateFound = File.ReadAllText(Constants.UpdateMarker); + if (SemanticVersion.TryParse(rawUpdateFound, out ISemanticVersion updateFound)) + { + if (Constants.ApiVersion.IsPrerelease() && updateFound.IsNewerThan(Constants.ApiVersion)) + { + this.Monitor.Log("A new version of SMAPI was detected last time you played.", LogLevel.Error); + this.Monitor.Log($"You can update to {updateFound}: https://smapi.io.", LogLevel.Error); + this.Monitor.Log("Press any key to continue playing anyway. (This only appears when using a SMAPI beta.)", LogLevel.Info); + Console.ReadKey(); + } + } + File.Delete(Constants.UpdateMarker); + } + // show details if game crashed during last session if (File.Exists(Constants.FatalCrashMarker)) { @@ -548,6 +565,7 @@ namespace StardewModdingAPI this.Monitor.Log("Checking for updates...", LogLevel.Trace); // check SMAPI version + ISemanticVersion updateFound = null; try { ModInfoModel response = client.GetModInfo($"GitHub:{this.Settings.GitHubProjectName}").Single().Value; @@ -560,9 +578,15 @@ namespace StardewModdingAPI this.Monitor.Log($"Error: {response.Error}"); } else if (this.IsValidUpdate(Constants.ApiVersion, latestBeta, this.Settings.UseBetaChannel)) + { + updateFound = latestBeta; this.Monitor.Log($"You can update SMAPI to {latestBeta}: {Constants.HomePageUrl}", LogLevel.Alert); + } else if (this.IsValidUpdate(Constants.ApiVersion, latestStable, this.Settings.UseBetaChannel)) + { + updateFound = latestStable; this.Monitor.Log($"You can update SMAPI to {latestStable}: {Constants.HomePageUrl}", LogLevel.Alert); + } else this.Monitor.Log(" SMAPI okay.", LogLevel.Trace); } @@ -575,6 +599,10 @@ namespace StardewModdingAPI ); } + // show update message on next launch + if (updateFound != null) + File.WriteAllText(Constants.UpdateMarker, updateFound.ToString()); + // check mod versions if (mods.Any()) {