diff options
-rw-r--r-- | docs/release-notes.md | 1 | ||||
-rw-r--r-- | src/SMAPI.Installer/Program.cs | 25 |
2 files changed, 25 insertions, 1 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md index 7a4a0409..ebe44f09 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -10,6 +10,7 @@ ## Upcoming release * For players: * Fixed console showing _found 1 mod with warnings_ with no mods listed. + * If the installer crashes, the window now stays open if possible so you can read the error and ask for help. * For mod authors: * Added three stages to the `LoadStageChanged` event: `CreatedInitialLocations`/`SaveAddedLocations` (raised immediately after the game adds locations but before they're initialized), and `ReturningToTitle` (raised before exiting to the title screen). diff --git a/src/SMAPI.Installer/Program.cs b/src/SMAPI.Installer/Program.cs index 6c479621..d9c31dd6 100644 --- a/src/SMAPI.Installer/Program.cs +++ b/src/SMAPI.Installer/Program.cs @@ -3,6 +3,7 @@ using System.Diagnostics.CodeAnalysis; using System.IO; using System.IO.Compression; using System.Reflection; +using System.Threading; namespace StardewModdingApi.Installer { @@ -49,7 +50,15 @@ namespace StardewModdingApi.Installer // launch installer var installer = new InteractiveInstaller(bundleDir.FullName); - installer.Run(args); + + try + { + installer.Run(args); + } + catch (Exception ex) + { + Program.PrintErrorAndExit($"The installer failed with an unexpected exception.\nIf you need help fixing this error, see https://smapi.io/help\n\n{ex}"); + } } /********* @@ -76,5 +85,19 @@ namespace StardewModdingApi.Installer return null; } } + + /// <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) + { + Console.ForegroundColor = ConsoleColor.Red; + Console.WriteLine(message); + Console.ResetColor(); + + Console.WriteLine("Game has ended. Press any key to exit."); + Thread.Sleep(100); + Console.ReadKey(); + Environment.Exit(0); + } } } |