diff options
author | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-05-20 15:11:36 -0400 |
---|---|---|
committer | Jesse Plamondon-Willard <github@jplamondonw.com> | 2017-05-20 15:11:36 -0400 |
commit | d47e55d0405de145ea18f37eba078608f6deac9f (patch) | |
tree | c786ca0e141abbf914109229b109e78e433163ec | |
parent | 933e889c24e565d9028d3719ba2d65d512890564 (diff) | |
download | SMAPI-d47e55d0405de145ea18f37eba078608f6deac9f.tar.gz SMAPI-d47e55d0405de145ea18f37eba078608f6deac9f.tar.bz2 SMAPI-d47e55d0405de145ea18f37eba078608f6deac9f.zip |
show friendly errors when the game is missing or pre-1.2
-rw-r--r-- | release-notes.md | 7 | ||||
-rw-r--r-- | src/StardewModdingAPI/Program.cs | 54 |
2 files changed, 61 insertions, 0 deletions
diff --git a/release-notes.md b/release-notes.md index b7f5f1f7..7fee542c 100644 --- a/release-notes.md +++ b/release-notes.md @@ -10,6 +10,13 @@ For mod developers: images). --> +## 1.14 +See [log](https://github.com/Pathoschild/SMAPI/compare/1.13.1...1.14). + +For players: +* SMAPI now shows a friendly message when it can't detect the game. +* SMAPI now shows a friendly message when you have Stardew Valley 1.11 or earlier (which aren't compatible). + ## 1.13.1 See [log](https://github.com/Pathoschild/SMAPI/compare/1.13...1.13.1). diff --git a/src/StardewModdingAPI/Program.cs b/src/StardewModdingAPI/Program.cs index 06523144..21717cc3 100644 --- a/src/StardewModdingAPI/Program.cs +++ b/src/StardewModdingAPI/Program.cs @@ -78,6 +78,8 @@ namespace StardewModdingAPI /// <param name="args">The command-line arguments.</param> public static void Main(string[] args) { + Program.AssertMinimumCompatibility(); + // get flags from arguments bool writeToConsole = !args.Contains("--no-terminal"); @@ -261,6 +263,49 @@ namespace StardewModdingAPI /********* ** Private methods *********/ + /// <summary>Assert that the minimum conditions are present to initialise SMAPI without type load exceptions.</summary> + /// <returns>Returns whether the minimum conditions are met.</returns> + private static void AssertMinimumCompatibility() + { + void PrintErrorAndExit(string message) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(message); + Console.ResetColor(); + Program.PressAnyKeyToExit(showMessage: true); + } + + // get game assembly name + const string gameAssemblyName = +#if SMAPI_FOR_WINDOWS + "Stardew Valley"; +#else + "StardewValley"; +#endif + + // game not present + if (Type.GetType($"StardewValley.Game1, {gameAssemblyName}", throwOnError: false) == null) + { + PrintErrorAndExit( + "Oops! SMAPI can't find the game. " + + (Assembly.GetCallingAssembly().Location?.Contains(Path.Combine("internal", "Windows")) == true || Assembly.GetCallingAssembly().Location?.Contains(Path.Combine("internal", "Mono")) == true + ? "It looks like you're running SMAPI from the download package, but you need to run the installed version instead. " + : "Make sure you're running StardewModdingAPI.exe in your game folder. " + ) + + "See the readme.txt file for details." + ); + } + + // Stardew Valley 1.2 types not present + if (Type.GetType($"StardewValley.LocalizedContentManager+LanguageCode, {gameAssemblyName}", throwOnError: false) == null) + { + PrintErrorAndExit(Constants.GameVersion.IsOlderThan(Constants.MinimumGameVersion) + ? $"Oops! You're running Stardew Valley {Constants.GetGameDisplayVersion(Constants.GameVersion)}, but the oldest supported version is {Constants.GetGameDisplayVersion(Constants.MinimumGameVersion)}. Please update your game before using SMAPI." + : "Oops! SMAPI doesn't seem to be compatible with your game. Make sure you're running the latest version of Stardew Valley and SMAPI." + ); + } + } + /// <summary>Initialise SMAPI and mods after the game starts.</summary> private void InitialiseAfterGameStart() { @@ -655,6 +700,15 @@ namespace StardewModdingAPI private void PressAnyKeyToExit() { this.Monitor.Log("Game has ended. Press any key to exit.", LogLevel.Info); + Program.PressAnyKeyToExit(showMessage: false); + } + + /// <summary>Show a 'press any key to exit' message, and exit when they press a key.</summary> + /// <param name="showMessage">Whether to print a 'press any key to exit' message to the console.</param> + private static void PressAnyKeyToExit(bool showMessage) + { + if (showMessage) + Console.WriteLine("Game has ended. Press any key to exit."); Thread.Sleep(100); Console.ReadKey(); Environment.Exit(0); |