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,49 +93,68 @@ 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);
if (mainboardCount > 0)
{ {
IntPtr mainboardHandles = Marshal.AllocHGlobal(mainboardCount * IntPtr.Size); int mainboardCount = _AsusSDK.EnumerateMbController(IntPtr.Zero, 0);
_AsusSDK.EnumerateMbController(mainboardHandles, mainboardCount); if (mainboardCount > 0)
for (int i = 0; i < mainboardCount; i++)
{ {
IntPtr handle = Marshal.ReadIntPtr(mainboardHandles, i); IntPtr mainboardHandles = Marshal.AllocHGlobal(mainboardCount * IntPtr.Size);
_AsusSDK.SetMbMode(handle, 1); _AsusSDK.EnumerateMbController(mainboardHandles, mainboardCount);
AsusMainboardRGBDevice device = new AsusMainboardRGBDevice(new AsusMainboardRGBDeviceInfo(RGBDeviceType.Mainboard, handle));
device.Initialize(); for (int i = 0; i < mainboardCount; i++)
devices.Add(device); {
try
{
IntPtr handle = Marshal.ReadIntPtr(mainboardHandles, i);
_AsusSDK.SetMbMode(handle, 1);
AsusMainboardRGBDevice device =
new AsusMainboardRGBDevice(new AsusMainboardRGBDeviceInfo(RGBDeviceType.Mainboard, handle));
device.Initialize();
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)
int graphicCardCount = _AsusSDK.EnumerateGPU(IntPtr.Zero, 0);
if (graphicCardCount > 0)
{
IntPtr grapicsCardHandles = Marshal.AllocHGlobal(graphicCardCount * IntPtr.Size);
_AsusSDK.EnumerateGPU(grapicsCardHandles, graphicCardCount);
for (int i = 0; i < graphicCardCount; i++) try
{
int graphicCardCount = _AsusSDK.EnumerateGPU(IntPtr.Zero, 0);
if (graphicCardCount > 0)
{ {
IntPtr handle = Marshal.ReadIntPtr(grapicsCardHandles, i); IntPtr grapicsCardHandles = Marshal.AllocHGlobal(graphicCardCount * IntPtr.Size);
_AsusSDK.SetGPUMode(handle, 1); _AsusSDK.EnumerateGPU(grapicsCardHandles, graphicCardCount);
AsusGraphicsCardRGBDevice device = new AsusGraphicsCardRGBDevice(new AsusGraphicsCardRGBDeviceInfo(RGBDeviceType.GraphicsCard, handle));
device.Initialize(); for (int i = 0; i < graphicCardCount; i++)
devices.Add(device); {
try
{
IntPtr handle = Marshal.ReadIntPtr(grapicsCardHandles, i);
_AsusSDK.SetGPUMode(handle, 1);
AsusGraphicsCardRGBDevice device = new AsusGraphicsCardRGBDevice(new AsusGraphicsCardRGBDeviceInfo(RGBDeviceType.GraphicsCard, handle));
device.Initialize();
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,54 +163,66 @@ 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
IntPtr keyboardHandle = Marshal.AllocHGlobal(IntPtr.Size); try
if (_AsusSDK.CreateClaymoreKeyboard(keyboardHandle))
{ {
_AsusSDK.SetClaymoreKeyboardMode(keyboardHandle, 1); IntPtr keyboardHandle = Marshal.AllocHGlobal(IntPtr.Size);
AsusKeyboardRGBDevice device = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(RGBDeviceType.Keyboard, keyboardHandle, GetCulture())); if (_AsusSDK.CreateClaymoreKeyboard(keyboardHandle))
device.Initialize(); {
devices.Add(device); _AsusSDK.SetClaymoreKeyboardMode(keyboardHandle, 1);
AsusKeyboardRGBDevice device = new AsusKeyboardRGBDevice(new AsusKeyboardRGBDeviceInfo(RGBDeviceType.Keyboard, keyboardHandle, GetCulture()));
device.Initialize();
devices.Add(device);
}
} }
catch { if (throwExceptions) throw; }
#endregion #endregion
#region Mouse #region Mouse
IntPtr mouseHandle = Marshal.AllocHGlobal(IntPtr.Size); try
if (_AsusSDK.CreateRogMouse(mouseHandle))
{ {
_AsusSDK.SetRogMouseMode(mouseHandle, 1); IntPtr mouseHandle = Marshal.AllocHGlobal(IntPtr.Size);
AsusMouseRGBDevice device = new AsusMouseRGBDevice(new AsusMouseRGBDeviceInfo(RGBDeviceType.Mouse, mouseHandle)); if (_AsusSDK.CreateRogMouse(mouseHandle))
device.Initialize(); {
devices.Add(device); _AsusSDK.SetRogMouseMode(mouseHandle, 1);
AsusMouseRGBDevice device = new AsusMouseRGBDevice(new AsusMouseRGBDeviceInfo(RGBDeviceType.Mouse, mouseHandle));
device.Initialize();
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;
} }
@ -209,9 +240,9 @@ namespace RGB.NET.Devices.Asus
case RGBDeviceType.GraphicsCard: case RGBDeviceType.GraphicsCard:
_AsusSDK.SetGPUMode(deviceInfo.Handle, 0); _AsusSDK.SetGPUMode(deviceInfo.Handle, 0);
break; break;
//case RGBDeviceType.DRAM: //case RGBDeviceType.DRAM:
// _AsusSDK.SetDramMode(deviceInfo.Handle, 0); // _AsusSDK.SetDramMode(deviceInfo.Handle, 0);
// break; // break;
} }
} }
} }

View File

@ -95,10 +95,11 @@ namespace RGB.NET.Devices.CoolerMaster
foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes))) foreach (CoolerMasterDevicesIndexes index in Enum.GetValues(typeof(CoolerMasterDevicesIndexes)))
{ {
_CoolerMasterSDK.SetControlDevice(index);
if (_CoolerMasterSDK.IsDevicePlugged()) try
{ {
try _CoolerMasterSDK.SetControlDevice(index);
if (_CoolerMasterSDK.IsDevicePlugged())
{ {
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,123 +96,91 @@ namespace RGB.NET.Devices.Corsair
try try
{ {
_CUESDK.Reload(); _CUESDK.Reload();
ProtocolDetails = new CorsairProtocolDetails(_CUESDK.CorsairPerformProtocolHandshake());
CorsairError error = LastError;
if (error != CorsairError.Success)
throw new CUEException(error);
if (ProtocolDetails.BreakingChanges)
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})");
if (exclusiveAccessIfPossible)
{
if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
throw new CUEException(LastError);
HasExclusiveAccess = true;
}
else
HasExclusiveAccess = false;
IList<IRGBDevice> devices = new List<IRGBDevice>();
int deviceCount = _CUESDK.CorsairGetDeviceCount();
for (int i = 0; i < deviceCount; i++)
{
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
CorsairRGBDevice device;
switch (info.CorsairDeviceType)
{
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:
throw new RGBDeviceException("Unknown Device-Type");
}
device.Initialize();
AddSpecialParts(device);
error = LastError;
if (error != CorsairError.Success)
throw new CUEException(error);
devices.Add(device);
}
catch { if (throwExceptions) throw; }
}
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
IsInitialized = true;
} }
catch catch
{
if (throwExceptions)
throw;
else
return false;
}
ProtocolDetails = new CorsairProtocolDetails(_CUESDK.CorsairPerformProtocolHandshake());
CorsairError error = LastError;
if (error != CorsairError.Success)
{ {
Reset(); Reset();
if (throwExceptions) if (throwExceptions) throw;
throw new CUEException(error); return false;
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
HasExclusiveAccess = false;
IList<IRGBDevice> devices = new List<IRGBDevice>();
int deviceCount = _CUESDK.CorsairGetDeviceCount();
for (int i = 0; i < deviceCount; i++)
{
_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
CorsairRGBDevice device;
switch (info.CorsairDeviceType)
{
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 = new ReadOnlyCollection<IRGBDevice>(devices);
IsInitialized = true;
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,34 +96,40 @@ namespace RGB.NET.Devices.Logitech
IList<IRGBDevice> devices = new List<IRGBDevice>(); IList<IRGBDevice> devices = new List<IRGBDevice>();
DeviceChecker.LoadDeviceList(); DeviceChecker.LoadDeviceList();
if (DeviceChecker.IsPerKeyDeviceConnected) try
{ {
(string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerKeyDeviceData; if (DeviceChecker.IsPerKeyDeviceConnected)
LogitechRGBDevice device = new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.PerKeyRGB, imageBasePath, imageLayout, layoutPath)); {
device.Initialize(); (string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerKeyDeviceData;
devices.Add(device); LogitechRGBDevice device = new LogitechPerKeyRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.PerKeyRGB, imageBasePath, imageLayout, layoutPath));
device.Initialize();
devices.Add(device);
}
} }
catch { if (throwExceptions) throw; }
if (DeviceChecker.IsPerDeviceDeviceConnected) try
{ {
(string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerDeviceDeviceData; if (DeviceChecker.IsPerDeviceDeviceConnected)
LogitechRGBDevice device = new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, imageBasePath, imageLayout, layoutPath)); {
device.Initialize(); (string model, RGBDeviceType deviceType, int _, string imageBasePath, string imageLayout, string layoutPath) = DeviceChecker.PerDeviceDeviceData;
devices.Add(device); LogitechRGBDevice device = new LogitechPerDeviceRGBDevice(new LogitechRGBDeviceInfo(deviceType, model, LogitechDeviceCaps.DeviceRGB, imageBasePath, imageLayout, layoutPath));
device.Initialize();
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

@ -100,21 +100,23 @@ namespace RGB.NET.Devices.Msi
for (int i = 0; i < deviceTypes.Length; i++) for (int i = 0; i < deviceTypes.Length; i++)
{ {
//TODO DarthAffe 11.11.2017: What is this deviceType? Find someone to try that out 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); 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,15 +66,16 @@ 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))
.FirstOrDefault(x => string.Equals(x.GetDeviceId(), outCaps.name, StringComparison.OrdinalIgnoreCase)); .Cast<Enum>()
.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;
} }