summaryrefslogtreecommitdiff
path: root/src/SMAPI/Framework
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-11-21 14:10:09 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2020-11-21 14:10:09 -0500
commit85b947dced10f5398055af36b5fdb6b8d32a6a6b (patch)
treeefc2f877a6f41869a40b6d0a320e6d5c4fd591ca /src/SMAPI/Framework
parente20d26adcf7276c7f12ab9ab6ea0311953aa5194 (diff)
parenta0cb83ed406fc0447e8edf00e680585005480d23 (diff)
downloadSMAPI-85b947dced10f5398055af36b5fdb6b8d32a6a6b.tar.gz
SMAPI-85b947dced10f5398055af36b5fdb6b8d32a6a6b.tar.bz2
SMAPI-85b947dced10f5398055af36b5fdb6b8d32a6a6b.zip
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Framework')
-rw-r--r--src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs4
-rw-r--r--src/SMAPI/Framework/Logging/LogManager.cs15
-rw-r--r--src/SMAPI/Framework/ModLoading/Rewriters/HeuristicFieldRewriter.cs2
-rw-r--r--src/SMAPI/Framework/SCore.cs57
4 files changed, 44 insertions, 34 deletions
diff --git a/src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs b/src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs
index 8fdd4282..f3731d16 100644
--- a/src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs
+++ b/src/SMAPI/Framework/Commands/HarmonySummaryCommand.cs
@@ -112,9 +112,9 @@ namespace StardewModdingAPI.Framework.Commands
private IEnumerable<SearchResult> GetAllPatches()
{
#if HARMONY_2
- foreach (MethodBase method in Harmony.GetAllPatchedMethods())
+ foreach (MethodBase method in Harmony.GetAllPatchedMethods().ToArray())
#else
- foreach (MethodBase method in this.HarmonyInstance.GetPatchedMethods())
+ foreach (MethodBase method in this.HarmonyInstance.GetPatchedMethods().ToArray())
#endif
{
// get metadata for method
diff --git a/src/SMAPI/Framework/Logging/LogManager.cs b/src/SMAPI/Framework/Logging/LogManager.cs
index 094dd749..1e484709 100644
--- a/src/SMAPI/Framework/Logging/LogManager.cs
+++ b/src/SMAPI/Framework/Logging/LogManager.cs
@@ -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();
}
diff --git a/src/SMAPI/Framework/ModLoading/Rewriters/HeuristicFieldRewriter.cs b/src/SMAPI/Framework/ModLoading/Rewriters/HeuristicFieldRewriter.cs
index ca04205c..f59a6ab1 100644
--- a/src/SMAPI/Framework/ModLoading/Rewriters/HeuristicFieldRewriter.cs
+++ b/src/SMAPI/Framework/ModLoading/Rewriters/HeuristicFieldRewriter.cs
@@ -68,7 +68,7 @@ namespace StardewModdingAPI.Framework.ModLoading.Rewriters
private bool TryRewriteToProperty(ModuleDefinition module, Instruction instruction, FieldReference fieldRef, TypeDefinition declaringType, bool isRead)
{
// get equivalent property
- PropertyDefinition property = declaringType.Properties.FirstOrDefault(p => p.Name == fieldRef.Name);
+ PropertyDefinition property = declaringType?.Properties.FirstOrDefault(p => p.Name == fieldRef.Name);
MethodDefinition method = isRead ? property?.GetMethod : property?.SetMethod;
if (method == null)
return false;
diff --git a/src/SMAPI/Framework/SCore.cs b/src/SMAPI/Framework/SCore.cs
index f07e41f0..1b4c32bb 100644
--- a/src/SMAPI/Framework/SCore.cs
+++ b/src/SMAPI/Framework/SCore.cs
@@ -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;
+ ISemanticVersion updateFound = null;
+ string updateUrl = 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;
+ updateFound = response.SuggestedUpdate?.Version;
+ updateUrl = response.SuggestedUpdate?.Url ?? Constants.HomePageUrl;
+
+ // 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())
+ // 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 may not be notified of new versions if this keeps happening.", LogLevel.Warn);
- this.Monitor.Log($"Error: {string.Join("\n", response.Errors)}");
+ 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()}"
+ );
}
- }
- 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());
+ // show update message on next launch
+ if (updateFound != null)
+ this.LogManager.WriteUpdateMarker(updateFound.ToString(), updateUrl);
+ }
// check mod versions
if (mods.Any())