diff options
author | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-02-21 23:05:17 -0500 |
---|---|---|
committer | Jesse Plamondon-Willard <Pathoschild@users.noreply.github.com> | 2021-02-21 23:05:17 -0500 |
commit | db011ee751bdfb8bbd9abbeb706966db4c4e2461 (patch) | |
tree | 4c1ca1c2fb2db41ac0d8b337e2f17209b4ad66f5 /src/SMAPI/Program.cs | |
parent | f1505b0ebe5c8fa7cf3c160231f0ed7d1bd6619a (diff) | |
parent | 9c4c10d2d22cbf67ccadbd35fdf1ffced0541cc2 (diff) | |
download | SMAPI-db011ee751bdfb8bbd9abbeb706966db4c4e2461.tar.gz SMAPI-db011ee751bdfb8bbd9abbeb706966db4c4e2461.tar.bz2 SMAPI-db011ee751bdfb8bbd9abbeb706966db4c4e2461.zip |
Merge branch 'develop' into stable
Diffstat (limited to 'src/SMAPI/Program.cs')
-rw-r--r-- | src/SMAPI/Program.cs | 31 |
1 files changed, 28 insertions, 3 deletions
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs index 23ee8453..986d2780 100644 --- a/src/SMAPI/Program.cs +++ b/src/SMAPI/Program.cs @@ -73,8 +73,22 @@ namespace StardewModdingAPI /// <remarks>This must be checked *before* any references to <see cref="Constants"/>, and this method should not reference <see cref="Constants"/> itself to avoid errors in Mono or when the game isn't present.</remarks> private static void AssertGamePresent() { - if (Type.GetType($"StardewValley.Game1, {EarlyConstants.GameAssemblyName}", throwOnError: false) == null) - Program.PrintErrorAndExit("Oops! SMAPI can't find the game. Make sure you're running StardewModdingAPI.exe in your game folder. See the readme.txt file for details."); + try + { + _ = Type.GetType($"StardewValley.Game1, {EarlyConstants.GameAssemblyName}", throwOnError: true); + } + catch (Exception ex) + { + // file doesn't exist + if (!File.Exists(Path.Combine(EarlyConstants.ExecutionPath, $"{EarlyConstants.GameAssemblyName}.exe"))) + Program.PrintErrorAndExit("Oops! SMAPI can't find the game. Make sure you're running StardewModdingAPI.exe in your game folder."); + + // can't load file + Program.PrintErrorAndExit( + message: "Oops! SMAPI couldn't load the game executable. The technical details below may have more info.", + technicalMessage: $"Technical details: {ex}" + ); + } } /// <summary>Assert that the game version is within <see cref="Constants.MinimumGameVersion"/> and <see cref="Constants.MaximumGameVersion"/>.</summary> @@ -130,11 +144,22 @@ namespace StardewModdingAPI /// <summary>Write an error directly to the console and exit.</summary> /// <param name="message">The error message to display.</param> - private static void PrintErrorAndExit(string message) + /// <param name="technicalMessage">An additional message to log with technical details.</param> + private static void PrintErrorAndExit(string message, string technicalMessage = null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(message); Console.ResetColor(); + + if (technicalMessage != null) + { + Console.WriteLine(); + Console.ForegroundColor = ConsoleColor.Gray; + Console.WriteLine(technicalMessage); + Console.ResetColor(); + Console.WriteLine(); + } + Program.PressAnyKeyToExit(showMessage: true); } |