1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 09:38: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
private readonly List<T> _decorators = new();
private readonly List<T> _decorators = [];
/// <inheritdoc />
public IReadOnlyList<T> Decorators { get; }

View File

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

View File

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

View File

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

View File

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

View File

@ -25,7 +25,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
/// <summary>
/// The list of devices managed by this device-provider.
/// </summary>
protected List<IRGBDevice> InternalDevices { get; } = new();
protected List<IRGBDevice> InternalDevices { get; } = [];
/// <inheritdoc />
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.
/// Normally <see cref="UpdateTriggers"/> should be used to access them.
/// </summary>
protected Dictionary<int, IDeviceUpdateTrigger> UpdateTriggerMapping { get; } = new();
protected Dictionary<int, IDeviceUpdateTrigger> UpdateTriggerMapping { get; } = [];
/// <inheritdoc />
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);
List<IRGBDevice> devices = new();
List<IRGBDevice> devices = [];
foreach (IRGBDevice device in LoadDevices())
{
try
@ -189,7 +189,7 @@ public abstract class AbstractRGBDeviceProvider : IRGBDeviceProvider
foreach (IRGBDevice device in Devices)
device.Dispose();
List<IRGBDevice> devices = new(InternalDevices);
List<IRGBDevice> devices = [..InternalDevices];
foreach (IRGBDevice device in devices)
RemoveDevice(device);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -12,9 +12,9 @@ public static class IdGenerator
#region Properties & Fields
// ReSharper disable InconsistentNaming
private static readonly HashSet<string> _registeredIds = new();
private static readonly Dictionary<Assembly, Dictionary<string, string>> _idMappings = new();
private static readonly Dictionary<Assembly, Dictionary<string, int>> _counter = new();
private static readonly HashSet<string> _registeredIds = [];
private static readonly Dictionary<Assembly, Dictionary<string, string>> _idMappings = [];
private static readonly Dictionary<Assembly, Dictionary<string, int>> _counter = [];
// ReSharper restore InconsistentNaming
#endregion
@ -33,8 +33,8 @@ public static class IdGenerator
{
if (!_idMappings.TryGetValue(callingAssembly, out Dictionary<string, string>? idMapping))
{
_idMappings.Add(callingAssembly, idMapping = new Dictionary<string, string>());
_counter.Add(callingAssembly, new Dictionary<string, int>());
_idMappings.Add(callingAssembly, idMapping = []);
_counter.Add(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
public static LedMapping<T> Empty { get; } = new();
public static LedMapping<T> Empty { get; } = [];
#endregion
#region Properties & Fields
private readonly Dictionary<LedId, T> _mapping = new();
private readonly Dictionary<T, LedId> _reverseMapping = new();
private readonly Dictionary<LedId, T> _mapping = [];
private readonly Dictionary<T, LedId> _reverseMapping = [];
/// <summary>
/// Gets the number of entries in this mapping.

View File

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

View File

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

View File

@ -2,26 +2,11 @@
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
public void Dispose() => _onDispose();
public void Dispose() => onDispose();
#endregion
}

View File

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

View File

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

View File

@ -31,5 +31,4 @@ public interface IUpdateQueue<TIdentifier, TData> : IReferenceCounting, IDisposa
/// <summary>
/// Represents a generic update queue processing <see cref="Color"/>-data using <see cref="object"/>-identifiers.
/// </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 IDeviceUpdateTrigger _updateTrigger;
private readonly Dictionary<TIdentifier, TData> _currentDataSet = new();
private readonly Dictionary<TIdentifier, TData> _currentDataSet = [];
/// <inheritdoc />
public bool RequiresFlush { get; private set; }

View File

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

View File

@ -25,8 +25,8 @@ public sealed class AsusKeyboardRGBDevice : AsusRGBDevice<AsusKeyboardRGBDeviceI
#region Properties & Fields
private readonly LedMapping<AsusLedId>? _ledMapping;
private readonly Dictionary<LedId, AsusLedId> _ledAsusLed = new();
private readonly Dictionary<LedId, int> _ledAsusLights = new();
private readonly Dictionary<LedId, AsusLedId> _ledAsusLed = [];
private readonly Dictionary<LedId, int> _ledAsusLights = [];
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>
/// </summary>
// ReSharper disable once InconsistentNaming
public static readonly List<AsusKeyboardExtraMapping> ExtraLedMappings = new()
{
new AsusKeyboardExtraMapping(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15),
new AsusKeyboardExtraMapping(new Regex("(ROG Strix G513QM).*?"), LedMappings.ROGStrixG15)
};
public static readonly List<AsusKeyboardExtraMapping> ExtraLedMappings =
[
new AsusKeyboardExtraMapping(new Regex("(ROG Zephyrus Duo 15).*?"), LedMappings.ROGZephyrusDuo15),
new AsusKeyboardExtraMapping(new Regex("(ROG Strix G513QM).*?"), LedMappings.ROGStrixG15)
];
#endregion
@ -66,7 +66,7 @@ public sealed class AsusKeyboardRGBDevice : AsusRGBDevice<AsusKeyboardRGBDeviceI
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 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.
/// Keep a list of those and rely on <see cref="WMIHelper.GetSystemModelInfo()"/> to get the real model
/// </summary>
private static readonly List<string> GENERIC_DEVICE_NAMES = new() { "NotebookKeyboard" };
private static readonly List<string> GENERIC_DEVICE_NAMES = ["NotebookKeyboard"];
/// <inheritdoc />
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.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/CMSDK.dll" };
public static List<string> PossibleX86NativePaths { get; } = ["x86/CMSDK.dll"];
/// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/CMSDK.dll" };
public static List<string> PossibleX64NativePaths { get; } = ["x64/CMSDK.dll"];
#endregion

View File

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

View File

@ -16,14 +16,14 @@ internal static class _CoolerMasterSDK
{
#region Libary Management
private static IntPtr _handle = IntPtr.Zero;
private static nint _handle = 0;
/// <summary>
/// Reloads the SDK.
/// </summary>
internal static void Reload()
{
if (_handle != IntPtr.Zero)
if (_handle != 0)
{
foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes)))
EnableLedControl(false, index);
@ -34,7 +34,7 @@ internal static class _CoolerMasterSDK
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
List<string> possiblePathList = (Environment.Is64BitProcess ? CoolerMasterDeviceProvider.PossibleX64NativePaths : CoolerMasterDeviceProvider.PossibleX86NativePaths)
@ -47,7 +47,7 @@ internal static class _CoolerMasterSDK
#if NET6_0
if (_handle == IntPtr.Zero) throw new RGBDeviceException($"CoolerMaster LoadLibrary failed with error code {Marshal.GetLastPInvokeError()}");
#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
_getSDKVersionPointer = (GetSDKVersionPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_handle, "GetCM_SDK_DllVer"), typeof(GetSDKVersionPointer));
@ -62,7 +62,7 @@ internal static class _CoolerMasterSDK
internal static void UnloadCMSDK()
{
if (_handle == IntPtr.Zero) return;
if (_handle == 0) return;
_getSDKVersionPointer = null;
_setControlDevicenPointer = null;
@ -74,14 +74,14 @@ internal static class _CoolerMasterSDK
_setAllLedColorPointer = null;
NativeLibrary.Free(_handle);
_handle = IntPtr.Zero;
_handle = 0;
}
[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)]
private static extern IntPtr GetProcAddress(IntPtr dllHandle, string name);
private static extern nint GetProcAddress(nint dllHandle, string name);
#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.
/// The first match will be used.
/// </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>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used.
/// </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>
/// 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)
{
LedMapping<CorsairLedId> mapping = new();
LedMapping<CorsairLedId> mapping = [];
int counter = 0;
foreach (CorsairLedId corsairLedId in ids.OrderBy(x => x))
mapping.Add(referenceId + counter++, corsairLedId);

View File

@ -19,6 +19,7 @@ internal sealed class _CorsairDeviceFilter
/// <summary>
/// iCUE-SDK: mask that describes device types, formed as logical “or” of CorsairDeviceType enum values
/// </summary>
// ReSharper disable once NotAccessedField.Global
internal CorsairDeviceType deviceTypeMask;
#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.
/// The first match will be used.
/// </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>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used.
/// </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>
/// Gets the protocol details for the current SDK-connection.
@ -170,7 +170,7 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider
foreach (_CorsairChannelInfo channelInfo in channels)
{
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++)
{
_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);
ledOffset += channelDeviceInfo.deviceLedCount;
channelDeviceInfoPtr = new IntPtr(channelDeviceInfoPtr.ToInt64() + channelDeviceInfoStructSize);
channelDeviceInfoPtr += channelDeviceInfoStructSize;
}
}
break;
@ -195,13 +195,13 @@ public sealed class CorsairLegacyDeviceProvider : AbstractRGBDeviceProvider
_CorsairChannelsInfo? channelsInfo = deviceInfo.channels;
if (channelsInfo == null) yield break;
IntPtr channelInfoPtr = channelsInfo.channels;
nint channelInfoPtr = channelsInfo.channels;
for (int channel = 0; channel < channelsInfo.channelsCount; channel++)
{
yield return (_CorsairChannelInfo)Marshal.PtrToStructure(channelInfoPtr, 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 UnusedMember.Global
using System;
using System.Linq;
using System.Runtime.InteropServices;
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="updateQueue">The queue used to update this device.</param>
internal CorsairCustomRGBDevice(CorsairCustomRGBDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
: base(info, new LedMapping<CorsairLedId>(), updateQueue)
: base(info, [], updateQueue)
{ }
#endregion
@ -40,7 +39,7 @@ public class CorsairCustomRGBDevice : CorsairRGBDevice<CorsairCustomRGBDeviceInf
if (nativeLedPositions == null) return;
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);
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));
if (ledPosition == null)
{
ptr = new IntPtr(ptr.ToInt64() + structSize);
ptr += structSize;
continue;
}
@ -60,7 +59,7 @@ public class CorsairCustomRGBDevice : CorsairRGBDevice<CorsairCustomRGBDeviceInf
Rectangle rectangle = ledPosition.ToRectangle();
AddLed(ledId, rectangle.Location, rectangle.Size);
ptr = new IntPtr(ptr.ToInt64() + structSize);
ptr += structSize;
}
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>
internal CorsairCustomRGBDeviceInfo(int deviceIndex, _CorsairDeviceInfo nativeInfo, _CorsairChannelDeviceInfo channelDeviceInfo, int ledOffset)
: 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;

View File

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

View File

@ -1,7 +1,6 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
using System;
using System.Runtime.InteropServices;
using RGB.NET.Devices.CorsairLegacy.Native;
@ -54,8 +53,8 @@ public class CorsairProtocolDetails
/// <param name="nativeDetails">The native CorsairProtocolDetails-struct</param>
internal CorsairProtocolDetails(_CorsairProtocolDetails nativeDetails)
{
this.SdkVersion = nativeDetails.sdkVersion == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeDetails.sdkVersion);
this.ServerVersion = nativeDetails.serverVersion == IntPtr.Zero ? null : Marshal.PtrToStringAnsi(nativeDetails.serverVersion);
this.SdkVersion = nativeDetails.sdkVersion == 0 ? null : Marshal.PtrToStringAnsi(nativeDetails.sdkVersion);
this.ServerVersion = nativeDetails.serverVersion == 0 ? null : Marshal.PtrToStringAnsi(nativeDetails.serverVersion);
this.SdkProtocolVersion = nativeDetails.sdkProtocolVersion;
this.ServerProtocolVersion = nativeDetails.serverProtocolVersion;
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.Devices.CorsairLegacy.Native;
@ -50,14 +49,14 @@ public abstract class CorsairRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceI
if (nativeLedPositions == null) return;
int structSize = Marshal.SizeOf(typeof(_CorsairLedPosition));
IntPtr ptr = nativeLedPositions.pLedPosition;
nint ptr = nativeLedPositions.pLedPosition;
for (int i = 0; i < nativeLedPositions.numberOfLed; i++)
{
_CorsairLedPosition? ledPosition = (_CorsairLedPosition?)Marshal.PtrToStructure(ptr, typeof(_CorsairLedPosition));
if (ledPosition == null)
{
ptr = new IntPtr(ptr.ToInt64() + structSize);
ptr += structSize;
continue;
}
@ -65,7 +64,7 @@ public abstract class CorsairRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceI
Rectangle rectangle = ledPosition.ToRectangle();
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 RGB.NET.Core;
using RGB.NET.Devices.CorsairLegacy.Native;
@ -65,7 +64,7 @@ public class CorsairRGBDeviceInfo : IRGBDeviceInfo
this.CorsairDeviceIndex = deviceIndex;
this.DeviceType = deviceType;
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.CapsMask = (CorsairDeviceCaps)nativeInfo.capsMask;

View File

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

View File

@ -7,7 +7,7 @@ internal static class NativeExtensions
{
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 height = position.height < 0.5f ? 10 : (float)position.height;
float posX = (float)position.left;

View File

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

View File

@ -3,7 +3,6 @@
#pragma warning disable 649 // Field 'x' is never assigned
#pragma warning disable IDE1006 // Naming Styles
using System;
using System.Runtime.InteropServices;
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.
/// Index of the LED-device in array is same as the index of the LED-device connected to the DIY-device.
/// </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 IDE1006 // Naming Styles
using System;
using System.Runtime.InteropServices;
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.
/// Index of the channel in the array is same as index of the channel on the DIY-device.
/// </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 IDE1006 // Naming Styles
using System;
using System.Runtime.InteropServices;
namespace RGB.NET.Devices.CorsairLegacy.Native;
@ -23,7 +22,7 @@ internal class _CorsairDeviceInfo
/// <summary>
/// CUE-SDK: null - terminated device model(like “K95RGB”)
/// </summary>
internal IntPtr model;
internal nint model;
/// <summary>
/// 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 649 // Field 'x' is never assigned
using System;
using System.Runtime.InteropServices;
namespace RGB.NET.Devices.CorsairLegacy.Native;
@ -22,5 +21,5 @@ internal class _CorsairLedPositions
/// <summary>
/// CUE-SDK: array of led positions
/// </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 649 // Field 'x' is never assigned
using System;
using System.Runtime.InteropServices;
namespace RGB.NET.Devices.CorsairLegacy.Native;
@ -17,12 +16,12 @@ internal struct _CorsairProtocolDetails
/// <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
/// </summary>
internal IntPtr sdkVersion;
internal nint sdkVersion;
/// <summary>
/// CUE-SDK: null - terminated string containing version of CUE(like “1.0.0.1”) or NULL if CUE was not found.
/// </summary>
internal IntPtr serverVersion;
internal nint serverVersion;
/// <summary>
/// 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>
/// Gets a list of all defined device-definitions.
/// </summary>
public List<IDMXDeviceDefinition> DeviceDefinitions { get; } = new();
public List<IDMXDeviceDefinition> DeviceDefinitions { get; } = [];
#endregion

View File

@ -55,7 +55,7 @@ public sealed class E131DMXDeviceDefinition : IDMXDeviceDefinition
/// <summary>
/// Gets or sets the led-mappings used to create the device.
/// </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>
/// 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>
/// Marker interface for DMX device definitions.
/// </summary>
public interface IDMXDeviceDefinition
{ }
public interface IDMXDeviceDefinition;

View File

@ -5,20 +5,12 @@ using RGB.NET.Core;
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
private readonly List<(int channel, Func<Color, byte> getValue)> _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);
}
private readonly List<(int channel, Func<Color, byte> getValue)> _mappings = [..mappings];
#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

View File

@ -3,16 +3,8 @@ using RGB.NET.Core;
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
protected override bool Update(in ReadOnlySpan<(object key, Color color)> dataSet) => true;

View File

@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Logitech;
/// <summary>
/// Represents a logitech RGB-device.
/// </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;
// ReSharper disable once StaticMemberInGenericType - This is used like a const
private static readonly List<int> RECEIVER_PIDS = new()
{
0xC539,
0xC53A,
0xC541,
0xC545,
0xC547
};
private static readonly List<int> RECEIVER_PIDS =
[
0xC539,
0xC53A,
0xC541,
0xC545,
0xC547
];
#endregion
#region Properties & Fields
private readonly Dictionary<int, HIDDeviceDefinition<TLed, TData>> _deviceDefinitions = new();
private readonly Dictionary<int, HIDDeviceDefinition<TLed, TData>> _deviceDefinitions = [];
/// <summary>
/// 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_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))
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.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/LogitechLedEnginesWrapper.dll" };
public static List<string> PossibleX86NativePaths { get; } = ["x86/LogitechLedEnginesWrapper.dll"];
/// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/LogitechLedEnginesWrapper.dll" };
public static List<string> PossibleX64NativePaths { get; } = ["x64/LogitechLedEnginesWrapper.dll"];
private LogitechPerDeviceUpdateQueue? _perDeviceUpdateQueue;
private LogitechPerKeyUpdateQueue? _perKeyUpdateQueue;
@ -162,7 +162,7 @@ public class LogitechDeviceProvider : AbstractRGBDeviceProvider
/// <summary>
/// Gets the HID-definitions for wireless per-device-devices.
/// </summary>
public static LightspeedHIDLoader<int, int> PerDeviceWirelessDeviceDefinitions { get; } = new();
public static LightspeedHIDLoader<int, int> PerDeviceWirelessDeviceDefinitions { get; } = [];
#endregion

View File

@ -17,7 +17,7 @@ internal static class _LogitechGSDK
{
#region Libary Management
private static IntPtr _handle = IntPtr.Zero;
private static nint _handle = 0;
/// <summary>
/// Reloads the SDK.
@ -30,7 +30,7 @@ internal static class _LogitechGSDK
private static void LoadLogitechGSDK()
{
if (_handle != IntPtr.Zero) return;
if (_handle != 0) return;
List<string> possiblePathList = GetPossibleLibraryPaths().ToList();
@ -70,21 +70,21 @@ internal static class _LogitechGSDK
internal static void UnloadLogitechGSDK()
{
if (_handle == IntPtr.Zero) return;
if (_handle == 0) return;
_logiLedInitPointer = IntPtr.Zero;
_logiLedShutdownPointer = IntPtr.Zero;
_logiLedSetTargetDevicePointer = IntPtr.Zero;
_logiLedGetSdkVersionPointer = IntPtr.Zero;
_lgiLedSaveCurrentLightingPointer = IntPtr.Zero;
_logiLedRestoreLightingPointer = IntPtr.Zero;
_logiLedSetLightingPointer = IntPtr.Zero;
_logiLedSetLightingForKeyWithKeyNamePointer = IntPtr.Zero;
_logiLedSetLightingFromBitmapPointer = IntPtr.Zero;
_logiLedSetLightingForTargetZonePointer = IntPtr.Zero;
_logiLedInitPointer = 0;
_logiLedShutdownPointer = 0;
_logiLedSetTargetDevicePointer = 0;
_logiLedGetSdkVersionPointer = 0;
_lgiLedSaveCurrentLightingPointer = 0;
_logiLedRestoreLightingPointer = 0;
_logiLedSetLightingPointer = 0;
_logiLedSetLightingForKeyWithKeyNamePointer = 0;
_logiLedSetLightingFromBitmapPointer = 0;
_logiLedSetLightingForTargetZonePointer = 0;
NativeLibrary.Free(_handle);
_handle = IntPtr.Zero;
_handle = 0;
}
#endregion
@ -93,16 +93,16 @@ internal static class _LogitechGSDK
#region Pointers
private static IntPtr _logiLedInitPointer;
private static IntPtr _logiLedShutdownPointer;
private static IntPtr _logiLedSetTargetDevicePointer;
private static IntPtr _logiLedGetSdkVersionPointer;
private static IntPtr _lgiLedSaveCurrentLightingPointer;
private static IntPtr _logiLedRestoreLightingPointer;
private static IntPtr _logiLedSetLightingPointer;
private static IntPtr _logiLedSetLightingForKeyWithKeyNamePointer;
private static IntPtr _logiLedSetLightingFromBitmapPointer;
private static IntPtr _logiLedSetLightingForTargetZonePointer;
private static nint _logiLedInitPointer;
private static nint _logiLedShutdownPointer;
private static nint _logiLedSetTargetDevicePointer;
private static nint _logiLedGetSdkVersionPointer;
private static nint _lgiLedSaveCurrentLightingPointer;
private static nint _logiLedRestoreLightingPointer;
private static nint _logiLedSetLightingPointer;
private static nint _logiLedSetLightingForKeyWithKeyNamePointer;
private static nint _logiLedSetLightingFromBitmapPointer;
private static nint _logiLedSetLightingForTargetZonePointer;
#endregion
@ -146,9 +146,9 @@ internal static class _LogitechGSDK
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);
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;
}

View File

@ -5,5 +5,4 @@ namespace RGB.NET.Devices.Msi;
/// <summary>
/// Represents a MSI RGB-device.
/// </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.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/MysticLight_SDK.dll" };
public static List<string> PossibleX86NativePaths { get; } = ["x86/MysticLight_SDK.dll"];
/// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/MysticLight_SDK.dll" };
public static List<string> PossibleX64NativePaths { get; } = ["x64/MysticLight_SDK.dll"];
#endregion

View File

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

View File

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

View File

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

View File

@ -17,7 +17,7 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
// ReSharper disable once InconsistentNaming
private static readonly object _lock = new();
private readonly List<OpenRgbClient> _clients = new();
private readonly List<OpenRgbClient> _clients = [];
private static OpenRGBDeviceProvider? _instance;
@ -36,7 +36,7 @@ public sealed class OpenRGBDeviceProvider : AbstractRGBDeviceProvider
/// <summary>
/// Gets a list of all defined device-definitions.
/// </summary>
public List<OpenRGBServerDefinition> DeviceDefinitions { get; } = new();
public List<OpenRGBServerDefinition> DeviceDefinitions { get; } = [];
/// <summary>
/// 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>
/// Gets the defautlt offset-mapping.
/// </summary>
public static LedMapping<int> StripeMapping = new();
public static LedMapping<int> StripeMapping = [];
#endregion

View File

@ -49,7 +49,7 @@ public sealed class PicoPiDeviceProvider : AbstractRGBDeviceProvider
{ PicoPiSDK.HID_BULK_CONTROLLER_PID, RGBDeviceType.LedStripe, "WS2812B-Controller", LedMappings.StripeMapping, 0 },
};
private readonly List<PicoPiSDK> _sdks = new();
private readonly List<PicoPiSDK> _sdks = [];
/// <summary>
/// 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
/// <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];
@ -35,14 +35,14 @@ public sealed class RazerChromaLinkUpdateQueue : RazerUpdateQueue
_ChromaLinkCustomEffect effectParams = new()
{ Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false);
return ptr;
}
/// <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
}

View File

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

View File

@ -386,20 +386,20 @@ public static class LedMappings
/// <summary>
/// Gets the mapping for mousepads.
/// </summary>
public static LedMapping<int> Mousepad { get; } = new();
public static LedMapping<int> Mousepad { get; } = [];
/// <summary>
/// Gets the mapping for headsets.
/// </summary>
public static LedMapping<int> Headset { get; } = new();
public static LedMapping<int> Headset { get; } = [];
/// <summary>
/// Gets the mapping for keypads.
/// </summary>
public static LedMapping<int> Keypad { get; } = new();
public static LedMapping<int> Keypad { get; } = [];
/// <summary>
/// Gets the mapping for chroma link devices.
/// </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
{
IntPtr effectParams = CreateEffectParams(dataSet);
nint effectParams = CreateEffectParams(dataSet);
Guid effectId = Guid.NewGuid();
CreateEffect(effectParams, ref effectId);
@ -60,7 +60,7 @@ public abstract class RazerUpdateQueue : UpdateQueue
/// </summary>
/// <param name="effectParams">The parameters of the effect.</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 />
public override void Reset()
@ -77,7 +77,7 @@ public abstract class RazerUpdateQueue : UpdateQueue
/// </summary>
/// <param name="dataSet">The data to be updated.</param>
/// <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
}

View File

@ -25,7 +25,7 @@ public sealed class RazerHeadsetUpdateQueue : RazerUpdateQueue
#region Methods
/// <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];
@ -35,14 +35,14 @@ public sealed class RazerHeadsetUpdateQueue : RazerUpdateQueue
_HeadsetCustomEffect effectParams = new()
{ Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false);
return ptr;
}
/// <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
}

View File

@ -25,7 +25,7 @@ public sealed class RazerKeyboardUpdateQueue : RazerUpdateQueue
#region Methods
/// <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];
@ -34,14 +34,14 @@ public sealed class RazerKeyboardUpdateQueue : RazerUpdateQueue
_KeyboardCustomEffect effectParams = new() { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false);
return ptr;
}
/// <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
}

View File

@ -25,7 +25,7 @@ public sealed class RazerKeypadUpdateQueue : RazerUpdateQueue
#region Methods
/// <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];
@ -34,14 +34,14 @@ public sealed class RazerKeypadUpdateQueue : RazerUpdateQueue
_KeypadCustomEffect effectParams = new() { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false);
return ptr;
}
/// <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
}

View File

@ -25,7 +25,7 @@ public sealed class RazerMouseUpdateQueue : RazerUpdateQueue
#region Methods
/// <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];
@ -34,7 +34,7 @@ public sealed class RazerMouseUpdateQueue : RazerUpdateQueue
_MouseCustomEffect effectParams = new() { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false);
return ptr;
@ -42,7 +42,7 @@ public sealed class RazerMouseUpdateQueue : RazerUpdateQueue
/// <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
}

View File

@ -25,7 +25,7 @@ public sealed class RazerMousepadUpdateQueue : RazerUpdateQueue
#region Methods
/// <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];
@ -34,14 +34,14 @@ public sealed class RazerMousepadUpdateQueue : RazerUpdateQueue
_MousepadCustomEffect effectParams = new() { Color = colors };
IntPtr ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
nint ptr = Marshal.AllocHGlobal(Marshal.SizeOf(effectParams));
Marshal.StructureToPtr(effectParams, ptr, false);
return ptr;
}
/// <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
}

View File

@ -10,11 +10,12 @@ namespace RGB.NET.Devices.Razer.Native;
// ReSharper disable once InconsistentNaming
[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
public uint Color;
public uint Color = red + ((uint)green << 8) + ((uint)blue << 16);
#endregion
@ -23,11 +24,5 @@ internal struct _Color
public _Color(Color color)
: 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
}

View File

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

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.
/// The first match will be used.
/// </summary>
public static List<string> PossibleX86NativePaths { get; } = new() { @"%systemroot%\SysWOW64\RzChromaSDK.dll" };
public static List<string> PossibleX86NativePaths { get; } = [@"%systemroot%\SysWOW64\RzChromaSDK.dll"];
/// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used.
/// </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>
/// 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
[JsonPropertyName("data")]
public Dictionary<string, object> Data { get; } = new();
public Dictionary<string, object> Data { get; } = [];
#endregion

View File

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

View File

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

View File

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

View File

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

View File

@ -39,7 +39,7 @@ public sealed class BitwizardWS281XDeviceDefinition : IWS281XDeviceDefinition
/// <summary>
/// Gets a list of LED-strips configured on this device.
/// </summary>
public List<(int pin, int stripLength)> Strips { get; } = new();
public List<(int pin, int stripLength)> Strips { get; } = [];
/// <summary>
/// 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 UdpClient? _udpClient;
private readonly Dictionary<int, byte[]> _dataBuffer = new();
private readonly Dictionary<int, byte> _sequenceNumbers = new();
private readonly Dictionary<int, byte[]> _dataBuffer = [];
private readonly Dictionary<int, byte> _sequenceNumbers = [];
private readonly Action<byte[]> _sendDataAction;

View File

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

View File

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

View File

@ -15,7 +15,7 @@ internal static class _WootingSDK
{
#region Library management
private static IntPtr _handle = IntPtr.Zero;
private static nint _handle = 0;
internal static object SdkLock = new();
/// <summary>
@ -29,7 +29,7 @@ internal static class _WootingSDK
private static void LoadWootingSDK()
{
if (_handle != IntPtr.Zero) return;
if (_handle != 0) return;
List<string> possiblePathList = GetPossibleLibraryPaths().ToList();
@ -71,21 +71,21 @@ internal static class _WootingSDK
internal static void UnloadWootingSDK()
{
if (_handle == IntPtr.Zero) return;
if (_handle == 0) return;
Close();
_getDeviceInfoPointer = IntPtr.Zero;
_keyboardConnectedPointer = IntPtr.Zero;
_resetPointer = IntPtr.Zero;
_closePointer = IntPtr.Zero;
_arrayUpdateKeyboardPointer = IntPtr.Zero;
_arraySetSinglePointer = IntPtr.Zero;
_getDeviceCountPointer = IntPtr.Zero;
_selectDevicePointer = IntPtr.Zero;
_getDeviceInfoPointer = 0;
_keyboardConnectedPointer = 0;
_resetPointer = 0;
_closePointer = 0;
_arrayUpdateKeyboardPointer = 0;
_arraySetSinglePointer = 0;
_getDeviceCountPointer = 0;
_selectDevicePointer = 0;
NativeLibrary.Free(_handle);
_handle = IntPtr.Zero;
_handle = 0;
}
#endregion
@ -94,18 +94,18 @@ internal static class _WootingSDK
#region Pointers
private static IntPtr _getDeviceInfoPointer;
private static IntPtr _keyboardConnectedPointer;
private static IntPtr _resetPointer;
private static IntPtr _closePointer;
private static IntPtr _arrayUpdateKeyboardPointer;
private static IntPtr _arraySetSinglePointer;
private static IntPtr _getDeviceCountPointer;
private static IntPtr _selectDevicePointer;
private static nint _getDeviceInfoPointer;
private static nint _keyboardConnectedPointer;
private static nint _resetPointer;
private static nint _closePointer;
private static nint _arrayUpdateKeyboardPointer;
private static nint _arraySetSinglePointer;
private static nint _getDeviceCountPointer;
private static nint _selectDevicePointer;
#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 Reset() => ((delegate* unmanaged[Cdecl]<bool>)ThrowIfZero(_resetPointer))();
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 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;
}

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.
/// The first match will be used.
/// </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>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 windows applications.
/// The first match will be used.
/// </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>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 linux applications.
/// The first match will be used.
/// </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>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 MacOS applications.
/// The first match will be used.
/// </summary>
// 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

View File

@ -24,7 +24,7 @@ public sealed class HIDLoader<TLed, TData> : IEnumerable<HIDDeviceDefinition<TLe
{
#region Properties & Fields
private readonly Dictionary<int, HIDDeviceDefinition<TLed, TData>> _deviceDefinitions = new();
private readonly Dictionary<int, HIDDeviceDefinition<TLed, TData>> _deviceDefinitions = [];
/// <summary>
/// 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.
/// </summary>
[XmlArray("Leds")]
public List<LedLayout> InternalLeds { get; set; } = new();
public List<LedLayout> InternalLeds { get; set; } = [];
/// <summary>
/// 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