From a4ed4c466b5729d4a609a8626e436d75b49c9fdc Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Thu, 17 Dec 2020 17:44:34 +0100 Subject: [PATCH] Updated Asus-device-detection --- RGB.NET.Devices.Asus/Helper/WMIHelper.cs | 53 ++++++++++--------- .../RGB.NET.Devices.Asus.csproj | 4 ++ 2 files changed, 32 insertions(+), 25 deletions(-) diff --git a/RGB.NET.Devices.Asus/Helper/WMIHelper.cs b/RGB.NET.Devices.Asus/Helper/WMIHelper.cs index 0ea746e..0a43046 100644 --- a/RGB.NET.Devices.Asus/Helper/WMIHelper.cs +++ b/RGB.NET.Devices.Asus/Helper/WMIHelper.cs @@ -1,4 +1,4 @@ -#if NETFULL +using System; using System.Management; namespace RGB.NET.Devices.Asus @@ -8,11 +8,26 @@ namespace RGB.NET.Devices.Asus { #region Properties & Fields - private static ManagementObjectSearcher _mainboardSearcher = new ManagementObjectSearcher(@"root\CIMV2", "SELECT Manufacturer,Product FROM Win32_BaseBoard"); - private static ManagementObjectSearcher _graphicsCardSearcher = new ManagementObjectSearcher(@"root\CIMV2", "SELECT Name FROM Win32_VideoController"); + // ReSharper disable InconsistentNaming + private static readonly ManagementObjectSearcher? _mainboardSearcher; + private static readonly ManagementObjectSearcher? _graphicsCardSearcher; + // ReSharper restore InconsistentNaming private static (string manufacturer, string model)? _mainboardInfo; - private static string _graphicsCardInfo; + private static string? _graphicsCardInfo; + + #endregion + + #region Constructors + + static WMIHelper() + { + if (OperatingSystem.IsWindows()) + { + _mainboardSearcher = new ManagementObjectSearcher(@"root\CIMV2", "SELECT Manufacturer,Product FROM Win32_BaseBoard"); + _graphicsCardSearcher = new ManagementObjectSearcher(@"root\CIMV2", "SELECT Name FROM Win32_VideoController"); + } + } #endregion @@ -20,19 +35,23 @@ namespace RGB.NET.Devices.Asus internal static (string manufacturer, string model)? GetMainboardInfo() { - if (!_mainboardInfo.HasValue) + if (!OperatingSystem.IsWindows()) return null; + + if (!_mainboardInfo.HasValue && (_mainboardSearcher != null)) foreach (ManagementBaseObject managementBaseObject in _mainboardSearcher.Get()) { - _mainboardInfo = (managementBaseObject["Manufacturer"]?.ToString(), managementBaseObject["Product"]?.ToString()); + _mainboardInfo = (managementBaseObject["Manufacturer"]?.ToString() ?? string.Empty, managementBaseObject["Product"]?.ToString() ?? string.Empty); break; } return _mainboardInfo; } - internal static string GetGraphicsCardsInfo() + internal static string? GetGraphicsCardsInfo() { - if (_graphicsCardInfo == null) + if (!OperatingSystem.IsWindows()) return null; + + if ((_graphicsCardInfo == null) && (_graphicsCardSearcher != null)) foreach (ManagementBaseObject managementBaseObject in _graphicsCardSearcher.Get()) { _graphicsCardInfo = managementBaseObject["Name"]?.ToString(); @@ -44,20 +63,4 @@ namespace RGB.NET.Devices.Asus #endregion } -} -#else -namespace RGB.NET.Devices.Asus -{ - // ReSharper disable once InconsistentNaming - internal static class WMIHelper - { - #region Methods - - internal static (string manufacturer, string model)? GetMainboardInfo() => null; - - internal static string GetGraphicsCardsInfo() => null; - - #endregion - } -} -#endif +} \ No newline at end of file diff --git a/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj b/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj index f8071f8..3b81186 100644 --- a/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj +++ b/RGB.NET.Devices.Asus/RGB.NET.Devices.Asus.csproj @@ -50,6 +50,10 @@ $(DefineConstants);RELEASE + + + + <_PackageFiles Include="$(OutputPath)\net5.0\Interop.AuraServiceLib.dll"> None