Fixed warnings

This commit is contained in:
DarthAffe committed 2021-02-02 23:37:56 +01:00
1 parent 57dc9afb32
commit a0a1521658
118 files changed
+802 -1181

No files matched your search

@@ -1,21 +0,0 @@
// ReSharper disable InconsistentNaming
// ReSharper disable UnusedMember.Global
#pragma warning disable 1591 // Missing XML comment for publicly visible type or member
namespace RGB.NET.Devices.Wooting.Enum
{
/// <summary>
/// Contains list of available logical layouts for cooler master keyboards.
/// </summary>
/// <remarks>
/// Based on what is available in the shop: https://wooting.store/collections/wooting-keyboards/products/wooting-two
/// </remarks>
public enum WootingLogicalKeyboardLayout
{
US = 0,
UK = 1,
DE = 2,
ND = 3
};
}
@@ -23,7 +23,7 @@ namespace RGB.NET.Devices.Wooting.Generic
/// Gets or sets the update queue performing updates for this device.
/// </summary>
// ReSharper disable once MemberCanBePrivate.Global
protected UpdateQueue UpdateQueue { get; set; }
protected UpdateQueue? UpdateQueue { get; set; }
#endregion
@@ -51,7 +51,7 @@ namespace RGB.NET.Devices.Wooting.Generic
if (Size == Size.Invalid)
{
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
Rectangle ledRectangle = new(this.Select(x => x.LedRectangle));
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
}
@@ -1,5 +1,4 @@
using System;
using RGB.NET.Core;
using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Enum;
using RGB.NET.Devices.Wooting.Helper;
@@ -47,7 +46,7 @@ namespace RGB.NET.Devices.Wooting.Generic
this.DeviceType = deviceType;
this.DeviceIndex = deviceIndex;
Model = deviceIndex.GetDescription();
Model = deviceIndex.GetDescription() ?? "Unknown";
DeviceName = $"{Manufacturer} {Model}";
}
@@ -1,7 +1,6 @@
using System;
using System.ComponentModel;
using System.Reflection;
using RGB.NET.Core;
namespace RGB.NET.Devices.Wooting.Helper
{
@@ -14,26 +13,21 @@ namespace RGB.NET.Devices.Wooting.Helper
/// Gets the value of the <see cref="DescriptionAttribute"/>.
/// </summary>
/// <param name="source">The enum value to get the description from.</param>
/// <typeparam name="T">The generic enum-type</typeparam>
/// <returns>The value of the <see cref="DescriptionAttribute"/> or the <see cref="Enum.ToString()" /> result of the source.</returns>
internal static string GetDescription<T>(this T source)
where T : struct
{
return source.GetAttribute<DescriptionAttribute, T>()?.Description ?? source.ToString();
}
/// <returns>The value of the <see cref="DescriptionAttribute"/> or the <see cref="System.Enum.ToString()" /> result of the source.</returns>
internal static string? GetDescription(this System.Enum source)
=> source.GetAttribute<DescriptionAttribute>()?.Description ?? source.ToString();
/// <summary>
/// Gets the attribute of type T.
/// </summary>
/// <param name="source">The enum value to get the attribute from</param>
/// <typeparam name="T">The generic attribute type</typeparam>
/// <typeparam name="TEnum">The generic enum-type</typeparam>
/// <returns>The <see cref="Attribute"/>.</returns>
private static T GetAttribute<T, TEnum>(this TEnum source)
private static T? GetAttribute<T>(this System.Enum source)
where T : Attribute
where TEnum : struct
{
FieldInfo fi = source.GetType().GetField(source.ToString());
FieldInfo? fi = source.GetType().GetField(source.ToString());
if (fi == null) return null;
T[] attributes = (T[])fi.GetCustomAttributes(typeof(T), false);
return attributes.Length > 0 ? attributes[0] : null;
}
@@ -15,8 +15,8 @@ namespace RGB.NET.Devices.Wooting.Keyboard
#region Wooting One
private static readonly Dictionary<LedId, (int row, int column)> WootingOne_US = new Dictionary<LedId, (int row, int column)>
{
private static readonly Dictionary<LedId, (int row, int column)> WootingOne_US = new()
{
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,2) },
{ LedId.Keyboard_F2, (0,3) },
@@ -111,8 +111,8 @@ namespace RGB.NET.Devices.Wooting.Keyboard
{ LedId.Keyboard_ArrowRight, (5,16) }
};
private static readonly Dictionary<LedId, (int row, int column)> WootingOne_UK = new Dictionary<LedId, (int row, int column)>
{
private static readonly Dictionary<LedId, (int row, int column)> WootingOne_UK = new()
{
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,2) },
{ LedId.Keyboard_F2, (0,3) },
@@ -213,8 +213,8 @@ namespace RGB.NET.Devices.Wooting.Keyboard
#region Wooting Two
private static readonly Dictionary<LedId, (int row, int column)> WootingTwo_US = new Dictionary<LedId, (int row, int column)>
{
private static readonly Dictionary<LedId, (int row, int column)> WootingTwo_US = new()
{
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,2) },
{ LedId.Keyboard_F2, (0,3) },
@@ -330,8 +330,8 @@ namespace RGB.NET.Devices.Wooting.Keyboard
{ LedId.Keyboard_NumPeriodAndDelete, (5,19) }
};
private static readonly Dictionary<LedId, (int row, int column)> WootingTwo_UK = new Dictionary<LedId, (int row, int column)>
{
private static readonly Dictionary<LedId, (int row, int column)> WootingTwo_UK = new()
{
{ LedId.Keyboard_Escape, (0,0) },
{ LedId.Keyboard_F1, (0,2) },
{ LedId.Keyboard_F2, (0,3) },
@@ -455,7 +455,7 @@ namespace RGB.NET.Devices.Wooting.Keyboard
/// Contains all the hardware-id mappings for Wooting devices.
/// </summary>
public static readonly Dictionary<WootingDevicesIndexes, Dictionary<WootingPhysicalKeyboardLayout, Dictionary<LedId, (int row, int column)>>> Mapping =
new Dictionary<WootingDevicesIndexes, Dictionary<WootingPhysicalKeyboardLayout, Dictionary<LedId, (int row, int column)>>>
new()
{
{ WootingDevicesIndexes.WootingOne, new Dictionary<WootingPhysicalKeyboardLayout, Dictionary<LedId, (int row, int column)>>
{
@@ -39,7 +39,7 @@ namespace RGB.NET.Devices.Wooting.Keyboard
protected override object GetLedCustomData(LedId ledId) => WootingKeyboardLedMappings.Mapping[DeviceInfo.DeviceIndex][DeviceInfo.PhysicalLayout][ledId];
/// <inheritdoc />
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
protected override void UpdateLeds(IEnumerable<Led> ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0));
#endregion
}
@@ -18,11 +18,6 @@ namespace RGB.NET.Devices.Wooting.Keyboard
/// </summary>
public WootingPhysicalKeyboardLayout PhysicalLayout { get; }
/// <summary>
/// Gets the <see cref="WootingLogicalKeyboardLayout"/> of the <see cref="WootingKeyboardRGBDevice"/>.
/// </summary>
public WootingLogicalKeyboardLayout LogicalLayout { get; private set; }
#endregion
#region Constructors
@@ -33,29 +28,10 @@ namespace RGB.NET.Devices.Wooting.Keyboard
/// </summary>
/// <param name="deviceIndex">The index of the <see cref="T:RGB.NET.Devices.Wooting.WootingKeyboardRGBDevice" />.</param>
/// <param name="physicalKeyboardLayout">The <see cref="T:RGB.NET.Devices.Wooting.WootingPhysicalKeyboardLayout" /> of the <see cref="T:RGB.NET.Devices.Wooting.WootingKeyboardRGBDevice" />.</param>
/// <param name="culture">The <see cref="T:System.Globalization.CultureInfo" /> of the layout this keyboard is using</param>
internal WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes deviceIndex, WootingPhysicalKeyboardLayout physicalKeyboardLayout,
CultureInfo culture)
internal WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes deviceIndex, WootingPhysicalKeyboardLayout physicalKeyboardLayout)
: base(RGBDeviceType.Keyboard, deviceIndex)
{
this.PhysicalLayout = physicalKeyboardLayout;
DetermineLogicalLayout(culture.KeyboardLayoutId);
}
private void DetermineLogicalLayout(int keyboardLayoutId)
{
switch (keyboardLayoutId)
{
// TODO SpoinkyNL 15-12-2019: There doesn't seem to be an accurate way to determine this, perhaps it should be a configurable thing..
// I'm using US International and it's reporting nl-NL's 1043. Also you can after all just swap your keycaps
default:
if (PhysicalLayout == WootingPhysicalKeyboardLayout.US)
LogicalLayout = WootingLogicalKeyboardLayout.US;
else
LogicalLayout = WootingLogicalKeyboardLayout.UK;
break;
}
}
#endregion
+14 -19
View File
@@ -17,11 +17,6 @@ namespace RGB.NET.Devices.Wooting.Native
private static IntPtr _dllHandle = IntPtr.Zero;
/// <summary>
/// Gets the loaded architecture (x64/x86).
/// </summary>
internal static string LoadedArchitecture { get; private set; }
/// <summary>
/// Reloads the SDK.
/// </summary>
@@ -37,10 +32,10 @@ namespace RGB.NET.Devices.Wooting.Native
// HACK: Load library at runtime to support both, x86 and x64 with one managed dll
List<string> possiblePathList = Environment.Is64BitProcess ? WootingDeviceProvider.PossibleX64NativePaths : WootingDeviceProvider.PossibleX86NativePaths;
string dllPath = possiblePathList.FirstOrDefault(File.Exists);
string? dllPath = possiblePathList.FirstOrDefault(File.Exists);
if (dllPath == null) throw new RGBDeviceException($"Can't find the Wooting-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'");
SetDllDirectory(Path.GetDirectoryName(Path.GetFullPath(dllPath)));
SetDllDirectory(Path.GetDirectoryName(Path.GetFullPath(dllPath))!);
_dllHandle = LoadLibrary(dllPath);
@@ -79,12 +74,12 @@ namespace RGB.NET.Devices.Wooting.Native
#region Pointers
private static GetDeviceInfoPointer _getDeviceInfoPointer;
private static KeyboardConnectedPointer _keyboardConnectedPointer;
private static ResetPointer _resetPointer;
private static ClosePointer _closePointer;
private static ArrayUpdateKeyboardPointer _arrayUpdateKeyboardPointer;
private static ArraySetSinglePointer _arraySetSinglePointer;
private static GetDeviceInfoPointer? _getDeviceInfoPointer;
private static KeyboardConnectedPointer? _keyboardConnectedPointer;
private static ResetPointer? _resetPointer;
private static ClosePointer? _closePointer;
private static ArrayUpdateKeyboardPointer? _arrayUpdateKeyboardPointer;
private static ArraySetSinglePointer? _arraySetSinglePointer;
#endregion
@@ -110,12 +105,12 @@ namespace RGB.NET.Devices.Wooting.Native
#endregion
internal static IntPtr GetDeviceInfo() => _getDeviceInfoPointer();
internal static bool KeyboardConnected() => _keyboardConnectedPointer();
internal static bool Reset() => _resetPointer();
internal static bool Close() => _closePointer();
internal static bool ArrayUpdateKeyboard() => _arrayUpdateKeyboardPointer();
internal static bool ArraySetSingle(byte row, byte column, byte red, byte green, byte blue) => _arraySetSinglePointer(row, column, red, green, blue);
internal static IntPtr GetDeviceInfo() => (_getDeviceInfoPointer ?? throw new RGBDeviceException("The Wooting-SDK is not initialized.")).Invoke();
internal static bool KeyboardConnected() => (_keyboardConnectedPointer ?? throw new RGBDeviceException("The Wooting-SDK is not initialized.")).Invoke();
internal static bool Reset() => (_resetPointer ?? throw new RGBDeviceException("The Wooting-SDK is not initialized.")).Invoke();
internal static bool Close() => (_closePointer ?? throw new RGBDeviceException("The Wooting-SDK is not initialized.")).Invoke();
internal static bool ArrayUpdateKeyboard() => (_arrayUpdateKeyboardPointer ?? throw new RGBDeviceException("The Wooting-SDK is not initialized.")).Invoke();
internal static bool ArraySetSingle(byte row, byte column, byte red, byte green, byte blue) => (_arraySetSinglePointer ?? throw new RGBDeviceException("The Wooting-SDK is not initialized.")).Invoke(row, column, red, green, blue);
#endregion
}
@@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Runtime.InteropServices;
using RGB.NET.Core;
using RGB.NET.Devices.Wooting.Enum;
@@ -18,7 +19,7 @@ namespace RGB.NET.Devices.Wooting
{
#region Properties & Fields
private static WootingDeviceProvider _instance;
private static WootingDeviceProvider? _instance;
/// <summary>
/// Gets the singleton <see cref="WootingDeviceProvider"/> instance.
/// </summary>
@@ -28,13 +29,13 @@ namespace RGB.NET.Devices.Wooting
/// 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 List<string> { "x86/wooting-rgb-sdk.dll" };
public static List<string> PossibleX86NativePaths { get; } = new() { "x86/wooting-rgb-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 List<string> { "x64/wooting-rgb-sdk64.dll" };
public static List<string> PossibleX64NativePaths { get; } = new() { "x64/wooting-rgb-sdk64.dll" };
/// <inheritdoc />
/// <summary>
@@ -42,24 +43,13 @@ namespace RGB.NET.Devices.Wooting
/// </summary>
public bool IsInitialized { get; private set; }
/// <summary>
/// Gets the loaded architecture (x64/x86).
/// </summary>
public string LoadedArchitecture => _WootingSDK.LoadedArchitecture;
/// <inheritdoc />
/// <summary>
/// Gets whether the application has exclusive access to the SDK or not.
/// </summary>
public bool HasExclusiveAccess => false;
/// <inheritdoc />
public IEnumerable<IRGBDevice> Devices { get; private set; }
public IEnumerable<IRGBDevice> Devices { get; private set; } = Enumerable.Empty<IRGBDevice>();
/// <summary>
/// The <see cref="DeviceUpdateTrigger"/> used to trigger the updates for cooler master devices.
/// </summary>
public DeviceUpdateTrigger UpdateTrigger { get; private set; }
public DeviceUpdateTrigger UpdateTrigger { get; }
#endregion
@@ -84,45 +74,33 @@ namespace RGB.NET.Devices.Wooting
/// <inheritdoc />
/// <exception cref="RGBDeviceException">Thrown if the SDK failed to initialize</exception>
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false,
bool throwExceptions = false)
public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
{
IsInitialized = false;
try
{
UpdateTrigger?.Stop();
UpdateTrigger.Stop();
_WootingSDK.Reload();
IList<IRGBDevice> devices = new List<IRGBDevice>();
if (_WootingSDK.KeyboardConnected())
{
_WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo));
IWootingRGBDevice device;
// TODO: Find an accurate way to determine physical and logical layouts
if (nativeDeviceInfo.Model == "Wooting two")
_WootingDeviceInfo nativeDeviceInfo = (_WootingDeviceInfo)Marshal.PtrToStructure(_WootingSDK.GetDeviceInfo(), typeof(_WootingDeviceInfo))!;
IWootingRGBDevice device = nativeDeviceInfo.Model switch
{
device = new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingTwo,
WootingPhysicalKeyboardLayout.US,
CultureHelper.GetCurrentCulture()));
}
else if (nativeDeviceInfo.Model == "Wooting one")
{
device = new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingOne,
WootingPhysicalKeyboardLayout.US,
CultureHelper.GetCurrentCulture()));
}
else
{
throw new RGBDeviceException("No supported Wooting keyboard connected");
}
// TODO: Find an accurate way to determine physical and logical layouts
"Wooting two" => new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingTwo, WootingPhysicalKeyboardLayout.US)),
"Wooting one" => new WootingKeyboardRGBDevice(new WootingKeyboardRGBDeviceInfo(WootingDevicesIndexes.WootingOne, WootingPhysicalKeyboardLayout.US)),
_ => throw new RGBDeviceException("No supported Wooting keyboard connected")
};
device.Initialize(UpdateTrigger);
devices.Add(device);
}
UpdateTrigger?.Start();
UpdateTrigger.Start();
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
IsInitialized = true;
@@ -143,7 +121,7 @@ namespace RGB.NET.Devices.Wooting
/// <inheritdoc />
public void Dispose()
{
try { UpdateTrigger?.Dispose(); }
try { UpdateTrigger.Dispose(); }
catch { /* at least we tried */ }
try { _WootingSDK.Close(); }