add prompt when in beta channel and a new version is found

This commit is contained in:
Jesse Plamondon-Willard 2018-05-03 00:23:26 -04:00
parent 6a6001c7e6
commit 4bee6311c4
3 changed files with 32 additions and 0 deletions

View File

@ -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`.

View File

@ -88,6 +88,9 @@ namespace StardewModdingAPI
/// <summary>The file path which stores a fatal crash message for the next run.</summary>
internal static string FatalCrashMarker => Path.Combine(Constants.ExecutionPath, "StardewModdingAPI.crash.marker");
/// <summary>The file path which stores the detected update version for the next run.</summary>
internal static string UpdateMarker => Path.Combine(Constants.ExecutionPath, "StardewModdingAPI.update.marker");
/// <summary>The full path to the folder containing mods.</summary>
internal static string ModPath { get; } = Path.Combine(Constants.ExecutionPath, "Mods");

View File

@ -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())
{