use update URL from server instead of hardcoding it
This commit is contained in:
parent
1cac389284
commit
70cf63c907
|
@ -195,9 +195,10 @@ namespace StardewModdingAPI.Framework.Logging
|
|||
|
||||
/// <summary>Write an update alert marker file.</summary>
|
||||
/// <param name="version">The new version found.</param>
|
||||
public void WriteUpdateMarker(string version)
|
||||
/// <param name="url">The download URL for the update.</param>
|
||||
public void WriteUpdateMarker(string version, string url)
|
||||
{
|
||||
File.WriteAllText(Constants.UpdateMarker, version);
|
||||
File.WriteAllText(Constants.UpdateMarker, $"{version}|{url}");
|
||||
}
|
||||
|
||||
/// <summary>Check whether SMAPI crashed or detected an update during the last session, and display them in the SMAPI console.</summary>
|
||||
|
@ -206,13 +207,17 @@ namespace StardewModdingAPI.Framework.Logging
|
|||
// show update alert
|
||||
if (File.Exists(Constants.UpdateMarker))
|
||||
{
|
||||
string rawUpdateFound = File.ReadAllText(Constants.UpdateMarker);
|
||||
if (SemanticVersion.TryParse(rawUpdateFound, out ISemanticVersion updateFound))
|
||||
string[] rawUpdateFound = File.ReadAllText(Constants.UpdateMarker).Split(new [] { '|' }, 2);
|
||||
if (SemanticVersion.TryParse(rawUpdateFound[0], out ISemanticVersion updateFound))
|
||||
{
|
||||
if (Constants.ApiVersion.IsPrerelease() && updateFound.IsNewerThan(Constants.ApiVersion))
|
||||
{
|
||||
string url = rawUpdateFound.Length > 1
|
||||
? rawUpdateFound[1]
|
||||
: Constants.HomePageUrl;
|
||||
|
||||
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($"You can update to {updateFound}: {url}.", LogLevel.Error);
|
||||
this.Monitor.Log("Press any key to continue playing anyway. (This only appears when using a SMAPI beta.)", LogLevel.Info);
|
||||
Console.ReadKey();
|
||||
}
|
||||
|
|
|
@ -1195,37 +1195,42 @@ namespace StardewModdingAPI.Framework
|
|||
this.Monitor.Log("Checking for updates...");
|
||||
|
||||
// check SMAPI version
|
||||
ISemanticVersion updateFound = null;
|
||||
try
|
||||
{
|
||||
// fetch update check
|
||||
ModEntryModel response = client.GetModInfo(new[] { new ModSearchEntryModel("Pathoschild.SMAPI", Constants.ApiVersion, new[] { $"GitHub:{this.Settings.GitHubProjectName}" }) }, apiVersion: Constants.ApiVersion, gameVersion: Constants.GameVersion, platform: Constants.Platform).Single().Value;
|
||||
if (response.SuggestedUpdate != null)
|
||||
this.Monitor.Log($"You can update SMAPI to {response.SuggestedUpdate.Version}: {Constants.HomePageUrl}", LogLevel.Alert);
|
||||
else
|
||||
this.Monitor.Log(" SMAPI okay.");
|
||||
|
||||
updateFound = response.SuggestedUpdate?.Version;
|
||||
|
||||
// show errors
|
||||
if (response.Errors.Any())
|
||||
ISemanticVersion updateFound = null;
|
||||
string updateUrl = null;
|
||||
try
|
||||
{
|
||||
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: {string.Join("\n", response.Errors)}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Monitor.Log("Couldn't check for a new version of SMAPI. 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()}"
|
||||
);
|
||||
}
|
||||
// fetch update check
|
||||
ModEntryModel response = client.GetModInfo(new[] { new ModSearchEntryModel("Pathoschild.SMAPI", Constants.ApiVersion, new[] { $"GitHub:{this.Settings.GitHubProjectName}" }) }, apiVersion: Constants.ApiVersion, gameVersion: Constants.GameVersion, platform: Constants.Platform).Single().Value;
|
||||
updateFound = response.SuggestedUpdate?.Version;
|
||||
updateUrl = response.SuggestedUpdate?.Url ?? Constants.HomePageUrl;
|
||||
|
||||
// show update message on next launch
|
||||
if (updateFound != null)
|
||||
this.LogManager.WriteUpdateMarker(updateFound.ToString());
|
||||
// log message
|
||||
if (updateFound != null)
|
||||
this.Monitor.Log($"You can update SMAPI to {updateFound}: {updateUrl}", LogLevel.Alert);
|
||||
else
|
||||
this.Monitor.Log(" SMAPI okay.");
|
||||
|
||||
// show errors
|
||||
if (response.Errors.Any())
|
||||
{
|
||||
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: {string.Join("\n", response.Errors)}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
this.Monitor.Log("Couldn't check for a new version of SMAPI. 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()}"
|
||||
);
|
||||
}
|
||||
|
||||
// show update message on next launch
|
||||
if (updateFound != null)
|
||||
this.LogManager.WriteUpdateMarker(updateFound.ToString(), updateUrl);
|
||||
}
|
||||
|
||||
// check mod versions
|
||||
if (mods.Any())
|
||||
|
|
Loading…
Reference in New Issue