From 47770c00b84ca74b0f3c91924e8a5173ba689182 Mon Sep 17 00:00:00 2001 From: DarthAffe Date: Sat, 8 Feb 2025 12:07:48 +0100 Subject: [PATCH 1/3] Used new collection-initialization --- RGB.NET.Core/Devices/AbstractRGBDevice.cs | 4 ++-- RGB.NET.Core/Groups/ListLedGroup.cs | 4 ++-- RGB.NET.Core/RGBSurface.cs | 4 ++-- RGB.NET.Core/Update/CustomUpdateData.cs | 2 +- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs index 07663f3..311c468 100644 --- a/RGB.NET.Core/Devices/AbstractRGBDevice.cs +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -43,7 +43,7 @@ public abstract class AbstractRGBDevice : Placeable, IRGBDevice DeviceInfo; /// - public IList ColorCorrections { get; } = new List(); + public IList ColorCorrections { get; } = []; /// /// Gets or sets if the device needs to be flushed on every update. @@ -63,7 +63,7 @@ public abstract class AbstractRGBDevice : Placeable, IRGBDevice - Led? IRGBDevice.this[LedId ledId] => LedMapping.TryGetValue(ledId, out Led? led) ? led : null; + Led? IRGBDevice.this[LedId ledId] => LedMapping.GetValueOrDefault(ledId); /// Led? IRGBDevice.this[Point location] => LedMapping.Values.FirstOrDefault(x => x.Boundary.Contains(location)); diff --git a/RGB.NET.Core/Groups/ListLedGroup.cs b/RGB.NET.Core/Groups/ListLedGroup.cs index 4bca2fb..511cdad 100644 --- a/RGB.NET.Core/Groups/ListLedGroup.cs +++ b/RGB.NET.Core/Groups/ListLedGroup.cs @@ -20,7 +20,7 @@ public sealed class ListLedGroup : AbstractLedGroup /// /// Gets the list containing the of this . /// - private readonly IList _groupLeds = new List(); + private readonly IList _groupLeds = []; #endregion @@ -142,7 +142,7 @@ public sealed class ListLedGroup : AbstractLedGroup public override IList ToList() { lock (_groupLeds) - return new List(_groupLeds); + return [.._groupLeds]; } protected override IDisposable ToListUnsafe(out IList leds) diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs index 5c3387f..2de9c13 100644 --- a/RGB.NET.Core/RGBSurface.cs +++ b/RGB.NET.Core/RGBSurface.cs @@ -20,8 +20,8 @@ public sealed class RGBSurface : AbstractBindable, IDisposable private readonly Stopwatch _deltaTimeCounter; - private readonly IList _devices = new List(); - private readonly IList _updateTriggers = new List(); + private readonly IList _devices = []; + private readonly IList _updateTriggers = []; private readonly List _ledGroups = []; /// diff --git a/RGB.NET.Core/Update/CustomUpdateData.cs b/RGB.NET.Core/Update/CustomUpdateData.cs index 0d85aa7..bce97f3 100644 --- a/RGB.NET.Core/Update/CustomUpdateData.cs +++ b/RGB.NET.Core/Update/CustomUpdateData.cs @@ -68,7 +68,7 @@ public sealed class CustomUpdateData : ICustomUpdateData /// The value represented by the specified key. public object? this[string key] { - get => _data.TryGetValue(key, out object? data) ? data : default; + get => _data.GetValueOrDefault(key); set => _data[key] = value; } From 5633f82b3bb22f61f09c2cc85ee39a05b2998d57 Mon Sep 17 00:00:00 2001 From: DarthAffe Date: Sat, 8 Feb 2025 12:08:12 +0100 Subject: [PATCH 2/3] Changed locks to use the new Lock-type for .net9 --- RGB.NET.Core/Compatibility/Lock.cs | 7 +++++++ RGB.NET.Core/Helper/TimerHelper.cs | 2 +- RGB.NET.Core/RGB.NET.Core.csproj | 4 ++++ RGB.NET.Core/Update/Devices/UpdateQueue.cs | 3 ++- RGB.NET.Core/Update/TimerUpdateTrigger.cs | 2 +- RGB.NET.Devices.Asus/AsusDeviceProvider.cs | 3 ++- RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj | 4 ++++ RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs | 3 ++- .../RGB.NET.Devices.CoolerMaster.csproj | 4 ++++ RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs | 2 +- RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj | 4 ++++ .../CorsairLegacyDeviceProvider.cs | 3 ++- .../RGB.NET.Devices.Corsair_Legacy.csproj | 4 ++++ RGB.NET.Devices.DMX/DMXDeviceProvider.cs | 3 ++- RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj | 4 ++++ RGB.NET.Devices.Debug/DebugDeviceProvider.cs | 3 ++- RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj | 4 ++++ RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs | 3 ++- RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj | 4 ++++ RGB.NET.Devices.Msi/MsiDeviceProvider.cs | 3 ++- RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj | 4 ++++ RGB.NET.Devices.Novation/NovationDeviceProvider.cs | 3 ++- RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj | 4 ++++ RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs | 3 ++- RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj | 4 ++++ RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs | 3 ++- RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj | 4 ++++ RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj | 4 ++++ RGB.NET.Devices.Razer/RazerDeviceProvider.cs | 3 ++- .../RGB.NET.Devices.SteelSeries.csproj | 4 ++++ RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs | 3 ++- RGB.NET.Devices.WLED/RGB.NET.Devices.WLED.csproj | 4 ++++ RGB.NET.Devices.WLED/WLedDeviceProvider.cs | 3 ++- RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj | 4 ++++ RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs | 3 ++- RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj | 4 ++++ RGB.NET.Devices.Wooting/WootingDeviceProvider.cs | 3 ++- RGB.NET.HID/RGB.NET.HID.csproj | 4 ++++ RGB.NET.Layout/RGB.NET.Layout.csproj | 4 ++++ RGB.NET.Presets/RGB.NET.Presets.csproj | 4 ++++ RGB.NET.sln.DotSettings | 6 ++++++ 41 files changed, 128 insertions(+), 19 deletions(-) create mode 100644 RGB.NET.Core/Compatibility/Lock.cs diff --git a/RGB.NET.Core/Compatibility/Lock.cs b/RGB.NET.Core/Compatibility/Lock.cs new file mode 100644 index 0000000..e8e5af1 --- /dev/null +++ b/RGB.NET.Core/Compatibility/Lock.cs @@ -0,0 +1,7 @@ +#if NET8_0 + +namespace RGB.NET.Core.Compatibility.Net8; + +public sealed class Lock; + +#endif \ No newline at end of file diff --git a/RGB.NET.Core/Helper/TimerHelper.cs b/RGB.NET.Core/Helper/TimerHelper.cs index e2742ab..1da32e6 100644 --- a/RGB.NET.Core/Helper/TimerHelper.cs +++ b/RGB.NET.Core/Helper/TimerHelper.cs @@ -24,7 +24,7 @@ public static class TimerHelper #region Properties & Fields - private static readonly object HIGH_RESOLUTION_TIMER_LOCK = new(); + private static readonly Lock HIGH_RESOLUTION_TIMER_LOCK = new(); private static bool _areHighResolutionTimersEnabled = false; diff --git a/RGB.NET.Core/RGB.NET.Core.csproj b/RGB.NET.Core/RGB.NET.Core.csproj index 7a4e2c4..a945aa4 100644 --- a/RGB.NET.Core/RGB.NET.Core.csproj +++ b/RGB.NET.Core/RGB.NET.Core.csproj @@ -52,6 +52,10 @@ RELEASE + + + + diff --git a/RGB.NET.Core/Update/Devices/UpdateQueue.cs b/RGB.NET.Core/Update/Devices/UpdateQueue.cs index 7db3517..ba9e3bb 100644 --- a/RGB.NET.Core/Update/Devices/UpdateQueue.cs +++ b/RGB.NET.Core/Update/Devices/UpdateQueue.cs @@ -1,6 +1,7 @@ using System; using System.Buffers; using System.Collections.Generic; +using System.Threading; namespace RGB.NET.Core; @@ -14,7 +15,7 @@ public abstract class UpdateQueue : AbstractReferenceCountin { #region Properties & Fields - private readonly object _dataLock = new(); + private readonly Lock _dataLock = new(); private readonly IDeviceUpdateTrigger _updateTrigger; private readonly Dictionary _currentDataSet = []; diff --git a/RGB.NET.Core/Update/TimerUpdateTrigger.cs b/RGB.NET.Core/Update/TimerUpdateTrigger.cs index 6b94b3f..303b517 100644 --- a/RGB.NET.Core/Update/TimerUpdateTrigger.cs +++ b/RGB.NET.Core/Update/TimerUpdateTrigger.cs @@ -14,7 +14,7 @@ public sealed class TimerUpdateTrigger : AbstractUpdateTrigger { #region Properties & Fields - private readonly object _lock = new(); + private readonly Lock _lock = new(); private readonly CustomUpdateData? _customUpdateData; diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs index 5515bc1..f6ea312 100644 --- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Threading; using AuraServiceLib; using RGB.NET.Core; @@ -17,7 +18,7 @@ public sealed class AsusDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static AsusDeviceProvider? _instance; /// diff --git a/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj b/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj index 08d6fd3..b04586c 100644 --- a/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj +++ b/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj @@ -51,6 +51,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index cecc41d..d681384 100644 --- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Threading; using RGB.NET.Core; using RGB.NET.Devices.CoolerMaster.Helper; using RGB.NET.Devices.CoolerMaster.Native; @@ -18,7 +19,7 @@ public sealed class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static CoolerMasterDeviceProvider? _instance; /// diff --git a/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj b/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj index 88a58d0..c54ced2 100644 --- a/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj +++ b/RGB.NET.Devices.CoolerMaster/RGB.NET.Devices.CoolerMaster.csproj @@ -51,6 +51,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index 4dba9ea..1d0e7d6 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -18,7 +18,7 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static CorsairDeviceProvider? _instance; /// diff --git a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj index 51228f4..ff0914d 100644 --- a/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj +++ b/RGB.NET.Devices.Corsair/RGB.NET.Devices.Corsair.csproj @@ -52,6 +52,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs b/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs index 9f770e8..d893dfd 100644 --- a/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair_Legacy/CorsairLegacyDeviceProvider.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; +using System.Threading; using RGB.NET.Core; using RGB.NET.Devices.CorsairLegacy.Native; @@ -19,7 +20,7 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static CorsairLegacyDeviceProvider? _instance; /// diff --git a/RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj b/RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj index 7604e5b..e9c4509 100644 --- a/RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj +++ b/RGB.NET.Devices.Corsair_Legacy/RGB.NET.Devices.Corsair_Legacy.csproj @@ -52,6 +52,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs index b5d725c..5e65459 100644 --- a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs +++ b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Threading; using RGB.NET.Core; using RGB.NET.Devices.DMX.E131; @@ -17,7 +18,7 @@ public sealed class DMXDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static DMXDeviceProvider? _instance; /// diff --git a/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj b/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj index 7056936..679d94d 100644 --- a/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj +++ b/RGB.NET.Devices.DMX/RGB.NET.Devices.DMX.csproj @@ -51,6 +51,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs index 636e57f..cbd97a2 100644 --- a/RGB.NET.Devices.Debug/DebugDeviceProvider.cs +++ b/RGB.NET.Devices.Debug/DebugDeviceProvider.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Threading; using RGB.NET.Core; using RGB.NET.Layout; @@ -17,7 +18,7 @@ public sealed class DebugDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static DebugDeviceProvider? _instance; /// diff --git a/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj b/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj index fa11d56..14db0ca 100644 --- a/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj +++ b/RGB.NET.Devices.Debug/RGB.NET.Devices.Debug.csproj @@ -51,6 +51,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs index 2acbd31..edf61ec 100644 --- a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs +++ b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using HidSharp; using RGB.NET.Core; using RGB.NET.Devices.Logitech.Native; @@ -21,7 +22,7 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static LogitechDeviceProvider? _instance; /// diff --git a/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj b/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj index 2659fed..4c27d96 100644 --- a/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj +++ b/RGB.NET.Devices.Logitech/RGB.NET.Devices.Logitech.csproj @@ -52,6 +52,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index 54be621..d7022a3 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Threading; using RGB.NET.Core; using RGB.NET.Devices.Msi.Exceptions; using RGB.NET.Devices.Msi.Native; @@ -18,7 +19,7 @@ public class MsiDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static MsiDeviceProvider? _instance; /// diff --git a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj index a0b1d32..4409e88 100644 --- a/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj +++ b/RGB.NET.Devices.Msi/RGB.NET.Devices.Msi.csproj @@ -51,6 +51,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs index e3c9b77..c2e2435 100644 --- a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs +++ b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using RGB.NET.Core; using Sanford.Multimedia.Midi; @@ -18,7 +19,7 @@ public sealed class NovationDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static NovationDeviceProvider? _instance; /// diff --git a/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj b/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj index c75ab22..a526cfb 100644 --- a/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj +++ b/RGB.NET.Devices.Novation/RGB.NET.Devices.Novation.csproj @@ -51,6 +51,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs index 26b3a2a..33ac334 100644 --- a/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs +++ b/RGB.NET.Devices.OpenRGB/OpenRGBDeviceProvider.cs @@ -3,6 +3,7 @@ using RGB.NET.Core; using System; using System.Collections.Generic; using System.Linq; +using System.Threading; namespace RGB.NET.Devices.OpenRGB; @@ -15,7 +16,7 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private readonly List _clients = []; diff --git a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj index dbcb857..5f7a014 100644 --- a/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj +++ b/RGB.NET.Devices.OpenRGB/RGB.NET.Devices.OpenRGB.csproj @@ -51,6 +51,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs b/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs index ebcdff5..f5b879d 100644 --- a/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs +++ b/RGB.NET.Devices.PicoPi/PicoPiDeviceProvider.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using HidSharp; using RGB.NET.Core; using RGB.NET.Devices.PicoPi.Enum; @@ -26,7 +27,7 @@ public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static PicoPiDeviceProvider? _instance; /// diff --git a/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj b/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj index de287c0..b42f361 100644 --- a/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj +++ b/RGB.NET.Devices.PicoPi/RGB.NET.Devices.PicoPi.csproj @@ -51,6 +51,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj b/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj index 84dc712..bf46462 100644 --- a/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj +++ b/RGB.NET.Devices.Razer/RGB.NET.Devices.Razer.csproj @@ -52,6 +52,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 7a7c2a8..e7e3d87 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Threading; using RGB.NET.Core; using RGB.NET.Devices.Razer.Native; using RGB.NET.HID; @@ -20,7 +21,7 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static RazerDeviceProvider? _instance; /// diff --git a/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj b/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj index aed6e92..fd5b281 100644 --- a/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj +++ b/RGB.NET.Devices.SteelSeries/RGB.NET.Devices.SteelSeries.csproj @@ -51,6 +51,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs index 7a3f101..5748511 100644 --- a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs +++ b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Threading; using RGB.NET.Core; using RGB.NET.Devices.SteelSeries.API; using RGB.NET.HID; @@ -21,7 +22,7 @@ public sealed class SteelSeriesDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static SteelSeriesDeviceProvider? _instance; /// diff --git a/RGB.NET.Devices.WLED/RGB.NET.Devices.WLED.csproj b/RGB.NET.Devices.WLED/RGB.NET.Devices.WLED.csproj index a7893b4..65bd108 100644 --- a/RGB.NET.Devices.WLED/RGB.NET.Devices.WLED.csproj +++ b/RGB.NET.Devices.WLED/RGB.NET.Devices.WLED.csproj @@ -51,6 +51,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.WLED/WLedDeviceProvider.cs b/RGB.NET.Devices.WLED/WLedDeviceProvider.cs index 978565e..e49b5e8 100644 --- a/RGB.NET.Devices.WLED/WLedDeviceProvider.cs +++ b/RGB.NET.Devices.WLED/WLedDeviceProvider.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Threading; using RGB.NET.Core; namespace RGB.NET.Devices.WLED; @@ -23,7 +24,7 @@ public sealed class WledDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static WledDeviceProvider? _instance; /// diff --git a/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj b/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj index 57c1c15..f7a0dfd 100644 --- a/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj +++ b/RGB.NET.Devices.WS281X/RGB.NET.Devices.WS281X.csproj @@ -51,6 +51,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs index 109877a..de7e6ee 100644 --- a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs +++ b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; +using System.Threading; using RGB.NET.Core; namespace RGB.NET.Devices.WS281X; @@ -17,7 +18,7 @@ public sealed class WS281XDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static WS281XDeviceProvider? _instance; /// diff --git a/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj b/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj index 5ea6bbe..778d0b9 100644 --- a/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj +++ b/RGB.NET.Devices.Wooting/RGB.NET.Devices.Wooting.csproj @@ -52,6 +52,10 @@ RELEASE + + + + diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index 8b36ff7..cb58d18 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Runtime.InteropServices; +using System.Threading; using RGB.NET.Core; using RGB.NET.Devices.Wooting.Enum; using RGB.NET.Devices.Wooting.Generic; @@ -19,7 +20,7 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider #region Properties & Fields // ReSharper disable once InconsistentNaming - private static readonly object _lock = new(); + private static readonly Lock _lock = new(); private static WootingDeviceProvider? _instance; /// diff --git a/RGB.NET.HID/RGB.NET.HID.csproj b/RGB.NET.HID/RGB.NET.HID.csproj index 3dd2ce3..22196ce 100644 --- a/RGB.NET.HID/RGB.NET.HID.csproj +++ b/RGB.NET.HID/RGB.NET.HID.csproj @@ -51,6 +51,10 @@ RELEASE + + + + diff --git a/RGB.NET.Layout/RGB.NET.Layout.csproj b/RGB.NET.Layout/RGB.NET.Layout.csproj index ab00d34..163c204 100644 --- a/RGB.NET.Layout/RGB.NET.Layout.csproj +++ b/RGB.NET.Layout/RGB.NET.Layout.csproj @@ -51,6 +51,10 @@ RELEASE + + + + diff --git a/RGB.NET.Presets/RGB.NET.Presets.csproj b/RGB.NET.Presets/RGB.NET.Presets.csproj index f2db2c1..04ecdb6 100644 --- a/RGB.NET.Presets/RGB.NET.Presets.csproj +++ b/RGB.NET.Presets/RGB.NET.Presets.csproj @@ -52,6 +52,10 @@ RELEASE + + + + diff --git a/RGB.NET.sln.DotSettings b/RGB.NET.sln.DotSettings index a13f331..c7ee5e7 100644 --- a/RGB.NET.sln.DotSettings +++ b/RGB.NET.sln.DotSettings @@ -308,6 +308,11 @@ <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AA_BB" /> + <Policy><Descriptor Staticness="Static" AccessRightKinds="Private" Description="Static readonly fields (private)"><ElementKinds><Kind Name="READONLY_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AA_BB" /></Policy> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Private" Description="Constant fields (private)"><ElementKinds><Kind Name="CONSTANT_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AA_BB" /></Policy> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="Constant fields (not private)"><ElementKinds><Kind Name="CONSTANT_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AA_BB" /></Policy> + <Policy><Descriptor Staticness="Any" AccessRightKinds="Any" Description="Local constants"><ElementKinds><Kind Name="LOCAL_CONSTANT" /></ElementKinds></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AA_BB" /></Policy> + <Policy><Descriptor Staticness="Static" AccessRightKinds="Protected, ProtectedInternal, Internal, Public, PrivateProtected" Description="Static readonly fields (not private)"><ElementKinds><Kind Name="READONLY_FIELD" /></ElementKinds></Descriptor><Policy Inspect="True" WarnAboutPrefixesAndSuffixes="False" Prefix="" Suffix="" Style="AA_BB" /></Policy> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> @@ -358,6 +363,7 @@ True True True + True True True True \ No newline at end of file From aae509b275a2e9c003126ecd4fc13c03e72e0399 Mon Sep 17 00:00:00 2001 From: DarthAffe Date: Sat, 8 Feb 2025 12:13:14 +0100 Subject: [PATCH 3/3] More code issues fixed --- RGB.NET.Core/Compatibility/Lock.cs | 1 + RGB.NET.Core/Extensions/RectangleExtensions.cs | 6 +++--- RGB.NET.Core/Helper/ConversionHelper.cs | 2 +- .../Keyboard/AsusKeyboardRGBDevice.cs | 4 ++-- .../Keyboard/AsusKeyboardRGBDeviceInfo.cs | 2 +- RGB.NET.Devices.Corsair/Native/_CUESDK.cs | 2 +- .../Custom/CorsairCustomRGBDeviceInfo.cs | 13 ++++++++----- RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs | 2 +- RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs | 8 ++++---- RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs | 2 +- RGB.NET.Devices.Msi/Native/_MsiSDK.cs | 2 +- RGB.NET.Devices.Razer/Native/_RazerSDK.cs | 2 +- RGB.NET.Devices.Wooting/Native/_WootingSDK.cs | 2 +- 13 files changed, 26 insertions(+), 22 deletions(-) diff --git a/RGB.NET.Core/Compatibility/Lock.cs b/RGB.NET.Core/Compatibility/Lock.cs index e8e5af1..0a28501 100644 --- a/RGB.NET.Core/Compatibility/Lock.cs +++ b/RGB.NET.Core/Compatibility/Lock.cs @@ -1,5 +1,6 @@ #if NET8_0 +// ReSharper disable once CheckNamespace namespace RGB.NET.Core.Compatibility.Net8; public sealed class Lock; diff --git a/RGB.NET.Core/Extensions/RectangleExtensions.cs b/RGB.NET.Core/Extensions/RectangleExtensions.cs index 741742b..077c193 100644 --- a/RGB.NET.Core/Extensions/RectangleExtensions.cs +++ b/RGB.NET.Core/Extensions/RectangleExtensions.cs @@ -154,9 +154,9 @@ public static class RectangleExtensions Point[] points = [ rect.Location, // top left - new Point(rect.Location.X + rect.Size.Width, rect.Location.Y), // top right - new Point(rect.Location.X + rect.Size.Width, rect.Location.Y + rect.Size.Height), // bottom right - new Point(rect.Location.X, rect.Location.Y + rect.Size.Height), // bottom right + new(rect.Location.X + rect.Size.Width, rect.Location.Y), // top right + new(rect.Location.X + rect.Size.Width, rect.Location.Y + rect.Size.Height), // bottom right + new(rect.Location.X, rect.Location.Y + rect.Size.Height), // bottom right ]; float sin = MathF.Sin(rotation.Radians); diff --git a/RGB.NET.Core/Helper/ConversionHelper.cs b/RGB.NET.Core/Helper/ConversionHelper.cs index 0be3dfb..d05b94b 100644 --- a/RGB.NET.Core/Helper/ConversionHelper.cs +++ b/RGB.NET.Core/Helper/ConversionHelper.cs @@ -40,7 +40,7 @@ public static class ConversionHelper public static byte[] HexToBytes(ReadOnlySpan hexString) { if ((hexString.Length == 0) || ((hexString.Length % 2) != 0)) - return Array.Empty(); + return []; byte[] buffer = new byte[hexString.Length / 2]; for (int bx = 0, sx = 0; bx < buffer.Length; ++bx, ++sx) diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs index 1200429..50a0878 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDevice.cs @@ -37,8 +37,8 @@ public sealed class AsusKeyboardRGBDevice : AsusRGBDevice ExtraLedMappings = [ - new AsusKeyboardExtraMapping(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15), - new AsusKeyboardExtraMapping(new Regex("(ROG Strix G513QM).*?"), LedMappings.ROGStrixG15) + new(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15), + new(new Regex("(ROG Strix G513QM).*?"), LedMappings.ROGStrixG15) ]; #endregion diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs index 8516bec..3baf728 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs @@ -36,7 +36,7 @@ public sealed class AsusKeyboardRGBDeviceInfo : AsusRGBDeviceInfo, IKeyboardDevi #region Methods - private static string? GetKeyboardModel(string deviceName) => GENERIC_DEVICE_NAMES.Contains(deviceName) ? "Asus Keyboard" : deviceName; + private static string GetKeyboardModel(string deviceName) => GENERIC_DEVICE_NAMES.Contains(deviceName) ? "Asus Keyboard" : deviceName; #endregion } \ No newline at end of file diff --git a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs index 38324e3..6c48745 100644 --- a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs +++ b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs @@ -133,7 +133,7 @@ internal static unsafe class _CUESDK if (OperatingSystem.IsWindows()) possibleLibraryPaths = Environment.Is64BitProcess ? CorsairDeviceProvider.PossibleX64NativePaths : CorsairDeviceProvider.PossibleX86NativePaths; else - possibleLibraryPaths = Enumerable.Empty(); + possibleLibraryPaths = []; return possibleLibraryPaths.Select(Environment.ExpandEnvironmentVariables); } diff --git a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs index 783089e..967bd5d 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Custom/CorsairCustomRGBDeviceInfo.cs @@ -124,16 +124,19 @@ public class CorsairCustomRGBDeviceInfo : CorsairRGBDeviceInfo // LS100 Led Strips are reported as one big strip if configured in monitor mode in iCUE, 138 LEDs for dual monitor, 84 for single if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 138)) return "LS100 LED Strip (dual monitor)"; - else if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 84)) + + if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 84)) return "LS100 LED Strip (single monitor)"; + // Any other value means an "External LED Strip" in iCUE, these are reported per-strip, 15 for short strips, 27 for long - else if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 15)) + if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 15)) return "LS100 LED Strip (short)"; - else if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 27)) + + if ((model == "LS100 Starter Kit") && (channelDeviceInfo.deviceLedCount == 27)) return "LS100 LED Strip (long)"; + // Device model is "Commander Pro" for regular LED strips - else - return "LED Strip"; + return "LED Strip"; case CorsairChannelDeviceType.DAP: return "DAP Fan"; diff --git a/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs b/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs index 3ace435..dda97dd 100644 --- a/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs +++ b/RGB.NET.Devices.Corsair_Legacy/Native/_CUESDK.cs @@ -64,7 +64,7 @@ internal static class _CUESDK if (OperatingSystem.IsWindows()) possibleLibraryPaths = Environment.Is64BitProcess ? CorsairLegacyDeviceProvider.PossibleX64NativePaths : CorsairLegacyDeviceProvider.PossibleX86NativePaths; else - possibleLibraryPaths = Enumerable.Empty(); + possibleLibraryPaths = []; return possibleLibraryPaths.Select(Environment.ExpandEnvironmentVariables); } diff --git a/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs b/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs index 4d0aeac..e1dc242 100644 --- a/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs +++ b/RGB.NET.Devices.Logitech/HID/LightspeedHidLoader.cs @@ -139,7 +139,7 @@ public sealed class LightspeedHIDLoader : IEnumerable : IEnumerable : IEnumerable : IEnumerable(); + possibleLibraryPaths = []; return possibleLibraryPaths.Select(Environment.ExpandEnvironmentVariables); } diff --git a/RGB.NET.Devices.Msi/Native/_MsiSDK.cs b/RGB.NET.Devices.Msi/Native/_MsiSDK.cs index 1bc63fd..91fbd92 100644 --- a/RGB.NET.Devices.Msi/Native/_MsiSDK.cs +++ b/RGB.NET.Devices.Msi/Native/_MsiSDK.cs @@ -68,7 +68,7 @@ internal static class _MsiSDK if (OperatingSystem.IsWindows()) possibleLibraryPaths = Environment.Is64BitProcess ? MsiDeviceProvider.PossibleX64NativePaths : MsiDeviceProvider.PossibleX86NativePaths; else - possibleLibraryPaths = Enumerable.Empty(); + possibleLibraryPaths = []; return possibleLibraryPaths.Select(Environment.ExpandEnvironmentVariables); } diff --git a/RGB.NET.Devices.Razer/Native/_RazerSDK.cs b/RGB.NET.Devices.Razer/Native/_RazerSDK.cs index 4b99cc6..e7f7196 100644 --- a/RGB.NET.Devices.Razer/Native/_RazerSDK.cs +++ b/RGB.NET.Devices.Razer/Native/_RazerSDK.cs @@ -64,7 +64,7 @@ internal static class _RazerSDK if (OperatingSystem.IsWindows()) possibleLibraryPaths = Environment.Is64BitProcess ? RazerDeviceProvider.PossibleX64NativePaths : RazerDeviceProvider.PossibleX86NativePaths; else - possibleLibraryPaths = Enumerable.Empty(); + possibleLibraryPaths = []; return possibleLibraryPaths.Select(Environment.ExpandEnvironmentVariables); } diff --git a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs index cc0018c..0d4f7bb 100644 --- a/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs +++ b/RGB.NET.Devices.Wooting/Native/_WootingSDK.cs @@ -64,7 +64,7 @@ internal static class _WootingSDK else if (OperatingSystem.IsMacOS()) possibleLibraryPaths = WootingDeviceProvider.PossibleNativePathsMacOS; else - possibleLibraryPaths = Enumerable.Empty(); + possibleLibraryPaths = []; return possibleLibraryPaths.Select(Environment.ExpandEnvironmentVariables); }