From 27c0d3f0ae2b6d02aaf5b16acbce939bd64cf728 Mon Sep 17 00:00:00 2001 From: Dev Date: Thu, 14 Mar 2024 17:08:20 +0000 Subject: [PATCH] Added patch failure handling, thanks to Drakia --- project/Aki.Core/AkiCorePlugin.cs | 1 + project/Aki.Custom/AkiCustomPlugin.cs | 2 + project/Aki.Custom/Utils/MessageBoxHelper.cs | 56 ++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 project/Aki.Custom/Utils/MessageBoxHelper.cs diff --git a/project/Aki.Core/AkiCorePlugin.cs b/project/Aki.Core/AkiCorePlugin.cs index 5c020f3..db5436d 100644 --- a/project/Aki.Core/AkiCorePlugin.cs +++ b/project/Aki.Core/AkiCorePlugin.cs @@ -32,6 +32,7 @@ namespace Aki.Core { Logger.LogError($"A PATCH IN {GetType().Name} FAILED. SUBSEQUENT PATCHES HAVE NOT LOADED"); Logger.LogError($"{GetType().Name}: {ex}"); + throw; } diff --git a/project/Aki.Custom/AkiCustomPlugin.cs b/project/Aki.Custom/AkiCustomPlugin.cs index ebf9634..2898ce5 100644 --- a/project/Aki.Custom/AkiCustomPlugin.cs +++ b/project/Aki.Custom/AkiCustomPlugin.cs @@ -80,6 +80,8 @@ namespace Aki.Custom { Logger.LogError($"A PATCH IN {GetType().Name} FAILED. SUBSEQUENT PATCHES HAVE NOT LOADED"); Logger.LogError($"{GetType().Name}: {ex}"); + MessageBoxHelper.Show($"A PATCH IN {GetType().Name} FAILED. SUBSEQUENT PATCHES HAVE NOT LOADED, CHECK LOG FOR MORE DETAILS", "ERROR", MessageBoxHelper.MessageBoxType.OK); + throw; } diff --git a/project/Aki.Custom/Utils/MessageBoxHelper.cs b/project/Aki.Custom/Utils/MessageBoxHelper.cs new file mode 100644 index 0000000..d3fe762 --- /dev/null +++ b/project/Aki.Custom/Utils/MessageBoxHelper.cs @@ -0,0 +1,56 @@ +using System; +using System.Runtime.InteropServices; + +namespace Aki.Custom.Utils +{ + public class MessageBoxHelper + { + public enum MessageBoxType : uint + { + ABORTRETRYIGNORE = (uint)(0x00000002L | 0x00000010L), + CANCELTRYCONTINUE = (uint)(0x00000006L | 0x00000030L), + HELP = (uint)(0x00004000L | 0x00000040L), + OK = (uint)(0x00000000L | 0x00000040L), + OKCANCEL = (uint)(0x00000001L | 0x00000040L), + RETRYCANCEL = (uint)0x00000005L, + YESNO = (uint)(0x00000004L | 0x00000040L), + YESNOCANCEL = (uint)(0x00000003L | 0x00000040L), + DEFAULT = (uint)(0x00000000L | 0x00000010L) + } + + public enum MessageBoxResult + { + ERROR = -1, + OK = 1, + CANCEL = 2, + ABORT = 3, + RETRY = 4, + IGNORE = 5, + YES = 6, + NO = 7, + TRY_AGAIN = 10 + } + + [DllImport("user32.dll")] + private static extern IntPtr GetActiveWindow(); + [DllImport("user32.dll", SetLastError = true)] + static extern int MessageBox(IntPtr hwnd, String lpText, String lpCaption, uint uType); + + public static IntPtr GetWindowHandle() + { + return GetActiveWindow(); + } + + public static MessageBoxResult Show(string text, string caption, MessageBoxType type = MessageBoxType.DEFAULT) + { + try + { + return (MessageBoxResult)MessageBox(GetWindowHandle(), text, caption, (uint)type); ; + } + catch (Exception) + { + return MessageBoxResult.ERROR; + } + } + } +}