diff --git a/OpenRA.CrashDialog/Program.cs b/OpenRA.GameMonitor/GameMonitor.cs similarity index 66% rename from OpenRA.CrashDialog/Program.cs rename to OpenRA.GameMonitor/GameMonitor.cs index de59d416a0..fdaf6625a6 100644 --- a/OpenRA.CrashDialog/Program.cs +++ b/OpenRA.GameMonitor/GameMonitor.cs @@ -9,23 +9,45 @@ #endregion using System; +using System.Collections.Generic; using System.Diagnostics; using System.Drawing; -using System.IO; using System.Media; using System.Reflection; using System.Windows.Forms; -namespace OpenRA.CrashDialog +namespace OpenRA { - class FatalErrorDialog + class GameMonitor { - static Settings settings; + static string processName = "OpenRA.Game.exe"; + static Process gameProcess; + [STAThread] - public static void Main(string[] args) + static void Main(string[] args) { - settings = new Settings(Platform.ResolvePath("^", "settings.yaml"), new Arguments()); + var psi = new ProcessStartInfo(processName, string.Join(" ", args)); + try + { + gameProcess = Process.Start(psi); + } + catch + { + return; + } + + if (gameProcess == null) + return; + + gameProcess.EnableRaisingEvents = true; + gameProcess.Exited += GameProcessExited; + + Application.Run(); + } + + static void ShowErrorDialog() + { var form = new Form { Size = new Size(315, 140), @@ -34,6 +56,7 @@ namespace OpenRA.CrashDialog MaximizeBox = false, FormBorderStyle = FormBorderStyle.FixedDialog, StartPosition = FormStartPosition.CenterScreen, + TopLevel = true, Icon = Icon.ExtractAssociatedIcon(Assembly.GetExecutingAssembly().Location) }; @@ -44,69 +67,78 @@ namespace OpenRA.CrashDialog Text = "OpenRA has encountered a fatal error and must close.{0}Refer to the crash logs and FAQ for more information.".F(Environment.NewLine), TextAlign = ContentAlignment.TopCenter }; - form.Controls.Add(notice); - - var dontShowAgain = new CheckBox - { - Location = new Point(25, 50), - AutoSize = true, - Text = "Don't show this message again", - }; - form.Controls.Add(dontShowAgain); - + var viewLogs = new Button { Location = new Point(10, 80), Size = new Size(75, 23), Text = "View Logs" }; - viewLogs.Click += ViewLogsClicked; - form.Controls.Add(viewLogs); - + var viewFaq = new Button { Location = new Point(90, 80), Size = new Size(75, 23), Text = "View FAQ" }; - viewFaq.Click += ViewFaqClicked; - form.Controls.Add(viewFaq); var quit = new Button { Location = new Point(225, 80), Size = new Size(75, 23), - Text = "Quit" + Text = "Quit", + DialogResult = DialogResult.Cancel }; - quit.DialogResult = DialogResult.Cancel; + + form.Controls.Add(notice); + form.Controls.Add(viewLogs); + form.Controls.Add(viewFaq); form.Controls.Add(quit); - form.FormClosed += (sender, e) => - { - settings.Debug.ShowFatalErrorDialog = !dontShowAgain.Checked; - settings.Save(); - }; + viewLogs.Click += ViewLogsClicked; + viewFaq.Click += ViewFaqClicked; + form.FormClosed += FormClosed; SystemSounds.Exclamation.Play(); form.ShowDialog(); } + static void GameProcessExited(object sender, EventArgs e) + { + if (gameProcess.ExitCode != 0) + ShowErrorDialog(); + + Exit(); + } + static void ViewLogsClicked(object sender, EventArgs e) { try { Process.Start(Platform.ResolvePath("^", "Logs")); } - catch { } + catch + { } } static void ViewFaqClicked(object sender, EventArgs e) { try { - Process.Start(settings.Debug.FatalErrorDialogFaq); + Process.Start("http://wiki.openra.net/FAQ"); } - catch { } + catch + { } + } + + static void FormClosed(object sender, EventArgs e) + { + Exit(); + } + + static void Exit() + { + Environment.Exit(0); } } } diff --git a/OpenRA.CrashDialog/OpenRA.CrashDialog.csproj b/OpenRA.GameMonitor/OpenRA.GameMonitor.csproj similarity index 84% rename from OpenRA.CrashDialog/OpenRA.CrashDialog.csproj rename to OpenRA.GameMonitor/OpenRA.GameMonitor.csproj index a3ab69b70f..561169dcd0 100644 --- a/OpenRA.CrashDialog/OpenRA.CrashDialog.csproj +++ b/OpenRA.GameMonitor/OpenRA.GameMonitor.csproj @@ -2,11 +2,11 @@ Debug - AnyCPU - {47F1B0EE-EB35-47F2-93E4-273C70909157} - Exe + x86 + {68295755-7902-4602-AC2C-9A8AC36D5EF7} + WinExe OpenRA - OpenRA.CrashDialog + OpenRA true @@ -34,7 +34,7 @@ - + \ No newline at end of file diff --git a/OpenRA.CrashDialog/Settings.StyleCop b/OpenRA.GameMonitor/Settings.StyleCop similarity index 100% rename from OpenRA.CrashDialog/Settings.StyleCop rename to OpenRA.GameMonitor/Settings.StyleCop diff --git a/OpenRA.sln b/OpenRA.sln index 89b342a0ab..125b1a8330 100644 --- a/OpenRA.sln +++ b/OpenRA.sln @@ -70,7 +70,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "System Lua scripts", "Syste lua\stacktraceplus.lua = lua\stacktraceplus.lua EndProjectSection EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.CrashDialog", "OpenRA.CrashDialog\OpenRA.CrashDialog.csproj", "{47F1B0EE-EB35-47F2-93E4-273C70909157}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenRA.GameMonitor", "OpenRA.GameMonitor\OpenRA.GameMonitor.csproj", "{68295755-7902-4602-AC2C-9A8AC36D5EF7}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -101,8 +101,8 @@ Global {5457CBF5-4CE4-421E-A8BF-9FD6C9732E1D}.Debug|x86.Build.0 = Debug|x86 {33D03738-C154-4028-8EA8-63A3C488A651}.Debug|x86.ActiveCfg = Debug|x86 {33D03738-C154-4028-8EA8-63A3C488A651}.Debug|x86.Build.0 = Debug|x86 - {47F1B0EE-EB35-47F2-93E4-273C70909157}.Debug|x86.ActiveCfg = Debug|x86 - {47F1B0EE-EB35-47F2-93E4-273C70909157}.Debug|x86.Build.0 = Debug|x86 + {68295755-7902-4602-AC2C-9A8AC36D5EF7}.Debug|x86.ActiveCfg = Debug|x86 + {68295755-7902-4602-AC2C-9A8AC36D5EF7}.Debug|x86.Build.0 = Debug|x86 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE