From 230099692635a7ca53edfebf4ed9225b5b1d5779 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Wed, 25 Apr 2018 20:41:52 -0400 Subject: simplify beta channel logic (#457) --- docs/release-notes.md | 2 +- src/SMAPI/Framework/Models/SConfig.cs | 3 +++ src/SMAPI/Program.cs | 29 +++++++++++------------------ src/SMAPI/StardewModdingAPI.config.json | 6 ++++++ 4 files changed, 21 insertions(+), 19 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index 86475d6e..5e14f34d 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -4,8 +4,8 @@ * Added support for Stardew Valley 1.3+; no longer compatible with earlier versions. * Added warning for mods which don't have update checks configured. * Added friendly error when game can't start audio. + * Added beta update channel. * Fixed detection of GOG install path in rare cases. - * Fixed SMAPI update checks not showing newer beta versions when using a beta version. * Fixed console color scheme on Mac or PowerShell, and added override option to `StardewModdingAPI.config.json`. * Fixed `world_settime` console command sometimes breaking NPC schedules (e.g. so they stay in bed). diff --git a/src/SMAPI/Framework/Models/SConfig.cs b/src/SMAPI/Framework/Models/SConfig.cs index b504f38b..be84a6b9 100644 --- a/src/SMAPI/Framework/Models/SConfig.cs +++ b/src/SMAPI/Framework/Models/SConfig.cs @@ -12,6 +12,9 @@ namespace StardewModdingAPI.Framework.Models /// Whether to check for newer versions of SMAPI and mods on startup. public bool CheckForUpdates { get; set; } + /// Whether to show beta versions as valid updates. + public bool UseBetaChannel { get; set; } = Constants.ApiVersion.Build != null; + /// SMAPI's GitHub project name, used to perform update checks. public string GitHubProjectName { get; set; } diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index eda85866..4075dae4 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -550,15 +550,18 @@ namespace StardewModdingAPI try { ModInfoModel response = client.GetModInfo($"GitHub:{this.Settings.GitHubProjectName}").Single().Value; + ISemanticVersion latestStable = response.Version != null ? new SemanticVersion(response.Version) : null; + ISemanticVersion latestBeta = response.PreviewVersion != null ? new SemanticVersion(response.PreviewVersion) : null; + if (response.Error != null) { this.Monitor.Log("Couldn't check for a new version of SMAPI. 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: {response.Error}"); } - else if (this.IsValidUpdate(Constants.ApiVersion, new SemanticVersion(response.Version))) - this.Monitor.Log($"You can update SMAPI to {response.Version}: {Constants.HomePageUrl}", LogLevel.Alert); - else if (response.PreviewVersion != null && this.IsValidUpdate(Constants.ApiVersion, new SemanticVersion(response.PreviewVersion))) - this.Monitor.Log($"You can update SMAPI to {response.PreviewVersion}: {Constants.HomePageUrl}", LogLevel.Alert); + else if (this.IsValidUpdate(Constants.ApiVersion, latestBeta, this.Settings.UseBetaChannel)) + this.Monitor.Log($"You can update SMAPI to {latestBeta}: {Constants.HomePageUrl}", LogLevel.Alert); + else if (this.IsValidUpdate(Constants.ApiVersion, latestStable, this.Settings.UseBetaChannel)) + this.Monitor.Log($"You can update SMAPI to {latestStable}: {Constants.HomePageUrl}", LogLevel.Alert); else this.Monitor.Log(" SMAPI okay.", LogLevel.Trace); } @@ -658,22 +661,12 @@ namespace StardewModdingAPI /// Get whether a given version should be offered to the user as an update. /// The current semantic version. /// The target semantic version. - private bool IsValidUpdate(ISemanticVersion currentVersion, ISemanticVersion newVersion) + /// Whether the user enabled the beta channel and should be offered pre-release updates. + private bool IsValidUpdate(ISemanticVersion currentVersion, ISemanticVersion newVersion, bool useBetaChannel) { - // basic eligibility - bool isNewer = newVersion.IsNewerThan(currentVersion); - bool isPrerelease = newVersion.Build != null; - bool isEquallyStable = !isPrerelease || currentVersion.Build != null; // don't update stable => prerelease - if (!isNewer || !isEquallyStable) - return false; - if (!isPrerelease) - return true; - - // prerelease eligible if same version (excluding prerelease tag) return - newVersion.MajorVersion == currentVersion.MajorVersion - && newVersion.MinorVersion == currentVersion.MinorVersion - && newVersion.PatchVersion == currentVersion.PatchVersion; + newVersion.IsNewerThan(currentVersion) + && (useBetaChannel || newVersion.Build == null); } /// Create a directory path if it doesn't exist. diff --git a/src/SMAPI/StardewModdingAPI.config.json b/src/SMAPI/StardewModdingAPI.config.json index 06c63e8b..f37c6fc1 100644 --- a/src/SMAPI/StardewModdingAPI.config.json +++ b/src/SMAPI/StardewModdingAPI.config.json @@ -21,6 +21,12 @@ This file contains advanced configuration for SMAPI. You generally shouldn't cha */ "CheckForUpdates": true, + /** + * Whether SMAPI should show newer beta versions as an available update. If not specified, SMAPI + * will only show beta updates if the current version is beta. + */ + //"UseBetaChannel": true, + /** * SMAPI's GitHub project name, used to perform update checks. */ -- cgit