1
0
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:
Darth Affe 2017-11-19 21:20:23 +01:00
parent 800a9c2e72
commit 338936d42f
6 changed files with 190 additions and 196 deletions

View File

@ -93,7 +93,8 @@ namespace RGB.NET.Devices.Asus
#region Mainboard #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); int mainboardCount = _AsusSDK.EnumerateMbController(IntPtr.Zero, 0);
if (mainboardCount > 0) if (mainboardCount > 0)
{ {
@ -101,20 +102,30 @@ namespace RGB.NET.Devices.Asus
_AsusSDK.EnumerateMbController(mainboardHandles, mainboardCount); _AsusSDK.EnumerateMbController(mainboardHandles, mainboardCount);
for (int i = 0; i < mainboardCount; i++) for (int i = 0; i < mainboardCount; i++)
{
try
{ {
IntPtr handle = Marshal.ReadIntPtr(mainboardHandles, i); IntPtr handle = Marshal.ReadIntPtr(mainboardHandles, i);
_AsusSDK.SetMbMode(handle, 1); _AsusSDK.SetMbMode(handle, 1);
AsusMainboardRGBDevice device = new AsusMainboardRGBDevice(new AsusMainboardRGBDeviceInfo(RGBDeviceType.Mainboard, handle)); AsusMainboardRGBDevice device =
new AsusMainboardRGBDevice(new AsusMainboardRGBDeviceInfo(RGBDeviceType.Mainboard, handle));
device.Initialize(); device.Initialize();
devices.Add(device); devices.Add(device);
} }
catch { if (throwExceptions) throw; }
} }
}
}
catch { if (throwExceptions) throw; }
#endregion #endregion
#region Graphics cards #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) //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); int graphicCardCount = _AsusSDK.EnumerateGPU(IntPtr.Zero, 0);
if (graphicCardCount > 0) if (graphicCardCount > 0)
{ {
@ -122,6 +133,8 @@ namespace RGB.NET.Devices.Asus
_AsusSDK.EnumerateGPU(grapicsCardHandles, graphicCardCount); _AsusSDK.EnumerateGPU(grapicsCardHandles, graphicCardCount);
for (int i = 0; i < graphicCardCount; i++) for (int i = 0; i < graphicCardCount; i++)
{
try
{ {
IntPtr handle = Marshal.ReadIntPtr(grapicsCardHandles, i); IntPtr handle = Marshal.ReadIntPtr(grapicsCardHandles, i);
_AsusSDK.SetGPUMode(handle, 1); _AsusSDK.SetGPUMode(handle, 1);
@ -129,13 +142,19 @@ namespace RGB.NET.Devices.Asus
device.Initialize(); device.Initialize();
devices.Add(device); devices.Add(device);
} }
catch { if (throwExceptions) throw; }
} }
}
}
catch { if (throwExceptions) throw; }
#endregion #endregion
#region DRAM #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. //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); //int dramCount = _AsusSDK.EnumerateDram(IntPtr.Zero, 0);
//if (dramCount > 0) //if (dramCount > 0)
//{ //{
@ -144,18 +163,26 @@ namespace RGB.NET.Devices.Asus
// for (int i = 0; i < dramCount; i++) // for (int i = 0; i < dramCount; i++)
// { // {
//try
//{
// IntPtr handle = Marshal.ReadIntPtr(dramHandles, i); // IntPtr handle = Marshal.ReadIntPtr(dramHandles, i);
// _AsusSDK.SetDramMode(handle, 1); // _AsusSDK.SetDramMode(handle, 1);
// AsusDramRGBDevice device = new AsusDramRGBDevice(new AsusDramRGBDeviceInfo(RGBDeviceType.DRAM, handle)); // AsusDramRGBDevice device = new AsusDramRGBDevice(new AsusDramRGBDeviceInfo(RGBDeviceType.DRAM, handle));
// device.Initialize(); // device.Initialize();
// devices.Add(device); // devices.Add(device);
// } // }
//catch { if (throwExceptions) throw; }
// }
//} //}
//}
// catch { if (throwExceptions) throw; }
#endregion #endregion
#region Keyboard #region Keyboard
try
{
IntPtr keyboardHandle = Marshal.AllocHGlobal(IntPtr.Size); IntPtr keyboardHandle = Marshal.AllocHGlobal(IntPtr.Size);
if (_AsusSDK.CreateClaymoreKeyboard(keyboardHandle)) if (_AsusSDK.CreateClaymoreKeyboard(keyboardHandle))
{ {
@ -164,11 +191,15 @@ namespace RGB.NET.Devices.Asus
device.Initialize(); device.Initialize();
devices.Add(device); devices.Add(device);
} }
}
catch { if (throwExceptions) throw; }
#endregion #endregion
#region Mouse #region Mouse
try
{
IntPtr mouseHandle = Marshal.AllocHGlobal(IntPtr.Size); IntPtr mouseHandle = Marshal.AllocHGlobal(IntPtr.Size);
if (_AsusSDK.CreateRogMouse(mouseHandle)) if (_AsusSDK.CreateRogMouse(mouseHandle))
{ {
@ -177,21 +208,21 @@ namespace RGB.NET.Devices.Asus
device.Initialize(); device.Initialize();
devices.Add(device); devices.Add(device);
} }
}
catch { if (throwExceptions) throw; }
#endregion #endregion
Devices = new ReadOnlyCollection<IRGBDevice>(devices); Devices = new ReadOnlyCollection<IRGBDevice>(devices);
IsInitialized = true;
} }
catch catch
{ {
if (throwExceptions) if (throwExceptions)
throw; throw;
else
return false; return false;
} }
IsInitialized = true;
return true; return true;
} }

View File

@ -94,11 +94,12 @@ namespace RGB.NET.Devices.CoolerMaster
IList<IRGBDevice> devices = new List<IRGBDevice>(); IList<IRGBDevice> devices = new List<IRGBDevice>();
foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes))) foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes)))
{
try
{ {
_CoolerMasterSDK.SetControlDevice(index); _CoolerMasterSDK.SetControlDevice(index);
if (_CoolerMasterSDK.IsDevicePlugged()) if (_CoolerMasterSDK.IsDevicePlugged())
{
try
{ {
CoolerMasterRGBDevice device; CoolerMasterRGBDevice device;
switch (index.GetDeviceType()) switch (index.GetDeviceType())
@ -119,28 +120,20 @@ namespace RGB.NET.Devices.CoolerMaster
device.Initialize(); device.Initialize();
devices.Add(device); devices.Add(device);
} }
catch
{
if (throwExceptions)
throw;
else
continue;
}
} }
catch { if (throwExceptions) throw; }
} }
Devices = new ReadOnlyCollection<IRGBDevice>(devices); Devices = new ReadOnlyCollection<IRGBDevice>(devices);
IsInitialized = true;
} }
catch catch
{ {
if (throwExceptions) if (throwExceptions)
throw; throw;
else
return false; return false;
} }
IsInitialized = true;
return true; return true;
} }

View File

@ -96,48 +96,23 @@ namespace RGB.NET.Devices.Corsair
try try
{ {
_CUESDK.Reload(); _CUESDK.Reload();
}
catch
{
if (throwExceptions)
throw;
else
return false;
}
ProtocolDetails = new CorsairProtocolDetails(_CUESDK.CorsairPerformProtocolHandshake()); ProtocolDetails = new CorsairProtocolDetails(_CUESDK.CorsairPerformProtocolHandshake());
CorsairError error = LastError; CorsairError error = LastError;
if (error != CorsairError.Success) if (error != CorsairError.Success)
{
Reset();
if (throwExceptions)
throw new CUEException(error); throw new CUEException(error);
else
return false;
}
if (ProtocolDetails.BreakingChanges) if (ProtocolDetails.BreakingChanges)
{
Reset();
if (throwExceptions)
throw new RGBDeviceException("The SDK currently used isn't compatible with the installed version of CUE.\r\n" 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" + $"CUE-Version: {ProtocolDetails.ServerVersion} (Protocol {ProtocolDetails.ServerProtocolVersion})\r\n"
+ $"SDK-Version: {ProtocolDetails.SdkVersion} (Protocol {ProtocolDetails.SdkProtocolVersion})"); + $"SDK-Version: {ProtocolDetails.SdkVersion} (Protocol {ProtocolDetails.SdkProtocolVersion})");
else
return false;
}
if (exclusiveAccessIfPossible) if (exclusiveAccessIfPossible)
{ {
if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl)) if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
{
Reset();
if (throwExceptions)
throw new CUEException(LastError); throw new CUEException(LastError);
else
return false;
}
HasExclusiveAccess = true; HasExclusiveAccess = true;
} }
else else
@ -147,8 +122,9 @@ namespace RGB.NET.Devices.Corsair
int deviceCount = _CUESDK.CorsairGetDeviceCount(); int deviceCount = _CUESDK.CorsairGetDeviceCount();
for (int i = 0; i < deviceCount; i++) for (int i = 0; i < deviceCount; i++)
{ {
_CorsairDeviceInfo nativeDeviceInfo = try
(_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo)); {
_CorsairDeviceInfo nativeDeviceInfo = (_CorsairDeviceInfo)Marshal.PtrToStructure(_CUESDK.CorsairGetDeviceInfo(i), typeof(_CorsairDeviceInfo));
CorsairRGBDeviceInfo info = new CorsairRGBDeviceInfo(i, RGBDeviceType.Unknown, nativeDeviceInfo); CorsairRGBDeviceInfo info = new CorsairRGBDeviceInfo(i, RGBDeviceType.Unknown, nativeDeviceInfo);
if (!info.CapsMask.HasFlag(CorsairDeviceCaps.Lighting)) if (!info.CapsMask.HasFlag(CorsairDeviceCaps.Lighting))
continue; // Everything that doesn't support lighting control is useless continue; // Everything that doesn't support lighting control is useless
@ -159,60 +135,52 @@ namespace RGB.NET.Devices.Corsair
case CorsairDeviceType.Keyboard: case CorsairDeviceType.Keyboard:
device = new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo)); device = new CorsairKeyboardRGBDevice(new CorsairKeyboardRGBDeviceInfo(i, nativeDeviceInfo));
break; break;
case CorsairDeviceType.Mouse: case CorsairDeviceType.Mouse:
device = new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(i, nativeDeviceInfo)); device = new CorsairMouseRGBDevice(new CorsairMouseRGBDeviceInfo(i, nativeDeviceInfo));
break; break;
case CorsairDeviceType.Headset: case CorsairDeviceType.Headset:
device = new CorsairHeadsetRGBDevice(new CorsairHeadsetRGBDeviceInfo(i, nativeDeviceInfo)); device = new CorsairHeadsetRGBDevice(new CorsairHeadsetRGBDeviceInfo(i, nativeDeviceInfo));
break; break;
case CorsairDeviceType.Mousepad: case CorsairDeviceType.Mousepad:
device = new CorsairMousepadRGBDevice(new CorsairMousepadRGBDeviceInfo(i, nativeDeviceInfo)); device = new CorsairMousepadRGBDevice(new CorsairMousepadRGBDeviceInfo(i, nativeDeviceInfo));
break; break;
// ReSharper disable once RedundantCaseLabel // ReSharper disable once RedundantCaseLabel
case CorsairDeviceType.Unknown: case CorsairDeviceType.Unknown:
default: default:
if (throwExceptions)
throw new RGBDeviceException("Unknown Device-Type"); throw new RGBDeviceException("Unknown Device-Type");
else
continue;
} }
try
{
device.Initialize(); device.Initialize();
AddSpecialParts(device); AddSpecialParts(device);
}
catch
{
if (throwExceptions)
throw;
else
continue;
}
devices.Add(device);
error = LastError; error = LastError;
if (error != CorsairError.Success) if (error != CorsairError.Success)
{
Reset();
if (throwExceptions)
throw new CUEException(error); throw new CUEException(error);
else
return false; devices.Add(device);
} }
catch { if (throwExceptions) throw; }
} }
Devices = new ReadOnlyCollection<IRGBDevice>(devices); Devices = new ReadOnlyCollection<IRGBDevice>(devices);
IsInitialized = true; IsInitialized = true;
}
catch
{
Reset();
if (throwExceptions) throw;
return false;
}
return true; return true;
} }
private void AddSpecialParts(CorsairRGBDevice device) 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)); device.AddSpecialDevicePart(new LightbarSpecialPart(device));
} }

View File

@ -82,8 +82,7 @@ namespace RGB.NET.Devices.Logitech
if (IsInitialized) if (IsInitialized)
_LogitechGSDK.LogiLedRestoreLighting(); _LogitechGSDK.LogiLedRestoreLighting();
} }
catch catch { /* At least we tried ... */ }
{ /* At least we tried ... */ }
IsInitialized = false; IsInitialized = false;
@ -97,6 +96,8 @@ namespace RGB.NET.Devices.Logitech
IList<IRGBDevice> devices = new List<IRGBDevice>(); IList<IRGBDevice> devices = new List<IRGBDevice>();
DeviceChecker.LoadDeviceList(); DeviceChecker.LoadDeviceList();
try
{
if (DeviceChecker.IsPerKeyDeviceConnected) if (DeviceChecker.IsPerKeyDeviceConnected)
{ {
(string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerKeyDeviceData; (string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerKeyDeviceData;
@ -104,7 +105,11 @@ namespace RGB.NET.Devices.Logitech
device.Initialize(); device.Initialize();
devices.Add(device); devices.Add(device);
} }
}
catch { if (throwExceptions) throw; }
try
{
if (DeviceChecker.IsPerDeviceDeviceConnected) if (DeviceChecker.IsPerDeviceDeviceConnected)
{ {
(string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerDeviceDeviceData; (string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerDeviceDeviceData;
@ -112,19 +117,19 @@ namespace RGB.NET.Devices.Logitech
device.Initialize(); device.Initialize();
devices.Add(device); devices.Add(device);
} }
}
catch { if (throwExceptions) throw; }
Devices = new ReadOnlyCollection<IRGBDevice>(devices); Devices = new ReadOnlyCollection<IRGBDevice>(devices);
IsInitialized = true;
} }
catch catch
{ {
if (throwExceptions) if (throwExceptions)
throw; throw;
else
return false; return false;
} }
IsInitialized = true;
return true; return true;
} }

View File

@ -99,22 +99,24 @@ namespace RGB.NET.Devices.Msi
ThrowMsiError(errorCode); ThrowMsiError(errorCode);
for (int i = 0; i < deviceTypes.Length; i++) for (int i = 0; i < deviceTypes.Length; i++)
{
try
{ {
//TODO DarthAffe 11.11.2017: What is this deviceType? Find someone to try that out //TODO DarthAffe 11.11.2017: What is this deviceType? Find someone to try that out
} }
catch { if (throwExceptions) throw; }
}
Devices = new ReadOnlyCollection<IRGBDevice>(devices); Devices = new ReadOnlyCollection<IRGBDevice>(devices);
IsInitialized = true;
} }
catch catch
{ {
if (throwExceptions) if (throwExceptions)
throw; throw;
else
return false; return false;
} }
IsInitialized = true;
return true; return true;
} }

View File

@ -66,14 +66,15 @@ namespace RGB.NET.Devices.Novation
{ {
IList<IRGBDevice> devices = new List<IRGBDevice>(); IList<IRGBDevice> devices = new List<IRGBDevice>();
try
{
for (int index = 0; index < OutputDeviceBase.DeviceCount; index++) for (int index = 0; index < OutputDeviceBase.DeviceCount; index++)
{
try
{ {
MidiOutCaps outCaps = OutputDeviceBase.GetDeviceCapabilities(index); MidiOutCaps outCaps = OutputDeviceBase.GetDeviceCapabilities(index);
if (outCaps.name == null) continue; 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)); .FirstOrDefault(x => string.Equals(x.GetDeviceId(), outCaps.name, StringComparison.OrdinalIgnoreCase));
if (deviceId == null) continue; if (deviceId == null) continue;
@ -82,25 +83,19 @@ namespace RGB.NET.Devices.Novation
device.Initialize(); device.Initialize();
devices.Add(device); devices.Add(device);
} }
} catch { if (throwExceptions) throw; }
catch
{
if (throwExceptions)
throw;
} }
Devices = new ReadOnlyCollection<IRGBDevice>(devices); Devices = new ReadOnlyCollection<IRGBDevice>(devices);
IsInitialized = true;
} }
catch catch
{ {
if (throwExceptions) if (throwExceptions)
throw; throw;
else
return false; return false;
} }
IsInitialized = true;
return true; return true;
} }