From 02ce104425c1c258a2b05f60b6d2ce0357ffd849 Mon Sep 17 00:00:00 2001 From: Evan Dixon Date: Thu, 25 Aug 2016 22:59:29 -0500 Subject: [PATCH] Added overload to Util.Error to use ErrorWindow --- PKHeX/MainWindow/Main.cs | 8 +++--- PKHeX/Misc/ErrorWindow.cs | 3 +- PKHeX/PKM/PKX.cs | 2 +- .../Save Editors/Gen5/SAV_CGearSkin.cs | 2 +- PKHeX/Subforms/Save Editors/SAV_BoxViewer.cs | 2 +- PKHeX/Subforms/Save Editors/SAV_EventFlags.cs | 4 +-- PKHeX/Subforms/Save Editors/SAV_Wondercard.cs | 6 ++-- PKHeX/Util/FormUtil.cs | 28 +++++++++++++++++-- 8 files changed, 39 insertions(+), 16 deletions(-) diff --git a/PKHeX/MainWindow/Main.cs b/PKHeX/MainWindow/Main.cs index 1d348a793..e0cbead28 100644 --- a/PKHeX/MainWindow/Main.cs +++ b/PKHeX/MainWindow/Main.cs @@ -551,7 +551,7 @@ namespace PKHeX catch (Exception e) { Util.Error("File is in use by another program!", path, e.ToString()); return; } try { openFile(input, path, ext); } - catch (Exception e) { Util.Error("Unable to load file.", e.ToString()); } + catch (Exception e) { Util.Error("Unable to load file.", e); } } } private void openFile(byte[] input, string path, string ext) @@ -2503,7 +2503,7 @@ namespace PKHeX DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move); } catch (Exception x) - { Util.Error("Drag & Drop Error", x.ToString()); } + { Util.Error("Drag & Drop Error", x); } Cursor = DragInfo.Cursor = DefaultCursor; File.Delete(newfile); } @@ -2559,7 +2559,7 @@ namespace PKHeX try { Directory.CreateDirectory(BackupPath); Util.Alert("Backup folder created!", $"If you wish to no longer automatically back up save files, delete the \"{BackupPath}\" folder."); } - catch { Util.Error($"Unable to create backup folder @ {BackupPath}"); } + catch(Exception ex) { Util.Error($"Unable to create backup folder @ {BackupPath}", ex); } } private void clickExportSAV(object sender, EventArgs e) { @@ -3428,7 +3428,7 @@ namespace PKHeX } catch (Exception x) { - Util.Error("Drag & Drop Error:", x.ToString()); + Util.Error("Drag & Drop Error", x); } DragInfo.Reset(); Cursor = DefaultCursor; diff --git a/PKHeX/Misc/ErrorWindow.cs b/PKHeX/Misc/ErrorWindow.cs index 2e59f25f0..592222b65 100644 --- a/PKHeX/Misc/ErrorWindow.cs +++ b/PKHeX/Misc/ErrorWindow.cs @@ -11,7 +11,7 @@ namespace PKHeX.Misc { public partial class ErrorWindow : Form { - public static void ShowErrorDialog(string friendlyMessage, Exception ex, bool allowContinue) + public static DialogResult ShowErrorDialog(string friendlyMessage, Exception ex, bool allowContinue) { var lang = System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName; var dialog = new ErrorWindow(lang); @@ -24,6 +24,7 @@ namespace PKHeX.Misc { Application.Exit(); } + return dialogResult; } public ErrorWindow() diff --git a/PKHeX/PKM/PKX.cs b/PKHeX/PKM/PKX.cs index 8aebbcbae..5fca30531 100644 --- a/PKHeX/PKM/PKX.cs +++ b/PKHeX/PKM/PKX.cs @@ -544,7 +544,7 @@ namespace PKHeX AddFontMemResourceEx(fontPtr, (uint)Resources.pgldings_normalregular.Length, IntPtr.Zero, ref dummy); Marshal.FreeCoTaskMem(fontPtr); } - catch { Util.Error("Unable to add ingame font."); } + catch (Exception ex) { Util.Error("Unable to add ingame font.", ex); } } // Personal.dat diff --git a/PKHeX/Subforms/Save Editors/Gen5/SAV_CGearSkin.cs b/PKHeX/Subforms/Save Editors/Gen5/SAV_CGearSkin.cs index 3d0b6ea42..5128b4349 100644 --- a/PKHeX/Subforms/Save Editors/Gen5/SAV_CGearSkin.cs +++ b/PKHeX/Subforms/Save Editors/Gen5/SAV_CGearSkin.cs @@ -46,7 +46,7 @@ namespace PKHeX } catch (Exception ex) { - Util.Error(ex.Message); + Util.Error("An unexpected error has occurred.", ex); } } private void B_ExportPNG_Click(object sender, EventArgs e) diff --git a/PKHeX/Subforms/Save Editors/SAV_BoxViewer.cs b/PKHeX/Subforms/Save Editors/SAV_BoxViewer.cs index d7a2fffe2..d6267a547 100644 --- a/PKHeX/Subforms/Save Editors/SAV_BoxViewer.cs +++ b/PKHeX/Subforms/Save Editors/SAV_BoxViewer.cs @@ -193,7 +193,7 @@ namespace PKHeX } catch (Exception x) { - Util.Error("Drag & Drop Error:", x.ToString()); + Util.Error("Drag & Drop Error", x); } DragInfo.Reset(); Cursor = DefaultCursor; diff --git a/PKHeX/Subforms/Save Editors/SAV_EventFlags.cs b/PKHeX/Subforms/Save Editors/SAV_EventFlags.cs index 4d15c321f..f80ecd218 100644 --- a/PKHeX/Subforms/Save Editors/SAV_EventFlags.cs +++ b/PKHeX/Subforms/Save Editors/SAV_EventFlags.cs @@ -324,7 +324,7 @@ namespace PKHeX } catch (Exception e) { - Util.Error(e.ToString()); + Util.Error("An unexpected error has occurred.", e); Console.Write(e); } TB_IsSet.Text = tbIsSet; @@ -344,7 +344,7 @@ namespace PKHeX } catch (Exception e) { - Util.Error(e.ToString()); + Util.Error("An unexpected error has occurred.", e); Console.Write(e); } diff --git a/PKHeX/Subforms/Save Editors/SAV_Wondercard.cs b/PKHeX/Subforms/Save Editors/SAV_Wondercard.cs index 2c72ad174..a9ddbd317 100644 --- a/PKHeX/Subforms/Save Editors/SAV_Wondercard.cs +++ b/PKHeX/Subforms/Save Editors/SAV_Wondercard.cs @@ -99,7 +99,7 @@ namespace PKHeX } catch (Exception e) { - Util.Error("Loading of data failed... is this really a Wonder Card?", e.ToString()); + Util.Error("Loading of data failed... is this really a Wonder Card?", e); RTB.Clear(); } } @@ -390,8 +390,8 @@ namespace PKHeX File.WriteAllBytes(newfile, card.Data); DoDragDrop(new DataObject(DataFormats.FileDrop, new[] { newfile }), DragDropEffects.Move); } - catch (ArgumentException x) - { Util.Error("Drag & Drop Error:", x.ToString()); } + catch (Exception x) + { Util.Error("Drag & Drop Error", x); } File.Delete(newfile); wc_slot = -1; } diff --git a/PKHeX/Util/FormUtil.cs b/PKHeX/Util/FormUtil.cs index c76a198d9..52f880faf 100644 --- a/PKHeX/Util/FormUtil.cs +++ b/PKHeX/Util/FormUtil.cs @@ -1,4 +1,5 @@ -using System; +using PKHeX.Misc; +using System; using System.Collections.Generic; using System.Drawing; using System.IO; @@ -9,7 +10,7 @@ namespace PKHeX { public partial class Util { - // Form Translation + #region Form Translation internal static void TranslateInterface(Control form, string lang) { // Check to see if a the translation file exists in the same folder as the executable @@ -113,20 +114,40 @@ namespace PKHeX int y = parent.Location.Y + (parent.Height - child.Height) / 2; child.Location = new Point(Math.Max(x, 0), Math.Max(y, 0)); } + #endregion - // Message Displays + #region Message Displays + /// + /// Displays a dialog showing the details of an error. + /// + /// User-friendly message about the error. + /// Instance of the error's . + /// The associated with the dialog. + internal static DialogResult Error(string friendlyMessage, Exception exception) + { + System.Media.SystemSounds.Exclamation.Play(); + return ErrorWindow.ShowErrorDialog(friendlyMessage, exception, true, true); + } + + /// + /// Displays a dialog showing the details of an error. + /// + /// User-friendly message about the error. + /// The associated with the dialog. internal static DialogResult Error(params string[] lines) { System.Media.SystemSounds.Exclamation.Play(); string msg = string.Join(Environment.NewLine + Environment.NewLine, lines); return MessageBox.Show(msg, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } + internal static DialogResult Alert(params string[] lines) { System.Media.SystemSounds.Asterisk.Play(); string msg = string.Join(Environment.NewLine + Environment.NewLine, lines); return MessageBox.Show(msg, "Alert", MessageBoxButtons.OK, MessageBoxIcon.Warning); } + internal static DialogResult Prompt(MessageBoxButtons btn, params string[] lines) { System.Media.SystemSounds.Question.Play(); @@ -152,5 +173,6 @@ namespace PKHeX break; } } + #endregion } }