1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00

Applied some C#12 stuff

This commit is contained in:
Darth Affe 2023-12-22 20:56:56 +01:00
parent 0444730aca
commit d85f1559b3
105 changed files with 329 additions and 422 deletions

View File

@ -11,7 +11,7 @@ public abstract class AbstractDecoratable<T> : AbstractBindable, IDecoratable<T>
{ {
#region Properties & Fields #region Properties & Fields
private readonly List<T> _decorators = new(); private readonly List<T> _decorators = [];
/// <inheritdoc /> /// <inheritdoc />
public IReadOnlyList<T> Decorators { get; } public IReadOnlyList<T> Decorators { get; }

View File

@ -29,7 +29,7 @@ public abstract class AbstractDecorator : AbstractBindable, IDecorator
/// <summary> /// <summary>
/// Gets a readonly-list of all <see cref="IDecoratable"/> this decorator is attached to. /// Gets a readonly-list of all <see cref="IDecoratable"/> this decorator is attached to.
/// </summary> /// </summary>
protected List<IDecoratable> DecoratedObjects { get; } = new(); protected List<IDecoratable> DecoratedObjects { get; } = [];
#endregion #endregion
@ -46,7 +46,7 @@ public abstract class AbstractDecorator : AbstractBindable, IDecorator
/// </summary> /// </summary>
protected virtual void Detach() protected virtual void Detach()
{ {
List<IDecoratable> decoratables = new(DecoratedObjects); List<IDecoratable> decoratables = [..DecoratedObjects];
foreach (IDecoratable decoratable in decoratables) foreach (IDecoratable decoratable in decoratables)
{ {
IEnumerable<Type> types = decoratable.GetType().GetInterfaces().Where(t => t.IsGenericType IEnumerable<Type> types = decoratable.GetType().GetInterfaces().Where(t => t.IsGenericType

View File

@ -6,8 +6,7 @@ namespace RGB.NET.Core;
/// <summary> /// <summary>
/// Represents a basic decoratable. /// Represents a basic decoratable.
/// </summary> /// </summary>
public interface IDecoratable : INotifyPropertyChanged public interface IDecoratable : INotifyPropertyChanged;
{ }
/// <inheritdoc /> /// <inheritdoc />
/// <summary> /// <summary>

View File

@ -4,5 +4,4 @@
/// <summary> /// <summary>
/// Represents a basic decorator decorating a <see cref="T:RGB.NET.Core.ILedGroup" />. /// Represents a basic decorator decorating a <see cref="T:RGB.NET.Core.ILedGroup" />.
/// </summary> /// </summary>
public interface ILedGroupDecorator : IDecorator public interface ILedGroupDecorator : IDecorator;
{ }

View File

@ -53,7 +53,7 @@ public abstract class AbstractRGBDevice<TDeviceInfo> : Placeable, IRGBDevice<TDe
/// <summary> /// <summary>
/// Gets a dictionary containing all <see cref="Led"/> of the <see cref="IRGBDevice"/>. /// Gets a dictionary containing all <see cref="Led"/> of the <see cref="IRGBDevice"/>.
/// </summary> /// </summary>
protected Dictionary<LedId, Led> LedMapping { get; } = new(); protected Dictionary<LedId, Led> LedMapping { get; } = [];
/// <summary> /// <summary>
/// Gets the update queue used to update this device. /// Gets the update queue used to update this device.

View File

@ -25,7 +25,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// <summary> /// <summary>
/// The list of devices managed by this device-provider. /// The list of devices managed by this device-provider.
/// </summary> /// </summary>
protected List<IRGBDevice> InternalDevices { get; } = new(); protected List<IRGBDevice> InternalDevices { get; } = [];
/// <inheritdoc /> /// <inheritdoc />
public virtual IReadOnlyList<IRGBDevice> Devices => new ReadOnlyCollection<IRGBDevice>(InternalDevices); public virtual IReadOnlyList<IRGBDevice> Devices => new ReadOnlyCollection<IRGBDevice>(InternalDevices);
@ -34,7 +34,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// Gets the dictionary containing the registered update triggers. /// Gets the dictionary containing the registered update triggers.
/// Normally <see cref="UpdateTriggers"/> should be used to access them. /// Normally <see cref="UpdateTriggers"/> should be used to access them.
/// </summary> /// </summary>
protected Dictionary<int, IDeviceUpdateTrigger> UpdateTriggerMapping { get; } = new(); protected Dictionary<int, IDeviceUpdateTrigger> UpdateTriggerMapping { get; } = [];
/// <inheritdoc /> /// <inheritdoc />
public IReadOnlyList<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers => new ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)>(UpdateTriggerMapping.Select(x => (x.Key, x.Value)).ToList()); public IReadOnlyList<(int id, IDeviceUpdateTrigger trigger)> UpdateTriggers => new ReadOnlyCollection<(int id, IDeviceUpdateTrigger trigger)>(UpdateTriggerMapping.Select(x => (x.Key, x.Value)).ToList());
@ -116,7 +116,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
{ {
if (_isDisposed) throw new ObjectDisposedException(GetType().FullName); if (_isDisposed) throw new ObjectDisposedException(GetType().FullName);
List<IRGBDevice> devices = new(); List<IRGBDevice> devices = [];
foreach (IRGBDevice device in LoadDevices()) foreach (IRGBDevice device in LoadDevices())
{ {
try try
@ -189,7 +189,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
foreach (IRGBDevice device in Devices) foreach (IRGBDevice device in Devices)
device.Dispose(); device.Dispose();
List<IRGBDevice> devices = new(InternalDevices); List<IRGBDevice> devices = [..InternalDevices];
foreach (IRGBDevice device in devices) foreach (IRGBDevice device in devices)
RemoveDevice(device); RemoveDevice(device);

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Represents a cooler-device /// Represents a cooler-device
/// </summary> /// </summary>
public interface ICooler : IRGBDevice public interface ICooler : IRGBDevice;
{ }

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Represents a DRAM-device /// Represents a DRAM-device
/// </summary> /// </summary>
public interface IDRAM : IRGBDevice public interface IDRAM : IRGBDevice;
{ }

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// represents a fan-device /// represents a fan-device
/// </summary> /// </summary>
public interface IFan : IRGBDevice public interface IFan : IRGBDevice;
{ }

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Represents a gamecontroller-device /// Represents a gamecontroller-device
/// </summary> /// </summary>
public interface IGameController: IRGBDevice public interface IGameController: IRGBDevice;
{ }

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Represents a graphics-card-device /// Represents a graphics-card-device
/// </summary> /// </summary>
public interface IGraphicsCard : IRGBDevice public interface IGraphicsCard : IRGBDevice;
{ }

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Represents a headset-device /// Represents a headset-device
/// </summary> /// </summary>
public interface IHeadset : IRGBDevice public interface IHeadset : IRGBDevice;
{ }

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Represents a headset-stand-device /// Represents a headset-stand-device
/// </summary> /// </summary>
public interface IHeadsetStand : IRGBDevice public interface IHeadsetStand : IRGBDevice;
{ }

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Represents a keypad-device /// Represents a keypad-device
/// </summary> /// </summary>
public interface IKeypad : IRGBDevice public interface IKeypad : IRGBDevice;
{ }

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Represents a led-matrix-device /// Represents a led-matrix-device
/// </summary> /// </summary>
public interface ILedMatrix : IRGBDevice public interface ILedMatrix : IRGBDevice;
{ }

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Represents a led-stripe-device /// Represents a led-stripe-device
/// </summary> /// </summary>
public interface ILedStripe : IRGBDevice public interface ILedStripe : IRGBDevice;
{ }

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Represents a mainboard-device /// Represents a mainboard-device
/// </summary> /// </summary>
public interface IMainboard : IRGBDevice public interface IMainboard : IRGBDevice;
{ }

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Represents a mouse-device /// Represents a mouse-device
/// </summary> /// </summary>
public interface IMouse : IRGBDevice public interface IMouse : IRGBDevice;
{ }

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Represents a mousepad-device /// Represents a mousepad-device
/// </summary> /// </summary>
public interface IMousepad : IRGBDevice public interface IMousepad : IRGBDevice;
{ }

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Represents a speaker-device /// Represents a speaker-device
/// </summary> /// </summary>
public interface ISpeaker : IRGBDevice public interface ISpeaker : IRGBDevice;
{ }

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Represents a device with unkown or not specified type. /// Represents a device with unkown or not specified type.
/// </summary> /// </summary>
public interface IUnknownDevice : IRGBDevice public interface IUnknownDevice : IRGBDevice;
{ }

View File

@ -2,22 +2,13 @@
namespace RGB.NET.Core; namespace RGB.NET.Core;
public sealed class DevicesChangedEventArgs : EventArgs public sealed class DevicesChangedEventArgs(IRGBDevice device, DevicesChangedEventArgs.DevicesChangedAction action)
: EventArgs
{ {
#region Properties & Fields #region Properties & Fields
public IRGBDevice Device { get; } public IRGBDevice Device { get; } = device;
public DevicesChangedAction Action { get; } public DevicesChangedAction Action { get; } = action;
#endregion
#region Constructors
public DevicesChangedEventArgs(IRGBDevice device, DevicesChangedAction action)
{
this.Device = device;
this.Action = action;
}
#endregion #endregion

View File

@ -6,5 +6,4 @@ namespace RGB.NET.Core;
/// <summary> /// <summary>
/// Represents the information supplied with an <see cref="E:RGB.NET.Core.RGBSurface.Updated" />-event. /// Represents the information supplied with an <see cref="E:RGB.NET.Core.RGBSurface.Updated" />-event.
/// </summary> /// </summary>
public class UpdatedEventArgs : EventArgs public class UpdatedEventArgs : EventArgs;
{ }

View File

@ -46,7 +46,7 @@ public static class TimerHelper
} }
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
private static readonly HashSet<HighResolutionTimerDisposable> _timerLeases = new(); private static readonly HashSet<HighResolutionTimerDisposable> _timerLeases = [];
#endregion #endregion
@ -143,7 +143,7 @@ public static class TimerHelper
/// </summary> /// </summary>
public static void DisposeAllHighResolutionTimerRequests() public static void DisposeAllHighResolutionTimerRequests()
{ {
List<HighResolutionTimerDisposable> timerLeases = new(_timerLeases); List<HighResolutionTimerDisposable> timerLeases = [.._timerLeases];
foreach (HighResolutionTimerDisposable timer in timerLeases) foreach (HighResolutionTimerDisposable timer in timerLeases)
timer.Dispose(); timer.Dispose();
} }

View File

@ -12,9 +12,9 @@ public static class IdGenerator
#region Properties & Fields #region Properties & Fields
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
private static readonly HashSet<string> _registeredIds = new(); private static readonly HashSet<string> _registeredIds = [];
private static readonly Dictionary<Assembly, Dictionary<string, string>> _idMappings = new(); private static readonly Dictionary<Assembly, Dictionary<string, string>> _idMappings = [];
private static readonly Dictionary<Assembly, Dictionary<string, int>> _counter = new(); private static readonly Dictionary<Assembly, Dictionary<string, int>> _counter = [];
// ReSharper restore InconsistentNaming // ReSharper restore InconsistentNaming
#endregion #endregion
@ -33,8 +33,8 @@ public static class IdGenerator
{ {
if (!_idMappings.TryGetValue(callingAssembly, out Dictionary<string, string>? idMapping)) if (!_idMappings.TryGetValue(callingAssembly, out Dictionary<string, string>? idMapping))
{ {
_idMappings.Add(callingAssembly, idMapping = new Dictionary<string, string>()); _idMappings.Add(callingAssembly, idMapping = []);
_counter.Add(callingAssembly, new Dictionary<string, int>()); _counter.Add(callingAssembly, []);
} }
Dictionary<string, int> counterMapping = _counter[callingAssembly]; Dictionary<string, int> counterMapping = _counter[callingAssembly];

View File

@ -13,14 +13,14 @@ public sealed class LedMapping<T> : IEnumerable<(LedId ledId, T mapping)>
{ {
#region Constants #region Constants
public static LedMapping<T> Empty { get; } = new(); public static LedMapping<T> Empty { get; } = [];
#endregion #endregion
#region Properties & Fields #region Properties & Fields
private readonly Dictionary<LedId, T> _mapping = new(); private readonly Dictionary<LedId, T> _mapping = [];
private readonly Dictionary<T, LedId> _reverseMapping = new(); private readonly Dictionary<T, LedId> _reverseMapping = [];
/// <summary> /// <summary>
/// Gets the number of entries in this mapping. /// Gets the number of entries in this mapping.

View File

@ -5,5 +5,4 @@ namespace RGB.NET.Core;
/// <summary> /// <summary>
/// Represents a basic bindable class which notifies when a property value changes. /// Represents a basic bindable class which notifies when a property value changes.
/// </summary> /// </summary>
public interface IBindable : INotifyPropertyChanged public interface IBindable : INotifyPropertyChanged;
{ }

View File

@ -6,7 +6,7 @@ public abstract class AbstractReferenceCounting : IReferenceCounting
{ {
#region Properties & Fields #region Properties & Fields
private readonly HashSet<object> _referencingObjects = new(); private readonly HashSet<object> _referencingObjects = [];
/// <inheritdoc /> /// <inheritdoc />
public int ActiveReferenceCount public int ActiveReferenceCount

View File

@ -2,26 +2,11 @@
namespace RGB.NET.Core; namespace RGB.NET.Core;
public sealed class ActionDisposable : IDisposable public sealed class ActionDisposable(Action onDispose) : IDisposable
{ {
#region Properties & Fields
private readonly Action _onDispose;
#endregion
#region Constructors
public ActionDisposable(Action onDispose)
{
this._onDispose = onDispose;
}
#endregion
#region Methods #region Methods
public void Dispose() => _onDispose(); public void Dispose() => onDispose();
#endregion #endregion
} }

View File

@ -22,7 +22,7 @@ public sealed class RGBSurface : AbstractBindable, IDisposable
private readonly IList<IRGBDevice> _devices = new List<IRGBDevice>(); private readonly IList<IRGBDevice> _devices = new List<IRGBDevice>();
private readonly IList<IUpdateTrigger> _updateTriggers = new List<IUpdateTrigger>(); private readonly IList<IUpdateTrigger> _updateTriggers = new List<IUpdateTrigger>();
private readonly List<ILedGroup> _ledGroups = new(); private readonly List<ILedGroup> _ledGroups = [];
/// <summary> /// <summary>
/// Gets a readonly list containing all loaded <see cref="IRGBDevice"/>. /// Gets a readonly list containing all loaded <see cref="IRGBDevice"/>.
@ -184,7 +184,7 @@ public sealed class RGBSurface : AbstractBindable, IDisposable
{ {
List<IRGBDevice> devices; List<IRGBDevice> devices;
lock (Devices) lock (Devices)
devices = new List<IRGBDevice>(_devices); devices = [.._devices];
foreach (IRGBDevice device in devices) foreach (IRGBDevice device in devices)
try { Detach(device); } try { Detach(device); }

View File

@ -52,7 +52,7 @@ public sealed class CustomUpdateData : ICustomUpdateData
{ {
#region Properties & Fields #region Properties & Fields
private readonly Dictionary<string, object?> _data = new(); private readonly Dictionary<string, object?> _data = [];
#endregion #endregion

View File

@ -31,5 +31,4 @@ public interface IUpdateQueue<TIdentifier, TData> : IReferenceCounting, IDisposa
/// <summary> /// <summary>
/// Represents a generic update queue processing <see cref="Color"/>-data using <see cref="object"/>-identifiers. /// Represents a generic update queue processing <see cref="Color"/>-data using <see cref="object"/>-identifiers.
/// </summary> /// </summary>
public interface IUpdateQueue : IUpdateQueue<object, Color> public interface IUpdateQueue : IUpdateQueue<object, Color>;
{ }

View File

@ -16,7 +16,7 @@ public abstract class UpdateQueue<TIdentifier, TData> : AbstractReferenceCountin
private readonly object _dataLock = new(); private readonly object _dataLock = new();
private readonly IDeviceUpdateTrigger _updateTrigger; private readonly IDeviceUpdateTrigger _updateTrigger;
private readonly Dictionary<TIdentifier, TData> _currentDataSet = new(); private readonly Dictionary<TIdentifier, TData> _currentDataSet = [];
/// <inheritdoc /> /// <inheritdoc />
public bool RequiresFlush { get; private set; } public bool RequiresFlush { get; private set; }

View File

@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Asus;
/// <summary> /// <summary>
/// Represents a asus RGB-device. /// Represents a asus RGB-device.
/// </summary> /// </summary>
public interface IAsusRGBDevice : IRGBDevice public interface IAsusRGBDevice : IRGBDevice;
{ }

View File

@ -25,8 +25,8 @@ public sealed class AsusKeyboardRGBDevice : AsusRGBDevice<AsusKeyboardRGBDeviceI
#region Properties & Fields #region Properties & Fields
private readonly LedMapping<AsusLedId>? _ledMapping; private readonly LedMapping<AsusLedId>? _ledMapping;
private readonly Dictionary<LedId, AsusLedId> _ledAsusLed = new(); private readonly Dictionary<LedId, AsusLedId> _ledAsusLed = [];
private readonly Dictionary<LedId, int> _ledAsusLights = new(); private readonly Dictionary<LedId, int> _ledAsusLights = [];
IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo; IKeyboardDeviceInfo IKeyboard.DeviceInfo => DeviceInfo;
@ -35,11 +35,11 @@ public sealed class AsusKeyboardRGBDevice : AsusRGBDevice<AsusKeyboardRGBDeviceI
/// <para>Note: These LED mappings should be based on light indexes.</para> /// <para>Note: These LED mappings should be based on light indexes.</para>
/// </summary> /// </summary>
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
public static readonly List<AsusKeyboardExtraMapping> ExtraLedMappings = new() public static readonly List<AsusKeyboardExtraMapping> ExtraLedMappings =
{ [
new AsusKeyboardExtraMapping(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15), new AsusKeyboardExtraMapping(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15),
new AsusKeyboardExtraMapping(new Regex("(ROG Strix G513QM).*?"), LedMappings.ROGStrixG15) new AsusKeyboardExtraMapping(new Regex("(ROG Strix G513QM).*?"), LedMappings.ROGStrixG15)
}; ];
#endregion #endregion
@ -66,7 +66,7 @@ public sealed class AsusKeyboardRGBDevice : AsusRGBDevice<AsusKeyboardRGBDeviceI
private void InitializeLayout() private void InitializeLayout()
{ {
if (DeviceInfo.Device.Type != (uint)AsusDeviceType.NB_KB_4ZONE_RGB && DeviceInfo.Device.Type !=(uint)AsusDeviceType.KEYBOARD_5ZONE_RGB) if ((DeviceInfo.Device.Type != (uint)AsusDeviceType.NB_KB_4ZONE_RGB) && (DeviceInfo.Device.Type !=(uint)AsusDeviceType.KEYBOARD_5ZONE_RGB))
{ {
int pos = 0; int pos = 0;
int unknownLed = (int)LedId.Unknown1; int unknownLed = (int)LedId.Unknown1;

View File

@ -15,7 +15,7 @@ public sealed class AsusKeyboardRGBDeviceInfo : AsusRGBDeviceInfo, IKeyboardDevi
/// The ASUS SDK returns useless names for notebook keyboards, possibly for others as well. /// The ASUS SDK returns useless names for notebook keyboards, possibly for others as well.
/// Keep a list of those and rely on <see cref="WMIHelper.GetSystemModelInfo()"/> to get the real model /// Keep a list of those and rely on <see cref="WMIHelper.GetSystemModelInfo()"/> to get the real model
/// </summary> /// </summary>
private static readonly List<string> GENERIC_DEVICE_NAMES = new() { "NotebookKeyboard" }; private static readonly List<string> GENERIC_DEVICE_NAMES = ["NotebookKeyboard"];
/// <inheritdoc /> /// <inheritdoc />
public KeyboardLayoutType Layout => KeyboardLayoutType.Unknown; public KeyboardLayoutType Layout => KeyboardLayoutType.Unknown;

View File

@ -37,13 +37,13 @@ public sealed class CoolerMasterDeviceProvider : AbstractRGBDeviceProvider
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/CMSDK.dll" }; public static List<string> PossibleX86NativePaths { get; } = ["x86/CMSDK.dll"];
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/CMSDK.dll" }; public static List<string> PossibleX64NativePaths { get; } = ["x64/CMSDK.dll"];
#endregion #endregion

View File

@ -5,5 +5,4 @@ namespace RGB.NET.Devices.CoolerMaster;
/// <summary> /// <summary>
/// Represents a CoolerMaster RGB-device. /// Represents a CoolerMaster RGB-device.
/// </summary> /// </summary>
public interface ICoolerMasterRGBDevice : IRGBDevice public interface ICoolerMasterRGBDevice : IRGBDevice;
{ }

View File

@ -16,14 +16,14 @@ internal static class _CoolerMasterSDK
{ {
#region Libary Management #region Libary Management
private static IntPtr _handle = IntPtr.Zero; private static nint _handle = 0;
/// <summary> /// <summary>
/// Reloads the SDK. /// Reloads the SDK.
/// </summary> /// </summary>
internal static void Reload() internal static void Reload()
{ {
if (_handle != IntPtr.Zero) if (_handle != 0)
{ {
foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes))) foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes)))
EnableLedControl(false, index); EnableLedControl(false, index);
@ -34,7 +34,7 @@ internal static class _CoolerMasterSDK
private static void LoadCMSDK() private static void LoadCMSDK()
{ {
if (_handle != IntPtr.Zero) return; if (_handle != 0) return;
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll // HACK: Load library at runtime to support both, x86 and x64 with one managed dll
List<string> possiblePathList = (Environment.Is64BitProcess ? CoolerMasterDeviceProvider.PossibleX64NativePaths : CoolerMasterDeviceProvider.PossibleX86NativePaths) List<string> possiblePathList = (Environment.Is64BitProcess ? CoolerMasterDeviceProvider.PossibleX64NativePaths : CoolerMasterDeviceProvider.PossibleX86NativePaths)
@ -47,7 +47,7 @@ internal static class _CoolerMasterSDK
#if NET6_0 #if NET6_0
if (_handle == IntPtr.Zero) throw new RGBDeviceException($"CoolerMaster LoadLibrary failed with error code {Marshal.GetLastPInvokeError()}"); if (_handle == IntPtr.Zero) throw new RGBDeviceException($"CoolerMaster LoadLibrary failed with error code {Marshal.GetLastPInvokeError()}");
#else #else
if (_handle == IntPtr.Zero) throw new RGBDeviceException($"CoolerMaster LoadLibrary failed with error code {Marshal.GetLastWin32Error()}"); if (_handle == 0) throw new RGBDeviceException($"CoolerMaster LoadLibrary failed with error code {Marshal.GetLastWin32Error()}");
#endif #endif
_getSDKVersionPointer = (GetSDKVersionPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_handle, "GetCM_SDK_DllVer"), typeof(GetSDKVersionPointer)); _getSDKVersionPointer = (GetSDKVersionPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_handle, "GetCM_SDK_DllVer"), typeof(GetSDKVersionPointer));
@ -62,7 +62,7 @@ internal static class _CoolerMasterSDK
internal static void UnloadCMSDK() internal static void UnloadCMSDK()
{ {
if (_handle == IntPtr.Zero) return; if (_handle == 0) return;
_getSDKVersionPointer = null; _getSDKVersionPointer = null;
_setControlDevicenPointer = null; _setControlDevicenPointer = null;
@ -74,14 +74,14 @@ internal static class _CoolerMasterSDK
_setAllLedColorPointer = null; _setAllLedColorPointer = null;
NativeLibrary.Free(_handle); NativeLibrary.Free(_handle);
_handle = IntPtr.Zero; _handle = 0;
} }
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr LoadLibrary(string dllToLoad); private static extern nint LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll", CharSet = CharSet.Ansi)] [DllImport("kernel32.dll", CharSet = CharSet.Ansi)]
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name); private static extern nint GetProcAddress(nint dllHandle, string name);
#endregion #endregion

View File

@ -37,13 +37,13 @@ public sealed class CorsairDeviceProvider : AbstractRGBDeviceProvider
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/iCUESDK.dll", "x86/CUESDK_2019.dll" }; public static List<string> PossibleX86NativePaths { get; } = ["x86/iCUESDK.dll", "x86/CUESDK_2019.dll"];
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/iCUESDK.dll", "x64/iCUESDK.x64_2019.dll", "x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll" }; public static List<string> PossibleX64NativePaths { get; } = ["x64/iCUESDK.dll", "x64/iCUESDK.x64_2019.dll", "x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll"];
/// <summary> /// <summary>
/// Gets or sets the timeout used when connecting to the SDK. /// Gets or sets the timeout used when connecting to the SDK.

View File

@ -165,7 +165,7 @@ internal static class LedMappings
internal static LedMapping<CorsairLedId> CreateMapping(IEnumerable<CorsairLedId> ids, LedId referenceId) internal static LedMapping<CorsairLedId> CreateMapping(IEnumerable<CorsairLedId> ids, LedId referenceId)
{ {
LedMapping<CorsairLedId> mapping = new(); LedMapping<CorsairLedId> mapping = [];
int counter = 0; int counter = 0;
foreach (CorsairLedId corsairLedId in ids.OrderBy(x => x)) foreach (CorsairLedId corsairLedId in ids.OrderBy(x => x))
mapping.Add(referenceId + counter++, corsairLedId); mapping.Add(referenceId + counter++, corsairLedId);

View File

@ -19,6 +19,7 @@ internal sealed class _CorsairDeviceFilter
/// <summary> /// <summary>
/// iCUE-SDK: mask that describes device types, formed as logical “or” of CorsairDeviceType enum values /// iCUE-SDK: mask that describes device types, formed as logical “or” of CorsairDeviceType enum values
/// </summary> /// </summary>
// ReSharper disable once NotAccessedField.Global
internal CorsairDeviceType deviceTypeMask; internal CorsairDeviceType deviceTypeMask;
#endregion #endregion

View File

@ -38,13 +38,13 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/CUESDK.dll", "x86/CUESDK_2019.dll", "x86/CUESDK_2017.dll", "x86/CUESDK_2015.dll", "x86/CUESDK_2013.dll" }; public static List<string> PossibleX86NativePaths { get; } = ["x86/CUESDK.dll", "x86/CUESDK_2019.dll", "x86/CUESDK_2017.dll", "x86/CUESDK_2015.dll", "x86/CUESDK_2013.dll"];
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll", "x64/CUESDK.x64_2017.dll", "x64/CUESDK_2019.dll", "x64/CUESDK_2017.dll", "x64/CUESDK_2015.dll", "x64/CUESDK_2013.dll" }; public static List<string> PossibleX64NativePaths { get; } = ["x64/CUESDK.dll", "x64/CUESDK.x64_2019.dll", "x64/CUESDK.x64_2017.dll", "x64/CUESDK_2019.dll", "x64/CUESDK_2017.dll", "x64/CUESDK_2015.dll", "x64/CUESDK_2013.dll"];
/// <summary> /// <summary>
/// Gets the protocol details for the current SDK-connection. /// Gets the protocol details for the current SDK-connection.
@ -170,7 +170,7 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider
foreach (_CorsairChannelInfo channelInfo in channels) foreach (_CorsairChannelInfo channelInfo in channels)
{ {
int channelDeviceInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelDeviceInfo)); int channelDeviceInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelDeviceInfo));
IntPtr channelDeviceInfoPtr = channelInfo.devices; nint channelDeviceInfoPtr = channelInfo.devices;
for (int device = 0; (device < channelInfo.devicesCount) && (ledOffset < nativeDeviceInfo.ledsCount); device++) for (int device = 0; (device < channelInfo.devicesCount) && (ledOffset < nativeDeviceInfo.ledsCount); device++)
{ {
_CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo))!; _CorsairChannelDeviceInfo channelDeviceInfo = (_CorsairChannelDeviceInfo)Marshal.PtrToStructure(channelDeviceInfoPtr, typeof(_CorsairChannelDeviceInfo))!;
@ -178,7 +178,7 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider
yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(i, nativeDeviceInfo, channelDeviceInfo, ledOffset), updateQueue); yield return new CorsairCustomRGBDevice(new CorsairCustomRGBDeviceInfo(i, nativeDeviceInfo, channelDeviceInfo, ledOffset), updateQueue);
ledOffset += channelDeviceInfo.deviceLedCount; ledOffset += channelDeviceInfo.deviceLedCount;
channelDeviceInfoPtr = new IntPtr(channelDeviceInfoPtr.ToInt64() + channelDeviceInfoStructSize); channelDeviceInfoPtr += channelDeviceInfoStructSize;
} }
} }
break; break;
@ -195,13 +195,13 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider
_CorsairChannelsInfo? channelsInfo = deviceInfo.channels; _CorsairChannelsInfo? channelsInfo = deviceInfo.channels;
if (channelsInfo == null) yield break; if (channelsInfo == null) yield break;
IntPtr channelInfoPtr = channelsInfo.channels; nint channelInfoPtr = channelsInfo.channels;
for (int channel = 0; channel < channelsInfo.channelsCount; channel++) for (int channel = 0; channel < channelsInfo.channelsCount; channel++)
{ {
yield return (_CorsairChannelInfo)Marshal.PtrToStructure(channelInfoPtr, typeof(_CorsairChannelInfo))!; yield return (_CorsairChannelInfo)Marshal.PtrToStructure(channelInfoPtr, typeof(_CorsairChannelInfo))!;
int channelInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelInfo)); int channelInfoStructSize = Marshal.SizeOf(typeof(_CorsairChannelInfo));
channelInfoPtr = new IntPtr(channelInfoPtr.ToInt64() + channelInfoStructSize); channelInfoPtr += channelInfoStructSize;
} }
} }

View File

@ -1,7 +1,6 @@
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System;
using System.Linq; using System.Linq;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
@ -24,7 +23,7 @@ public class CorsairCustomRGBDevice : CorsairRGBDevice<CorsairCustomRGBDeviceInf
/// <param name="info">The specific information provided by CUE for the custom-device.</param> /// <param name="info">The specific information provided by CUE for the custom-device.</param>
/// <param name="updateQueue">The queue used to update this device.</param> /// <param name="updateQueue">The queue used to update this device.</param>
internal CorsairCustomRGBDevice(CorsairCustomRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue) internal CorsairCustomRGBDevice(CorsairCustomRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, new LedMapping<CorsairLedId>(), updateQueue) : base(info, [], updateQueue)
{ } { }
#endregion #endregion
@ -40,7 +39,7 @@ public class CorsairCustomRGBDevice : CorsairRGBDevice<CorsairCustomRGBDeviceInf
if (nativeLedPositions == null) return; if (nativeLedPositions == null) return;
int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition)); int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition));
IntPtr ptr = new(nativeLedPositions.pLedPosition.ToInt64() + (structSize * DeviceInfo.LedOffset)); nint ptr = nativeLedPositions.pLedPosition + (structSize * DeviceInfo.LedOffset);
LedId referenceLedId = GetReferenceLed(DeviceInfo.DeviceType); LedId referenceLedId = GetReferenceLed(DeviceInfo.DeviceType);
for (int i = 0; i < DeviceInfo.LedCount; i++) for (int i = 0; i < DeviceInfo.LedCount; i++)
@ -49,7 +48,7 @@ public class CorsairCustomRGBDevice : CorsairRGBDevice<CorsairCustomRGBDeviceInf
_CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition)); _CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
if (ledPosition == null) if (ledPosition == null)
{ {
ptr = new IntPtr(ptr.ToInt64() + structSize); ptr += structSize;
continue; continue;
} }
@ -60,7 +59,7 @@ public class CorsairCustomRGBDevice : CorsairRGBDevice<CorsairCustomRGBDeviceInf
Rectangle rectangle = ledPosition.ToRectangle(); Rectangle rectangle = ledPosition.ToRectangle();
AddLed(ledId, rectangle.Location, rectangle.Size); AddLed(ledId, rectangle.Location, rectangle.Size);
ptr = new IntPtr(ptr.ToInt64() + structSize); ptr += structSize;
} }
if (DeviceInfo.LedOffset > 0) if (DeviceInfo.LedOffset > 0)

View File

@ -41,7 +41,7 @@ public class CorsairCustomRGBDeviceInfo : CorsairRGBDeviceInfo
/// <param name="ledOffset">The offset used to find the LEDs of this device.</param> /// <param name="ledOffset">The offset used to find the LEDs of this device.</param>
internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo, int ledOffset) internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo, int ledOffset)
: base(deviceIndex, GetDeviceType(channelDeviceInfo.type), nativeInfo, : base(deviceIndex, GetDeviceType(channelDeviceInfo.type), nativeInfo,
GetModelName(nativeInfo.model == IntPtr.Zero ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase), channelDeviceInfo)) GetModelName(nativeInfo.model == 0 ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase), channelDeviceInfo))
{ {
this.LedOffset = ledOffset; this.LedOffset = ledOffset;

View File

@ -40,8 +40,8 @@ public class CorsairDeviceUpdateQueue : UpdateQueue
try try
{ {
int structSize = Marshal.SizeOf(typeof(_CorsairLedColor)); int structSize = Marshal.SizeOf(typeof(_CorsairLedColor));
IntPtr ptr = Marshal.AllocHGlobal(structSize * dataSet.Length); nint ptr = Marshal.AllocHGlobal(structSize * dataSet.Length);
IntPtr addPtr = new(ptr.ToInt64()); nint addPtr = ptr;
try try
{ {
foreach ((object key, Color color) in dataSet) foreach ((object key, Color color) in dataSet)
@ -55,7 +55,7 @@ public class CorsairDeviceUpdateQueue : UpdateQueue
}; };
Marshal.StructureToPtr(corsairColor, addPtr, false); Marshal.StructureToPtr(corsairColor, addPtr, false);
addPtr = new IntPtr(addPtr.ToInt64() + structSize); addPtr += structSize;
} }
_CUESDK.CorsairSetLedsColorsBufferByDeviceIndex(_deviceIndex, dataSet.Length, ptr); _CUESDK.CorsairSetLedsColorsBufferByDeviceIndex(_deviceIndex, dataSet.Length, ptr);

View File

@ -1,7 +1,6 @@
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global // ReSharper disable UnusedAutoPropertyAccessor.Global
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using RGB.NET.Devices.CorsairLegacy.Native; using RGB.NET.Devices.CorsairLegacy.Native;
@ -54,8 +53,8 @@ public class CorsairProtocolDetails
/// <param name="nativeDetails">The native CorsairProtocolDetails-struct</param> /// <param name="nativeDetails">The native CorsairProtocolDetails-struct</param>
internal CorsairProtocolDetails(_CorsairProtocolDetails nativeDetails) internal CorsairProtocolDetails(_CorsairProtocolDetails nativeDetails)
{ {
this.SdkVersion = nativeDetails.sdkVersion == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeDetails.sdkVersion); this.SdkVersion = nativeDetails.sdkVersion == 0 ? null : Marshal.PtrToStringAnsi(nativeDetails.sdkVersion);
this.ServerVersion = nativeDetails.serverVersion == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeDetails.serverVersion); this.ServerVersion = nativeDetails.serverVersion == 0 ? null : Marshal.PtrToStringAnsi(nativeDetails.serverVersion);
this.SdkProtocolVersion = nativeDetails.sdkProtocolVersion; this.SdkProtocolVersion = nativeDetails.sdkProtocolVersion;
this.ServerProtocolVersion = nativeDetails.serverProtocolVersion; this.ServerProtocolVersion = nativeDetails.serverProtocolVersion;
this.BreakingChanges = nativeDetails.breakingChanges != 0; this.BreakingChanges = nativeDetails.breakingChanges != 0;

View File

@ -1,5 +1,4 @@
using System; using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.CorsairLegacy.Native; using RGB.NET.Devices.CorsairLegacy.Native;
@ -50,14 +49,14 @@ public abstract class CorsairRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceI
if (nativeLedPositions == null) return; if (nativeLedPositions == null) return;
int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition)); int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition));
IntPtr ptr = nativeLedPositions.pLedPosition; nint ptr = nativeLedPositions.pLedPosition;
for (int i = 0; i < nativeLedPositions.numberOfLed; i++) for (int i = 0; i < nativeLedPositions.numberOfLed; i++)
{ {
_CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition)); _CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
if (ledPosition == null) if (ledPosition == null)
{ {
ptr = new IntPtr(ptr.ToInt64() + structSize); ptr += structSize;
continue; continue;
} }
@ -65,7 +64,7 @@ public abstract class CorsairRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceI
Rectangle rectangle = ledPosition.ToRectangle(); Rectangle rectangle = ledPosition.ToRectangle();
AddLed(ledId, rectangle.Location, rectangle.Size); AddLed(ledId, rectangle.Location, rectangle.Size);
ptr = new IntPtr(ptr.ToInt64() + structSize); ptr += structSize;
} }
} }

View File

@ -1,5 +1,4 @@
using System; using System.Runtime.InteropServices;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using RGB.NET.Core; using RGB.NET.Core;
using RGB.NET.Devices.CorsairLegacy.Native; using RGB.NET.Devices.CorsairLegacy.Native;
@ -65,7 +64,7 @@ public class CorsairRGBDeviceInfo : IRGBDeviceInfo
this.CorsairDeviceIndex = deviceIndex; this.CorsairDeviceIndex = deviceIndex;
this.DeviceType = deviceType; this.DeviceType = deviceType;
this.CorsairDeviceType = nativeInfo.type; this.CorsairDeviceType = nativeInfo.type;
this.Model = nativeInfo.model == IntPtr.Zero ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase); this.Model = nativeInfo.model == 0 ? string.Empty : Regex.Replace(Marshal.PtrToStringAnsi(nativeInfo.model) ?? string.Empty, " ?DEMO", string.Empty, RegexOptions.IgnoreCase);
this.DeviceId = nativeInfo.deviceId ?? string.Empty; this.DeviceId = nativeInfo.deviceId ?? string.Empty;
this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask; this.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask;

View File

@ -34,27 +34,27 @@ public static class LedMappings
/// <summary> /// <summary>
/// Gets the mapping for graphics cards. /// Gets the mapping for graphics cards.
/// </summary> /// </summary>
public static LedMapping<CorsairLedId> GraphicsCard { get; } = new(); public static LedMapping<CorsairLedId> GraphicsCard { get; } = [];
/// <summary> /// <summary>
/// Gets the mapping for headsets. /// Gets the mapping for headsets.
/// </summary> /// </summary>
public static LedMapping<CorsairLedId> HeadsetStand { get; } = new(); public static LedMapping<CorsairLedId> HeadsetStand { get; } = [];
/// <summary> /// <summary>
/// Gets the mapping for mainboards. /// Gets the mapping for mainboards.
/// </summary> /// </summary>
public static LedMapping<CorsairLedId> Mainboard { get; } = new(); public static LedMapping<CorsairLedId> Mainboard { get; } = [];
/// <summary> /// <summary>
/// Gets the mapping for memory. /// Gets the mapping for memory.
/// </summary> /// </summary>
public static LedMapping<CorsairLedId> Memory { get; } = new(); public static LedMapping<CorsairLedId> Memory { get; } = [];
/// <summary> /// <summary>
/// Gets the mapping for mousepads. /// Gets the mapping for mousepads.
/// </summary> /// </summary>
public static LedMapping<CorsairLedId> Mousepad { get; } = new(); public static LedMapping<CorsairLedId> Mousepad { get; } = [];
/// <summary> /// <summary>
/// Gets the mapping for headsets. /// Gets the mapping for headsets.

View File

@ -7,7 +7,7 @@ internal static class NativeExtensions
{ {
internal static Rectangle ToRectangle(this _CorsairLedPosition position) internal static Rectangle ToRectangle(this _CorsairLedPosition position)
{ {
//HACK DarthAffe 08.07.2018: It seems like corsair introduced a bug here - it's always 0. //HACK DarthAffe 08.07.2018: It seems like corsair introduced a issue here - it's always 0.
float width = position.width < 0.5f ? 10 : (float)position.width; float width = position.width < 0.5f ? 10 : (float)position.width;
float height = position.height < 0.5f ? 10 : (float)position.height; float height = position.height < 0.5f ? 10 : (float)position.height;
float posX = (float)position.left; float posX = (float)position.left;

View File

@ -16,7 +16,7 @@ internal static class _CUESDK
{ {
#region Libary Management #region Libary Management
private static IntPtr _handle = IntPtr.Zero; private static nint _handle = 0;
/// <summary> /// <summary>
/// Reloads the SDK. /// Reloads the SDK.
@ -29,7 +29,7 @@ internal static class _CUESDK
private static void LoadCUESDK() private static void LoadCUESDK()
{ {
if (_handle != IntPtr.Zero) return; if (_handle != 0) return;
List<string> possiblePathList = GetPossibleLibraryPaths().ToList(); List<string> possiblePathList = GetPossibleLibraryPaths().ToList();
@ -71,23 +71,23 @@ internal static class _CUESDK
internal static void UnloadCUESDK() internal static void UnloadCUESDK()
{ {
if (_handle == IntPtr.Zero) return; if (_handle == 0) return;
_corsairSetLedsColorsBufferByDeviceIndexPointer = IntPtr.Zero; _corsairSetLedsColorsBufferByDeviceIndexPointer = 0;
_corsairSetLedsColorsFlushBufferPointer = IntPtr.Zero; _corsairSetLedsColorsFlushBufferPointer = 0;
_corsairGetLedsColorsByDeviceIndexPointer = IntPtr.Zero; _corsairGetLedsColorsByDeviceIndexPointer = 0;
_corsairSetLayerPriorityPointer = IntPtr.Zero; _corsairSetLayerPriorityPointer = 0;
_corsairGetDeviceCountPointer = IntPtr.Zero; _corsairGetDeviceCountPointer = 0;
_corsairGetDeviceInfoPointer = IntPtr.Zero; _corsairGetDeviceInfoPointer = 0;
_corsairGetLedIdForKeyNamePointer = IntPtr.Zero; _corsairGetLedIdForKeyNamePointer = 0;
_corsairGetLedPositionsByDeviceIndexPointer = IntPtr.Zero; _corsairGetLedPositionsByDeviceIndexPointer = 0;
_corsairRequestControlPointer = IntPtr.Zero; _corsairRequestControlPointer = 0;
_corsairReleaseControlPointer = IntPtr.Zero; _corsairReleaseControlPointer = 0;
_corsairPerformProtocolHandshakePointer = IntPtr.Zero; _corsairPerformProtocolHandshakePointer = 0;
_corsairGetLastErrorPointer = IntPtr.Zero; _corsairGetLastErrorPointer = 0;
NativeLibrary.Free(_handle); NativeLibrary.Free(_handle);
_handle = IntPtr.Zero; _handle = 0;
} }
#endregion #endregion
@ -96,18 +96,18 @@ internal static class _CUESDK
#region Pointers #region Pointers
private static IntPtr _corsairSetLedsColorsBufferByDeviceIndexPointer; private static nint _corsairSetLedsColorsBufferByDeviceIndexPointer;
private static IntPtr _corsairSetLedsColorsFlushBufferPointer; private static nint _corsairSetLedsColorsFlushBufferPointer;
private static IntPtr _corsairGetLedsColorsByDeviceIndexPointer; private static nint _corsairGetLedsColorsByDeviceIndexPointer;
private static IntPtr _corsairSetLayerPriorityPointer; private static nint _corsairSetLayerPriorityPointer;
private static IntPtr _corsairGetDeviceCountPointer; private static nint _corsairGetDeviceCountPointer;
private static IntPtr _corsairGetDeviceInfoPointer; private static nint _corsairGetDeviceInfoPointer;
private static IntPtr _corsairGetLedIdForKeyNamePointer; private static nint _corsairGetLedIdForKeyNamePointer;
private static IntPtr _corsairGetLedPositionsByDeviceIndexPointer; private static nint _corsairGetLedPositionsByDeviceIndexPointer;
private static IntPtr _corsairRequestControlPointer; private static nint _corsairRequestControlPointer;
private static IntPtr _corsairReleaseControlPointer; private static nint _corsairReleaseControlPointer;
private static IntPtr _corsairPerformProtocolHandshakePointer; private static nint _corsairPerformProtocolHandshakePointer;
private static IntPtr _corsairGetLastErrorPointer; private static nint _corsairGetLastErrorPointer;
#endregion #endregion
@ -118,8 +118,8 @@ internal static class _CUESDK
/// and follows after one or more calls of CorsairSetLedsColorsBufferByDeviceIndex to set the LEDs buffer. /// and follows after one or more calls of CorsairSetLedsColorsBufferByDeviceIndex to set the LEDs buffer.
/// This function does not take logical layout into account. /// This function does not take logical layout into account.
/// </summary> /// </summary>
internal static unsafe bool CorsairSetLedsColorsBufferByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors) internal static unsafe bool CorsairSetLedsColorsBufferByDeviceIndex(int deviceIndex, int size, nint ledsColors)
=> ((delegate* unmanaged[Cdecl]<int, int, IntPtr, bool>)ThrowIfZero(_corsairSetLedsColorsBufferByDeviceIndexPointer))(deviceIndex, size, ledsColors); => ((delegate* unmanaged[Cdecl]<int, int, nint, bool>)ThrowIfZero(_corsairSetLedsColorsBufferByDeviceIndexPointer))(deviceIndex, size, ledsColors);
/// <summary> /// <summary>
/// CUE-SDK: writes to the devices LEDs colors buffer which is previously filled by the CorsairSetLedsColorsBufferByDeviceIndex function. /// CUE-SDK: writes to the devices LEDs colors buffer which is previously filled by the CorsairSetLedsColorsBufferByDeviceIndex function.
@ -132,8 +132,8 @@ internal static class _CUESDK
/// The color should represent the actual state of the hardware LED, which could be a combination of SDK and/or CUE input. /// The color should represent the actual state of the hardware LED, which could be a combination of SDK and/or CUE input.
/// This function works for keyboard, mouse, mousemat, headset, headset stand and DIY-devices. /// This function works for keyboard, mouse, mousemat, headset, headset stand and DIY-devices.
/// </summary> /// </summary>
internal static unsafe bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, int size, IntPtr ledsColors) internal static unsafe bool CorsairGetLedsColorsByDeviceIndex(int deviceIndex, int size, nint ledsColors)
=> ((delegate* unmanaged[Cdecl]<int, int, IntPtr, bool>)ThrowIfZero(_corsairGetLedsColorsByDeviceIndexPointer))(deviceIndex, size, ledsColors); => ((delegate* unmanaged[Cdecl]<int, int, nint, bool>)ThrowIfZero(_corsairGetLedsColorsByDeviceIndexPointer))(deviceIndex, size, ledsColors);
/// <summary> /// <summary>
/// CUE-SDK: set layer priority for this shared client. /// CUE-SDK: set layer priority for this shared client.
@ -150,12 +150,12 @@ internal static class _CUESDK
/// <summary> /// <summary>
/// CUE-SDK: returns information about device at provided index. /// CUE-SDK: returns information about device at provided index.
/// </summary> /// </summary>
internal static unsafe IntPtr CorsairGetDeviceInfo(int deviceIndex) => ((delegate* unmanaged[Cdecl]<int, IntPtr>)ThrowIfZero(_corsairGetDeviceInfoPointer))(deviceIndex); internal static unsafe nint CorsairGetDeviceInfo(int deviceIndex) => ((delegate* unmanaged[Cdecl]<int, nint>)ThrowIfZero(_corsairGetDeviceInfoPointer))(deviceIndex);
/// <summary> /// <summary>
/// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions. /// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions.
/// </summary> /// </summary>
internal static unsafe IntPtr CorsairGetLedPositionsByDeviceIndex(int deviceIndex) => ((delegate* unmanaged[Cdecl]<int, IntPtr>)ThrowIfZero(_corsairGetLedPositionsByDeviceIndexPointer))(deviceIndex); internal static unsafe nint CorsairGetLedPositionsByDeviceIndex(int deviceIndex) => ((delegate* unmanaged[Cdecl]<int, nint>)ThrowIfZero(_corsairGetLedPositionsByDeviceIndexPointer))(deviceIndex);
/// <summary> /// <summary>
/// CUE-SDK: retrieves led id for key name taking logical layout into account. /// CUE-SDK: retrieves led id for key name taking logical layout into account.
@ -183,9 +183,9 @@ internal static class _CUESDK
/// </summary> /// </summary>
internal static unsafe CorsairError CorsairGetLastError() => ((delegate* unmanaged[Cdecl]<CorsairError>)ThrowIfZero(_corsairGetLastErrorPointer))(); internal static unsafe CorsairError CorsairGetLastError() => ((delegate* unmanaged[Cdecl]<CorsairError>)ThrowIfZero(_corsairGetLastErrorPointer))();
private static IntPtr ThrowIfZero(IntPtr ptr) private static nint ThrowIfZero(nint ptr)
{ {
if (ptr == IntPtr.Zero) throw new RGBDeviceException("The Corsair-SDK is not initialized."); if (ptr == 0) throw new RGBDeviceException("The Corsair-SDK is not initialized.");
return ptr; return ptr;
} }

View File

@ -3,7 +3,6 @@
#pragma warning disable 649 // Field 'x' is never assigned #pragma warning disable 649 // Field 'x' is never assigned
#pragma warning disable IDE1006 // Naming Styles #pragma warning disable IDE1006 // Naming Styles
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace RGB.NET.Devices.CorsairLegacy.Native; namespace RGB.NET.Devices.CorsairLegacy.Native;
@ -29,5 +28,5 @@ internal class _CorsairChannelInfo
/// CUE-SDK: array containing information about each separate LED-device connected to the channel controlled by the DIY device. /// CUE-SDK: array containing information about each separate LED-device connected to the channel controlled by the DIY device.
/// Index of the LED-device in array is same as the index of the LED-device connected to the DIY-device. /// Index of the LED-device in array is same as the index of the LED-device connected to the DIY-device.
/// </summary> /// </summary>
internal IntPtr devices; internal nint devices;
} }

View File

@ -3,7 +3,6 @@
#pragma warning disable 649 // Field 'x' is never assigned #pragma warning disable 649 // Field 'x' is never assigned
#pragma warning disable IDE1006 // Naming Styles #pragma warning disable IDE1006 // Naming Styles
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace RGB.NET.Devices.CorsairLegacy.Native; namespace RGB.NET.Devices.CorsairLegacy.Native;
@ -24,5 +23,5 @@ internal class _CorsairChannelsInfo
/// CUE-SDK: array containing information about each separate channel of the DIY-device. /// CUE-SDK: array containing information about each separate channel of the DIY-device.
/// Index of the channel in the array is same as index of the channel on the DIY-device. /// Index of the channel in the array is same as index of the channel on the DIY-device.
/// </summary> /// </summary>
internal IntPtr channels; internal nint channels;
} }

View File

@ -3,7 +3,6 @@
#pragma warning disable 649 // Field 'x' is never assigned #pragma warning disable 649 // Field 'x' is never assigned
#pragma warning disable IDE1006 // Naming Styles #pragma warning disable IDE1006 // Naming Styles
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace RGB.NET.Devices.CorsairLegacy.Native; namespace RGB.NET.Devices.CorsairLegacy.Native;
@ -23,7 +22,7 @@ internal class _CorsairDeviceInfo
/// <summary> /// <summary>
/// CUE-SDK: null - terminated device model(like “K95RGB”) /// CUE-SDK: null - terminated device model(like “K95RGB”)
/// </summary> /// </summary>
internal IntPtr model; internal nint model;
/// <summary> /// <summary>
/// CUE-SDK: enum describing physical layout of the keyboard or mouse /// CUE-SDK: enum describing physical layout of the keyboard or mouse

View File

@ -2,7 +2,6 @@
#pragma warning disable 414 // Field 'x' is assigned but its value never used #pragma warning disable 414 // Field 'x' is assigned but its value never used
#pragma warning disable 649 // Field 'x' is never assigned #pragma warning disable 649 // Field 'x' is never assigned
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace RGB.NET.Devices.CorsairLegacy.Native; namespace RGB.NET.Devices.CorsairLegacy.Native;
@ -22,5 +21,5 @@ internal class _CorsairLedPositions
/// <summary> /// <summary>
/// CUE-SDK: array of led positions /// CUE-SDK: array of led positions
/// </summary> /// </summary>
internal IntPtr pLedPosition; internal nint pLedPosition;
} }

View File

@ -2,7 +2,6 @@
#pragma warning disable 414 // Field 'x' is assigned but its value never used #pragma warning disable 414 // Field 'x' is assigned but its value never used
#pragma warning disable 649 // Field 'x' is never assigned #pragma warning disable 649 // Field 'x' is never assigned
using System;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
namespace RGB.NET.Devices.CorsairLegacy.Native; namespace RGB.NET.Devices.CorsairLegacy.Native;
@ -17,12 +16,12 @@ internal struct _CorsairProtocolDetails
/// <summary> /// <summary>
/// CUE-SDK: null - terminated string containing version of SDK(like “1.0.0.1”). Always contains valid value even if there was no CUE found /// CUE-SDK: null - terminated string containing version of SDK(like “1.0.0.1”). Always contains valid value even if there was no CUE found
/// </summary> /// </summary>
internal IntPtr sdkVersion; internal nint sdkVersion;
/// <summary> /// <summary>
/// CUE-SDK: null - terminated string containing version of CUE(like “1.0.0.1”) or NULL if CUE was not found. /// CUE-SDK: null - terminated string containing version of CUE(like “1.0.0.1”) or NULL if CUE was not found.
/// </summary> /// </summary>
internal IntPtr serverVersion; internal nint serverVersion;
/// <summary> /// <summary>
/// CUE-SDK: integer number that specifies version of protocol that is implemented by current SDK. /// CUE-SDK: integer number that specifies version of protocol that is implemented by current SDK.

View File

@ -35,7 +35,7 @@ public sealed class DMXDeviceProvider : AbstractRGBDeviceProvider
/// <summary> /// <summary>
/// Gets a list of all defined device-definitions. /// Gets a list of all defined device-definitions.
/// </summary> /// </summary>
public List<IDMXDeviceDefinition> DeviceDefinitions { get; } = new(); public List<IDMXDeviceDefinition> DeviceDefinitions { get; } = [];
#endregion #endregion

View File

@ -55,7 +55,7 @@ public sealed class E131DMXDeviceDefinition : IDMXDeviceDefinition
/// <summary> /// <summary>
/// Gets or sets the led-mappings used to create the device. /// Gets or sets the led-mappings used to create the device.
/// </summary> /// </summary>
public Dictionary<LedId, List<(int channel, Func<Color, byte> getValueFunc)>> Leds { get; } = new(); public Dictionary<LedId, List<(int channel, Func<Color, byte> getValueFunc)>> Leds { get; } = [];
/// <summary> /// <summary>
/// The time in ms after which the device is updated even if no changes are made in the meantime to prevent the target from timing out or similar problems. /// The time in ms after which the device is updated even if no changes are made in the meantime to prevent the target from timing out or similar problems.

View File

@ -3,5 +3,4 @@
/// <summary> /// <summary>
/// Marker interface for DMX device definitions. /// Marker interface for DMX device definitions.
/// </summary> /// </summary>
public interface IDMXDeviceDefinition public interface IDMXDeviceDefinition;
{ }

View File

@ -5,20 +5,12 @@ using RGB.NET.Core;
namespace RGB.NET.Devices.DMX; namespace RGB.NET.Devices.DMX;
internal sealed class LedChannelMapping : IEnumerable<(int channel, Func<Color, byte> getValue)> internal sealed class LedChannelMapping(List<(int channel, Func<Color, byte> getValue)> mappings)
: IEnumerable<(int channel, Func<Color, byte> getValue)>
{ {
#region Properties & Fields #region Properties & Fields
private readonly List<(int channel, Func<Color, byte> getValue)> _mappings; private readonly List<(int channel, Func<Color, byte> getValue)> _mappings = [..mappings];
#endregion
#region Constructors
public LedChannelMapping(List<(int channel, Func<Color, byte> getValue)> mappings)
{
this._mappings = new List<(int channel, Func<Color, byte> getValue)>(mappings);
}
#endregion #endregion

View File

@ -32,7 +32,7 @@ public sealed class DebugDeviceProvider : AbstractRGBDeviceProvider
} }
} }
private List<(IDeviceLayout layout, Action<IEnumerable<Led>>? updateLedsAction)> _fakeDeviceDefinitions = new(); private readonly List<(IDeviceLayout layout, Action<IEnumerable<Led>>? updateLedsAction)> _fakeDeviceDefinitions = [];
#endregion #endregion

View File

@ -3,16 +3,8 @@ using RGB.NET.Core;
namespace RGB.NET.Devices.Debug; namespace RGB.NET.Devices.Debug;
internal sealed class DebugDeviceUpdateQueue : UpdateQueue internal sealed class DebugDeviceUpdateQueue() : UpdateQueue(new DeviceUpdateTrigger())
{ {
#region Constructors
public DebugDeviceUpdateQueue()
: base(new DeviceUpdateTrigger())
{ }
#endregion
#region Methods #region Methods
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) => true; protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) => true;

View File

@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Logitech;
/// <summary> /// <summary>
/// Represents a logitech RGB-device. /// Represents a logitech RGB-device.
/// </summary> /// </summary>
public interface ILogitechRGBDevice : IRGBDevice public interface ILogitechRGBDevice : IRGBDevice;
{ }

View File

@ -23,20 +23,20 @@ public sealed class LightspeedHIDLoader<TLed, TData> : IEnumerable<HIDDeviceDefi
private const int VENDOR_ID = 0x046D; private const int VENDOR_ID = 0x046D;
// ReSharper disable once StaticMemberInGenericType - This is used like a const // ReSharper disable once StaticMemberInGenericType - This is used like a const
private static readonly List<int> RECEIVER_PIDS = new() private static readonly List<int> RECEIVER_PIDS =
{ [
0xC539, 0xC539,
0xC53A, 0xC53A,
0xC541, 0xC541,
0xC545, 0xC545,
0xC547 0xC547
}; ];
#endregion #endregion
#region Properties & Fields #region Properties & Fields
private readonly Dictionary<int, HIDDeviceDefinition<TLed, TData>> _deviceDefinitions = new(); private readonly Dictionary<int, HIDDeviceDefinition<TLed, TData>> _deviceDefinitions = [];
/// <summary> /// <summary>
/// Gets the vendor id used for this loader. /// Gets the vendor id used for this loader.
@ -117,7 +117,7 @@ public sealed class LightspeedHIDLoader<TLed, TData> : IEnumerable<HIDDeviceDefi
const byte LOGITECH_SET_REGISTER_REQUEST = 0x80; const byte LOGITECH_SET_REGISTER_REQUEST = 0x80;
const byte LOGITECH_GET_REGISTER_REQUEST = 0x81; const byte LOGITECH_GET_REGISTER_REQUEST = 0x81;
Dictionary<int, byte> map = new(); Dictionary<int, byte> map = [];
if (!deviceUsages.TryGetValue(1, out HidDevice? device) || !device.TryOpen(out HidStream stream)) if (!deviceUsages.TryGetValue(1, out HidDevice? device) || !device.TryOpen(out HidStream stream))
return map; return map;

View File

@ -40,13 +40,13 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/LogitechLedEnginesWrapper.dll" }; public static List<string> PossibleX86NativePaths { get; } = ["x86/LogitechLedEnginesWrapper.dll"];
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/LogitechLedEnginesWrapper.dll" }; public static List<string> PossibleX64NativePaths { get; } = ["x64/LogitechLedEnginesWrapper.dll"];
private LogitechPerDeviceUpdateQueue? _perDeviceUpdateQueue; private LogitechPerDeviceUpdateQueue? _perDeviceUpdateQueue;
private LogitechPerKeyUpdateQueue? _perKeyUpdateQueue; private LogitechPerKeyUpdateQueue? _perKeyUpdateQueue;
@ -162,7 +162,7 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
/// <summary> /// <summary>
/// Gets the HID-definitions for wireless per-device-devices. /// Gets the HID-definitions for wireless per-device-devices.
/// </summary> /// </summary>
public static LightspeedHIDLoader<int, int> PerDeviceWirelessDeviceDefinitions { get; } = new(); public static LightspeedHIDLoader<int, int> PerDeviceWirelessDeviceDefinitions { get; } = [];
#endregion #endregion

View File

@ -17,7 +17,7 @@ internal static class _LogitechGSDK
{ {
#region Libary Management #region Libary Management
private static IntPtr _handle = IntPtr.Zero; private static nint _handle = 0;
/// <summary> /// <summary>
/// Reloads the SDK. /// Reloads the SDK.
@ -30,7 +30,7 @@ internal static class _LogitechGSDK
private static void LoadLogitechGSDK() private static void LoadLogitechGSDK()
{ {
if (_handle != IntPtr.Zero) return; if (_handle != 0) return;
List<string> possiblePathList = GetPossibleLibraryPaths().ToList(); List<string> possiblePathList = GetPossibleLibraryPaths().ToList();
@ -70,21 +70,21 @@ internal static class _LogitechGSDK
internal static void UnloadLogitechGSDK() internal static void UnloadLogitechGSDK()
{ {
if (_handle == IntPtr.Zero) return; if (_handle == 0) return;
_logiLedInitPointer = IntPtr.Zero; _logiLedInitPointer = 0;
_logiLedShutdownPointer = IntPtr.Zero; _logiLedShutdownPointer = 0;
_logiLedSetTargetDevicePointer = IntPtr.Zero; _logiLedSetTargetDevicePointer = 0;
_logiLedGetSdkVersionPointer = IntPtr.Zero; _logiLedGetSdkVersionPointer = 0;
_lgiLedSaveCurrentLightingPointer = IntPtr.Zero; _lgiLedSaveCurrentLightingPointer = 0;
_logiLedRestoreLightingPointer = IntPtr.Zero; _logiLedRestoreLightingPointer = 0;
_logiLedSetLightingPointer = IntPtr.Zero; _logiLedSetLightingPointer = 0;
_logiLedSetLightingForKeyWithKeyNamePointer = IntPtr.Zero; _logiLedSetLightingForKeyWithKeyNamePointer = 0;
_logiLedSetLightingFromBitmapPointer = IntPtr.Zero; _logiLedSetLightingFromBitmapPointer = 0;
_logiLedSetLightingForTargetZonePointer = IntPtr.Zero; _logiLedSetLightingForTargetZonePointer = 0;
NativeLibrary.Free(_handle); NativeLibrary.Free(_handle);
_handle = IntPtr.Zero; _handle = 0;
} }
#endregion #endregion
@ -93,16 +93,16 @@ internal static class _LogitechGSDK
#region Pointers #region Pointers
private static IntPtr _logiLedInitPointer; private static nint _logiLedInitPointer;
private static IntPtr _logiLedShutdownPointer; private static nint _logiLedShutdownPointer;
private static IntPtr _logiLedSetTargetDevicePointer; private static nint _logiLedSetTargetDevicePointer;
private static IntPtr _logiLedGetSdkVersionPointer; private static nint _logiLedGetSdkVersionPointer;
private static IntPtr _lgiLedSaveCurrentLightingPointer; private static nint _lgiLedSaveCurrentLightingPointer;
private static IntPtr _logiLedRestoreLightingPointer; private static nint _logiLedRestoreLightingPointer;
private static IntPtr _logiLedSetLightingPointer; private static nint _logiLedSetLightingPointer;
private static IntPtr _logiLedSetLightingForKeyWithKeyNamePointer; private static nint _logiLedSetLightingForKeyWithKeyNamePointer;
private static IntPtr _logiLedSetLightingFromBitmapPointer; private static nint _logiLedSetLightingFromBitmapPointer;
private static IntPtr _logiLedSetLightingForTargetZonePointer; private static nint _logiLedSetLightingForTargetZonePointer;
#endregion #endregion
@ -146,9 +146,9 @@ internal static class _LogitechGSDK
internal static unsafe bool LogiLedSetLightingForTargetZone(LogitechDeviceType deviceType, int zone, int redPercentage, int greenPercentage, int bluePercentage) internal static unsafe bool LogiLedSetLightingForTargetZone(LogitechDeviceType deviceType, int zone, int redPercentage, int greenPercentage, int bluePercentage)
=> ((delegate* unmanaged[Cdecl]<LogitechDeviceType, int, int, int, int, bool>)ThrowIfZero(_logiLedSetLightingForTargetZonePointer))(deviceType, zone, redPercentage, greenPercentage, bluePercentage); => ((delegate* unmanaged[Cdecl]<LogitechDeviceType, int, int, int, int, bool>)ThrowIfZero(_logiLedSetLightingForTargetZonePointer))(deviceType, zone, redPercentage, greenPercentage, bluePercentage);
private static IntPtr ThrowIfZero(IntPtr ptr) private static nint ThrowIfZero(nint ptr)
{ {
if (ptr == IntPtr.Zero) throw new RGBDeviceException("The Logitech-SDK is not initialized."); if (ptr == 0) throw new RGBDeviceException("The Logitech-SDK is not initialized.");
return ptr; return ptr;
} }

View File

@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Msi;
/// <summary> /// <summary>
/// Represents a MSI RGB-device. /// Represents a MSI RGB-device.
/// </summary> /// </summary>
public interface IMsiRGBDevice : IRGBDevice public interface IMsiRGBDevice : IRGBDevice;
{ }

View File

@ -37,13 +37,13 @@ public class MsiDeviceProvider : AbstractRGBDeviceProvider
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/MysticLight_SDK.dll" }; public static List<string> PossibleX86NativePaths { get; } = ["x86/MysticLight_SDK.dll"];
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/MysticLight_SDK.dll" }; public static List<string> PossibleX64NativePaths { get; } = ["x64/MysticLight_SDK.dll"];
#endregion #endregion

View File

@ -16,7 +16,7 @@ internal static class _MsiSDK
{ {
#region Libary Management #region Libary Management
private static IntPtr _handle = IntPtr.Zero; private static nint _handle = 0;
/// <summary> /// <summary>
/// Reloads the SDK. /// Reloads the SDK.
@ -29,7 +29,7 @@ internal static class _MsiSDK
private static void LoadMsiSDK() private static void LoadMsiSDK()
{ {
if (_handle != IntPtr.Zero) return; if (_handle != 0) return;
List<string> possiblePathList = GetPossibleLibraryPaths().ToList(); List<string> possiblePathList = GetPossibleLibraryPaths().ToList();
@ -75,7 +75,7 @@ internal static class _MsiSDK
internal static void UnloadMsiSDK() internal static void UnloadMsiSDK()
{ {
if (_handle == IntPtr.Zero) return; if (_handle == 0) return;
_initializePointer = null; _initializePointer = null;
_getDeviceInfoPointer = null; _getDeviceInfoPointer = null;
@ -93,7 +93,7 @@ internal static class _MsiSDK
_getErrorMessagePointer = null; _getErrorMessagePointer = null;
NativeLibrary.Free(_handle); NativeLibrary.Free(_handle);
_handle = IntPtr.Zero; _handle = 0;
} }
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)] [DllImport("kernel32.dll", CharSet = CharSet.Unicode)]

View File

@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Novation;
/// <summary> /// <summary>
/// Represents a novation RGB-device. /// Represents a novation RGB-device.
/// </summary> /// </summary>
public interface INovationRGBDevice : IRGBDevice public interface INovationRGBDevice : IRGBDevice;
{ }

View File

@ -5,5 +5,4 @@ namespace RGB.NET.Devices.OpenRGB;
/// <summary> /// <summary>
/// Represents a generic OpenRGB Device. /// Represents a generic OpenRGB Device.
/// </summary> /// </summary>
public interface IOpenRGBDevice : IRGBDevice public interface IOpenRGBDevice : IRGBDevice;
{ }

View File

@ -17,7 +17,7 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
private static readonly object _lock = new(); private static readonly object _lock = new();
private readonly List<OpenRgbClient> _clients = new(); private readonly List<OpenRgbClient> _clients = [];
private static OpenRGBDeviceProvider? _instance; private static OpenRGBDeviceProvider? _instance;
@ -36,7 +36,7 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
/// <summary> /// <summary>
/// Gets a list of all defined device-definitions. /// Gets a list of all defined device-definitions.
/// </summary> /// </summary>
public List<OpenRGBServerDefinition> DeviceDefinitions { get; } = new(); public List<OpenRGBServerDefinition> DeviceDefinitions { get; } = [];
/// <summary> /// <summary>
/// Indicates whether all devices will be added, or just the ones with a 'Direct' mode. Defaults to false. /// Indicates whether all devices will be added, or just the ones with a 'Direct' mode. Defaults to false.

View File

@ -12,7 +12,7 @@ public static class LedMappings
/// <summary> /// <summary>
/// Gets the defautlt offset-mapping. /// Gets the defautlt offset-mapping.
/// </summary> /// </summary>
public static LedMapping<int> StripeMapping = new(); public static LedMapping<int> StripeMapping = [];
#endregion #endregion

View File

@ -49,7 +49,7 @@ public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider
{ PicoPiSDK.HID_BULK_CONTROLLER_PID, RGBDeviceType.LedStripe, "WS2812B-Controller", LedMappings.StripeMapping, 0 }, { PicoPiSDK.HID_BULK_CONTROLLER_PID, RGBDeviceType.LedStripe, "WS2812B-Controller", LedMappings.StripeMapping, 0 },
}; };
private readonly List<PicoPiSDK> _sdks = new(); private readonly List<PicoPiSDK> _sdks = [];
/// <summary> /// <summary>
/// Gets or sets the endpoint used to update devices. (default <see cref="PicoPi.Enum.UpdateMode.Auto"/>). /// Gets or sets the endpoint used to update devices. (default <see cref="PicoPi.Enum.UpdateMode.Auto"/>).

View File

@ -25,7 +25,7 @@ public sealed class RazerChromaLinkUpdateQueue : RazerUpdateQueue
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
_Color[] colors = new _Color[_Defines.CHROMALINK_MAX_LEDS]; _Color[] colors = new _Color[_Defines.CHROMALINK_MAX_LEDS];
@ -35,14 +35,14 @@ public sealed class RazerChromaLinkUpdateQueue : RazerUpdateQueue
_ChromaLinkCustomEffect effectParams = new() _ChromaLinkCustomEffect effectParams = new()
{ Color = colors }; { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false); Marshal.StructureToPtr(effectParams, ptr, false);
return ptr; return ptr;
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateChromaLinkEffect(_Defines.CHROMALINK_EFFECT_ID, effectParams, ref effectId); protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateChromaLinkEffect(_Defines.CHROMALINK_EFFECT_ID, effectParams, ref effectId);
#endregion #endregion
} }

View File

@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Razer;
/// <summary> /// <summary>
/// Represents a razer RGB-device. /// Represents a razer RGB-device.
/// </summary> /// </summary>
public interface IRazerRGBDevice : IRGBDevice public interface IRazerRGBDevice : IRGBDevice;
{ }

View File

@ -386,20 +386,20 @@ public static class LedMappings
/// <summary> /// <summary>
/// Gets the mapping for mousepads. /// Gets the mapping for mousepads.
/// </summary> /// </summary>
public static LedMapping<int> Mousepad { get; } = new(); public static LedMapping<int> Mousepad { get; } = [];
/// <summary> /// <summary>
/// Gets the mapping for headsets. /// Gets the mapping for headsets.
/// </summary> /// </summary>
public static LedMapping<int> Headset { get; } = new(); public static LedMapping<int> Headset { get; } = [];
/// <summary> /// <summary>
/// Gets the mapping for keypads. /// Gets the mapping for keypads.
/// </summary> /// </summary>
public static LedMapping<int> Keypad { get; } = new(); public static LedMapping<int> Keypad { get; } = [];
/// <summary> /// <summary>
/// Gets the mapping for chroma link devices. /// Gets the mapping for chroma link devices.
/// </summary> /// </summary>
public static LedMapping<int> ChromaLink { get; } = new(); public static LedMapping<int> ChromaLink { get; } = [];
} }

View File

@ -34,7 +34,7 @@ public abstract class RazerUpdateQueue : UpdateQueue
{ {
try try
{ {
IntPtr effectParams = CreateEffectParams(dataSet); nint effectParams = CreateEffectParams(dataSet);
Guid effectId = Guid.NewGuid(); Guid effectId = Guid.NewGuid();
CreateEffect(effectParams, ref effectId); CreateEffect(effectParams, ref effectId);
@ -60,7 +60,7 @@ public abstract class RazerUpdateQueue : UpdateQueue
/// </summary> /// </summary>
/// <param name="effectParams">The parameters of the effect.</param> /// <param name="effectParams">The parameters of the effect.</param>
/// <param name="effectId">The id this effect is created with.</param> /// <param name="effectId">The id this effect is created with.</param>
protected abstract void CreateEffect(IntPtr effectParams, ref Guid effectId); protected abstract void CreateEffect(nint effectParams, ref Guid effectId);
/// <inheritdoc /> /// <inheritdoc />
public override void Reset() public override void Reset()
@ -77,7 +77,7 @@ public abstract class RazerUpdateQueue : UpdateQueue
/// </summary> /// </summary>
/// <param name="dataSet">The data to be updated.</param> /// <param name="dataSet">The data to be updated.</param>
/// <returns>An <see cref="IntPtr"/> pointing to the effect parameter struct.</returns> /// <returns>An <see cref="IntPtr"/> pointing to the effect parameter struct.</returns>
protected abstract IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet); protected abstract nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet);
#endregion #endregion
} }

View File

@ -25,7 +25,7 @@ public sealed class RazerHeadsetUpdateQueue : RazerUpdateQueue
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
_Color[] colors = new _Color[_Defines.HEADSET_MAX_LEDS]; _Color[] colors = new _Color[_Defines.HEADSET_MAX_LEDS];
@ -35,14 +35,14 @@ public sealed class RazerHeadsetUpdateQueue : RazerUpdateQueue
_HeadsetCustomEffect effectParams = new() _HeadsetCustomEffect effectParams = new()
{ Color = colors }; { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false); Marshal.StructureToPtr(effectParams, ptr, false);
return ptr; return ptr;
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateHeadsetEffect(_Defines.HEADSET_EFFECT_ID, effectParams, ref effectId); protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateHeadsetEffect(_Defines.HEADSET_EFFECT_ID, effectParams, ref effectId);
#endregion #endregion
} }

View File

@ -25,7 +25,7 @@ public sealed class RazerKeyboardUpdateQueue : RazerUpdateQueue
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
_Color[] colors = new _Color[_Defines.KEYBOARD_MAX_LEDS]; _Color[] colors = new _Color[_Defines.KEYBOARD_MAX_LEDS];
@ -34,14 +34,14 @@ public sealed class RazerKeyboardUpdateQueue : RazerUpdateQueue
_KeyboardCustomEffect effectParams = new() { Color = colors }; _KeyboardCustomEffect effectParams = new() { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false); Marshal.StructureToPtr(effectParams, ptr, false);
return ptr; return ptr;
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateKeyboardEffect(_Defines.KEYBOARD_EFFECT_ID, effectParams, ref effectId); protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateKeyboardEffect(_Defines.KEYBOARD_EFFECT_ID, effectParams, ref effectId);
#endregion #endregion
} }

View File

@ -25,7 +25,7 @@ public sealed class RazerKeypadUpdateQueue : RazerUpdateQueue
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
_Color[] colors = new _Color[_Defines.KEYPAD_MAX_LEDS]; _Color[] colors = new _Color[_Defines.KEYPAD_MAX_LEDS];
@ -34,14 +34,14 @@ public sealed class RazerKeypadUpdateQueue : RazerUpdateQueue
_KeypadCustomEffect effectParams = new() { Color = colors }; _KeypadCustomEffect effectParams = new() { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false); Marshal.StructureToPtr(effectParams, ptr, false);
return ptr; return ptr;
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateKeypadEffect(_Defines.KEYPAD_EFFECT_ID, effectParams, ref effectId); protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateKeypadEffect(_Defines.KEYPAD_EFFECT_ID, effectParams, ref effectId);
#endregion #endregion
} }

View File

@ -25,7 +25,7 @@ public sealed class RazerMouseUpdateQueue : RazerUpdateQueue
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
_Color[] colors = new _Color[_Defines.MOUSE_MAX_LEDS]; _Color[] colors = new _Color[_Defines.MOUSE_MAX_LEDS];
@ -34,7 +34,7 @@ public sealed class RazerMouseUpdateQueue : RazerUpdateQueue
_MouseCustomEffect effectParams = new() { Color = colors }; _MouseCustomEffect effectParams = new() { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false); Marshal.StructureToPtr(effectParams, ptr, false);
return ptr; return ptr;
@ -42,7 +42,7 @@ public sealed class RazerMouseUpdateQueue : RazerUpdateQueue
/// <inheritdoc /> /// <inheritdoc />
protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateMouseEffect(_Defines.MOUSE_EFFECT_ID, effectParams, ref effectId); protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateMouseEffect(_Defines.MOUSE_EFFECT_ID, effectParams, ref effectId);
#endregion #endregion
} }

View File

@ -25,7 +25,7 @@ public sealed class RazerMousepadUpdateQueue : RazerUpdateQueue
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override IntPtr CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet) protected override nint CreateEffectParams(in ReadOnlySpan<(object key, Color color)> dataSet)
{ {
_Color[] colors = new _Color[_Defines.MOUSEPAD_MAX_LEDS]; _Color[] colors = new _Color[_Defines.MOUSEPAD_MAX_LEDS];
@ -34,14 +34,14 @@ public sealed class RazerMousepadUpdateQueue : RazerUpdateQueue
_MousepadCustomEffect effectParams = new() { Color = colors }; _MousepadCustomEffect effectParams = new() { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams)); nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false); Marshal.StructureToPtr(effectParams, ptr, false);
return ptr; return ptr;
} }
/// <inheritdoc /> /// <inheritdoc />
protected override void CreateEffect(IntPtr effectParams, ref Guid effectId) => _RazerSDK.CreateMousepadEffect(_Defines.MOUSEPAD_EFFECT_ID, effectParams, ref effectId); protected override void CreateEffect(nint effectParams, ref Guid effectId) => _RazerSDK.CreateMousepadEffect(_Defines.MOUSEPAD_EFFECT_ID, effectParams, ref effectId);
#endregion #endregion
} }

View File

@ -10,11 +10,12 @@ namespace RGB.NET.Devices.Razer.Native;
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
[StructLayout(LayoutKind.Sequential, Size = sizeof(uint))] [StructLayout(LayoutKind.Sequential, Size = sizeof(uint))]
internal struct _Color [System.Diagnostics.CodeAnalysis.SuppressMessage("Style", "IDE1006:Naming Styles", Justification = "Native-naming")]
internal struct _Color(byte red, byte green, byte blue)
{ {
#region Properties & Fields #region Properties & Fields
public uint Color; public uint Color = red + ((uint)green << 8) + ((uint)blue << 16);
#endregion #endregion
@ -23,11 +24,5 @@ internal struct _Color
public _Color(Color color) public _Color(Color color)
: this(color.GetR(), color.GetG(), color.GetB()) { } : this(color.GetR(), color.GetG(), color.GetB()) { }
public _Color(byte red, byte green, byte blue)
: this()
{
Color = red + ((uint)green << 8) + ((uint)blue << 16);
}
#endregion #endregion
} }

View File

@ -16,7 +16,7 @@ internal static class _RazerSDK
{ {
#region Libary Management #region Libary Management
private static IntPtr _handle = IntPtr.Zero; private static nint _handle = 0;
/// <summary> /// <summary>
/// Reloads the SDK. /// Reloads the SDK.
@ -29,7 +29,7 @@ internal static class _RazerSDK
private static void LoadRazerSDK() private static void LoadRazerSDK()
{ {
if (_handle != IntPtr.Zero) return; if (_handle != 0) return;
List<string> possiblePathList = GetPossibleLibraryPaths().ToList(); List<string> possiblePathList = GetPossibleLibraryPaths().ToList();
@ -71,23 +71,23 @@ internal static class _RazerSDK
internal static void UnloadRazerSDK() internal static void UnloadRazerSDK()
{ {
if (_handle == IntPtr.Zero) return; if (_handle == 0) return;
_initPointer = IntPtr.Zero; _initPointer = 0;
_unInitPointer = IntPtr.Zero; _unInitPointer = 0;
_queryDevicePointer = IntPtr.Zero; _queryDevicePointer = 0;
_createEffectPointer = IntPtr.Zero; _createEffectPointer = 0;
_createHeadsetEffectPointer = IntPtr.Zero; _createHeadsetEffectPointer = 0;
_createChromaLinkEffectPointer = IntPtr.Zero; _createChromaLinkEffectPointer = 0;
_createKeyboardEffectPointer = IntPtr.Zero; _createKeyboardEffectPointer = 0;
_createKeypadEffectPointer = IntPtr.Zero; _createKeypadEffectPointer = 0;
_createMouseEffectPointer = IntPtr.Zero; _createMouseEffectPointer = 0;
_createMousepadEffectPointer = IntPtr.Zero; _createMousepadEffectPointer = 0;
_setEffectPointer = IntPtr.Zero; _setEffectPointer = 0;
_deleteEffectPointer = IntPtr.Zero; _deleteEffectPointer = 0;
NativeLibrary.Free(_handle); NativeLibrary.Free(_handle);
_handle = IntPtr.Zero; _handle = 0;
} }
#endregion #endregion
@ -96,18 +96,18 @@ internal static class _RazerSDK
#region Pointers #region Pointers
private static IntPtr _initPointer; private static nint _initPointer;
private static IntPtr _unInitPointer; private static nint _unInitPointer;
private static IntPtr _queryDevicePointer; private static nint _queryDevicePointer;
private static IntPtr _createEffectPointer; private static nint _createEffectPointer;
private static IntPtr _createHeadsetEffectPointer; private static nint _createHeadsetEffectPointer;
private static IntPtr _createChromaLinkEffectPointer; private static nint _createChromaLinkEffectPointer;
private static IntPtr _createKeyboardEffectPointer; private static nint _createKeyboardEffectPointer;
private static IntPtr _createKeypadEffectPointer; private static nint _createKeypadEffectPointer;
private static IntPtr _createMouseEffectPointer; private static nint _createMouseEffectPointer;
private static IntPtr _createMousepadEffectPointer; private static nint _createMousepadEffectPointer;
private static IntPtr _setEffectPointer; private static nint _setEffectPointer;
private static IntPtr _deleteEffectPointer; private static nint _deleteEffectPointer;
#endregion #endregion
@ -128,9 +128,9 @@ internal static class _RazerSDK
internal static unsafe RazerError QueryDevice(Guid deviceId, out _DeviceInfo deviceInfo) internal static unsafe RazerError QueryDevice(Guid deviceId, out _DeviceInfo deviceInfo)
{ {
int structSize = Marshal.SizeOf(typeof(_DeviceInfo)); int structSize = Marshal.SizeOf(typeof(_DeviceInfo));
IntPtr deviceInfoPtr = Marshal.AllocHGlobal(structSize); nint deviceInfoPtr = Marshal.AllocHGlobal(structSize);
RazerError error = ((delegate* unmanaged[Cdecl]<Guid, IntPtr, RazerError>)ThrowIfZero(_queryDevicePointer))(deviceId, deviceInfoPtr); RazerError error = ((delegate* unmanaged[Cdecl]<Guid, nint, RazerError>)ThrowIfZero(_queryDevicePointer))(deviceId, deviceInfoPtr);
deviceInfo = (_DeviceInfo)Marshal.PtrToStructure(deviceInfoPtr, typeof(_DeviceInfo))!; deviceInfo = (_DeviceInfo)Marshal.PtrToStructure(deviceInfoPtr, typeof(_DeviceInfo))!;
Marshal.FreeHGlobal(deviceInfoPtr); Marshal.FreeHGlobal(deviceInfoPtr);
@ -138,26 +138,26 @@ internal static class _RazerSDK
return error; return error;
} }
internal static unsafe RazerError CreateEffect(Guid deviceId, int effectType, IntPtr param, ref Guid effectId) internal static unsafe RazerError CreateEffect(Guid deviceId, int effectType, nint param, ref Guid effectId)
=> ((delegate* unmanaged[Cdecl]<Guid, int, IntPtr, ref Guid, RazerError>)ThrowIfZero(_createEffectPointer))(deviceId, effectType, param, ref effectId); => ((delegate* unmanaged[Cdecl]<Guid, int, nint, ref Guid, RazerError>)ThrowIfZero(_createEffectPointer))(deviceId, effectType, param, ref effectId);
internal static unsafe RazerError CreateHeadsetEffect(int effectType, IntPtr param, ref Guid effectId) internal static unsafe RazerError CreateHeadsetEffect(int effectType, nint param, ref Guid effectId)
=> ((delegate* unmanaged[Cdecl]<int, IntPtr, ref Guid, RazerError>)ThrowIfZero(_createHeadsetEffectPointer))(effectType, param, ref effectId); => ((delegate* unmanaged[Cdecl]<int, nint, ref Guid, RazerError>)ThrowIfZero(_createHeadsetEffectPointer))(effectType, param, ref effectId);
internal static unsafe RazerError CreateChromaLinkEffect(int effectType, IntPtr param, ref Guid effectId) internal static unsafe RazerError CreateChromaLinkEffect(int effectType, nint param, ref Guid effectId)
=> ((delegate* unmanaged[Cdecl]<int, IntPtr, ref Guid, RazerError>)ThrowIfZero(_createChromaLinkEffectPointer))(effectType, param, ref effectId); => ((delegate* unmanaged[Cdecl]<int, nint, ref Guid, RazerError>)ThrowIfZero(_createChromaLinkEffectPointer))(effectType, param, ref effectId);
internal static unsafe RazerError CreateKeyboardEffect(int effectType, IntPtr param, ref Guid effectId) internal static unsafe RazerError CreateKeyboardEffect(int effectType, nint param, ref Guid effectId)
=> ((delegate* unmanaged[Cdecl]<int, IntPtr, ref Guid, RazerError>)ThrowIfZero(_createKeyboardEffectPointer))(effectType, param, ref effectId); => ((delegate* unmanaged[Cdecl]<int, nint, ref Guid, RazerError>)ThrowIfZero(_createKeyboardEffectPointer))(effectType, param, ref effectId);
internal static unsafe RazerError CreateKeypadEffect(int effectType, IntPtr param, ref Guid effectId) internal static unsafe RazerError CreateKeypadEffect(int effectType, nint param, ref Guid effectId)
=> ((delegate* unmanaged[Cdecl]<int, IntPtr, ref Guid, RazerError>)ThrowIfZero(_createKeypadEffectPointer))(effectType, param, ref effectId); => ((delegate* unmanaged[Cdecl]<int, nint, ref Guid, RazerError>)ThrowIfZero(_createKeypadEffectPointer))(effectType, param, ref effectId);
internal static unsafe RazerError CreateMouseEffect(int effectType, IntPtr param, ref Guid effectId) internal static unsafe RazerError CreateMouseEffect(int effectType, nint param, ref Guid effectId)
=> ((delegate* unmanaged[Cdecl]<int, IntPtr, ref Guid, RazerError>)ThrowIfZero(_createMouseEffectPointer))(effectType, param, ref effectId); => ((delegate* unmanaged[Cdecl]<int, nint, ref Guid, RazerError>)ThrowIfZero(_createMouseEffectPointer))(effectType, param, ref effectId);
internal static unsafe RazerError CreateMousepadEffect(int effectType, IntPtr param, ref Guid effectId) internal static unsafe RazerError CreateMousepadEffect(int effectType, nint param, ref Guid effectId)
=> ((delegate* unmanaged[Cdecl]<int, IntPtr, ref Guid, RazerError>)ThrowIfZero(_createMousepadEffectPointer))(effectType, param, ref effectId); => ((delegate* unmanaged[Cdecl]<int, nint, ref Guid, RazerError>)ThrowIfZero(_createMousepadEffectPointer))(effectType, param, ref effectId);
internal static unsafe RazerError SetEffect(Guid effectId) internal static unsafe RazerError SetEffect(Guid effectId)
=> ((delegate* unmanaged[Cdecl]<Guid, RazerError>)ThrowIfZero(_setEffectPointer))(effectId); => ((delegate* unmanaged[Cdecl]<Guid, RazerError>)ThrowIfZero(_setEffectPointer))(effectId);
@ -165,9 +165,9 @@ internal static class _RazerSDK
internal static unsafe RazerError DeleteEffect(Guid effectId) internal static unsafe RazerError DeleteEffect(Guid effectId)
=> ((delegate* unmanaged[Cdecl]<Guid, RazerError>)ThrowIfZero(_deleteEffectPointer))(effectId); => ((delegate* unmanaged[Cdecl]<Guid, RazerError>)ThrowIfZero(_deleteEffectPointer))(effectId);
private static IntPtr ThrowIfZero(IntPtr ptr) private static nint ThrowIfZero(nint ptr)
{ {
if (ptr == IntPtr.Zero) throw new RGBDeviceException("The Razer-SDK is not initialized."); if (ptr == 0) throw new RGBDeviceException("The Razer-SDK is not initialized.");
return ptr; return ptr;
} }

View File

@ -39,13 +39,13 @@ public sealed class RazerDeviceProvider : AbstractRGBDeviceProvider
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX86NativePaths { get; } = new() { @"%systemroot%\SysWOW64\RzChromaSDK.dll" }; public static List<string> PossibleX86NativePaths { get; } = [@"%systemroot%\SysWOW64\RzChromaSDK.dll"];
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX64NativePaths { get; } = new() { @"%systemroot%\System32\RzChromaSDK.dll", @"%systemroot%\System32\RzChromaSDK64.dll" }; public static List<string> PossibleX64NativePaths { get; } = [@"%systemroot%\System32\RzChromaSDK.dll", @"%systemroot%\System32\RzChromaSDK64.dll"];
/// <summary> /// <summary>
/// Forces to load the devices represented by the emulator even if they aren't reported to exist. /// Forces to load the devices represented by the emulator even if they aren't reported to exist.

View File

@ -15,7 +15,7 @@ internal sealed class Event
// ReSharper disable once CollectionNeverQueried.Global // ReSharper disable once CollectionNeverQueried.Global
[JsonPropertyName("data")] [JsonPropertyName("data")]
public Dictionary<string, object> Data { get; } = new(); public Dictionary<string, object> Data { get; } = [];
#endregion #endregion

View File

@ -1,19 +1,10 @@
namespace RGB.NET.Devices.SteelSeries; namespace RGB.NET.Devices.SteelSeries;
internal sealed class APIName : System.Attribute internal sealed class APIName(string name) : System.Attribute
{ {
#region Properties & Fields #region Properties & Fields
public string Name { get; set; } public string Name { get; set; } = name;
#endregion
#region Constructors
public APIName(string name)
{
this.Name = name;
}
#endregion #endregion
} }

View File

@ -10,8 +10,8 @@ internal static class SteelSeriesEnumExtension
#region Properties & Fields #region Properties & Fields
// ReSharper disable InconsistentNaming // ReSharper disable InconsistentNaming
private static readonly Dictionary<SteelSeriesDeviceType, string?> _deviceTypeNames = new(); private static readonly Dictionary<SteelSeriesDeviceType, string?> _deviceTypeNames = [];
private static readonly Dictionary<SteelSeriesLedId, string?> _ledIdNames = new(); private static readonly Dictionary<SteelSeriesLedId, string?> _ledIdNames = [];
// ReSharper restore InconsistentNaming // ReSharper restore InconsistentNaming
#endregion #endregion

View File

@ -5,5 +5,4 @@ namespace RGB.NET.Devices.SteelSeries;
/// <summary> /// <summary>
/// Represents a steelseries RGB-device. /// Represents a steelseries RGB-device.
/// </summary> /// </summary>
internal interface ISteelSeriesRGBDevice : IRGBDevice internal interface ISteelSeriesRGBDevice : IRGBDevice;
{ }

View File

@ -21,7 +21,7 @@ public sealed class ArduinoWS2812USBUpdateQueue : SerialConnectionUpdateQueue<by
#region Properties & Fields #region Properties & Fields
private readonly Dictionary<int, byte[]> _dataBuffer = new(); private readonly Dictionary<int, byte[]> _dataBuffer = [];
#endregion #endregion

View File

@ -39,7 +39,7 @@ public sealed class BitwizardWS281XDeviceDefinition : IWS281XDeviceDefinition
/// <summary> /// <summary>
/// Gets a list of LED-strips configured on this device. /// Gets a list of LED-strips configured on this device.
/// </summary> /// </summary>
public List<(int pin, int stripLength)> Strips { get; } = new(); public List<(int pin, int stripLength)> Strips { get; } = [];
/// <summary> /// <summary>
/// Gets or sets the amount of leds controlled by one pin. /// Gets or sets the amount of leds controlled by one pin.

View File

@ -23,8 +23,8 @@ public sealed class NodeMCUWS2812USBUpdateQueue : UpdateQueue
private HttpClient _httpClient = new(); private HttpClient _httpClient = new();
private UdpClient? _udpClient; private UdpClient? _udpClient;
private readonly Dictionary<int, byte[]> _dataBuffer = new(); private readonly Dictionary<int, byte[]> _dataBuffer = [];
private readonly Dictionary<int, byte> _sequenceNumbers = new(); private readonly Dictionary<int, byte> _sequenceNumbers = [];
private readonly Action<byte[]> _sendDataAction; private readonly Action<byte[]> _sendDataAction;

View File

@ -37,7 +37,7 @@ public sealed class WS281XDeviceProvider : AbstractRGBDeviceProvider
/// </summary> /// </summary>
// ReSharper disable once CollectionNeverUpdated.Global // ReSharper disable once CollectionNeverUpdated.Global
// ReSharper disable once ReturnTypeCanBeEnumerable.Global // ReSharper disable once ReturnTypeCanBeEnumerable.Global
public List<IWS281XDeviceDefinition> DeviceDefinitions { get; } = new(); public List<IWS281XDeviceDefinition> DeviceDefinitions { get; } = [];
#endregion #endregion

View File

@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Wooting.Generic;
/// <summary> /// <summary>
/// Represents a Wooting RGB-device. /// Represents a Wooting RGB-device.
/// </summary> /// </summary>
public interface IWootingRGBDevice : IRGBDevice public interface IWootingRGBDevice : IRGBDevice;
{ }

View File

@ -15,7 +15,7 @@ internal static class _WootingSDK
{ {
#region Library management #region Library management
private static IntPtr _handle = IntPtr.Zero; private static nint _handle = 0;
internal static object SdkLock = new(); internal static object SdkLock = new();
/// <summary> /// <summary>
@ -29,7 +29,7 @@ internal static class _WootingSDK
private static void LoadWootingSDK() private static void LoadWootingSDK()
{ {
if (_handle != IntPtr.Zero) return; if (_handle != 0) return;
List<string> possiblePathList = GetPossibleLibraryPaths().ToList(); List<string> possiblePathList = GetPossibleLibraryPaths().ToList();
@ -71,21 +71,21 @@ internal static class _WootingSDK
internal static void UnloadWootingSDK() internal static void UnloadWootingSDK()
{ {
if (_handle == IntPtr.Zero) return; if (_handle == 0) return;
Close(); Close();
_getDeviceInfoPointer = IntPtr.Zero; _getDeviceInfoPointer = 0;
_keyboardConnectedPointer = IntPtr.Zero; _keyboardConnectedPointer = 0;
_resetPointer = IntPtr.Zero; _resetPointer = 0;
_closePointer = IntPtr.Zero; _closePointer = 0;
_arrayUpdateKeyboardPointer = IntPtr.Zero; _arrayUpdateKeyboardPointer = 0;
_arraySetSinglePointer = IntPtr.Zero; _arraySetSinglePointer = 0;
_getDeviceCountPointer = IntPtr.Zero; _getDeviceCountPointer = 0;
_selectDevicePointer = IntPtr.Zero; _selectDevicePointer = 0;
NativeLibrary.Free(_handle); NativeLibrary.Free(_handle);
_handle = IntPtr.Zero; _handle = 0;
} }
#endregion #endregion
@ -94,18 +94,18 @@ internal static class _WootingSDK
#region Pointers #region Pointers
private static IntPtr _getDeviceInfoPointer; private static nint _getDeviceInfoPointer;
private static IntPtr _keyboardConnectedPointer; private static nint _keyboardConnectedPointer;
private static IntPtr _resetPointer; private static nint _resetPointer;
private static IntPtr _closePointer; private static nint _closePointer;
private static IntPtr _arrayUpdateKeyboardPointer; private static nint _arrayUpdateKeyboardPointer;
private static IntPtr _arraySetSinglePointer; private static nint _arraySetSinglePointer;
private static IntPtr _getDeviceCountPointer; private static nint _getDeviceCountPointer;
private static IntPtr _selectDevicePointer; private static nint _selectDevicePointer;
#endregion #endregion
internal static unsafe IntPtr GetDeviceInfo() => ((delegate* unmanaged[Cdecl]<IntPtr>)ThrowIfZero(_getDeviceInfoPointer))(); internal static unsafe nint GetDeviceInfo() => ((delegate* unmanaged[Cdecl]<nint>)ThrowIfZero(_getDeviceInfoPointer))();
internal static unsafe bool KeyboardConnected() => ((delegate* unmanaged[Cdecl]<bool>)ThrowIfZero(_keyboardConnectedPointer))(); internal static unsafe bool KeyboardConnected() => ((delegate* unmanaged[Cdecl]<bool>)ThrowIfZero(_keyboardConnectedPointer))();
internal static unsafe bool Reset() => ((delegate* unmanaged[Cdecl]<bool>)ThrowIfZero(_resetPointer))(); internal static unsafe bool Reset() => ((delegate* unmanaged[Cdecl]<bool>)ThrowIfZero(_resetPointer))();
internal static unsafe bool Close() => ((delegate* unmanaged[Cdecl]<bool>)ThrowIfZero(_closePointer))(); internal static unsafe bool Close() => ((delegate* unmanaged[Cdecl]<bool>)ThrowIfZero(_closePointer))();
@ -115,9 +115,9 @@ internal static class _WootingSDK
internal static unsafe byte GetDeviceCount() => ((delegate* unmanaged[Cdecl]<byte>)ThrowIfZero(_getDeviceCountPointer))(); internal static unsafe byte GetDeviceCount() => ((delegate* unmanaged[Cdecl]<byte>)ThrowIfZero(_getDeviceCountPointer))();
internal static unsafe void SelectDevice(byte index) => ((delegate* unmanaged[Cdecl]<byte, void>)ThrowIfZero(_selectDevicePointer))(index); internal static unsafe void SelectDevice(byte index) => ((delegate* unmanaged[Cdecl]<byte, void>)ThrowIfZero(_selectDevicePointer))(index);
private static IntPtr ThrowIfZero(IntPtr ptr) private static nint ThrowIfZero(nint ptr)
{ {
if (ptr == IntPtr.Zero) throw new RGBDeviceException("The Wooting-SDK is not initialized."); if (ptr == 0) throw new RGBDeviceException("The Wooting-SDK is not initialized.");
return ptr; return ptr;
} }

View File

@ -38,26 +38,26 @@ public sealed class WootingDeviceProvider : AbstractRGBDeviceProvider
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 windows applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 windows applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX86NativePathsWindows { get; } = new() { "x86/wooting-rgb-sdk.dll" }; public static List<string> PossibleX86NativePathsWindows { get; } = ["x86/wooting-rgb-sdk.dll"];
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 windows applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 windows applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX64NativePathsWindows { get; } = new() { "x64/wooting-rgb-sdk64.dll" }; public static List<string> PossibleX64NativePathsWindows { get; } = ["x64/wooting-rgb-sdk64.dll"];
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 linux applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 linux applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleNativePathsLinux { get; } = new() { "x64/libwooting-rgb-sdk.so" }; public static List<string> PossibleNativePathsLinux { get; } = ["x64/libwooting-rgb-sdk.so"];
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 MacOS applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 MacOS applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
// ReSharper disable once InconsistentNaming // ReSharper disable once InconsistentNaming
public static List<string> PossibleNativePathsMacOS { get; } = new() { "x64/libwooting-rgb-sdk.dylib" }; public static List<string> PossibleNativePathsMacOS { get; } = ["x64/libwooting-rgb-sdk.dylib"];
#endregion #endregion

View File

@ -24,7 +24,7 @@ public sealed class HIDLoader<TLed, TData> : IEnumerable<HIDDeviceDefinition<TLe
{ {
#region Properties & Fields #region Properties & Fields
private readonly Dictionary<int, HIDDeviceDefinition<TLed, TData>> _deviceDefinitions = new(); private readonly Dictionary<int, HIDDeviceDefinition<TLed, TData>> _deviceDefinitions = [];
/// <summary> /// <summary>
/// Gets the vendor id used for this loader. /// Gets the vendor id used for this loader.

View File

@ -92,7 +92,7 @@ public class DeviceLayout : IDeviceLayout
/// Normally you should use <see cref="Leds"/> to access this data. /// Normally you should use <see cref="Leds"/> to access this data.
/// </summary> /// </summary>
[XmlArray("Leds")] [XmlArray("Leds")]
public List<LedLayout> InternalLeds { get; set; } = new(); public List<LedLayout> InternalLeds { get; set; } = [];
/// <summary> /// <summary>
/// Gets or sets a list of <see cref="LedLayout"/> representing all the <see cref="Led"/> of the <see cref="DeviceLayout"/>. /// Gets or sets a list of <see cref="LedLayout"/> representing all the <see cref="Led"/> of the <see cref="DeviceLayout"/>.

Some files were not shown because too many files have changed in this diff Show More