From d5f6e160dadfaa99f0bc3c3d1ac55a041a236399 Mon Sep 17 00:00:00 2001 From: WeeXnes Date: Fri, 24 Nov 2023 10:38:05 +0100 Subject: [PATCH] fully implemented user debug flag for trouble shooting --- WeeXnes/App.xaml.cs | 17 ++++++-------- WeeXnes/Core/{CustomConsole.cs => Console.cs} | 22 +++++++------------ WeeXnes/Core/Global.cs | 2 +- WeeXnes/Core/HandleLaunchArguments.cs | 7 +++++- WeeXnes/Core/LoginLib.cs | 10 ++++----- WeeXnes/Core/WXFile.cs | 4 ++-- WeeXnes/Views/DiscordRPC/AddRPCView.xaml.cs | 2 +- .../Views/DiscordRPC/DiscordRPCView.xaml.cs | 7 +++--- WeeXnes/Views/DiscordRPC/RunRPCView.xaml.cs | 8 +++---- WeeXnes/Views/KeyManager/KeyItem.cs | 1 - .../Views/KeyManager/KeyManagerView.xaml.cs | 2 +- .../PasswordGenerator/PasswordGenView.xaml.cs | 2 +- WeeXnes/Views/ProfileView/InboxView.xaml.cs | 1 + WeeXnes/Views/ProfileView/ProfileView.xaml.cs | 6 ++--- WeeXnes/Views/Settings/SettingsView.xaml.cs | 2 +- .../Views/Settings/UpdateFoundView.xaml.cs | 2 +- WeeXnes/WeeXnes.csproj | 5 +++-- 17 files changed, 48 insertions(+), 52 deletions(-) rename WeeXnes/Core/{CustomConsole.cs => Console.cs} (90%) diff --git a/WeeXnes/App.xaml.cs b/WeeXnes/App.xaml.cs index d92b58f..adaa07d 100644 --- a/WeeXnes/App.xaml.cs +++ b/WeeXnes/App.xaml.cs @@ -41,6 +41,7 @@ namespace WeeXnes private void App_OnStartup(object sender, StartupEventArgs e) { Environment.CurrentDirectory = Application.StartupPath; + Console.Data.Colors.colored_output = false; SetExceptionHandler(); CheckForDebugMode(); CheckUpdatedFiles(); @@ -66,7 +67,7 @@ namespace WeeXnes } catch (Exception ex) { - WeeXnes.Core.CustomConsole.Error(ex.ToString()); + Console.Error(ex.ToString()); } } } @@ -128,11 +129,11 @@ namespace WeeXnes { Game newGame = Game.Methods.GameFromIni(new INIFile(file.FullName)); DiscordRPCView.Data.Games.Add(newGame); - WeeXnes.Core.CustomConsole.WriteLine(file.Name + " loaded -> " + newGame.ProcessName); + Console.WriteLine(file.Name + " loaded -> " + newGame.ProcessName); } catch (Exception ex) { - WeeXnes.Core.CustomConsole.Error(file.Name + ": " + ex.Message); + Console.Error(file.Name + ": " + ex.Message); new FluentMessageBox(file.Name + ": " + ex.Message).ShowDialog(); } } @@ -154,12 +155,12 @@ namespace WeeXnes ); newItem.Filename = file.Name; KeyManagerView.Data.KeyItemsList.Add(newItem); - WeeXnes.Core.CustomConsole.WriteLine(file.Name + " loaded -> " + newItem.Name); + Console.WriteLine(file.Name + " loaded -> " + newItem.Name); } catch (Exception ex) { - WeeXnes.Core.CustomConsole.Error(file.Name + ": " + ex.Message); + Console.Error(file.Name + ": " + ex.Message); new FluentMessageBox(file.Name + ": " + ex.Message).ShowDialog(); } } @@ -187,11 +188,7 @@ namespace WeeXnes private void CheckForDebugMode() { #if DEBUG - DebugMode = true; - HandleLaunchArguments.arg_enableConsole(); - //Allow untrusted certs in Debug mode - ServicePointManager.ServerCertificateValidationCallback += - (sender, cert, chain, sslPolicyErrors) => true; + HandleLaunchArguments.arg_debugMode(); #endif } } diff --git a/WeeXnes/Core/CustomConsole.cs b/WeeXnes/Core/Console.cs similarity index 90% rename from WeeXnes/Core/CustomConsole.cs rename to WeeXnes/Core/Console.cs index e046aa4..8d2144c 100644 --- a/WeeXnes/Core/CustomConsole.cs +++ b/WeeXnes/Core/Console.cs @@ -1,13 +1,17 @@ -using System; +global using Console = WeeXnes.Core.Console; +global using VanillaConsole = System.Console; +using System; using System.Collections.Generic; -using System.IO; using System.Runtime.CompilerServices; using System.Text; -using VanillaConsole = System.Console; + + namespace WeeXnes.Core { - public class CustomConsole + + + public static class Console { public static class Data { @@ -28,7 +32,6 @@ namespace WeeXnes.Core public static string writeline_char = "•"; } } - private static void ConfiguredWriteline( string text, ConsoleColor color, @@ -36,9 +39,7 @@ namespace WeeXnes.Core { if(!App.DebugMode) return; - //VanillaConsole.OutputEncoding = Encoding.UTF8; - ConsoleColor prevColor = VanillaConsole.BackgroundColor; ConsoleColor prevForeColor = VanillaConsole.ForegroundColor; if (Data.Colors.colored_output) @@ -62,13 +63,6 @@ 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/Global.cs b/WeeXnes/Core/Global.cs index ff7ce6f..88d5973 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.5.0"; + public const string Version = "4.5.1"; public const string EncryptionHash = "8zf5#RdyQ]$4x4_"; public const string ApiUrl = "https://api.github.com/repos/weexnes/weexnessuite/releases/latest"; } diff --git a/WeeXnes/Core/HandleLaunchArguments.cs b/WeeXnes/Core/HandleLaunchArguments.cs index ee7ef4e..e5f05ab 100644 --- a/WeeXnes/Core/HandleLaunchArguments.cs +++ b/WeeXnes/Core/HandleLaunchArguments.cs @@ -1,4 +1,5 @@ using System; +using System.Net; using System.Runtime.InteropServices; using System.Windows; @@ -19,7 +20,11 @@ namespace WeeXnes.Core } public static void arg_debugMode() { - MessageBox.Show("user debug mode enabled"); + App.DebugMode = true; + HandleLaunchArguments.arg_enableConsole(); + //Allow untrusted certs in Debug mode + ServicePointManager.ServerCertificateValidationCallback += + (sender, cert, chain, sslPolicyErrors) => true; } public static void arg_enableConsole() { diff --git a/WeeXnes/Core/LoginLib.cs b/WeeXnes/Core/LoginLib.cs index d355eff..7ad7d19 100644 --- a/WeeXnes/Core/LoginLib.cs +++ b/WeeXnes/Core/LoginLib.cs @@ -37,13 +37,13 @@ namespace WeeXnes.Core } catch (Exception ex) { - WeeXnes.Core.CustomConsole.WriteLine(ex.ToString()); + Console.Error(ex.ToString()); this.ExceptionCache.Value = ex; } }; this._loginWorker.RunWorkerCompleted += (sender, args) => { - WeeXnes.Core.CustomConsole.WriteLine("LoginWorker complete"); + Console.WriteLine("LoginWorker complete"); }; this._loginUrl = loginUrl; this._userDataUrl = userDataUrl; @@ -79,7 +79,7 @@ namespace WeeXnes.Core } else { - WeeXnes.Core.CustomConsole.WriteLine("Error: " + response.StatusCode); + Console.Error("Error: " + response.StatusCode); LoginView.errorStringCache.Value = response.StatusCode.ToString(); return null; } @@ -117,7 +117,7 @@ namespace WeeXnes.Core user = user.user; // Now you can access the user object properties dynamically - WeeXnes.Core.CustomConsole.WriteLine("authenticated user: " + user.name); + Console.WriteLine("authenticated user: " + user.name); //Console.WriteLine($"Email: {user.email}"); // Access other properties as needed _currentUserCache.Value = user; @@ -129,7 +129,7 @@ namespace WeeXnes.Core // Handle the error, e.g., print the status code _currentUserCache.Value = null; - WeeXnes.Core.CustomConsole.WriteLine("Error: " + response.StatusCode); + Console.Error("Error: " + response.StatusCode); LoginView.errorStringCache.Value = response.StatusCode.ToString(); return null; diff --git a/WeeXnes/Core/WXFile.cs b/WeeXnes/Core/WXFile.cs index cfa16cf..dc84daf 100644 --- a/WeeXnes/Core/WXFile.cs +++ b/WeeXnes/Core/WXFile.cs @@ -29,7 +29,7 @@ namespace WeeXnes.Core } catch (Exception e) { - Console.WriteLine(e); + Console.WriteLine(e.ToString()); returnval = null; } } @@ -48,7 +48,7 @@ namespace WeeXnes.Core returnval = rawcontent[2]; }catch (Exception e) { - Console.WriteLine(e); + Console.WriteLine(e.ToString()); returnval = null; } } diff --git a/WeeXnes/Views/DiscordRPC/AddRPCView.xaml.cs b/WeeXnes/Views/DiscordRPC/AddRPCView.xaml.cs index 29738ae..dafdb4e 100644 --- a/WeeXnes/Views/DiscordRPC/AddRPCView.xaml.cs +++ b/WeeXnes/Views/DiscordRPC/AddRPCView.xaml.cs @@ -42,7 +42,7 @@ namespace WeeXnes.Views.DiscordRPC } catch (Exception ex) { - Console.WriteLine(ex); + Console.WriteLine(ex.ToString()); } CloseDialog(); diff --git a/WeeXnes/Views/DiscordRPC/DiscordRPCView.xaml.cs b/WeeXnes/Views/DiscordRPC/DiscordRPCView.xaml.cs index d3c4454..5dd5217 100644 --- a/WeeXnes/Views/DiscordRPC/DiscordRPCView.xaml.cs +++ b/WeeXnes/Views/DiscordRPC/DiscordRPCView.xaml.cs @@ -7,7 +7,6 @@ using System.Windows.Controls; using Microsoft.Win32; using Nocksoft.IO.ConfigFiles; using WeeXnes.Core; -using CConsole = WeeXnes.Core.CustomConsole; namespace WeeXnes.Views.DiscordRPC { @@ -67,7 +66,7 @@ namespace WeeXnes.Views.DiscordRPC if (dialog.ShowDialog() == true) { File.Copy(filepath, dialog.FileName, true); - CustomConsole.WriteLine("Exported to: " + dialog.FileName); + Console.WriteLine("Exported to: " + dialog.FileName); } } @@ -92,11 +91,11 @@ namespace WeeXnes.Views.DiscordRPC { File.Copy(dialog.FileName, Global.AppDataPathRPC.Value + "\\" + newGame.UUID + ".rpc", true); DiscordRPCView.Data.Games.Add(newGame); - CustomConsole.WriteLine("Imported: " + dialog.FileName); + Console.WriteLine("Imported: " + dialog.FileName); } else { - CustomConsole.Error("not imported: " + dialog.FileName); + Console.Error("not imported: " + dialog.FileName); } diff --git a/WeeXnes/Views/DiscordRPC/RunRPCView.xaml.cs b/WeeXnes/Views/DiscordRPC/RunRPCView.xaml.cs index 19e0209..6a61ae6 100644 --- a/WeeXnes/Views/DiscordRPC/RunRPCView.xaml.cs +++ b/WeeXnes/Views/DiscordRPC/RunRPCView.xaml.cs @@ -33,7 +33,7 @@ namespace WeeXnes.Views.DiscordRPC private void LogChanged() { - Console.WriteLine("Log Write Data: " + Data.LogCache.Value); + VanillaConsole.WriteLine("Log Write Data: " + Data.LogCache.Value); this.Dispatcher.Invoke(() => { RpcLogView.Items.Add(Data.LogCache.Value); @@ -58,7 +58,7 @@ namespace WeeXnes.Views.DiscordRPC } catch (Exception ex) { - Console.WriteLine(ex); + VanillaConsole.WriteLine(ex.ToString()); } } public void StopBackgroundWorker() @@ -71,7 +71,7 @@ namespace WeeXnes.Views.DiscordRPC } catch (Exception ex) { - Console.WriteLine(ex); + VanillaConsole.WriteLine(ex.ToString()); } //Stop RPC } @@ -98,7 +98,7 @@ namespace WeeXnes.Views.DiscordRPC { foreach (Game game in DiscordRPCView.Data.Games) game.Stop(); - Console.WriteLine("Thread Stopped"); + VanillaConsole.WriteLine("Thread Stopped"); Data.LogCache.Value = new customEvent("[INFO] RPC Thread has stopped", EventType.ProcessStoppedEvent); } diff --git a/WeeXnes/Views/KeyManager/KeyItem.cs b/WeeXnes/Views/KeyManager/KeyItem.cs index d4cfb0d..f830fd9 100644 --- a/WeeXnes/Views/KeyManager/KeyItem.cs +++ b/WeeXnes/Views/KeyManager/KeyItem.cs @@ -6,7 +6,6 @@ using System.Net; using Wpf.Ui.Controls; using Microsoft.Win32; using Path = System.Windows.Shapes.Path; -using Console = WeeXnes.Core.CustomConsole; namespace WeeXnes.Views.KeyManager { diff --git a/WeeXnes/Views/KeyManager/KeyManagerView.xaml.cs b/WeeXnes/Views/KeyManager/KeyManagerView.xaml.cs index d8b9e65..f7faa81 100644 --- a/WeeXnes/Views/KeyManager/KeyManagerView.xaml.cs +++ b/WeeXnes/Views/KeyManager/KeyManagerView.xaml.cs @@ -87,7 +87,7 @@ namespace WeeXnes.Views.KeyManager } catch (Exception ex) { - Console.WriteLine(ex); + Console.WriteLine(ex.ToString()); } } diff --git a/WeeXnes/Views/PasswordGenerator/PasswordGenView.xaml.cs b/WeeXnes/Views/PasswordGenerator/PasswordGenView.xaml.cs index 04f2e71..a994d14 100644 --- a/WeeXnes/Views/PasswordGenerator/PasswordGenView.xaml.cs +++ b/WeeXnes/Views/PasswordGenerator/PasswordGenView.xaml.cs @@ -43,7 +43,7 @@ namespace WeeXnes.Views.PasswordGenerator CustomPasswordBuilderString += PasswordBuilderStrings.special; - CustomConsole.WriteLine("Generating Password from: " + CustomPasswordBuilderString); + Console.WriteLine("Generating Password from: " + CustomPasswordBuilderString); //MessageBox.Show(CustomPasswordBuilderString); string generatedPassword = ""; diff --git a/WeeXnes/Views/ProfileView/InboxView.xaml.cs b/WeeXnes/Views/ProfileView/InboxView.xaml.cs index f036bfc..7a6e446 100644 --- a/WeeXnes/Views/ProfileView/InboxView.xaml.cs +++ b/WeeXnes/Views/ProfileView/InboxView.xaml.cs @@ -38,6 +38,7 @@ namespace WeeXnes.Views.ProfileView { CardAction button = (CardAction)sender; dynamic messageObj = button.Tag; + Console.WriteLine(messageObj.ToString()); MessageFullView.MessageToShow = messageObj; NavigationService.Navigate(new Uri("/Views/ProfileView/MessageFullView.xaml",UriKind.Relative)); } diff --git a/WeeXnes/Views/ProfileView/ProfileView.xaml.cs b/WeeXnes/Views/ProfileView/ProfileView.xaml.cs index 40c0131..f157ed5 100644 --- a/WeeXnes/Views/ProfileView/ProfileView.xaml.cs +++ b/WeeXnes/Views/ProfileView/ProfileView.xaml.cs @@ -22,9 +22,9 @@ namespace WeeXnes.Views.ProfileView auth.ExceptionCache.ValueChanged += LoginWorkerException; auth._currentUserCache.ValueChanged += userCacheChanged; LoginView.errorStringCache.ValueChanged += errorStringChanged; - WeeXnes.Core.CustomConsole.WriteLine("Error Hooks loaded"); + Console.WriteLine("Error Hooks loaded"); - WeeXnes.Core.CustomConsole.WriteLine("Event hooks loaded"); + Console.WriteLine("Event hooks loaded"); if (auth._currentUserCache.Value == null) { LoadingScreen.Visibility = Visibility.Visible; @@ -83,7 +83,7 @@ namespace WeeXnes.Views.ProfileView auth._currentUserCache.ValueChanged -= userCacheChanged; LoginView.errorStringCache.ValueChanged -= errorStringChanged; - WeeXnes.Core.CustomConsole.WriteLine("Event hooks unloaded"); + Console.WriteLine("Event hooks unloaded"); } private void errorStringChanged() { diff --git a/WeeXnes/Views/Settings/SettingsView.xaml.cs b/WeeXnes/Views/Settings/SettingsView.xaml.cs index 1a2ed7b..d2a4110 100644 --- a/WeeXnes/Views/Settings/SettingsView.xaml.cs +++ b/WeeXnes/Views/Settings/SettingsView.xaml.cs @@ -73,7 +73,7 @@ namespace WeeXnes.Views.Settings } catch (Exception ex) { - Console.WriteLine(ex); + Console.WriteLine(ex.ToString()); } } diff --git a/WeeXnes/Views/Settings/UpdateFoundView.xaml.cs b/WeeXnes/Views/Settings/UpdateFoundView.xaml.cs index 48e571e..879abe9 100644 --- a/WeeXnes/Views/Settings/UpdateFoundView.xaml.cs +++ b/WeeXnes/Views/Settings/UpdateFoundView.xaml.cs @@ -48,7 +48,7 @@ namespace WeeXnes.Views.Settings } catch (Exception ex) { - Console.WriteLine(ex); + Console.WriteLine(ex.ToString()); } } diff --git a/WeeXnes/WeeXnes.csproj b/WeeXnes/WeeXnes.csproj index 3d1eeba..8854bad 100644 --- a/WeeXnes/WeeXnes.csproj +++ b/WeeXnes/WeeXnes.csproj @@ -4,7 +4,7 @@ Debug AnyCPU - 4.5.0 + 4.5.1 {4B33CEE7-C74D-43B9-B99A-8B273D5195BC} WinExe WeeXnes @@ -15,6 +15,7 @@ 4 true wicns.ico + 10 AnyCPU @@ -70,7 +71,7 @@ MSBuild:Compile Designer - +