From 3993e6d612b614384efce816c5cce4f16bc0adea Mon Sep 17 00:00:00 2001 From: Stone_Red <56473591+Stone-Red-Code@users.noreply.github.com> Date: Fri, 15 Nov 2024 19:41:16 +0100 Subject: [PATCH] Fix multiple warnings --- src/DesktopMagic/App.xaml.cs | 14 +++--- src/DesktopMagic/Dialogs/ColorDialog.xaml.cs | 2 +- src/DesktopMagic/GlobalSuppressions.cs | 2 + src/DesktopMagic/Helpers/SampleAggregator.cs | 2 +- src/DesktopMagic/MainWindow.xaml.cs | 46 +++++++++---------- .../Drawing/FontComparer.cs | 7 ++- src/DesktopMagicPluginAPI/Settings/Slider.cs | 2 + 7 files changed, 41 insertions(+), 34 deletions(-) diff --git a/src/DesktopMagic/App.xaml.cs b/src/DesktopMagic/App.xaml.cs index a4949bf..e4beedc 100644 --- a/src/DesktopMagic/App.xaml.cs +++ b/src/DesktopMagic/App.xaml.cs @@ -102,7 +102,13 @@ public partial class App : Application eventThread?.Interrupt(); } - private void Setup(bool clearLogFile) + private static void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) + { + Exception exception = (Exception)e.ExceptionObject; + Logger.LogFatal(exception + (e.IsTerminating ? "\t Process terminating!" : ""), source: exception.Source ?? "Unknown"); + } + + private static void Setup(bool clearLogFile) { AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; @@ -127,10 +133,4 @@ public partial class App : Application Logger.LogInfo("Setup complete", source: "Setup"); } - - private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e) - { - Exception exception = (Exception)e.ExceptionObject; - Logger.LogFatal(exception + (e.IsTerminating ? "\t Process terminating!" : ""), source: exception.Source ?? "Unknown"); - } } \ No newline at end of file diff --git a/src/DesktopMagic/Dialogs/ColorDialog.xaml.cs b/src/DesktopMagic/Dialogs/ColorDialog.xaml.cs index 1f07499..0d92c20 100644 --- a/src/DesktopMagic/Dialogs/ColorDialog.xaml.cs +++ b/src/DesktopMagic/Dialogs/ColorDialog.xaml.cs @@ -97,7 +97,7 @@ public partial class ColorDialog : Window private void SetColorText() { - if (alphaSlider.Value == 255) + if ((int)alphaSlider.Value == 255) { colorHexTextBox.Text = "#"; } diff --git a/src/DesktopMagic/GlobalSuppressions.cs b/src/DesktopMagic/GlobalSuppressions.cs index 8b907aa..18fd782 100644 --- a/src/DesktopMagic/GlobalSuppressions.cs +++ b/src/DesktopMagic/GlobalSuppressions.cs @@ -10,3 +10,5 @@ using System.Diagnostics.CodeAnalysis; [assembly: SuppressMessage("Minor Code Smell", "S1075:URIs should not be hardcoded", Justification = "")] [assembly: SuppressMessage("Critical Code Smell", "S2696:Instance members should not write to \"static\" fields", Justification = "", Scope = "member", Target = "~P:DesktopMagic.DataContexts.MainWindowDataContext.Settings")] [assembly: SuppressMessage("Major Code Smell", "S3885:\"Assembly.Load\" should be used", Justification = "Assembly.Load does not load dependencies", Scope = "member", Target = "~M:DesktopMagic.PluginWindow.ExecuteSource")] +[assembly: SuppressMessage("Minor Code Smell", "S2325:Methods and properties that don't access instance data should be static", Justification = "", Scope = "member", Target = "~M:DesktopMagic.MainWindow.OpenPluginsFolderButton_Click(System.Object,System.Windows.RoutedEventArgs)")] +[assembly: SuppressMessage("Minor Code Smell", "S2325:Methods and properties that don't access instance data should be static", Justification = "", Scope = "member", Target = "~M:DesktopMagic.MainWindow.ScrollViewer_PreviewMouseWheel(System.Object,System.Windows.Input.MouseWheelEventArgs)")] diff --git a/src/DesktopMagic/Helpers/SampleAggregator.cs b/src/DesktopMagic/Helpers/SampleAggregator.cs index 38d68e9..62dee9c 100644 --- a/src/DesktopMagic/Helpers/SampleAggregator.cs +++ b/src/DesktopMagic/Helpers/SampleAggregator.cs @@ -47,7 +47,7 @@ internal class SampleAggregator } } - private bool IsPowerOfTwo(int x) + private static bool IsPowerOfTwo(int x) { return (x & (x - 1)) == 0; } diff --git a/src/DesktopMagic/MainWindow.xaml.cs b/src/DesktopMagic/MainWindow.xaml.cs index 227ccb9..cac7a68 100644 --- a/src/DesktopMagic/MainWindow.xaml.cs +++ b/src/DesktopMagic/MainWindow.xaml.cs @@ -160,6 +160,17 @@ namespace DesktopMagic #region Windows + private static void DisplayWindow_ContentRendered(object? sender, EventArgs e) + { + if (sender is not Window window) + { + return; + } + + WindowPos.SendWpfWindowBack(window); + WindowPos.SendWpfWindowBack(window); + } + private void EditCheckBox_Click(object? sender, RoutedEventArgs? e) { EditMode = EditCheckBox.IsChecked == true; @@ -256,17 +267,6 @@ namespace DesktopMagic WindowNames.Add(window.Title); } - private void DisplayWindow_ContentRendered(object? sender, EventArgs e) - { - if (sender is not Window window) - { - return; - } - - WindowPos.SendWpfWindowBack(window); - WindowPos.SendWpfWindowBack(window); - } - private void DisplayWindow_Closing(object? sender, System.ComponentModel.CancelEventArgs e) { e.Cancel = blockWindowsClosing; @@ -372,6 +372,18 @@ namespace DesktopMagic } } + private void OpenPluginsFolderButton_Click(object sender, RoutedEventArgs e) + { + _ = Process.Start("explorer.exe", App.ApplicationDataPath + "\\Plugins"); + } + + private void ScrollViewer_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) + { + ScrollViewer scv = (ScrollViewer)sender; + scv.ScrollToVerticalOffset(scv.VerticalOffset - e.Delta); + e.Handled = true; + } + private void TextBlock_Loaded(object sender, RoutedEventArgs e) { int index = 0; @@ -619,18 +631,6 @@ namespace DesktopMagic LoadLayout(false); } - private void OpenPluginsFolderButton_Click(object sender, RoutedEventArgs e) - { - _ = Process.Start("explorer.exe", App.ApplicationDataPath + "\\Plugins"); - } - - private void ScrollViewer_PreviewMouseWheel(object sender, System.Windows.Input.MouseWheelEventArgs e) - { - ScrollViewer scv = (ScrollViewer)sender; - scv.ScrollToVerticalOffset(scv.VerticalOffset - e.Delta); - e.Handled = true; - } - private void TaskbarIcon_TrayLeftClick(object? sender, EventArgs e) { RestoreWindow(); diff --git a/src/DesktopMagicPluginAPI/Drawing/FontComparer.cs b/src/DesktopMagicPluginAPI/Drawing/FontComparer.cs index 45a5171..295b8ff 100644 --- a/src/DesktopMagicPluginAPI/Drawing/FontComparer.cs +++ b/src/DesktopMagicPluginAPI/Drawing/FontComparer.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Drawing; @@ -6,6 +7,8 @@ namespace DesktopMagic.Api.Drawing; internal class FontComparer : IEqualityComparer { + private const float Tolerance = 0.01f; + public bool Equals(Font? font1, Font? font2) { if (font1 is null || font2 is null) @@ -18,7 +21,7 @@ internal class FontComparer : IEqualityComparer return false; } - if (font1.SizeInPoints != font2.SizeInPoints) + if (Math.Abs(font1.SizeInPoints - font2.SizeInPoints) > Tolerance) { return false; } diff --git a/src/DesktopMagicPluginAPI/Settings/Slider.cs b/src/DesktopMagicPluginAPI/Settings/Slider.cs index 813bd44..003a58a 100644 --- a/src/DesktopMagicPluginAPI/Settings/Slider.cs +++ b/src/DesktopMagicPluginAPI/Settings/Slider.cs @@ -1,4 +1,5 @@ using System; +using System.Diagnostics.CodeAnalysis; namespace DesktopMagic.Api.Settings; @@ -22,6 +23,7 @@ public sealed class Slider : Setting /// /// Gets or sets the value assigned to the element. /// + [SuppressMessage("Major Bug", "S1244:Floating point numbers should not be tested for equality", Justification = "Not applicable here since we want to detect changes in the value.")] public double Value { get => _value;