From d116f54eaa5a3e97879a9428ffddfcbf85232baa Mon Sep 17 00:00:00 2001 From: Michael Clayton Date: Thu, 12 Oct 2023 22:04:39 +0100 Subject: [PATCH] #30 - delinting --- src/FancyMouse.sln | 30 +++++++++++++++++++ src/FancyMouse/Helpers/ConfigHelper.cs | 15 ++++++---- src/FancyMouse/Helpers/MouseHelper.cs | 21 ------------- src/FancyMouse/Hotkeys/HotKeyManager.cs | 2 -- src/FancyMouse/Hotkeys/MessageLoop.cs | 4 +-- .../Models/Settings/V1/AppConfig.cs | 6 ++-- .../{FancyMouseSettings.cs => FancyMouse.cs} | 7 +++-- .../Settings/V2/ScreenshotStyleSettings.cs | 12 ++++---- src/FancyMouse/Program.cs | 2 +- 9 files changed, 56 insertions(+), 43 deletions(-) rename src/FancyMouse/Models/Settings/V1/{FancyMouseSettings.cs => FancyMouse.cs} (73%) diff --git a/src/FancyMouse.sln b/src/FancyMouse.sln index 910c45d..fb3c80e 100644 --- a/src/FancyMouse.sln +++ b/src/FancyMouse.sln @@ -18,17 +18,47 @@ EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU + Debug|ARM64 = Debug|ARM64 + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 Release|Any CPU = Release|Any CPU + Release|ARM64 = Release|ARM64 + Release|x64 = Release|x64 + Release|x86 = Release|x86 EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution {EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|Any CPU.Build.0 = Debug|Any CPU + {EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|ARM64.Build.0 = Debug|Any CPU + {EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|x64.ActiveCfg = Debug|Any CPU + {EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|x64.Build.0 = Debug|Any CPU + {EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|x86.ActiveCfg = Debug|Any CPU + {EFE2A257-6979-4067-99A7-0C762492A8C7}.Debug|x86.Build.0 = Debug|Any CPU {EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|Any CPU.ActiveCfg = Release|Any CPU {EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|Any CPU.Build.0 = Release|Any CPU + {EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|ARM64.ActiveCfg = Release|Any CPU + {EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|ARM64.Build.0 = Release|Any CPU + {EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|x64.ActiveCfg = Release|Any CPU + {EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|x64.Build.0 = Release|Any CPU + {EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|x86.ActiveCfg = Release|Any CPU + {EFE2A257-6979-4067-99A7-0C762492A8C7}.Release|x86.Build.0 = Release|Any CPU {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|ARM64.ActiveCfg = Debug|Any CPU + {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|ARM64.Build.0 = Debug|Any CPU + {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|x64.ActiveCfg = Debug|Any CPU + {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|x64.Build.0 = Debug|Any CPU + {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|x86.ActiveCfg = Debug|Any CPU + {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Debug|x86.Build.0 = Debug|Any CPU {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|Any CPU.ActiveCfg = Release|Any CPU {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|Any CPU.Build.0 = Release|Any CPU + {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|ARM64.ActiveCfg = Release|Any CPU + {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|ARM64.Build.0 = Release|Any CPU + {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|x64.ActiveCfg = Release|Any CPU + {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|x64.Build.0 = Release|Any CPU + {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|x86.ActiveCfg = Release|Any CPU + {9A9E15AF-3E85-4F20-AA23-A14ACA4805B5}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/FancyMouse/Helpers/ConfigHelper.cs b/src/FancyMouse/Helpers/ConfigHelper.cs index 6bc9865..1e800a8 100644 --- a/src/FancyMouse/Helpers/ConfigHelper.cs +++ b/src/FancyMouse/Helpers/ConfigHelper.cs @@ -7,7 +7,6 @@ internal static class ConfigHelper { private static readonly HotKeyManager _hotKeyManager; - private static string? _appSettingsPath; private static FileSystemWatcher? _appSettingsWatcher; private static AppSettings? _appSettings; @@ -18,6 +17,12 @@ static ConfigHelper() ConfigHelper._hotKeyManager = new HotKeyManager(); } + public static string? AppSettingsPath + { + get; + private set; + } + public static AppSettings? AppSettings { get @@ -33,7 +38,7 @@ public static AppSettings? AppSettings public static void SetAppSettingsPath(string appSettingsPath) { - _appSettingsPath = appSettingsPath; + ConfigHelper.AppSettingsPath = appSettingsPath; } public static void SetHotKeyEventHandler(EventHandler eventHandler) @@ -51,7 +56,7 @@ public static void SetHotKeyEventHandler(EventHandler eventHand public static void LoadAppSettings() { _hotKeyManager.SetHoKey(null); - _appSettings = AppSettingsReader.ReadFile(_appSettingsPath + _appSettings = AppSettingsReader.ReadFile(ConfigHelper.AppSettingsPath ?? throw new InvalidOperationException("AppSettings cannot be null")); _hotKeyManager.SetHoKey(_appSettings?.Hotkey ?? throw new InvalidOperationException($"{nameof(_appSettings.Hotkey)} cannot be null")); @@ -60,8 +65,8 @@ public static void LoadAppSettings() public static void StartWatcher() { // set up the filesystem watcher - var path = Path.GetDirectoryName(_appSettingsPath) ?? throw new InvalidOperationException(); - var filter = Path.GetFileName(_appSettingsPath) ?? throw new InvalidOperationException(); + var path = Path.GetDirectoryName(ConfigHelper.AppSettingsPath) ?? throw new InvalidOperationException(); + var filter = Path.GetFileName(ConfigHelper.AppSettingsPath) ?? throw new InvalidOperationException(); _appSettingsWatcher = new FileSystemWatcher(path, filter) { NotifyFilter = NotifyFilters.LastWrite, diff --git a/src/FancyMouse/Helpers/MouseHelper.cs b/src/FancyMouse/Helpers/MouseHelper.cs index 356f4ad..6d69729 100644 --- a/src/FancyMouse/Helpers/MouseHelper.cs +++ b/src/FancyMouse/Helpers/MouseHelper.cs @@ -44,27 +44,6 @@ public static PointInfo GetCursorPosition() point.x, point.y); } - public static PointInfo GetCursorPosition(PointInfo location) - { - var pos = new POINT(0, 0); - var lpPoint = new LPPOINT(pos); - - if (!User32.GetCursorPos(lpPoint)) - { - throw new InvalidOperationException(); - } - - if (lpPoint.IsNull) - { - throw new InvalidOperationException(); - } - - pos = lpPoint.ToStructure(); - lpPoint.Free(); - - return new PointInfo(pos.x, pos.y); - } - /// /// Moves the cursor to the specified location. /// diff --git a/src/FancyMouse/Hotkeys/HotKeyManager.cs b/src/FancyMouse/Hotkeys/HotKeyManager.cs index 63cd6cd..2fb663e 100644 --- a/src/FancyMouse/Hotkeys/HotKeyManager.cs +++ b/src/FancyMouse/Hotkeys/HotKeyManager.cs @@ -74,7 +74,6 @@ public void SetHoKey(Keystroke? hotKey) // do we need to unregister the existing hotkey first? if ((this.HotKey is not null) && hwnd.HasValue) { - // HotKeyHelper.PostPrivateThreadMessage(this.MessageLoop.NativeThreadId, HotKeyHelper.WM_PRIV_UNREGISTER_HOTKEY); HotKeyHelper.PostPrivateMessage(hwnd.Value, HotKeyHelper.WM_PRIV_UNREGISTER_HOTKEY); this.MessageSemaphore.Wait(); } @@ -84,7 +83,6 @@ public void SetHoKey(Keystroke? hotKey) // register the new hotkey if ((this.HotKey is not null) && hwnd.HasValue) { - // HotKeyHelper.PostPrivateThreadMessage(this.MessageLoop.NativeThreadId, HotKeyHelper.WM_PRIV_REGISTER_HOTKEY); HotKeyHelper.PostPrivateMessage(hwnd.Value, HotKeyHelper.WM_PRIV_REGISTER_HOTKEY); this.MessageSemaphore.Wait(); } diff --git a/src/FancyMouse/Hotkeys/MessageLoop.cs b/src/FancyMouse/Hotkeys/MessageLoop.cs index 3c16488..1dd07d0 100644 --- a/src/FancyMouse/Hotkeys/MessageLoop.cs +++ b/src/FancyMouse/Hotkeys/MessageLoop.cs @@ -11,7 +11,6 @@ internal sealed class MessageLoop public MessageLoop(string name, Func hwndCallback) { this.Name = name ?? throw new ArgumentNullException(nameof(name)); - this.HwndCallback = hwndCallback ?? throw new ArgumentNullException(nameof(hwndCallback)); this.RunningSemaphore = new SemaphoreSlim(1); @@ -159,8 +158,7 @@ public void Stop() } // signal to the internal message loop that it should stop - (this.CancellationTokenSource ?? throw new InvalidOperationException()) - .Cancel(); + this.CancellationTokenSource.Cancel(); // post a null message just in case GetMessageW needs a nudge to stop blocking the // message loop - the loop will then notice that we've set the cancellation token, diff --git a/src/FancyMouse/Models/Settings/V1/AppConfig.cs b/src/FancyMouse/Models/Settings/V1/AppConfig.cs index 1729713..dbc63a9 100644 --- a/src/FancyMouse/Models/Settings/V1/AppConfig.cs +++ b/src/FancyMouse/Models/Settings/V1/AppConfig.cs @@ -8,12 +8,12 @@ internal sealed class AppConfig { public AppConfig( - FancyMouseSettings? fancymouse) + FancyMouse? fancyMouse) { - this.FancyMouse = fancymouse; + this.FancyMouse = fancyMouse; } - public FancyMouseSettings? FancyMouse + public FancyMouse? FancyMouse { get; } diff --git a/src/FancyMouse/Models/Settings/V1/FancyMouseSettings.cs b/src/FancyMouse/Models/Settings/V1/FancyMouse.cs similarity index 73% rename from src/FancyMouse/Models/Settings/V1/FancyMouseSettings.cs rename to src/FancyMouse/Models/Settings/V1/FancyMouse.cs index ff9b2f4..b561f10 100644 --- a/src/FancyMouse/Models/Settings/V1/FancyMouseSettings.cs +++ b/src/FancyMouse/Models/Settings/V1/FancyMouse.cs @@ -2,9 +2,12 @@ namespace FancyMouse.Models.Settings.V1; -public sealed class FancyMouseSettings +/// +/// Represents the "fancymouse"' node in the V1 config file +/// +public sealed class FancyMouse { - public FancyMouseSettings( + public FancyMouse( string? hotkey, string? previewSize) { diff --git a/src/FancyMouse/Models/Settings/V2/ScreenshotStyleSettings.cs b/src/FancyMouse/Models/Settings/V2/ScreenshotStyleSettings.cs index d582485..ff4fe57 100644 --- a/src/FancyMouse/Models/Settings/V2/ScreenshotStyleSettings.cs +++ b/src/FancyMouse/Models/Settings/V2/ScreenshotStyleSettings.cs @@ -9,9 +9,9 @@ namespace FancyMouse.Models.Settings.V2; public sealed class ScreenshotStyleSettings { public ScreenshotStyleSettings( - MarginStyleSettings marginStyle, - BorderStyleSettings borderStyle, - BackgroundStyleSettings backgroundStyle) + MarginStyleSettings? marginStyle, + BorderStyleSettings? borderStyle, + BackgroundStyleSettings? backgroundStyle) { this.MarginStyle = marginStyle ?? throw new ArgumentNullException(nameof(marginStyle)); this.BorderStyle = borderStyle ?? throw new ArgumentNullException(nameof(borderStyle)); @@ -19,19 +19,19 @@ public ScreenshotStyleSettings( } [JsonPropertyName("margin")] - public MarginStyleSettings MarginStyle + public MarginStyleSettings? MarginStyle { get; } [JsonPropertyName("border")] - public BorderStyleSettings BorderStyle + public BorderStyleSettings? BorderStyle { get; } [JsonPropertyName("background")] - public BackgroundStyleSettings BackgroundStyle + public BackgroundStyleSettings? BackgroundStyle { get; } diff --git a/src/FancyMouse/Program.cs b/src/FancyMouse/Program.cs index 6778d25..0c2d9c0 100644 --- a/src/FancyMouse/Program.cs +++ b/src/FancyMouse/Program.cs @@ -7,7 +7,7 @@ namespace FancyMouse; internal static class Program { /// - /// The main entry point for the application. + /// The main entry point for the application. /// [STAThread] private static void Main()