From 6b8bd471436870f0032d811745bfded88b5b7690 Mon Sep 17 00:00:00 2001 From: Paul Chote Date: Sat, 3 May 2014 22:33:24 +1200 Subject: [PATCH] Add a native crash dialog for OSX. --- OpenRA.Game/Platform.cs | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/OpenRA.Game/Platform.cs b/OpenRA.Game/Platform.cs index dc9b81b33c..be1e52f53b 100644 --- a/OpenRA.Game/Platform.cs +++ b/OpenRA.Game/Platform.cs @@ -11,6 +11,7 @@ using System; using System.Diagnostics; using System.IO; +using System.Linq; using System.Reflection; using OpenRA.FileFormats; @@ -98,6 +99,36 @@ namespace OpenRA var process = "OpenRA.CrashDialog.exe"; var args = ""; + if (CurrentPlatform == PlatformType.OSX) + { + // Winforms requires X11 under OSX, which may not exist. + // Show a native dialog using applescript instead. + var title = "Fatal Error"; + var logsButton = "View Logs"; + var faqButton = "View FAQ"; + var quitButton = "Quit"; + var message = "OpenRA has encountered a fatal error.\nRefer to the crash logs and FAQ for more information."; + + var faqPath = Game.Settings.Debug.FatalErrorDialogFaq; + var logsPath = "file://" + Platform.SupportDir + "Logs" + Path.DirectorySeparatorChar; + + var iconPath = new [] { "./OpenRA.icns", "./packaging/osx/template.app/Contents/Resources/OpenRA.icns" }.FirstOrDefault(f => File.Exists(f)); + var icon = iconPath != null ? "with icon alias (POSIX file \\\"file://{0}\\\")".F(Environment.CurrentDirectory + "/" + iconPath) : ""; + + process = "/usr/bin/osascript"; + args = ( + "-e \"repeat\"\n" + + "-e \" tell application \\\"Finder\\\"\"\n" + + "-e \" set question to display dialog \\\"{1}\\\" with title \\\"{0}\\\" {2} buttons {{\\\"{3}\\\", \\\"{5}\\\", \\\"{7}\\\"}} default button 3\"\n" + + "-e \" if button returned of question is equal to \\\"{3}\\\" then open (POSIX file \\\"{4}\\\")\"\n" + + "-e \" if button returned of question is equal to \\\"{5}\\\" then open location \\\"{6}\\\"\"\n" + + "-e \" if button returned of question is equal to \\\"{7}\\\" then exit repeat\"\n" + + "-e \" activate\"\n" + + "-e \" end tell\"\n" + + "-e \"end repeat\"" + ).F(title, message, icon, logsButton, logsPath, faqButton, faqPath, quitButton); + } + var psi = new ProcessStartInfo(process, args); psi.UseShellExecute = false; psi.CreateNoWindow = true;