diff --git a/RGB.NET.Core/Devices/IRGBDeviceInfo.cs b/RGB.NET.Core/Devices/IRGBDeviceInfo.cs index 8bf1d90..3bb29c2 100644 --- a/RGB.NET.Core/Devices/IRGBDeviceInfo.cs +++ b/RGB.NET.Core/Devices/IRGBDeviceInfo.cs @@ -1,6 +1,4 @@ -using System; - -namespace RGB.NET.Core +namespace RGB.NET.Core { /// /// Represents a generic information for a diff --git a/RGB.NET.Core/Devices/IRGBDeviceProvider.cs b/RGB.NET.Core/Devices/IRGBDeviceProvider.cs index cac84e5..6060feb 100644 --- a/RGB.NET.Core/Devices/IRGBDeviceProvider.cs +++ b/RGB.NET.Core/Devices/IRGBDeviceProvider.cs @@ -21,5 +21,11 @@ namespace RGB.NET.Core IEnumerable Devices { get; } #endregion + + #region Methods + + bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false); + + #endregion } } diff --git a/RGB.NET.Core/Helper/PathHelper.cs b/RGB.NET.Core/Helper/PathHelper.cs deleted file mode 100644 index f61189a..0000000 --- a/RGB.NET.Core/Helper/PathHelper.cs +++ /dev/null @@ -1,83 +0,0 @@ -using System; -using System.IO; -using System.Reflection; - -namespace RGB.NET.Core -{ - /// - /// Offers some helper-methods for file-path related things. - /// - public static class PathHelper - { - #region Events - - /// - /// Occurs when a path is resolving. - /// - public static event EventHandler? ResolvingAbsolutePath; - - #endregion - - #region Methods - - /// - /// Returns an absolute path created from an relative path relatvie to the location of the executung assembly. - /// - /// The relative part of the path to convert. - /// The absolute path. - public static string GetAbsolutePath(string relativePath) => GetAbsolutePath((object?)null, relativePath); - - /// - /// Returns an absolute path created from an relative path relatvie to the location of the executung assembly. - /// - /// The relative part of the path to convert. - /// The file name of the path to convert. - /// The absolute path. - public static string GetAbsolutePath(string relativePath, string fileName) => GetAbsolutePath(null, relativePath, fileName); - - /// - /// Returns an absolute path created from an relative path relatvie to the location of the executung assembly. - /// - /// The requester of this path. (Used for better control when using the event to override this behavior.) - /// The relative path to convert. - /// The file name of the path to convert. - /// The absolute path. - public static string GetAbsolutePath(object? sender, string relativePath, string fileName) - { - string relativePart = Path.Combine(relativePath, fileName); - - string? assemblyLocation = Assembly.GetEntryAssembly()?.Location; - if (assemblyLocation == null) return relativePart; - - string? directoryName = Path.GetDirectoryName(assemblyLocation); - string path = directoryName == null ? string.Empty : Path.Combine(directoryName, relativePart); - - ResolvePathEventArgs args = new(relativePath, fileName, path); - ResolvingAbsolutePath?.Invoke(sender, args); - - return args.FinalPath; - } - - /// - /// Returns an absolute path created from an relative path relatvie to the location of the executung assembly. - /// - /// The requester of this path. (Used for better control when using the event to override this behavior.) - /// The relative path to convert. - /// The absolute path. - public static string GetAbsolutePath(object? sender, string relativePath) - { - string? assemblyLocation = Assembly.GetEntryAssembly()?.Location; - if (assemblyLocation == null) return relativePath; - - string? directoryName = Path.GetDirectoryName(assemblyLocation); - string path = directoryName == null ? string.Empty : Path.Combine(directoryName, relativePath); - - ResolvePathEventArgs args = new(relativePath, path); - ResolvingAbsolutePath?.Invoke(sender, args); - - return args.FinalPath; - } - - #endregion - } -} diff --git a/RGB.NET.Core/Positioning/Rotation.cs b/RGB.NET.Core/Positioning/Rotation.cs index a2f9219..623f64a 100644 --- a/RGB.NET.Core/Positioning/Rotation.cs +++ b/RGB.NET.Core/Positioning/Rotation.cs @@ -9,7 +9,7 @@ namespace RGB.NET.Core /// /// Represents an angular rotation. /// - [DebuggerDisplay("[{Degrees}°]")] + [DebuggerDisplay("[{" + nameof(Degrees) + "}°]")] public readonly struct Rotation { #region Constants diff --git a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs index 7ad35d4..7372b20 100644 --- a/RGB.NET.Devices.Asus/AsusDeviceProvider.cs +++ b/RGB.NET.Devices.Asus/AsusDeviceProvider.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Globalization; using System.Linq; using AuraServiceLib; using RGB.NET.Core; @@ -37,7 +36,7 @@ namespace RGB.NET.Devices.Asus /// /// The used to trigger the updates for asus devices. /// - public DeviceUpdateTrigger UpdateTrigger { get; private set; } + public DeviceUpdateTrigger UpdateTrigger { get; } private IAuraSdk2? _sdk; @@ -58,11 +57,11 @@ namespace RGB.NET.Devices.Asus } #endregion - + #region Methods /// - public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) + public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false) { IsInitialized = false; @@ -105,7 +104,7 @@ namespace RGB.NET.Devices.Asus case AsusDeviceType.KEYBOARD_RGB: case AsusDeviceType.NB_KB_RGB: case AsusDeviceType.NB_KB_4ZONE_RGB: - rgbDevice = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device, CultureInfo.CurrentCulture)); + rgbDevice = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(device, AsusPhysicalKeyboardLayout.Default)); break; case AsusDeviceType.MOUSE_RGB: @@ -144,19 +143,17 @@ namespace RGB.NET.Devices.Asus return true; } - /// - public void ResetDevices() - { - _sdk?.ReleaseControl(0); - _sdk?.SwitchMode(); - } - /// public void Dispose() { - try { UpdateTrigger?.Dispose(); } + try { UpdateTrigger.Dispose(); } catch { /* at least we tried */ } + foreach (IRGBDevice device in Devices) + try { device.Dispose(); } + catch { /* at least we tried */ } + Devices = Enumerable.Empty(); + try { _sdk?.ReleaseControl(0); } catch { /* at least we tried */ } diff --git a/RGB.NET.Devices.Asus/Enum/AsusLogicalKeyboardLayout.cs b/RGB.NET.Devices.Asus/Enum/AsusLogicalKeyboardLayout.cs deleted file mode 100644 index 60105e5..0000000 --- a/RGB.NET.Devices.Asus/Enum/AsusLogicalKeyboardLayout.cs +++ /dev/null @@ -1,15 +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.Asus -{ - /// - /// Contains list of available logical layouts for asus keyboards. - /// - public enum AsusLogicalKeyboardLayout - { - TODO - }; -} diff --git a/RGB.NET.Devices.Asus/Enum/AsusPhysicalKeyboardLayout.cs b/RGB.NET.Devices.Asus/Enum/AsusPhysicalKeyboardLayout.cs index b5e80de..fcc1082 100644 --- a/RGB.NET.Devices.Asus/Enum/AsusPhysicalKeyboardLayout.cs +++ b/RGB.NET.Devices.Asus/Enum/AsusPhysicalKeyboardLayout.cs @@ -10,6 +10,6 @@ namespace RGB.NET.Devices.Asus /// public enum AsusPhysicalKeyboardLayout { - TODO + Default } } diff --git a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs index 5b8a55e..122c0a9 100644 --- a/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Asus/Keyboard/AsusKeyboardRGBDeviceInfo.cs @@ -1,5 +1,4 @@ -using System.Globalization; -using AuraServiceLib; +using AuraServiceLib; using RGB.NET.Core; namespace RGB.NET.Devices.Asus @@ -15,12 +14,7 @@ namespace RGB.NET.Devices.Asus /// /// Gets the physical layout of the keyboard. /// - public AsusPhysicalKeyboardLayout PhysicalLayout { get; private set; } - - /// - /// Gets the logical layout of the keyboard. - /// - public AsusLogicalKeyboardLayout LogicalLayout { get; private set; } + public AsusPhysicalKeyboardLayout PhysicalLayout { get; } #endregion @@ -31,27 +25,10 @@ namespace RGB.NET.Devices.Asus /// Internal constructor of managed . /// /// The backing this RGB.NET device. - /// The of the layout this keyboard is using. - internal AsusKeyboardRGBDeviceInfo(IAuraSyncDevice device, CultureInfo culture) + internal AsusKeyboardRGBDeviceInfo(IAuraSyncDevice device, AsusPhysicalKeyboardLayout layout) : base(RGBDeviceType.Keyboard, device, device.Name) { - SetLayouts(culture.KeyboardLayoutId); - } - - #endregion - - #region Methods - - private void SetLayouts(int keyboardLayoutId) - { - switch (keyboardLayoutId) - { - //TODO DarthAffe 07.10.2017: Implement - default: - PhysicalLayout = AsusPhysicalKeyboardLayout.TODO; - LogicalLayout = AsusLogicalKeyboardLayout.TODO; - break; - } + this.PhysicalLayout = layout; } #endregion diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index 77f7a4a..f7e57dc 100644 --- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -42,7 +42,7 @@ namespace RGB.NET.Devices.CoolerMaster /// Indicates if the SDK is initialized and ready to use. /// public bool IsInitialized { get; private set; } - + /// public IEnumerable Devices { get; private set; } = Enumerable.Empty(); @@ -72,7 +72,7 @@ namespace RGB.NET.Devices.CoolerMaster #region Methods /// - public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) + public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false) { IsInitialized = false; @@ -140,38 +140,16 @@ namespace RGB.NET.Devices.CoolerMaster return true; } - /// - public void ResetDevices() - { - if (IsInitialized) - foreach (IRGBDevice device in Devices) - { - try - { - CoolerMasterRGBDeviceInfo deviceInfo = (CoolerMasterRGBDeviceInfo)device.DeviceInfo; - _CoolerMasterSDK.EnableLedControl(false, deviceInfo.DeviceIndex); - _CoolerMasterSDK.EnableLedControl(true, deviceInfo.DeviceIndex); - } - catch {/* shit happens */} - } - } - /// public void Dispose() { - try { UpdateTrigger?.Dispose(); } + try { UpdateTrigger.Dispose(); } catch { /* at least we tried */ } - if (IsInitialized) - foreach (IRGBDevice device in Devices) - { - try - { - CoolerMasterRGBDeviceInfo deviceInfo = (CoolerMasterRGBDeviceInfo)device.DeviceInfo; - _CoolerMasterSDK.EnableLedControl(false, deviceInfo.DeviceIndex); - } - catch {/* shit happens */} - } + foreach (IRGBDevice device in Devices) + try { device.Dispose(); } + catch { /* at least we tried */ } + Devices = Enumerable.Empty(); // DarthAffe 03.03.2020: Should be done but isn't possible due to an weird winodws-hook inside the sdk which corrupts the stack when unloading the dll //try { _CoolerMasterSDK.UnloadCMSDK(); } diff --git a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs index 6b63cbe..baa3c1b 100644 --- a/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.CoolerMaster/Keyboard/CoolerMasterKeyboardRGBDeviceInfo.cs @@ -25,7 +25,6 @@ namespace RGB.NET.Devices.CoolerMaster /// /// The index of the . /// The of the . - /// The of the layout this keyboard is using internal CoolerMasterKeyboardRGBDeviceInfo(CoolerMasterDevicesIndexes deviceIndex, CoolerMasterPhysicalKeyboardLayout physicalKeyboardLayout) : base(RGBDeviceType.Keyboard, deviceIndex) { diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index b484518..4f7a57a 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -42,7 +42,7 @@ namespace RGB.NET.Devices.Corsair /// Indicates if the SDK is initialized and ready to use. /// public bool IsInitialized { get; private set; } - + /// /// Gets the protocol details for the current SDK-connection. /// @@ -84,7 +84,7 @@ namespace RGB.NET.Devices.Corsair /// /// Thrown if the SDK is already initialized or if the SDK is not compatible to CUE. /// Thrown if the CUE-SDK provides an error. - public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) + public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false) { IsInitialized = false; @@ -126,8 +126,7 @@ namespace RGB.NET.Devices.Corsair { if ((device == null) || !loadFilter.HasFlag(device.DeviceInfo.DeviceType)) continue; - if (deviceUpdateQueue == null) - deviceUpdateQueue = new CorsairDeviceUpdateQueue(UpdateTrigger, info.CorsairDeviceIndex); + deviceUpdateQueue ??= new CorsairDeviceUpdateQueue(UpdateTrigger, info.CorsairDeviceIndex); device.Initialize(deviceUpdateQueue); @@ -231,28 +230,14 @@ namespace RGB.NET.Devices.Corsair { if (deviceType == CorsairDeviceType.Cooler) return CorsairLedId.CustomLiquidCoolerChannel1Led1; - else + + return channel switch { - switch (channel) - { - case 0: return CorsairLedId.CustomDeviceChannel1Led1; - case 1: return CorsairLedId.CustomDeviceChannel2Led1; - case 2: return CorsairLedId.CustomDeviceChannel3Led1; - } - } - - return CorsairLedId.Invalid; - } - - /// - public void ResetDevices() - { - if (IsInitialized) - try - { - _CUESDK.Reload(); - } - catch {/* shit happens */} + 0 => CorsairLedId.CustomDeviceChannel1Led1, + 1 => CorsairLedId.CustomDeviceChannel2Led1, + 2 => CorsairLedId.CustomDeviceChannel3Led1, + _ => CorsairLedId.Invalid + }; } private void Reset() @@ -265,9 +250,14 @@ namespace RGB.NET.Devices.Corsair /// public void Dispose() { - try { UpdateTrigger?.Dispose(); } + try { UpdateTrigger.Dispose(); } catch { /* at least we tried */ } + foreach (IRGBDevice device in Devices) + try { device.Dispose(); } + catch { /* at least we tried */ } + Devices = Enumerable.Empty(); + try { _CUESDK.UnloadCUESDK(); } catch { /* at least we tried */ } } diff --git a/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs b/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs index 7107aa0..0ea52b4 100644 --- a/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Custom/CorsairCustomRGBDevice.cs @@ -46,7 +46,7 @@ namespace RGB.NET.Devices.Corsair } } - protected override object? GetLedCustomData(LedId ledId) => _idMapping.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid; + protected override object GetLedCustomData(LedId ledId) => _idMapping.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid; protected virtual LedId GetReferenceLed(RGBDeviceType deviceType) { diff --git a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs index ec5614b..f9bfa42 100644 --- a/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs +++ b/RGB.NET.Devices.Corsair/Mouse/CorsairMouseRGBDevice.cs @@ -55,7 +55,7 @@ namespace RGB.NET.Devices.Corsair } } - protected override object? GetLedCustomData(LedId ledId) + protected override object GetLedCustomData(LedId ledId) { if (string.Equals(DeviceInfo.Model, "GLAIVE RGB", StringComparison.OrdinalIgnoreCase)) return MouseIdMapping.GLAIVE.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid; diff --git a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs index 7535198..4720e1e 100644 --- a/RGB.NET.Devices.DMX/DMXDeviceProvider.cs +++ b/RGB.NET.Devices.DMX/DMXDeviceProvider.cs @@ -67,7 +67,7 @@ namespace RGB.NET.Devices.DMX public void AddDeviceDefinition(IDMXDeviceDefinition deviceDefinition) => DeviceDefinitions.Add(deviceDefinition); /// - public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) + public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false) { IsInitialized = false; @@ -108,15 +108,16 @@ namespace RGB.NET.Devices.DMX return true; } - /// - public void ResetDevices() - { } - /// public void Dispose() { - try { UpdateTrigger?.Dispose(); } + try { UpdateTrigger.Dispose(); } catch { /* at least we tried */ } + + foreach (IRGBDevice device in Devices) + try { device.Dispose(); } + catch { /* at least we tried */ } + Devices = Enumerable.Empty(); } #endregion diff --git a/RGB.NET.Devices.DMX/E131/E131Device.cs b/RGB.NET.Devices.DMX/E131/E131Device.cs index 5131b9a..edb078e 100644 --- a/RGB.NET.Devices.DMX/E131/E131Device.cs +++ b/RGB.NET.Devices.DMX/E131/E131Device.cs @@ -52,7 +52,7 @@ namespace RGB.NET.Devices.DMX.E131 } /// - protected override object? GetLedCustomData(LedId ledId) => new LedChannelMapping(_ledMappings[ledId]); + protected override object GetLedCustomData(LedId ledId) => new LedChannelMapping(_ledMappings[ledId]); /// diff --git a/RGB.NET.Devices.Debug/DebugRGBDeviceInfo.cs b/RGB.NET.Devices.Debug/DebugRGBDeviceInfo.cs index be65426..b411f91 100644 --- a/RGB.NET.Devices.Debug/DebugRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Debug/DebugRGBDeviceInfo.cs @@ -1,5 +1,4 @@ -using System; -using RGB.NET.Core; +using RGB.NET.Core; namespace RGB.NET.Devices.Debug { diff --git a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs index d5fb52a..8e57da6 100644 --- a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs +++ b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs @@ -39,7 +39,7 @@ namespace RGB.NET.Devices.Logitech /// public bool IsInitialized { get; private set; } - + /// public IEnumerable Devices { get; private set; } = Enumerable.Empty(); @@ -76,7 +76,7 @@ namespace RGB.NET.Devices.Logitech #region Methods /// - public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) + public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false) { try { @@ -165,15 +165,17 @@ namespace RGB.NET.Devices.Logitech return true; } - /// - public void ResetDevices() => _LogitechGSDK.LogiLedRestoreLighting(); - /// public void Dispose() { - try { UpdateTrigger?.Dispose(); } + try { UpdateTrigger.Dispose(); } catch { /* at least we tried */ } + foreach (IRGBDevice device in Devices) + try { device.Dispose(); } + catch { /* at least we tried */ } + Devices = Enumerable.Empty(); + try { _LogitechGSDK.LogiLedRestoreLighting(); } catch { /* at least we tried */ } diff --git a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs index 68d7353..2b5a85d 100644 --- a/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs +++ b/RGB.NET.Devices.Logitech/PerKey/LogitechPerKeyRGBDevice.cs @@ -26,7 +26,7 @@ namespace RGB.NET.Devices.Logitech #region Methods /// - protected override object? GetLedCustomData(LedId ledId) => (ledId, PerKeyIdMapping.DEFAULT.TryGetValue(ledId, out LogitechLedId logitechLedId) ? logitechLedId : LogitechLedId.Invalid); + protected override object GetLedCustomData(LedId ledId) => (ledId, PerKeyIdMapping.DEFAULT.TryGetValue(ledId, out LogitechLedId logitechLedId) ? logitechLedId : LogitechLedId.Invalid); /// protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue?.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); diff --git a/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs b/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs index 87d2c8c..480e8c1 100644 --- a/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Msi/Generic/MsiRGBDeviceInfo.cs @@ -1,5 +1,4 @@ -using System; -using RGB.NET.Core; +using RGB.NET.Core; namespace RGB.NET.Devices.Msi { diff --git a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs index 62d3405..a5b718f 100644 --- a/RGB.NET.Devices.Msi/MsiDeviceProvider.cs +++ b/RGB.NET.Devices.Msi/MsiDeviceProvider.cs @@ -4,7 +4,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Globalization; using System.Linq; using RGB.NET.Core; using RGB.NET.Devices.Msi.Exceptions; @@ -73,7 +72,7 @@ namespace RGB.NET.Devices.Msi #region Methods /// - public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) + public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false) { IsInitialized = false; @@ -150,18 +149,17 @@ namespace RGB.NET.Devices.Msi private void ThrowMsiError(int errorCode) => throw new MysticLightException(errorCode, _MsiSDK.GetErrorMessage(errorCode)); - /// - public void ResetDevices() - { - //TODO DarthAffe 11.11.2017: Implement - } - /// public void Dispose() { - try { UpdateTrigger?.Dispose(); } + try { UpdateTrigger.Dispose(); } catch { /* at least we tried */ } + foreach (IRGBDevice device in Devices) + try { device.Dispose(); } + catch { /* at least we tried */ } + Devices = Enumerable.Empty(); + try { _MsiSDK.UnloadMsiSDK(); } catch { /* at least we tried */ } } diff --git a/RGB.NET.Devices.Novation/Generic/NovationRGBDeviceInfo.cs b/RGB.NET.Devices.Novation/Generic/NovationRGBDeviceInfo.cs index f750ecf..9d06dfe 100644 --- a/RGB.NET.Devices.Novation/Generic/NovationRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Novation/Generic/NovationRGBDeviceInfo.cs @@ -1,5 +1,4 @@ -using System; -using RGB.NET.Core; +using RGB.NET.Core; namespace RGB.NET.Devices.Novation { diff --git a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs index 8299301..89ef95d 100644 --- a/RGB.NET.Devices.Novation/NovationDeviceProvider.cs +++ b/RGB.NET.Devices.Novation/NovationDeviceProvider.cs @@ -59,7 +59,7 @@ namespace RGB.NET.Devices.Novation #region Methods /// - public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) + public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false) { IsInitialized = false; @@ -106,22 +106,17 @@ namespace RGB.NET.Devices.Novation return true; } - - /// - public void ResetDevices() - { - foreach (IRGBDevice device in Devices) - { - NovationLaunchpadRGBDevice? novationDevice = device as NovationLaunchpadRGBDevice; - novationDevice?.Reset(); - } - } - + /// public void Dispose() { try { UpdateTrigger.Dispose(); } catch { /* at least we tried */ } + + foreach (IRGBDevice device in Devices) + try { device.Dispose(); } + catch { /* at least we tried */ } + Devices = Enumerable.Empty(); } #endregion diff --git a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDeviceInfo.cs index d380028..b65676a 100644 --- a/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Razer/Keyboard/RazerKeyboardRGBDeviceInfo.cs @@ -20,7 +20,6 @@ namespace RGB.NET.Devices.Razer /// /// The Id of the . /// The model of the . - /// The of the layout this keyboard is using. internal RazerKeyboardRGBDeviceInfo(Guid deviceId, string model) : base(deviceId, RGBDeviceType.Keyboard, model) { } diff --git a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs index 70fa748..a44c4e2 100644 --- a/RGB.NET.Devices.Razer/RazerDeviceProvider.cs +++ b/RGB.NET.Devices.Razer/RazerDeviceProvider.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using System.Collections.ObjectModel; -using System.Globalization; using System.Linq; using RGB.NET.Core; using RGB.NET.Devices.Razer.Native; @@ -78,7 +77,7 @@ namespace RGB.NET.Devices.Razer #region Methods /// - public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) + public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false) { if (IsInitialized) TryUnInit(); @@ -189,14 +188,7 @@ namespace RGB.NET.Devices.Razer return true; } - - /// - public void ResetDevices() - { - foreach (IRGBDevice device in Devices) - ((IRazerRGBDevice)device).Reset(); - } - + private void ThrowRazerError(RazerError errorCode) => throw new RazerException(errorCode); private void TryUnInit() @@ -208,9 +200,14 @@ namespace RGB.NET.Devices.Razer /// public void Dispose() { - try { UpdateTrigger?.Dispose(); } + try { UpdateTrigger.Dispose(); } catch { /* at least we tried */ } + foreach (IRGBDevice device in Devices) + try { device.Dispose(); } + catch { /* at least we tried */ } + Devices = Enumerable.Empty(); + TryUnInit(); // DarthAffe 03.03.2020: Fails with an access-violation - verify if an unload is already triggered by uninit diff --git a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs index 2cbad8c..f42885f 100644 --- a/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs +++ b/RGB.NET.Devices.SteelSeries/SteelSeriesDeviceProvider.cs @@ -57,7 +57,7 @@ namespace RGB.NET.Devices.SteelSeries #region Methods /// - public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) + public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false) { try { @@ -98,24 +98,18 @@ namespace RGB.NET.Devices.SteelSeries return true; } - - /// - public void ResetDevices() - { - if (IsInitialized) - try - { - SteelSeriesSDK.ResetLeds(); - } - catch {/* shit happens */} - } - + /// public void Dispose() { - try { UpdateTrigger?.Dispose(); } + try { UpdateTrigger.Dispose(); } catch { /* at least we tried */ } + foreach (IRGBDevice device in Devices) + try { device.Dispose(); } + catch { /* at least we tried */ } + Devices = Enumerable.Empty(); + try { SteelSeriesSDK.Dispose(); } catch { /* shit happens */ } } diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs index ec4b053..53327cb 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDevice.cs @@ -74,7 +74,7 @@ namespace RGB.NET.Devices.WS281X.Arduino /// public override void Dispose() { - try { UpdateQueue?.Dispose(); } + try { UpdateQueue.Dispose(); } catch { /* at least we tried */ } base.Dispose(); diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDeviceInfo.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDeviceInfo.cs index 29abe19..2a78759 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDeviceInfo.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS2812USBDeviceInfo.cs @@ -1,5 +1,4 @@ -using System; -using RGB.NET.Core; +using RGB.NET.Core; namespace RGB.NET.Devices.WS281X.Arduino { diff --git a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs index 093dfb9..c6aa63c 100644 --- a/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs +++ b/RGB.NET.Devices.WS281X/Arduino/ArduinoWS281XDeviceDefinition.cs @@ -29,7 +29,7 @@ namespace RGB.NET.Devices.WS281X.Arduino /// /// Gets the baud-rate used by the serial-connection. /// - public int BaudRate => SerialConnection?.BaudRate ?? 0; + public int BaudRate => SerialConnection.BaudRate; /// /// Gets or sets the name used by this device. diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs index c8edc06..f76ab40 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDevice.cs @@ -68,7 +68,7 @@ namespace RGB.NET.Devices.WS281X.Bitwizard /// public override void Dispose() { - try { UpdateQueue?.Dispose(); } + try { UpdateQueue.Dispose(); } catch { /* at least we tried */ } base.Dispose(); diff --git a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDeviceInfo.cs b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDeviceInfo.cs index b1a7de8..0f980f7 100644 --- a/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDeviceInfo.cs +++ b/RGB.NET.Devices.WS281X/Bitwizard/BitwizardWS2812USBDeviceInfo.cs @@ -1,5 +1,4 @@ -using System; -using RGB.NET.Core; +using RGB.NET.Core; namespace RGB.NET.Devices.WS281X.Bitwizard { diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs index 6092200..6b24a74 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDevice.cs @@ -74,7 +74,7 @@ namespace RGB.NET.Devices.WS281X.NodeMCU /// public override void Dispose() { - try { UpdateQueue?.Dispose(); } + try { UpdateQueue.Dispose(); } catch { /* at least we tried */ } base.Dispose(); diff --git a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDeviceInfo.cs b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDeviceInfo.cs index e67d733..ed18fb6 100644 --- a/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDeviceInfo.cs +++ b/RGB.NET.Devices.WS281X/NodeMCU/NodeMCUWS2812USBDeviceInfo.cs @@ -1,5 +1,4 @@ -using System; -using RGB.NET.Core; +using RGB.NET.Core; namespace RGB.NET.Devices.WS281X.NodeMCU { diff --git a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs index e838ce6..aeee841 100644 --- a/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs +++ b/RGB.NET.Devices.WS281X/WS281XDeviceProvider.cs @@ -5,7 +5,6 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.Linq; using RGB.NET.Core; -using RGB.NET.Devices.WS281X.NodeMCU; namespace RGB.NET.Devices.WS281X { @@ -70,7 +69,7 @@ namespace RGB.NET.Devices.WS281X public void AddDeviceDefinition(IWS281XDeviceDefinition deviceDefinition) => DeviceDefinitions.Add(deviceDefinition); /// - public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.Unknown, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) + public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.Unknown, bool throwExceptions = false) { IsInitialized = false; @@ -101,21 +100,18 @@ namespace RGB.NET.Devices.WS281X return true; } - - /// - public void ResetDevices() - { - foreach (IRGBDevice device in Devices) - if (device is NodeMCUWS2812USBDevice nodemcuDevice) - nodemcuDevice.UpdateQueue.ResetDevice(); - } - + /// public void Dispose() { - try { UpdateTrigger?.Dispose(); } + try { UpdateTrigger.Dispose(); } catch { /* at least we tried */} + foreach (IRGBDevice device in Devices) + try { device.Dispose(); } + catch { /* at least we tried */ } + Devices = Enumerable.Empty(); + DeviceDefinitions.Clear(); } diff --git a/RGB.NET.Devices.Wooting/Generic/WootingRGBDeviceInfo.cs b/RGB.NET.Devices.Wooting/Generic/WootingRGBDeviceInfo.cs index 662c1b5..a91ba03 100644 --- a/RGB.NET.Devices.Wooting/Generic/WootingRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Wooting/Generic/WootingRGBDeviceInfo.cs @@ -46,7 +46,7 @@ namespace RGB.NET.Devices.Wooting.Generic this.DeviceType = deviceType; this.DeviceIndex = deviceIndex; - Model = deviceIndex.GetDescription() ?? "Unknown"; + Model = deviceIndex.GetDescription(); DeviceName = $"{Manufacturer} {Model}"; } diff --git a/RGB.NET.Devices.Wooting/Helper/EnumExtension.cs b/RGB.NET.Devices.Wooting/Helper/EnumExtension.cs index 0585f82..f0d186b 100644 --- a/RGB.NET.Devices.Wooting/Helper/EnumExtension.cs +++ b/RGB.NET.Devices.Wooting/Helper/EnumExtension.cs @@ -14,7 +14,7 @@ namespace RGB.NET.Devices.Wooting.Helper /// /// The enum value to get the description from. /// The value of the or the result of the source. - internal static string? GetDescription(this System.Enum source) + internal static string GetDescription(this System.Enum source) => source.GetAttribute()?.Description ?? source.ToString(); /// diff --git a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDeviceInfo.cs b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDeviceInfo.cs index b9a6641..7d53a92 100644 --- a/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDeviceInfo.cs +++ b/RGB.NET.Devices.Wooting/Keyboard/WootingKeyboardRGBDeviceInfo.cs @@ -1,5 +1,4 @@ -using System.Globalization; -using RGB.NET.Core; +using RGB.NET.Core; using RGB.NET.Devices.Wooting.Enum; using RGB.NET.Devices.Wooting.Generic; diff --git a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs index d9f3b49..9f779c2 100644 --- a/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs +++ b/RGB.NET.Devices.Wooting/WootingDeviceProvider.cs @@ -74,7 +74,7 @@ namespace RGB.NET.Devices.Wooting /// /// Thrown if the SDK failed to initialize - public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) + public bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false) { IsInitialized = false; @@ -113,17 +113,18 @@ namespace RGB.NET.Devices.Wooting return true; } - - /// - public void ResetDevices() - { } - + /// public void Dispose() { try { UpdateTrigger.Dispose(); } catch { /* at least we tried */ } + foreach (IRGBDevice device in Devices) + try { device.Dispose(); } + catch { /* at least we tried */ } + Devices = Enumerable.Empty(); + try { _WootingSDK.Close(); } catch { /* Unlucky.. */ }