From aa1733e0c65e34874bfce90e578931351ed35a5f Mon Sep 17 00:00:00 2001
From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com>
Date: Wed, 1 May 2024 17:41:27 +0200
Subject: [PATCH] Update libraries
---
src/DesktopMagic/App.xaml | 4 +-
src/DesktopMagic/App.xaml.cs | 98 +++++++++----------
.../MusicVisualizerPlugin.cs | 2 +-
src/DesktopMagic/DesktopMagic.csproj | 6 +-
.../Helpers/SettingElementGenerator.cs | 2 +-
src/DesktopMagic/MainWindow.xaml.cs | 22 ++---
src/DesktopMagic/Plugins/PluginWindow.xaml.cs | 20 ++--
7 files changed, 77 insertions(+), 77 deletions(-)
diff --git a/src/DesktopMagic/App.xaml b/src/DesktopMagic/App.xaml
index fd07349..e943dca 100644
--- a/src/DesktopMagic/App.xaml
+++ b/src/DesktopMagic/App.xaml
@@ -8,8 +8,10 @@
-
+
+
+
diff --git a/src/DesktopMagic/App.xaml.cs b/src/DesktopMagic/App.xaml.cs
index 25ce5ed..a4949bf 100644
--- a/src/DesktopMagic/App.xaml.cs
+++ b/src/DesktopMagic/App.xaml.cs
@@ -1,6 +1,4 @@
-global using Stone_Red_Utilities.Logging;
-
-using Stone_Red_C_Sharp_Utilities.Logging;
+using CuteUtils.Logging;
using System;
using System.IO;
@@ -17,20 +15,57 @@ public partial class App : Application
public const string AppGuid = "{{61FE5CE9-47C3-4255-A1F4-5BCF4ACA0879}";
public const string AppName = "Desktop Magic";
- private readonly string logFilePath;
+
+ private static readonly string logFilePath = Path.Combine(ApplicationDataPath, $"{AppName}.log");
private readonly Thread? eventThread;
+
private readonly EventWaitHandle eventWaitHandle;
- private readonly Logger logger = new Logger();
- public static string ApplicationDataPath { get; } = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "StoneRed", AppName);
+ public static Logger Logger { get; } = new Logger()
+ {
+ Config = new()
+ {
+ FatalConfig = new OutputConfig()
+ {
+ ConsoleColor = ConsoleColor.DarkRed,
+ LogTarget = LogTarget.DebugConsole | LogTarget.File,
+ FilePath = logFilePath
+ },
+ ErrorConfig = new OutputConfig()
+ {
+ ConsoleColor = ConsoleColor.Red,
+ LogTarget = LogTarget.DebugConsole | LogTarget.File,
+ FilePath = logFilePath
+ },
+ WarnConfig = new OutputConfig()
+ {
+ ConsoleColor = ConsoleColor.Yellow,
+ LogTarget = LogTarget.DebugConsole | LogTarget.File,
+ FilePath = logFilePath
+ },
+ InfoConfig = new OutputConfig()
+ {
+ ConsoleColor = ConsoleColor.White,
+ LogTarget = LogTarget.DebugConsole | LogTarget.File,
+ FilePath = logFilePath
+ },
+ DebugConfig = new OutputConfig()
+ {
+ ConsoleColor = ConsoleColor.Gray,
+ LogTarget = LogTarget.DebugConsole,
+ },
+ FormatConfig = new FormatConfig()
+ {
+ DebugConsoleFormat = $"> {{{LogFormatType.DateTime}:HH:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\nat {{{LogFormatType.LineNumber}}} | {{{LogFormatType.FilePath}}}"
+ }
+ }
+ };
- public static Logger Logger => ((App)Current).logger;
+ public static string ApplicationDataPath => Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "StoneRed", AppName);
public App()
{
- logFilePath = ApplicationDataPath + "\\log.log";
-
// Setup global event handler
eventWaitHandle = new EventWaitHandle(false, EventResetMode.AutoReset, AppGuid, out bool createdNew);
@@ -38,7 +73,7 @@ public partial class App : Application
if (!createdNew)
{
Setup(false);
- Logger.Log("Shutting down because other instance already running.", "Setup", LogSeverity.Warn);
+ Logger.LogWarn("Shutting down because other instance already running.", source: "Setup");
//Shutdown Application
_ = eventWaitHandle.Set();
Current.Shutdown();
@@ -71,50 +106,13 @@ public partial class App : Application
{
AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException;
- Logger.Config = new LogConfig()
- {
- FatalConfig = new OutputConfig()
- {
- Color = ConsoleColor.DarkRed,
- LogTarget = LogTarget.DebugConsole | LogTarget.File,
- FilePath = logFilePath
- },
- ErrorConfig = new OutputConfig()
- {
- Color = ConsoleColor.Red,
- LogTarget = LogTarget.DebugConsole | LogTarget.File,
- FilePath = logFilePath
- },
- WarnConfig = new OutputConfig()
- {
- Color = ConsoleColor.Yellow,
- LogTarget = LogTarget.DebugConsole | LogTarget.File,
- FilePath = logFilePath
- },
- InfoConfig = new OutputConfig()
- {
- Color = ConsoleColor.White,
- LogTarget = LogTarget.DebugConsole | LogTarget.File,
- FilePath = logFilePath
- },
- DebugConfig = new OutputConfig()
- {
- Color = ConsoleColor.Gray,
- LogTarget = LogTarget.DebugConsole,
- },
- FormatConfig = new FormatConfig()
- {
- DebugConsoleFormat = $"> {{{LogFormatType.DateTime}:HH:mm:ss}} | {{{LogFormatType.LogSeverity},-5}} | {{{LogFormatType.Message}}}\nat {{{LogFormatType.LineNumber}}} | {{{LogFormatType.FilePath}}}"
- }
- };
-
try
{
if (!Directory.Exists(ApplicationDataPath))
{
_ = Directory.CreateDirectory(ApplicationDataPath);
}
- Logger.Log("Created ApplicationData Folder", "Main");
+ Logger.LogInfo("Created ApplicationData Folder", source: "Main");
}
catch (Exception ex)
{
@@ -127,12 +125,12 @@ public partial class App : Application
Logger.ClearLogFile(LogSeverity.Info);
}
- Logger.Log("Log setup complete", "Setup");
+ Logger.LogInfo("Setup complete", source: "Setup");
}
private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
{
Exception exception = (Exception)e.ExceptionObject;
- Logger.Log(exception + (e.IsTerminating ? "\t Process terminating!" : ""), exception.Source, LogSeverity.Fatal);
+ Logger.LogFatal(exception + (e.IsTerminating ? "\t Process terminating!" : ""), source: exception.Source ?? "Unknown");
}
}
\ No newline at end of file
diff --git a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs
index 12eb17c..50eb70a 100644
--- a/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs
+++ b/src/DesktopMagic/BuiltInWindowElements/MusicVisualizerPlugin.cs
@@ -272,7 +272,7 @@ internal class MusicVisualizerPlugin : Plugin
}
catch (Exception ex)
{
- App.Logger.Log(ex.Message, "Music Visualizer", LogSeverity.Error);
+ App.Logger.LogError(ex.Message, source: "Music Visualizer");
}
}
diff --git a/src/DesktopMagic/DesktopMagic.csproj b/src/DesktopMagic/DesktopMagic.csproj
index 70bf0fa..494b51e 100644
--- a/src/DesktopMagic/DesktopMagic.csproj
+++ b/src/DesktopMagic/DesktopMagic.csproj
@@ -36,11 +36,11 @@
-
-
+
+
+
-
diff --git a/src/DesktopMagic/Helpers/SettingElementGenerator.cs b/src/DesktopMagic/Helpers/SettingElementGenerator.cs
index 0e85262..4c6e3ef 100644
--- a/src/DesktopMagic/Helpers/SettingElementGenerator.cs
+++ b/src/DesktopMagic/Helpers/SettingElementGenerator.cs
@@ -222,7 +222,7 @@ internal class SettingElementGenerator(ComboBox optionsComboBox)
private void DisplayException(string message)
{
- App.Logger.Log(message, "PluginInput");
+ App.Logger.LogInfo(message, source: "PluginInput");
_ = MessageBox.Show("File execution error:\n" + message, "Error", MessageBoxButton.OK, MessageBoxImage.Error);
int index = MainWindow.WindowNames.IndexOf(optionsComboBox.SelectedItem.ToString() ?? string.Empty);
diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs
index 4dcf35d..2f743e1 100644
--- a/src/DesktopMagic/MainWindow.xaml.cs
+++ b/src/DesktopMagic/MainWindow.xaml.cs
@@ -86,23 +86,23 @@ namespace DesktopMagic
{
_ = Directory.CreateDirectory(App.ApplicationDataPath + "\\Plugins");
}
- App.Logger.Log("Created Plugins Folder", "Main");
+ App.Logger.LogInfo("Created Plugins Folder", source: "Main");
//Write To Log File and Load Elements
- App.Logger.Log("Loading Plugin names", "Main");
+ App.Logger.LogInfo("Loading Plugin names", source: "Main");
LoadPlugins();
- App.Logger.Log("Loading Layout names", "Main");
+ App.Logger.LogInfo("Loading Layout names", source: "Main");
LoadSettings();
- App.Logger.Log("Loading Layout", "Main");
+ App.Logger.LogInfo("Loading Layout", source: "Main");
LoadLayout();
loaded = true;
- App.Logger.Log("Window Loaded", "Main");
+ App.Logger.LogInfo("Window Loaded", source: "Main");
}
catch (Exception ex)
{
- App.Logger.Log(ex.Message, "Main", LogSeverity.Error);
+ App.Logger.LogError(ex.Message, source: "Main");
_ = MessageBox.Show(ex.ToString());
}
}
@@ -126,13 +126,13 @@ namespace DesktopMagic
if (pluginDllPath is null)
{
- App.Logger.Log($"Plugin \"{directory}\" has no \"main.dll\"", "Main", LogSeverity.Error);
+ App.Logger.LogError($"Plugin \"{directory}\" has no \"main.dll\"", source: "Main");
continue;
}
if (pluginMetadataPath is null)
{
- App.Logger.Log($"Plugin \"{directory}\" has no \"metadata.json\"", "Main", LogSeverity.Warn);
+ App.Logger.LogWarn($"Plugin \"{directory}\" has no \"metadata.json\"", source: "Main");
continue;
}
@@ -140,13 +140,13 @@ namespace DesktopMagic
if (pluginMetadata is null)
{
- App.Logger.Log($"Plugin \"{directory}\" has no valid \"metadata.json\"", "Main", LogSeverity.Error);
+ App.Logger.LogError($"Plugin \"{directory}\" has no valid \"metadata.json\"", source: "Main");
continue;
}
if (plugins.ContainsKey(pluginMetadata.Id))
{
- App.Logger.Log($"Plugin \"{directory}\" has the same id as another plugin", "Main", LogSeverity.Error);
+ App.Logger.LogError($"Plugin \"{directory}\" has the same id as another plugin", source: "Main");
continue;
}
@@ -204,7 +204,7 @@ namespace DesktopMagic
}
catch (Exception ex)
{
- App.Logger.Log(ex.Message, "Main", LogSeverity.Error);
+ App.Logger.LogError(ex.Message, source: "Main");
}
}
return;
diff --git a/src/DesktopMagic/Plugins/PluginWindow.xaml.cs b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
index dde7122..3375d1b 100644
--- a/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
+++ b/src/DesktopMagic/Plugins/PluginWindow.xaml.cs
@@ -121,7 +121,7 @@ public partial class PluginWindow : Window
private void Window_ContentRendered(object? sender, EventArgs e)
{
- App.Logger.Log($"\"{PluginMetadata.Name}\" - Starting plugin thread", "Plugin");
+ App.Logger.LogInfo($"\"{PluginMetadata.Name}\" - Starting plugin thread", source: "Plugin");
pluginThread = new Thread(LoadPlugin);
pluginThread.Start();
}
@@ -172,11 +172,11 @@ public partial class PluginWindow : Window
private void LoadPlugin()
{
- App.Logger.Log($"\"{PluginMetadata.Name}\" - Loading plugin", "Plugin");
+ App.Logger.LogInfo($"\"{PluginMetadata.Name}\" - Loading plugin", source: "Plugin");
if (pluginClassInstance is null && !File.Exists($"{PluginFolderPath}\\main.dll"))
{
- App.Logger.Log($"\"{PluginMetadata.Name}\" - File \"main.dll\" does not exist", "Plugin", LogSeverity.Error);
+ App.Logger.LogError($"\"{PluginMetadata.Name}\" - File \"main.dll\" does not exist", source: "Plugin");
_ = MessageBox.Show("File \"main.dll\" does not exist!", $"Error \"{PluginMetadata.Name}\"", MessageBoxButton.OK, MessageBoxImage.Error);
Exit();
@@ -189,7 +189,7 @@ public partial class PluginWindow : Window
}
catch (Exception ex)
{
- App.Logger.Log($"\"{PluginMetadata.Name}\" - {ex}", "Plugin", LogSeverity.Error);
+ App.Logger.LogError($"\"{PluginMetadata.Name}\" - {ex}", source: "Plugin");
_ = MessageBox.Show("File execution error:\n" + ex, $"Error \"{PluginMetadata.Name}\"", MessageBoxButton.OK, MessageBoxImage.Error);
Exit();
return;
@@ -207,7 +207,7 @@ public partial class PluginWindow : Window
if (instanceType is null)
{
- App.Logger.Log($"\"{PluginMetadata.Name}\" - The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", "Plugin", LogSeverity.Error);
+ App.Logger.LogError($"\"{PluginMetadata.Name}\" - The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", source: "Plugin");
_ = MessageBox.Show($"The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", $"Error \"{PluginMetadata.Name}\"", MessageBoxButton.OK, MessageBoxImage.Error);
Exit();
@@ -223,7 +223,7 @@ public partial class PluginWindow : Window
}
else
{
- App.Logger.Log($"\"{PluginMetadata.Name}\" - The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", "Plugin", LogSeverity.Error);
+ App.Logger.LogError($"\"{PluginMetadata.Name}\" - The \"Plugin\" class could not be found! It has to inherit from \"{typeof(Plugin).FullName}\"", source: "Plugin");
_ = MessageBox.Show($"The \"Plugin\" class has to inherit from \"{typeof(Plugin).FullName}\"", $"Error \"{PluginMetadata.Name}\"", MessageBoxButton.OK, MessageBoxImage.Error);
Exit();
return;
@@ -284,7 +284,7 @@ public partial class PluginWindow : Window
private void LoadOptions(object instance)
{
- App.Logger.Log($"\"{PluginMetadata.Name}\" - Loading plugin options", "Plugin");
+ App.Logger.LogInfo($"\"{PluginMetadata.Name}\" - Loading plugin options", source: "Plugin");
try
{
@@ -322,7 +322,7 @@ public partial class PluginWindow : Window
catch (Exception ex)
{
IsRunning = false;
- App.Logger.Log($"\"{PluginMetadata.Name}\" - {ex}", "Plugin", LogSeverity.Error);
+ App.Logger.LogError($"\"{PluginMetadata.Name}\" - {ex}", source: "Plugin");
_ = MessageBox.Show("File execution error:\n" + ex, $"Error \"{PluginMetadata.Name}\"", MessageBoxButton.OK, MessageBoxImage.Error);
Exit();
}
@@ -367,7 +367,7 @@ public partial class PluginWindow : Window
catch (Exception ex)
{
IsRunning = false;
- App.Logger.Log($"\"{PluginMetadata.Name}\" - {ex}", "Plugin", LogSeverity.Error);
+ App.Logger.LogError($"\"{PluginMetadata.Name}\" - {ex}", source: "Plugin");
_ = MessageBox.Show("File execution error:\n" + ex, $"Error \"{PluginMetadata.Name}\"", MessageBoxButton.OK, MessageBoxImage.Error);
Exit();
return;
@@ -381,7 +381,7 @@ public partial class PluginWindow : Window
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
- App.Logger.Log($"\"{PluginMetadata.Name}\" - Stopping plugin", "Plugin");
+ App.Logger.LogInfo($"\"{PluginMetadata.Name}\" - Stopping plugin", source: "Plugin");
IsRunning = false;
pluginClassInstance?.Stop();
}