From 7264731eb11de145aac22f59e2277189a9bdadf3 Mon Sep 17 00:00:00 2001 From: Darth Affe Date: Sat, 13 May 2017 07:55:20 +0200 Subject: [PATCH] Added properties to change the search-paths for native-libaries (sdks) --- RGB.NET.Core/Devices/IRGBDeviceProvider.cs | 2 +- .../CoolerMasterDeviceProvider.cs | 12 ++++++++++++ .../Native/_CoolerMasterSDK.cs | 8 +++++--- RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs | 12 ++++++++++++ RGB.NET.Devices.Corsair/Native/_CUESDK.cs | 8 +++++--- RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs | 12 ++++++++++++ RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs | 8 +++++--- 7 files changed, 52 insertions(+), 10 deletions(-) diff --git a/RGB.NET.Core/Devices/IRGBDeviceProvider.cs b/RGB.NET.Core/Devices/IRGBDeviceProvider.cs index cb1f95e..00123fb 100644 --- a/RGB.NET.Core/Devices/IRGBDeviceProvider.cs +++ b/RGB.NET.Core/Devices/IRGBDeviceProvider.cs @@ -27,7 +27,7 @@ namespace RGB.NET.Core #endregion #region Methods - + /// /// Initializes the if not already happened or reloads it if it is already initialized. /// diff --git a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs index 5e354a7..27c1472 100644 --- a/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs +++ b/RGB.NET.Devices.CoolerMaster/CoolerMasterDeviceProvider.cs @@ -21,6 +21,18 @@ namespace RGB.NET.Devices.CoolerMaster /// public static CoolerMasterDeviceProvider Instance { get; } = new CoolerMasterDeviceProvider(); + /// + /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. + /// The first match will be used. + /// + public static List PossibleX86NativePaths { get; } = new List { "x86/CMSDK.dll" }; + + /// + /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. + /// The first match will be used. + /// + public static List PossibleX64NativePaths { get; } = new List { "x64/CMSDK.dll" }; + /// /// Indicates if the SDK is initialized and ready to use. /// diff --git a/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs index 151400a..cd1b586 100644 --- a/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs +++ b/RGB.NET.Devices.CoolerMaster/Native/_CoolerMasterSDK.cs @@ -2,7 +2,9 @@ // ReSharper disable UnusedMember.Global using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using System.Runtime.InteropServices; using RGB.NET.Core.Exceptions; @@ -34,9 +36,9 @@ namespace RGB.NET.Devices.CoolerMaster.Native if (_dllHandle != IntPtr.Zero) return; // HACK: Load library at runtime to support both, x86 and x64 with one managed dll - string dllPath = (LoadedArchitecture = Environment.Is64BitProcess ? "x64" : "x86") + "/CMSDK.dll"; - if (!File.Exists(dllPath)) - throw new RGBDeviceException($"Can't find the CoolerMaster-SDK at the expected location '{Path.GetFullPath(dllPath)}'"); + List possiblePathList = Environment.Is64BitProcess ? CoolerMasterDeviceProvider.PossibleX64NativePaths : CoolerMasterDeviceProvider.PossibleX86NativePaths; + string dllPath = possiblePathList.FirstOrDefault(File.Exists); + if (dllPath == null) throw new RGBDeviceException($"Can't find the CoolerMaster-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'"); _dllHandle = LoadLibrary(dllPath); diff --git a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs index 66ea7f2..d9d0f28 100644 --- a/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs +++ b/RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs @@ -22,6 +22,18 @@ namespace RGB.NET.Devices.Corsair /// public static CorsairDeviceProvider Instance { get; } = new CorsairDeviceProvider(); + /// + /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. + /// The first match will be used. + /// + public static List PossibleX86NativePaths { get; } = new List { "x86/CUESDK.dll", "x86/CUESDK_2015.dll", "x86/CUESDK_2013.dll" }; + + /// + /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. + /// The first match will be used. + /// + public static List PossibleX64NativePaths { get; } = new List { "x64/CUESDK.dll", "x64/CUESDK_2015.dll", "x64/CUESDK_2013.dll" }; + /// /// Indicates if the SDK is initialized and ready to use. /// diff --git a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs index 261f3e0..ebe94d8 100644 --- a/RGB.NET.Devices.Corsair/Native/_CUESDK.cs +++ b/RGB.NET.Devices.Corsair/Native/_CUESDK.cs @@ -2,7 +2,9 @@ // ReSharper disable UnusedMember.Global using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using System.Runtime.InteropServices; using RGB.NET.Core.Exceptions; @@ -34,9 +36,9 @@ namespace RGB.NET.Devices.Corsair.Native if (_dllHandle != IntPtr.Zero) return; // HACK: Load library at runtime to support both, x86 and x64 with one managed dll - string dllPath = (LoadedArchitecture = Environment.Is64BitProcess ? "x64" : "x86") + "/CUESDK.dll"; - if (!File.Exists(dllPath)) - throw new RGBDeviceException($"Can't find the CUE-SDK at the expected location '{Path.GetFullPath(dllPath)}'"); + List possiblePathList = Environment.Is64BitProcess ? CorsairDeviceProvider.PossibleX64NativePaths : CorsairDeviceProvider.PossibleX86NativePaths; + string dllPath = possiblePathList.FirstOrDefault(File.Exists); + if (dllPath == null) throw new RGBDeviceException($"Can't find the CUE-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'"); _dllHandle = LoadLibrary(dllPath); diff --git a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs index 18eb79f..1d9a4c0 100644 --- a/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs +++ b/RGB.NET.Devices.Logitech/LogitechDeviceProvider.cs @@ -20,6 +20,18 @@ namespace RGB.NET.Devices.Logitech /// public static LogitechDeviceProvider Instance { get; } = new LogitechDeviceProvider(); + /// + /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. + /// The first match will be used. + /// + public static List PossibleX86NativePaths { get; } = new List { "x86/LogitechLedEnginesWrapper.dll" }; + + /// + /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. + /// The first match will be used. + /// + public static List PossibleX64NativePaths { get; } = new List { "x64/LogitechLedEnginesWrapper.dll" }; + /// public bool IsInitialized { get; private set; } diff --git a/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs b/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs index cd4db5b..b1b1bb0 100644 --- a/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs +++ b/RGB.NET.Devices.Logitech/Native/_LogitechGSDK.cs @@ -3,7 +3,9 @@ // ReSharper disable MemberCanBePrivate.Global using System; +using System.Collections.Generic; using System.IO; +using System.Linq; using System.Runtime.InteropServices; using RGB.NET.Core.Exceptions; @@ -35,9 +37,9 @@ namespace RGB.NET.Devices.Logitech.Native if (_dllHandle != IntPtr.Zero) return; // HACK: Load library at runtime to support both, x86 and x64 with one managed dll - string dllPath = (LoadedArchitecture = Environment.Is64BitProcess ? "x64" : "x86") + "/LogitechLedEnginesWrapper.dll"; - if (!File.Exists(dllPath)) - throw new RGBDeviceException($"Can't find the Logitech-SDK at the expected location '{Path.GetFullPath(dllPath)}'"); + List possiblePathList = Environment.Is64BitProcess ? LogitechDeviceProvider.PossibleX64NativePaths : LogitechDeviceProvider.PossibleX86NativePaths; + string dllPath = possiblePathList.FirstOrDefault(File.Exists); + if (dllPath == null) throw new RGBDeviceException($"Can't find the Logitech-SDK at one of the expected locations:\r\n '{string.Join("\r\n", possiblePathList.Select(Path.GetFullPath))}'"); _dllHandle = LoadLibrary(dllPath);