2016-08-22 01:05:41 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Windows.Forms;
|
|
|
|
|
|
2017-01-08 07:54:09 +00:00
|
|
|
|
namespace PKHeX.WinForms
|
2016-08-22 01:05:41 +00:00
|
|
|
|
{
|
2018-07-27 02:34:27 +00:00
|
|
|
|
public sealed partial class ErrorWindow : Form
|
2016-08-22 01:05:41 +00:00
|
|
|
|
{
|
2016-08-26 03:59:29 +00:00
|
|
|
|
public static DialogResult ShowErrorDialog(string friendlyMessage, Exception ex, bool allowContinue)
|
2016-08-22 01:05:41 +00:00
|
|
|
|
{
|
2016-08-22 01:12:09 +00:00
|
|
|
|
var lang = System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
|
2019-10-08 01:40:09 +00:00
|
|
|
|
using var dialog = new ErrorWindow(lang)
|
2016-09-19 05:50:32 +00:00
|
|
|
|
{
|
|
|
|
|
ShowContinue = allowContinue,
|
|
|
|
|
Message = friendlyMessage,
|
|
|
|
|
Error = ex
|
|
|
|
|
};
|
2016-08-22 01:05:41 +00:00
|
|
|
|
var dialogResult = dialog.ShowDialog();
|
|
|
|
|
if (dialogResult == DialogResult.Abort)
|
2016-10-20 00:47:43 +00:00
|
|
|
|
Environment.Exit(1);
|
2016-08-26 03:59:29 +00:00
|
|
|
|
return dialogResult;
|
2016-08-22 01:05:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private ErrorWindow()
|
2016-08-22 01:05:41 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private ErrorWindow(string lang) : this()
|
2016-08-22 01:05:41 +00:00
|
|
|
|
{
|
2017-01-08 07:54:09 +00:00
|
|
|
|
WinFormsUtil.TranslateInterface(this, lang);
|
2016-08-22 01:05:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Gets or sets whether or not the "Continue" button is visible.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>For UI exceptions, continuing could be safe.
|
|
|
|
|
/// For application exceptions, continuing is not possible, so the button should not be shown.</remarks>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private bool ShowContinue
|
2016-08-22 01:05:41 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => B_Continue.Visible;
|
|
|
|
|
set => B_Continue.Visible = value;
|
2016-08-22 01:05:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Friendly, context-specific method shown to the user.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <remarks>This property is intended to be a user-friendly context-specific message about what went wrong.
|
|
|
|
|
/// For example: "An error occurred while attempting to automatically load the save file."</remarks>
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private string Message
|
2016-08-22 01:05:41 +00:00
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => L_Message.Text;
|
|
|
|
|
set => L_Message.Text = value;
|
2016-08-22 01:05:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-07-27 02:34:27 +00:00
|
|
|
|
private Exception _error;
|
|
|
|
|
|
2016-08-22 01:05:41 +00:00
|
|
|
|
public Exception Error
|
|
|
|
|
{
|
2017-05-13 03:32:36 +00:00
|
|
|
|
get => _error;
|
2016-08-22 01:05:41 +00:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
_error = value;
|
2018-05-12 15:13:39 +00:00
|
|
|
|
UpdateExceptionDetailsMessage();
|
2016-08-30 02:22:15 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-08-22 14:14:37 +00:00
|
|
|
|
|
2016-08-30 02:22:15 +00:00
|
|
|
|
private void UpdateExceptionDetailsMessage()
|
|
|
|
|
{
|
|
|
|
|
var details = new StringBuilder();
|
|
|
|
|
details.AppendLine("Exception Details:");
|
|
|
|
|
details.AppendLine(Error.ToString());
|
|
|
|
|
details.AppendLine();
|
2016-08-22 14:14:37 +00:00
|
|
|
|
|
2016-08-30 02:22:15 +00:00
|
|
|
|
details.AppendLine("Loaded Assemblies:");
|
|
|
|
|
details.AppendLine("--------------------");
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
foreach (var item in AppDomain.CurrentDomain.GetAssemblies())
|
2016-08-22 14:14:37 +00:00
|
|
|
|
{
|
2016-08-30 02:22:15 +00:00
|
|
|
|
details.AppendLine(item.FullName);
|
|
|
|
|
details.AppendLine(item.Location);
|
|
|
|
|
details.AppendLine();
|
2016-08-22 14:14:37 +00:00
|
|
|
|
}
|
2016-08-22 01:05:41 +00:00
|
|
|
|
}
|
2016-08-30 02:22:15 +00:00
|
|
|
|
catch (Exception ex)
|
|
|
|
|
{
|
|
|
|
|
details.AppendLine("An error occurred while listing the Loaded Assemblies:");
|
|
|
|
|
details.AppendLine(ex.ToString());
|
|
|
|
|
}
|
|
|
|
|
details.AppendLine("--------------------");
|
|
|
|
|
|
|
|
|
|
// Include message in case it contains important information, like a file path.
|
|
|
|
|
details.AppendLine("User Message:");
|
|
|
|
|
details.AppendLine(Message);
|
|
|
|
|
|
|
|
|
|
T_ExceptionDetails.Text = details.ToString();
|
2016-08-22 01:05:41 +00:00
|
|
|
|
}
|
|
|
|
|
|
2019-11-23 05:23:00 +00:00
|
|
|
|
private void ClickCopyException(object sender, EventArgs e) => WinFormsUtil.SetClipboardText(T_ExceptionDetails.Text);
|
2016-08-22 01:05:41 +00:00
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickContinue(object sender, EventArgs e)
|
2016-08-22 01:05:41 +00:00
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.OK;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
|
2017-06-18 01:37:19 +00:00
|
|
|
|
private void ClickAbort(object sender, EventArgs e)
|
2016-08-22 01:05:41 +00:00
|
|
|
|
{
|
|
|
|
|
DialogResult = DialogResult.Abort;
|
|
|
|
|
Close();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|