1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.Threading.Tasks;
6 using System.Windows.Forms;
7 
8 namespace Mesen.GUI.Forms
9 {
10 	class MesenMsgBox
11 	{
Show(string text, MessageBoxButtons buttons, MessageBoxIcon icon, params string[] args)12 		public static DialogResult Show(string text, MessageBoxButtons buttons, MessageBoxIcon icon, params string[] args)
13 		{
14 			string resourceText = ResourceHelper.GetMessage(text, args);
15 
16 			if(resourceText.StartsWith("[[")) {
17 				if(args != null && args.Length > 0) {
18 					return MessageBox.Show(string.Format("Critical error (" + text + ") {0}", args), "Mesen", buttons, icon);
19 				} else {
20 					return MessageBox.Show(string.Format("Critical error (" + text + ")"), "Mesen", buttons, icon);
21 				}
22 			} else {
23 				Form mainForm = Application.OpenForms.Count > 0 ? Application.OpenForms[0] : null;
24 				if(mainForm?.InvokeRequired == true) {
25 					DialogResult result = DialogResult.Cancel;
26 					mainForm.Invoke((Action)(() => {
27 						result = MessageBox.Show(mainForm, ResourceHelper.GetMessage(text, args), "Mesen", buttons, icon);
28 					}));
29 					return result;
30 				} else {
31 					return MessageBox.Show(ResourceHelper.GetMessage(text, args), "Mesen", buttons, icon);
32 				}
33 			}
34 		}
35 	}
36 }
37