summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-07-21 00:43:43 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-07-21 00:43:43 -0400
commit7e5d77fb8c2606795af239717a596de460bc58f7 (patch)
tree2dc1cce2d75f3c97341ffc7b8686192075488d73 /src
parentc74702b027aeab927b4e038e440cbbb24d859cfd (diff)
downloadSMAPI-7e5d77fb8c2606795af239717a596de460bc58f7.tar.gz
SMAPI-7e5d77fb8c2606795af239717a596de460bc58f7.tar.bz2
SMAPI-7e5d77fb8c2606795af239717a596de460bc58f7.zip
add error if some SMAPI DLLs have mismatched versions
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI/Program.cs16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs
index 0257a03e..e6e51ac6 100644
--- a/src/SMAPI/Program.cs
+++ b/src/SMAPI/Program.cs
@@ -5,6 +5,7 @@ using System.Reflection;
using System.Threading;
using StardewModdingAPI.Framework;
using StardewModdingAPI.Toolkit.Framework;
+using StardewModdingAPI.Toolkit.Serialization.Models;
namespace StardewModdingAPI
{
@@ -32,6 +33,7 @@ namespace StardewModdingAPI
AppDomain.CurrentDomain.AssemblyResolve += Program.CurrentDomain_AssemblyResolve;
Program.AssertGamePresent();
Program.AssertGameVersion();
+ Program.AssertSmapiVersions();
Program.Start(args);
}
catch (BadImageFormatException ex) when (ex.FileName == "StardewValley" || ex.FileName == "Stardew Valley") // don't use EarlyConstants.GameAssemblyName, since we want to check both possible names
@@ -122,6 +124,20 @@ namespace StardewModdingAPI
#endif
}
+ /// <summary>Assert that the versions of all SMAPI components are correct.</summary>
+ /// <remarks>Players sometimes have mismatched versions (particularly when installed through Vortex), which can cause some very confusing bugs without this check.</remarks>
+ private static void AssertSmapiVersions()
+ {
+ // SMAPI toolkit
+ foreach (var type in new[] { typeof(IManifest), typeof(Manifest) })
+ {
+ Assembly assembly = type.Assembly;
+ var assemblyVersion = new SemanticVersion(assembly.GetName().Version);
+ if (!assemblyVersion.Equals(Constants.ApiVersion))
+ Program.PrintErrorAndExit($"Oops! The 'smapi-internal/{assembly.GetName().Name}.dll' file is version {assemblyVersion} instead of the required {Constants.ApiVersion}. SMAPI doesn't seem to be installed correctly.");
+ }
+ }
+
/// <summary>Initialize SMAPI and launch the game.</summary>
/// <param name="args">The command-line arguments.</param>
/// <remarks>This method is separate from <see cref="Main"/> because that can't contain any references to assemblies loaded by <see cref="CurrentDomain_AssemblyResolve"/> (e.g. via <see cref="Constants"/>), or Mono will incorrectly show an assembly resolution error before assembly resolution is set up.</remarks>