From e1351cc75694b772ccaa5d7a8db8fdb76514a898 Mon Sep 17 00:00:00 2001 From: WeeXnes Date: Thu, 8 Jun 2023 17:58:44 +0200 Subject: [PATCH] fixes + improved crash handler --- WeeXnes/App.xaml.cs | 10 ++++-- WeeXnes/Core/CustomConsole.cs | 21 +++++++----- WeeXnes/Core/Functions.cs | 5 +++ WeeXnes/Core/Global.cs | 2 +- WeeXnes/Views/KeyManager/KeyManagerView.xaml | 8 ++--- WeeXnes/Views/Settings/ChangePathsView.xaml | 21 ++++++++++-- .../Views/Settings/ChangePathsView.xaml.cs | 28 ++++++++++++++++ WeeXnes/Views/Settings/FluentMessageBox.xaml | 33 +++++++++++++++++++ .../Views/Settings/FluentMessageBox.xaml.cs | 14 ++++++++ WeeXnes/WeeXnes.csproj | 6 +++- 10 files changed, 129 insertions(+), 19 deletions(-) create mode 100644 WeeXnes/Views/Settings/FluentMessageBox.xaml create mode 100644 WeeXnes/Views/Settings/FluentMessageBox.xaml.cs diff --git a/WeeXnes/App.xaml.cs b/WeeXnes/App.xaml.cs index f9095c1..c13023a 100644 --- a/WeeXnes/App.xaml.cs +++ b/WeeXnes/App.xaml.cs @@ -2,6 +2,7 @@ using System.ComponentModel; using System.Windows; using System.IO; +using System.Windows.Media; using Newtonsoft.Json.Linq; using Nocksoft.IO.ConfigFiles; using WeeXnes.Core; @@ -17,6 +18,7 @@ namespace WeeXnes /// public partial class App { + public static bool DebugMode = false; private void SetExceptionHandler() { AppDomain currentDomain = default(AppDomain); @@ -30,6 +32,7 @@ namespace WeeXnes { writer.WriteLine(ex.ToString()); } + new FluentMessageBox(ex.Message).ShowDialog(); } private void App_OnStartup(object sender, StartupEventArgs e) { @@ -142,7 +145,7 @@ namespace WeeXnes ); newItem.Filename = file.Name; KeyManagerView.Data.KeyItemsList.Add(newItem); - WeeXnes.Core.CustomConsole.WriteLine(file.Name + " loaded"); + WeeXnes.Core.CustomConsole.WriteLineVerbose(file.Name + " loaded"); } catch (Exception ex) @@ -173,9 +176,10 @@ namespace WeeXnes private void CheckForDebugMode() { - #if DEBUG +#if DEBUG + DebugMode = true; HandleLaunchArguments.arg_enableConsole(); - #endif +#endif } } } \ No newline at end of file diff --git a/WeeXnes/Core/CustomConsole.cs b/WeeXnes/Core/CustomConsole.cs index ba3b935..edfc224 100644 --- a/WeeXnes/Core/CustomConsole.cs +++ b/WeeXnes/Core/CustomConsole.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.IO; using System.Runtime.CompilerServices; using System.Text; using VanillaConsole = System.Console; @@ -33,14 +34,11 @@ namespace WeeXnes.Core ConsoleColor color, ConsoleColor foregroundColor = ConsoleColor.White) { - try - { - VanillaConsole.OutputEncoding = Encoding.UTF8; - } - catch (Exception ex) - { - VanillaConsole.WriteLine("error setting OutputEncoding to UTF8"); - } + if(!App.DebugMode) + return; + + VanillaConsole.OutputEncoding = Encoding.UTF8; + ConsoleColor prevColor = VanillaConsole.BackgroundColor; ConsoleColor prevForeColor = VanillaConsole.ForegroundColor; if (Data.Colors.colored_output) @@ -64,6 +62,13 @@ namespace WeeXnes.Core { ConfiguredWriteline(" " + Data.Formatting.writeline_char + " (" + lineNumber + "|" + caller + ") " + text,VanillaConsole.BackgroundColor, ConsoleColor.White); } + public static void WriteLineVerbose(string text, + [CallerLineNumber] int lineNumber = 0, + [CallerMemberName] string caller = null, + [CallerFilePath] string filePath = null) + { + ConfiguredWriteline(" " + Data.Formatting.writeline_char + " (" + Path.GetFileName(filePath) + "|" + caller + "|" + lineNumber + ") " + text,VanillaConsole.BackgroundColor, ConsoleColor.White); + } public static void WriteLine(float text, [CallerLineNumber] int lineNumber = 0, [CallerMemberName] string caller = null) diff --git a/WeeXnes/Core/Functions.cs b/WeeXnes/Core/Functions.cs index 917aa54..cc3d081 100644 --- a/WeeXnes/Core/Functions.cs +++ b/WeeXnes/Core/Functions.cs @@ -39,5 +39,10 @@ namespace WeeXnes.Core } File.WriteAllLines(filepath, stringArray, Encoding.UTF8); } + + public static void ThrowTestException() + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/WeeXnes/Core/Global.cs b/WeeXnes/Core/Global.cs index e7671eb..fb42f6b 100644 --- a/WeeXnes/Core/Global.cs +++ b/WeeXnes/Core/Global.cs @@ -8,7 +8,7 @@ namespace WeeXnes.Core { public class Information { - public const string Version = "4.3.3"; + public const string Version = "4.3.4"; public const string EncryptionHash = "8zf5#RdyQ]$4x4_"; public const string ApiUrl = "https://api.github.com/repos/weexnes/weexnessuite/releases/latest"; } diff --git a/WeeXnes/Views/KeyManager/KeyManagerView.xaml b/WeeXnes/Views/KeyManager/KeyManagerView.xaml index 3f8ea68..8bd61df 100644 --- a/WeeXnes/Views/KeyManager/KeyManagerView.xaml +++ b/WeeXnes/Views/KeyManager/KeyManagerView.xaml @@ -19,16 +19,16 @@ SelectionChanged="ListviewKeys_OnSelectionChanged"> - - + + diff --git a/WeeXnes/Views/Settings/ChangePathsView.xaml b/WeeXnes/Views/Settings/ChangePathsView.xaml index 82de67e..89128fc 100644 --- a/WeeXnes/Views/Settings/ChangePathsView.xaml +++ b/WeeXnes/Views/Settings/ChangePathsView.xaml @@ -20,8 +20,25 @@ - - + + + + + + + + + + + + + + diff --git a/WeeXnes/Views/Settings/ChangePathsView.xaml.cs b/WeeXnes/Views/Settings/ChangePathsView.xaml.cs index 15ced7c..b3919e1 100644 --- a/WeeXnes/Views/Settings/ChangePathsView.xaml.cs +++ b/WeeXnes/Views/Settings/ChangePathsView.xaml.cs @@ -1,7 +1,11 @@ using System; using System.Windows; using System.Windows.Controls; +using System.Windows.Forms; using WeeXnes.Core; +using MessageBox = System.Windows.MessageBox; +using OpenFileDialog = Microsoft.Win32.OpenFileDialog; +using TextBox = System.Windows.Controls.TextBox; namespace WeeXnes.Views.Settings { @@ -29,5 +33,29 @@ namespace WeeXnes.Views.Settings Global.AppDataPathKEY.Value = TextboxKeyPath.Text; Global.ForceClose(); } + + private void ContextMenu_SelectKfFolder(object sender, RoutedEventArgs e) + { + CallOpenFolderDialog(TextboxKeyPath); + } + private void ContextMenu_SelectRpcFolder(object sender, RoutedEventArgs e) + { + CallOpenFolderDialog(TextboxRPCPath); + } + + private void CallOpenFolderDialog(TextBox textBoxToChange) + { + + + using(var fbd = new FolderBrowserDialog()) + { + DialogResult result = fbd.ShowDialog(); + + if (result == DialogResult.OK && !string.IsNullOrWhiteSpace(fbd.SelectedPath)) + { + textBoxToChange.Text = fbd.SelectedPath; + } + } + } } } \ No newline at end of file diff --git a/WeeXnes/Views/Settings/FluentMessageBox.xaml b/WeeXnes/Views/Settings/FluentMessageBox.xaml new file mode 100644 index 0000000..ace1d35 --- /dev/null +++ b/WeeXnes/Views/Settings/FluentMessageBox.xaml @@ -0,0 +1,33 @@ + + + + + + + + + + + diff --git a/WeeXnes/Views/Settings/FluentMessageBox.xaml.cs b/WeeXnes/Views/Settings/FluentMessageBox.xaml.cs new file mode 100644 index 0000000..854b185 --- /dev/null +++ b/WeeXnes/Views/Settings/FluentMessageBox.xaml.cs @@ -0,0 +1,14 @@ +using System.Windows; +using Wpf.Ui.Controls; + +namespace WeeXnes.Views.Settings +{ + public partial class FluentMessageBox : UiWindow + { + public FluentMessageBox(string messageContent) + { + InitializeComponent(); + ErrorDump.Content = "Exception: " + messageContent; + } + } +} \ No newline at end of file diff --git a/WeeXnes/WeeXnes.csproj b/WeeXnes/WeeXnes.csproj index fe1e28b..a3d0c9b 100644 --- a/WeeXnes/WeeXnes.csproj +++ b/WeeXnes/WeeXnes.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - 4.3.3 + 4.3.4 {4B33CEE7-C74D-43B9-B99A-8B273D5195BC} WinExe WeeXnes @@ -98,6 +98,9 @@ ChangePathsView.xaml + + FluentMessageBox.xaml + SettingsView.xaml @@ -127,6 +130,7 @@ +