summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-02-21 17:33:37 -0500
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-02-21 17:33:37 -0500
commit033b3856413f51e26e74498ea9fe3de291d4e93a (patch)
tree76704efb30e299d0aa6fbd83f3b6682613ae7a72 /src
parent8205b4bd3501360780ddbc51bea2cccfdaac7517 (diff)
downloadSMAPI-033b3856413f51e26e74498ea9fe3de291d4e93a.tar.gz
SMAPI-033b3856413f51e26e74498ea9fe3de291d4e93a.tar.bz2
SMAPI-033b3856413f51e26e74498ea9fe3de291d4e93a.zip
add detailed error message when Stardew Valley.exe can't be loaded
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI/Program.cs31
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);
}