Skip to content

Commit

Permalink
Interface.MessageBoxShow method for faking MessageBox.Show on Mac
Browse files Browse the repository at this point in the history
  • Loading branch information
JavidPack committed Oct 4, 2019
1 parent 5b39242 commit dcbafc8
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 24 deletions.
12 changes: 3 additions & 9 deletions patches/tModLoader/Terraria.ModLoader.Engine/GoGVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,9 +66,7 @@ private static bool GoGCheck() {
Logging.tML.Info("Vanilla Terraria.exe not found.");
string message = $"{vanillaPath} not found.\n\nGoG installs must have the unmodified Terraria exe to function.\n\nPlease restore your Terraria install, then install tModLoader using the provided tModLoaderInstaller.jar or by following the README.txt instructions.";
Logging.tML.Fatal(message);
#if !MAC
System.Windows.Forms.MessageBox.Show(message, "Terraria: Error" + $" ({ModLoader.versionedName})");
#endif
UI.Interface.MessageBoxShow(message);
Environment.Exit(1);
return false;
#endif
Expand All @@ -77,9 +75,7 @@ private static bool GoGCheck() {
if (!HashMatchesFile(vanillaGoGhash, vanillaPath)) {
string message = $"{vanillaPath} is not the unmodified Terraria executable.\n\nGoG installs must have the unmodified Terraria executable to function.\n\nPlease restore your Terraria install, then install tModLoader using the provided tModLoaderInstaller.jar or by following the README.txt instructions.";
Logging.tML.Fatal(message);
#if !MAC
System.Windows.Forms.MessageBox.Show(message, "Terraria: Error" + $" ({ModLoader.versionedName})");
#endif
UI.Interface.MessageBoxShow(message);
Environment.Exit(1);
return false;
}
Expand All @@ -92,9 +88,7 @@ private static void VerifySteamAPI(string steamAPIpath, byte[] steamAPIhash) {
if (!HashMatchesFile(steamAPIhash, steamAPIpath)) {
string message = "Steam API hash mismatch, assumed pirated.\n\ntModLoader requires a legitimate Terraria install to work.";
Logging.tML.Fatal(message);
#if !MAC
System.Windows.Forms.MessageBox.Show(message, "Terraria: Error" + $" ({ModLoader.versionedName})");
#endif
UI.Interface.MessageBoxShow(message);
Process.Start(@"https://terraria.org");
Environment.Exit(1);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,11 @@ private static void ReportFatalEngineReload()
}

//var modsAffected = ModContent.HiDefMods.Count == 0 ? "No mods will be affected." : $"The following mods will be affected {string.Join(", ", ModContent.HiDefMods.Select(m => m.DisplayName))}";
string message = $"tML encountered a crash when testing some experimental graphics features. If this issue persists consistently, you may have to edit config.json and set the Support4K setting to false. \nPlease restart your game.\nReport Status: {reportStatus}";
#if !MAC
MessageBox.Show($"tML encountered a crash when testing some experimental graphics features. If this issue persists consistently, you may have to edit config.json and set the Support4K setting to false. \nPlease restart your game.\nReport Status: {reportStatus}", "Graphics Engine Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
MessageBox.Show(message, "Graphics Engine Failure", MessageBoxButtons.OK, MessageBoxIcon.Error);
#else
UI.Interface.MessageBoxShow(message, "Graphics Engine Failure");
#endif
Environment.Exit(1);
}
Expand Down
12 changes: 12 additions & 0 deletions patches/tModLoader/Terraria.ModLoader.UI/Interface.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using Terraria.ID;
Expand Down Expand Up @@ -373,5 +374,16 @@ internal static void ServerModBrowserMenu() {
}
Console.Clear();
}

internal static void MessageBoxShow(string text, string caption = null) {
// MessageBox.Show fails on Mac, this method will open a text file to show a message.
caption = caption ?? "Terraria: Error" + $" ({ModLoader.versionedName})";
#if !MAC
System.Windows.Forms.MessageBox.Show(text, caption);
#else
File.WriteAllText("fake-messagebox.txt", $"{caption}\n\n{text}");
Process.Start("fake-messagebox.txt");
#endif
}
}
}
4 changes: 1 addition & 3 deletions patches/tModLoader/Terraria.ModLoader/ModLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ private static void DotNet45Check() {

var msg = Language.GetTextValue("tModLoader.LoadErrorDotNet45Required");
#if CLIENT
#if !MAC
MessageBox.Show(msg);
#endif
Interface.MessageBoxShow(msg);
Process.Start("https://www.microsoft.com/net/download/thank-you/net472");
#else
Console.ForegroundColor = ConsoleColor.Red;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
--- src/Terraria\Terraria.Social.Steam\CoreSocialModule.cs
+++ src/tModLoader\Terraria.Social.Steam\CoreSocialModule.cs
@@ -29,7 +_,9 @@
@@ -29,7 +_,7 @@
#endif
if (!SteamAPI.Init())
{
+#if !MAC
MessageBox.Show(Language.GetTextValue("Error.LaunchFromSteam"), Language.GetTextValue("Error.Error"));
+#endif
- MessageBox.Show(Language.GetTextValue("Error.LaunchFromSteam"), Language.GetTextValue("Error.Error"));
+ ModLoader.UI.Interface.MessageBoxShow(Language.GetTextValue("Error.LaunchFromSteam"), Language.GetTextValue("Error.Error"));
Environment.Exit(1);
}
this.IsSteamValid = true;
Expand Down
10 changes: 3 additions & 7 deletions patches/tModLoader/Terraria/Program.cs.patch
Original file line number Diff line number Diff line change
Expand Up @@ -105,23 +105,19 @@
}
}

@@ -263,9 +_,20 @@
@@ -263,9 +_,16 @@
streamWriter.WriteLine("");
}
#if CLIENT
- MessageBox.Show(e.ToString(), "Terraria: Error");
-#else
- Console.WriteLine(Language.GetTextValue("Error.ServerCrash"), DateTime.Now, e);
+#if !MAC
+ MessageBox.Show(e.ToString(), "Terraria: Error" + $" ({ModLoader.ModLoader.versionedName})");
+#endif
+ ModLoader.UI.Interface.MessageBoxShow(e.ToString());
+ if (e.Message.Contains("CSteamworks"))
+ Process.Start(@"https://github.com/tModLoader/tModLoader/wiki/Basic-tModLoader-Usage-FAQ#systemdllnotfoundexception-unable-to-load-dllcsteamworks");
+ if (e.StackTrace.Contains("LaunchLocalServer"))
+ {
+#if !MAC
+ MessageBox.Show("Looks like you didn't do a complete install. You are missing tModLoaderServer.exe. Check your install directory and read the install directions.", "Terraria: Error");
+#endif
+ ModLoader.UI.Interface.MessageBoxShow("Looks like you didn't do a complete install. You are missing tModLoaderServer.exe. Check your install directory and read the install directions.");
+ Process.Start(@"https://github.com/tModLoader/tModLoader/wiki/Basic-tModLoader-Usage-FAQ#host-and-play-the-system-cannot-find-the-file-specified");
+ }
+#else
Expand Down

0 comments on commit dcbafc8

Please sign in to comment.