From 36cb8e8fcb8afd2965ffe26e7755eb11838264d7 Mon Sep 17 00:00:00 2001 From: Jesse Plamondon-Willard Date: Sun, 7 Mar 2021 17:42:55 -0500 Subject: keep window open when installer crashes --- src/SMAPI.Installer/Program.cs | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) (limited to 'src') 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; } } + + /// Write an error directly to the console and exit. + /// The error message to display. + 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); + } } } -- cgit