public static void ThrowErrorMessage(Exception e, string action, MaidFiddler plugin) { if (errorThrown) { return; } StringBuilder sb = new StringBuilder(); sb.AppendLine("=== Maid Fiddler DUMP ===").AppendLine(); sb.AppendLine($"Game version: {GameVersion}"); sb.AppendLine($"Mod version: {MaidFiddler.VERSION}"); sb.AppendLine($"Info: {action}"); sb.AppendLine($"Error message: {e}"); if (e.InnerException != null) { sb.Append($"Underlying exception: {e.InnerException}"); } bool dumpCreated; string filename = $"MaidFiddler_err_{GenerateFileName()}.txt"; try { using (TextWriter tw = new StreamWriter(File.Create(filename))) { tw.Write(sb.ToString()); dumpCreated = true; } } catch (Exception) { dumpCreated = false; } string dumpCreatedMsg = $"A log named {filename} was created.\nPlease, send this log to the developer with the description of what you attempted to do"; string dumpNotCreatedMsg = $"Failed to create a dump message. Send a screenshot of the following stack trace to the developer:\n==START==\n{sb}\n==END=="; string title = Translation.IsTranslated("ERROR_LOG_MESSAGE_TITLE") ? Translation.GetTranslation("ERROR_LOG_MESSAGE_TITLE") : "Oh noes!"; string text = Translation.IsTranslated("ERROR_LOG_MESSAGE") && (dumpCreated && Translation.IsTranslated("ERROR_LOG_CREATED") || !dumpCreated && Translation.IsTranslated("ERROR_LOG_NOT_CREATED")) ? $"{Translation.GetTranslation("ERROR_LOG_MESSAGE")}\n{(dumpCreated ? string.Format(Translation.GetTranslation("ERROR_LOG_CREATED"), filename) : string.Format(Translation.GetTranslation("ERROR_LOG_NOT_CREATED"), sb))}" : $"Oh no! An error has occured in Maid Fiddler!\n{(dumpCreated ? dumpCreatedMsg : dumpNotCreatedMsg)}"; MessageBox.Show(text, title, MessageBoxButtons.OK, MessageBoxIcon.Error); MaidFiddlerGUI guiLoc = plugin.Gui; plugin.Gui = null; guiLoc?.Close(true); errorThrown = true; }
public void LoadGUI() { try { Application.SetCompatibleTextRenderingDefault(false); if (Gui == null) { Gui = new MaidFiddlerGUI(this); } Application.Run(Gui); } catch (Exception e) { FiddlerUtils.ThrowErrorMessage(e, "Generic error", this); } }