mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Changed all device-providers to load as much devices as possible without throwing exceptions
This commit is contained in:
parent
800a9c2e72
commit
338936d42f
@ -93,7 +93,8 @@ namespace RGB.NET.Devices.Asus
|
||||
|
||||
#region Mainboard
|
||||
|
||||
//TODO DarthAffe 21.10.2017: Requesting mainboards seems to fail if only a non mb-device (tested with only a gpu) is connected
|
||||
try
|
||||
{
|
||||
int mainboardCount = _AsusSDK.EnumerateMbController(IntPtr.Zero, 0);
|
||||
if (mainboardCount > 0)
|
||||
{
|
||||
@ -101,20 +102,30 @@ namespace RGB.NET.Devices.Asus
|
||||
_AsusSDK.EnumerateMbController(mainboardHandles, mainboardCount);
|
||||
|
||||
for (int i = 0; i < mainboardCount; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr handle = Marshal.ReadIntPtr(mainboardHandles, i);
|
||||
_AsusSDK.SetMbMode(handle, 1);
|
||||
AsusMainboardRGBDevice device = new AsusMainboardRGBDevice(new AsusMainboardRGBDeviceInfo(RGBDeviceType.Mainboard, handle));
|
||||
AsusMainboardRGBDevice device =
|
||||
new AsusMainboardRGBDevice(new AsusMainboardRGBDeviceInfo(RGBDeviceType.Mainboard, handle));
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Graphics cards
|
||||
|
||||
//TODO DarthAffe 21.10.2017: This somehow returns non-existant gpus (at least for me) which cause huge lags (if a real asus-ready gpu is connected this doesn't happen)
|
||||
|
||||
try
|
||||
{
|
||||
int graphicCardCount = _AsusSDK.EnumerateGPU(IntPtr.Zero, 0);
|
||||
if (graphicCardCount > 0)
|
||||
{
|
||||
@ -122,6 +133,8 @@ namespace RGB.NET.Devices.Asus
|
||||
_AsusSDK.EnumerateGPU(grapicsCardHandles, graphicCardCount);
|
||||
|
||||
for (int i = 0; i < graphicCardCount; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
IntPtr handle = Marshal.ReadIntPtr(grapicsCardHandles, i);
|
||||
_AsusSDK.SetGPUMode(handle, 1);
|
||||
@ -129,13 +142,19 @@ namespace RGB.NET.Devices.Asus
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
}
|
||||
}
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region DRAM
|
||||
|
||||
//TODO DarthAffe 29.10.2017: I don't know why they are even documented, but the asus guy said they aren't in the SDK right now.
|
||||
//try
|
||||
//{
|
||||
//int dramCount = _AsusSDK.EnumerateDram(IntPtr.Zero, 0);
|
||||
//if (dramCount > 0)
|
||||
//{
|
||||
@ -144,18 +163,26 @@ namespace RGB.NET.Devices.Asus
|
||||
|
||||
// for (int i = 0; i < dramCount; i++)
|
||||
// {
|
||||
//try
|
||||
//{
|
||||
// IntPtr handle = Marshal.ReadIntPtr(dramHandles, i);
|
||||
// _AsusSDK.SetDramMode(handle, 1);
|
||||
// AsusDramRGBDevice device = new AsusDramRGBDevice(new AsusDramRGBDeviceInfo(RGBDeviceType.DRAM, handle));
|
||||
// device.Initialize();
|
||||
// devices.Add(device);
|
||||
// }
|
||||
//catch { if (throwExceptions) throw; }
|
||||
// }
|
||||
//}
|
||||
//}
|
||||
// catch { if (throwExceptions) throw; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Keyboard
|
||||
|
||||
try
|
||||
{
|
||||
IntPtr keyboardHandle = Marshal.AllocHGlobal(IntPtr.Size);
|
||||
if (_AsusSDK.CreateClaymoreKeyboard(keyboardHandle))
|
||||
{
|
||||
@ -164,11 +191,15 @@ namespace RGB.NET.Devices.Asus
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Mouse
|
||||
|
||||
try
|
||||
{
|
||||
IntPtr mouseHandle = Marshal.AllocHGlobal(IntPtr.Size);
|
||||
if (_AsusSDK.CreateRogMouse(mouseHandle))
|
||||
{
|
||||
@ -177,21 +208,21 @@ namespace RGB.NET.Devices.Asus
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
|
||||
#endregion
|
||||
|
||||
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||
IsInitialized = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (throwExceptions)
|
||||
throw;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
IsInitialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -94,11 +94,12 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
IList<IRGBDevice> devices = new List<IRGBDevice>();
|
||||
|
||||
foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes)))
|
||||
{
|
||||
|
||||
try
|
||||
{
|
||||
_CoolerMasterSDK.SetControlDevice(index);
|
||||
if (_CoolerMasterSDK.IsDevicePlugged())
|
||||
{
|
||||
try
|
||||
{
|
||||
CoolerMasterRGBDevice device;
|
||||
switch (index.GetDeviceType())
|
||||
@ -119,28 +120,20 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (throwExceptions)
|
||||
throw;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
}
|
||||
|
||||
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||
IsInitialized = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (throwExceptions)
|
||||
throw;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
IsInitialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -96,48 +96,23 @@ namespace RGB.NET.Devices.Corsair
|
||||
try
|
||||
{
|
||||
_CUESDK.Reload();
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (throwExceptions)
|
||||
throw;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
ProtocolDetails = new CorsairProtocolDetails(_CUESDK.CorsairPerformProtocolHandshake());
|
||||
|
||||
CorsairError error = LastError;
|
||||
if (error != CorsairError.Success)
|
||||
{
|
||||
Reset();
|
||||
if (throwExceptions)
|
||||
throw new CUEException(error);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ProtocolDetails.BreakingChanges)
|
||||
{
|
||||
Reset();
|
||||
if (throwExceptions)
|
||||
throw new RGBDeviceException("The SDK currently used isn't compatible with the installed version of CUE.\r\n"
|
||||
+ $"CUE-Version: {ProtocolDetails.ServerVersion} (Protocol {ProtocolDetails.ServerProtocolVersion})\r\n"
|
||||
+ $"SDK-Version: {ProtocolDetails.SdkVersion} (Protocol {ProtocolDetails.SdkProtocolVersion})");
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
if (exclusiveAccessIfPossible)
|
||||
{
|
||||
if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
|
||||
{
|
||||
Reset();
|
||||
if (throwExceptions)
|
||||
throw new CUEException(LastError);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
HasExclusiveAccess = true;
|
||||
}
|
||||
else
|
||||
@ -147,8 +122,9 @@ namespace RGB.NET.Devices.Corsair
|
||||
int deviceCount = _CUESDK.CorsairGetDeviceCount();
|
||||
for (int i = 0; i < deviceCount; i++)
|
||||
{
|
||||
_CorsairDeviceInfo nativeDeviceInfo =
|
||||
(_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo));
|
||||
try
|
||||
{
|
||||
_CorsairDeviceInfo nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo));
|
||||
CorsairRGBDeviceInfo info = new CorsairRGBDeviceInfo(i, RGBDeviceType.Unknown, nativeDeviceInfo);
|
||||
if (!info.CapsMask.HasFlag(CorsairDeviceCaps.Lighting))
|
||||
continue; // Everything that doesn't support lighting control is useless
|
||||
@ -159,60 +135,52 @@ namespace RGB.NET.Devices.Corsair
|
||||
case CorsairDeviceType.Keyboard:
|
||||
device = new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
break;
|
||||
|
||||
case CorsairDeviceType.Mouse:
|
||||
device = new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
break;
|
||||
|
||||
case CorsairDeviceType.Headset:
|
||||
device = new CorsairHeadsetRGBDevice(new CorsairHeadsetRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
break;
|
||||
|
||||
case CorsairDeviceType.Mousepad:
|
||||
device = new CorsairMousepadRGBDevice(new CorsairMousepadRGBDeviceInfo(i, nativeDeviceInfo));
|
||||
break;
|
||||
|
||||
// ReSharper disable once RedundantCaseLabel
|
||||
case CorsairDeviceType.Unknown:
|
||||
default:
|
||||
if (throwExceptions)
|
||||
throw new RGBDeviceException("Unknown Device-Type");
|
||||
else
|
||||
continue;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
device.Initialize();
|
||||
|
||||
AddSpecialParts(device);
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (throwExceptions)
|
||||
throw;
|
||||
else
|
||||
continue;
|
||||
}
|
||||
devices.Add(device);
|
||||
|
||||
error = LastError;
|
||||
if (error != CorsairError.Success)
|
||||
{
|
||||
Reset();
|
||||
if (throwExceptions)
|
||||
throw new CUEException(error);
|
||||
else
|
||||
return false;
|
||||
|
||||
devices.Add(device);
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
}
|
||||
|
||||
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||
|
||||
IsInitialized = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
Reset();
|
||||
if (throwExceptions) throw;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private void AddSpecialParts(CorsairRGBDevice device)
|
||||
{
|
||||
//if (device.DeviceInfo.Model.Equals("K95 RGB Platinum", StringComparison.OrdinalIgnoreCase))
|
||||
if (device.DeviceInfo.Model.Equals("K95 RGB Platinum", StringComparison.OrdinalIgnoreCase))
|
||||
device.AddSpecialDevicePart(new LightbarSpecialPart(device));
|
||||
}
|
||||
|
||||
|
||||
@ -82,8 +82,7 @@ namespace RGB.NET.Devices.Logitech
|
||||
if (IsInitialized)
|
||||
_LogitechGSDK.LogiLedRestoreLighting();
|
||||
}
|
||||
catch
|
||||
{ /* At least we tried ... */ }
|
||||
catch { /* At least we tried ... */ }
|
||||
|
||||
IsInitialized = false;
|
||||
|
||||
@ -97,6 +96,8 @@ namespace RGB.NET.Devices.Logitech
|
||||
IList<IRGBDevice> devices = new List<IRGBDevice>();
|
||||
DeviceChecker.LoadDeviceList();
|
||||
|
||||
try
|
||||
{
|
||||
if (DeviceChecker.IsPerKeyDeviceConnected)
|
||||
{
|
||||
(string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerKeyDeviceData;
|
||||
@ -104,7 +105,11 @@ namespace RGB.NET.Devices.Logitech
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
|
||||
try
|
||||
{
|
||||
if (DeviceChecker.IsPerDeviceDeviceConnected)
|
||||
{
|
||||
(string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerDeviceDeviceData;
|
||||
@ -112,19 +117,19 @@ namespace RGB.NET.Devices.Logitech
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
|
||||
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||
IsInitialized = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (throwExceptions)
|
||||
throw;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
IsInitialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -99,22 +99,24 @@ namespace RGB.NET.Devices.Msi
|
||||
ThrowMsiError(errorCode);
|
||||
|
||||
for (int i = 0; i < deviceTypes.Length; i++)
|
||||
{
|
||||
try
|
||||
{
|
||||
//TODO DarthAffe 11.11.2017: What is this deviceType? Find someone to try that out
|
||||
}
|
||||
catch { if (throwExceptions) throw; }
|
||||
}
|
||||
|
||||
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||
IsInitialized = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (throwExceptions)
|
||||
throw;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
IsInitialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@ -66,14 +66,15 @@ namespace RGB.NET.Devices.Novation
|
||||
{
|
||||
IList<IRGBDevice> devices = new List<IRGBDevice>();
|
||||
|
||||
try
|
||||
{
|
||||
for (int index = 0; index < OutputDeviceBase.DeviceCount; index++)
|
||||
{
|
||||
try
|
||||
{
|
||||
MidiOutCaps outCaps = OutputDeviceBase.GetDeviceCapabilities(index);
|
||||
if (outCaps.name == null) continue;
|
||||
|
||||
NovationDevices? deviceId = (NovationDevices?)Enum.GetValues(typeof(NovationDevices)).Cast<Enum>()
|
||||
NovationDevices? deviceId = (NovationDevices?)Enum.GetValues(typeof(NovationDevices))
|
||||
.Cast<Enum>()
|
||||
.FirstOrDefault(x => string.Equals(x.GetDeviceId(), outCaps.name, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
if (deviceId == null) continue;
|
||||
@ -82,25 +83,19 @@ namespace RGB.NET.Devices.Novation
|
||||
device.Initialize();
|
||||
devices.Add(device);
|
||||
}
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (throwExceptions)
|
||||
throw;
|
||||
catch { if (throwExceptions) throw; }
|
||||
}
|
||||
|
||||
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||
IsInitialized = true;
|
||||
}
|
||||
catch
|
||||
{
|
||||
if (throwExceptions)
|
||||
throw;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
IsInitialized = true;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user