Skip to content

Commit b9dd91d

Browse files
Revert PR DarthAffe#339 Corsair-specific changes; route via DeviceHelper again
Reverts the Corsair half of the Aytackydln merge (PR DarthAffe#339) back to origin/Development. Drops the connection-state event refactor, the CreateSingleChannelDevice / CreateCorsairDeviceChannel helpers, and the direct IdGenerator.MakeUnique(typeof(...), ...) call sites — the provider now goes through DeviceHelper.CreateDeviceName the way every other provider does. Reason: PR DarthAffe#339's CorsairRGBDeviceInfo.cs calls IdGenerator.MakeUnique(object, string) directly, a signature that only exists in our patched RGB.NET.Core. Downstream consumers (Chromatics in particular) that load our RGB.NET.Devices.Corsair.dll alongside an upstream RGB.NET.Core.dll throw MissingMethodException on first device init — Sentry report traced to exactly this. Routing the call through DeviceHelper keeps the MakeUnique resolution internal to whichever Core assembly is loaded at runtime, so the Corsair DLL no longer needs the patched Core to function. The Core-level changes from PR DarthAffe#339 (RGBDeviceException catch in Initialize, [MethodImpl(Synchronized)] on GetUpdateTrigger, DeviceUpdateTrigger UpdateTask disposal reordering, and the IdGenerator Assembly->object change shared with PR DarthAffe#338) are intentionally kept — the OpenRGB provider still depends on the IdGenerator change. If a similar Sentry report ever lands for OpenRGB, the same revert recipe applies to RGB.NET.Devices.OpenRGB. Files reverted to origin/Development: - RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs - RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs - RGB.NET.Devices.Corsair/Generic/CorsairRGBDeviceInfo.cs - RGB.NET.Devices.Corsair/Generic/ICorsairRGBDevice.cs - RGB.NET.Devices.Corsair/Native/_CUESDK.cs - RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs Files deleted (added by PR DarthAffe#339): - RGB.NET.Devices.Corsair/Enum/CorsairEventId.cs - RGB.NET.Devices.Corsair/Native/_CorsairDeviceConnectionStatusChangedEvent.cs - RGB.NET.Devices.Corsair/Native/_CorsairEvent.cs Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9563781 commit b9dd91d

9 files changed

Lines changed: 179 additions & 374 deletions

RGB.NET.Devices.Corsair/CorsairDeviceProvider.cs

Lines changed: 163 additions & 204 deletions
Large diffs are not rendered by default.

RGB.NET.Devices.Corsair/Enum/CorsairEventId.cs

Lines changed: 0 additions & 8 deletions
This file was deleted.

RGB.NET.Devices.Corsair/Generic/CorsairRGBDevice.cs

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ public abstract class CorsairRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceI
1414
{
1515
#region Properties & Fields
1616

17-
/// <summary>
18-
/// <inheritdoc cref="ICorsairRGBDevice"/>
19-
/// </summary>
20-
public string DeviceId => DeviceInfo.DeviceId;
21-
2217
/// <summary>
2318
/// Gets the mapping of <see cref="LedId"/> to <see cref="CorsairLedId"/> used to update the LEDs of this device.
2419
/// </summary>
@@ -34,32 +29,14 @@ public abstract class CorsairRGBDevice<TDeviceInfo> : AbstractRGBDevice<TDeviceI
3429
/// <param name="info">The generic information provided by CUE for the device.</param>
3530
/// <param name="mapping">The mapping <see cref="LedId"/> to <see cref="CorsairLedId"/> used to update the LEDs of this device.</param>
3631
/// <param name="updateQueue">The queue used to update this device.</param>
37-
protected CorsairRGBDevice(TDeviceInfo info, IUpdateQueue updateQueue)
32+
protected CorsairRGBDevice(TDeviceInfo info, CorsairDeviceUpdateQueue updateQueue)
3833
: base(info, updateQueue)
3934
{ }
4035

4136
#endregion
4237

4338
#region Methods
4439

45-
protected bool Equals(CorsairRGBDevice<TDeviceInfo> other)
46-
{
47-
return DeviceId == other.DeviceId;
48-
}
49-
50-
public override bool Equals(object? obj)
51-
{
52-
if (ReferenceEquals(null, obj)) return false;
53-
if (ReferenceEquals(this, obj)) return true;
54-
if (obj.GetType() != this.GetType()) return false;
55-
return Equals((CorsairRGBDevice<TDeviceInfo>)obj);
56-
}
57-
58-
public override int GetHashCode()
59-
{
60-
return DeviceId.GetHashCode();
61-
}
62-
6340
void ICorsairRGBDevice.Initialize() => InitializeLayout();
6441

6542
/// <summary>

RGB.NET.Devices.Corsair/Generic/CorsairRGBDeviceInfo.cs

Lines changed: 4 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
using System;
2-
using System.Security.Cryptography;
3-
using System.Text;
4-
using System.Text.RegularExpressions;
1+
using System.Text.RegularExpressions;
52
using RGB.NET.Core;
63
using RGB.NET.Devices.Corsair.Native;
74

@@ -36,7 +33,7 @@ public class CorsairRGBDeviceInfo : IRGBDeviceInfo
3633
/// Returns the unique ID provided by the Corsair-SDK.
3734
/// Returns string.Empty for Custom devices.
3835
/// </summary>
39-
public string DeviceId { get; init; }
36+
public string DeviceId { get; }
4037

4138
/// <inheritdoc />
4239
public object? LayoutMetadata { get; set; }
@@ -70,14 +67,7 @@ internal CorsairRGBDeviceInfo(RGBDeviceType deviceType, _CorsairDeviceInfo nativ
7067
this.LedCount = ledCount;
7168
this.LedOffset = ledOffset;
7269

73-
if (nativeInfo.id == null) // this device is 99% unpluggable
74-
{
75-
DeviceName = IdGenerator.MakeUnique(typeof(CorsairDeviceProvider), Manufacturer + " " + Model);
76-
}
77-
else
78-
{
79-
DeviceName = Manufacturer + " " + Model + " #" + HashAndShorten(DeviceId);
80-
}
70+
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
8171
}
8272

8373
/// <summary>
@@ -96,34 +86,7 @@ internal CorsairRGBDeviceInfo(RGBDeviceType deviceType, _CorsairDeviceInfo nativ
9686
this.LedCount = ledCount;
9787
this.LedOffset = ledOffset;
9888

99-
if (nativeInfo.id == null)
100-
{
101-
DeviceName = IdGenerator.MakeUnique(typeof(CorsairDeviceProvider),Manufacturer + " " + Model) + " " + ledOffset;;
102-
}
103-
else
104-
{
105-
DeviceName = Manufacturer + " " + Model + " #" + HashAndShorten(DeviceId) + " " + ledOffset;
106-
}
107-
}
108-
109-
#endregion
110-
111-
#region Methods
112-
113-
private static string HashAndShorten(string input)
114-
{
115-
using SHA256 sha256Hash = SHA256.Create();
116-
byte[] bytes = sha256Hash.ComputeHash(Encoding.UTF8.GetBytes(input));
117-
// Take the first 4 bytes of the hash
118-
byte[] shortenedBytes = new byte[4];
119-
Array.Copy(bytes, shortenedBytes, 4);
120-
// Convert the bytes to a string
121-
StringBuilder shortenedHash = new();
122-
foreach (byte b in shortenedBytes)
123-
{
124-
shortenedHash.Append(b.ToString("X2"));
125-
}
126-
return shortenedHash.ToString();
89+
DeviceName = DeviceHelper.CreateDeviceName(Manufacturer, Model);
12790
}
12891

12992
#endregion

RGB.NET.Devices.Corsair/Generic/ICorsairRGBDevice.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,5 @@ namespace RGB.NET.Devices.Corsair;
77
/// </summary>
88
public interface ICorsairRGBDevice : IRGBDevice
99
{
10-
internal string DeviceId { get; }
11-
1210
internal void Initialize();
1311
}

RGB.NET.Devices.Corsair/Native/_CUESDK.cs

Lines changed: 10 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
namespace RGB.NET.Devices.Corsair.Native;
1313

1414
internal delegate void CorsairSessionStateChangedHandler(nint context, _CorsairSessionStateChanged eventData);
15-
internal delegate void CorsairEventHandler(nint context, _CorsairEvent corsairEvent);
1615

1716
// ReSharper disable once InconsistentNaming
1817
internal static unsafe class _CUESDK
@@ -51,15 +50,14 @@ internal static unsafe class _CUESDK
5150
// ReSharper disable once NotAccessedField.Local - This is important, the delegate can be collected if it's not stored!
5251
private static readonly CorsairSessionStateChangedHandler SESSION_STATE_CHANGED_CALLBACK;
5352

54-
internal static bool IsConnected => SessionState == CorsairSessionState.Connected;
55-
internal static CorsairSessionState SessionState { get; private set; }
53+
internal static bool IsConnected => SesionState == CorsairSessionState.Connected;
54+
internal static CorsairSessionState SesionState { get; private set; }
5655

5756
#endregion
5857

5958
#region Events
6059

6160
internal static event EventHandler<CorsairSessionState>? SessionStateChanged;
62-
internal static event EventHandler<_CorsairDeviceConnectionStatusChangedEvent>? DeviceConnectionEvent;
6361

6462
#endregion
6563

@@ -74,45 +72,10 @@ static _CUESDK()
7472

7573
#region Methods
7674

77-
private static void CorsairSessionStateChangedCallback(nint context, _CorsairSessionStateChanged eventData)
75+
private static void CorsairSessionStateChangedCallback(nint context, _CorsairSessionStateChanged eventdata)
7876
{
79-
SessionState = eventData.state;
80-
try
81-
{
82-
SessionStateChanged?.Invoke(null, eventData.state);
83-
}
84-
catch { /* dont let exception go to sdk */ }
85-
86-
switch (eventData.state)
87-
{
88-
case CorsairSessionState.Connected:
89-
_corsairSubscribeForEvents(CorsairEventCallback, 0);
90-
break;
91-
case CorsairSessionState.Closed:
92-
_corsairUnsubscribeForEvents();
93-
break;
94-
}
95-
}
96-
97-
private static void CorsairEventCallback(nint context, _CorsairEvent eventData)
98-
{
99-
if (eventData.id != CorsairEventId.DeviceConnectionStatusChangedEvent)
100-
{
101-
return;
102-
}
103-
104-
try
105-
{
106-
if (eventData.eventPointer == 0)
107-
{
108-
return;
109-
}
110-
111-
_CorsairDeviceConnectionStatusChangedEvent connectionStatusChangedEvent =
112-
Marshal.PtrToStructure<_CorsairDeviceConnectionStatusChangedEvent>(eventData.eventPointer)!;
113-
114-
DeviceConnectionEvent?.Invoke(null, connectionStatusChangedEvent);
115-
}catch { /* dont let exception go to sdk */ }
77+
SesionState = eventdata.state;
78+
SessionStateChanged?.Invoke(null, eventdata.state);
11679
}
11780

11881
#endregion
@@ -146,7 +109,7 @@ private static void LoadCUESDK()
146109
_corsairGetSessionDetails = (delegate* unmanaged[Cdecl]<nint, CorsairError>)LoadFunction("CorsairGetSessionDetails");
147110
_corsairDisconnect = (delegate* unmanaged[Cdecl]<CorsairError>)LoadFunction("CorsairDisconnect");
148111
_corsairGetDevices = (delegate* unmanaged[Cdecl]<_CorsairDeviceFilter, int, nint, out int, CorsairError>)LoadFunction("CorsairGetDevices");
149-
_corsairGetDeviceInfo = (delegate* unmanaged[Cdecl]<string, ref _CorsairDeviceInfo, CorsairError>)LoadFunction("CorsairGetDeviceInfo");
112+
_corsairGetDeviceInfo = (delegate* unmanaged[Cdecl]<string, _CorsairDeviceInfo, CorsairError>)LoadFunction("CorsairGetDeviceInfo");
150113
_corsairGetLedPositions = (delegate* unmanaged[Cdecl]<string, int, nint, out int, CorsairError>)LoadFunction("CorsairGetLedPositions");
151114
_corsairSetLedColors = (delegate* unmanaged[Cdecl]<string, int, nint, CorsairError>)LoadFunction("CorsairSetLedColors");
152115
_corsairSetLayerPriority = (delegate* unmanaged[Cdecl]<uint, CorsairError>)LoadFunction("CorsairSetLayerPriority");
@@ -155,8 +118,6 @@ private static void LoadCUESDK()
155118
_corsairReleaseControl = (delegate* unmanaged[Cdecl]<string, CorsairError>)LoadFunction("CorsairReleaseControl");
156119
_getDevicePropertyInfo = (delegate* unmanaged[Cdecl]<string, CorsairDevicePropertyId, uint, out CorsairDataType, out CorsairPropertyFlag, CorsairError>)LoadFunction("CorsairGetDevicePropertyInfo");
157120
_readDeviceProperty = (delegate* unmanaged[Cdecl]<string, CorsairDevicePropertyId, uint, nint, CorsairError>)LoadFunction("CorsairReadDeviceProperty");
158-
_corsairSubscribeForEvents = (delegate* unmanaged[Cdecl]<CorsairEventHandler, nint, CorsairError>)LoadFunction("CorsairSubscribeForEvents");
159-
_corsairUnsubscribeForEvents = (delegate* unmanaged[Cdecl]<CorsairError>)LoadFunction("CorsairSubscribeForEvents");
160121
}
161122

162123
private static nint LoadFunction(string function)
@@ -209,7 +170,7 @@ internal static void UnloadCUESDK()
209170
private static delegate* unmanaged[Cdecl]<nint, CorsairError> _corsairGetSessionDetails;
210171
private static delegate* unmanaged[Cdecl]<CorsairError> _corsairDisconnect;
211172
private static delegate* unmanaged[Cdecl]<_CorsairDeviceFilter, int, nint, out int, CorsairError> _corsairGetDevices;
212-
private static delegate* unmanaged[Cdecl]<string, ref _CorsairDeviceInfo, CorsairError> _corsairGetDeviceInfo;
173+
private static delegate* unmanaged[Cdecl]<string, _CorsairDeviceInfo, CorsairError> _corsairGetDeviceInfo;
213174
private static delegate* unmanaged[Cdecl]<string, int, nint, out int, CorsairError> _corsairGetLedPositions;
214175
private static delegate* unmanaged[Cdecl]<string, int, nint, CorsairError> _corsairSetLedColors;
215176
private static delegate* unmanaged[Cdecl]<uint, CorsairError> _corsairSetLayerPriority;
@@ -218,15 +179,12 @@ internal static void UnloadCUESDK()
218179
private static delegate* unmanaged[Cdecl]<string, CorsairError> _corsairReleaseControl;
219180
private static delegate* unmanaged[Cdecl]<string, CorsairDevicePropertyId, uint, out CorsairDataType, out CorsairPropertyFlag, CorsairError> _getDevicePropertyInfo;
220181
private static delegate* unmanaged[Cdecl]<string, CorsairDevicePropertyId, uint, nint, CorsairError> _readDeviceProperty;
221-
private static delegate* unmanaged[Cdecl]<CorsairEventHandler, nint, CorsairError> _corsairSubscribeForEvents;
222-
private static delegate* unmanaged[Cdecl]<CorsairError> _corsairUnsubscribeForEvents;
223182

224183
#endregion
225184

226185
internal static CorsairError CorsairConnect()
227186
{
228187
if (_corsairConnectPtr == null) throw new RGBDeviceException("The Corsair-SDK is not initialized.");
229-
if (SessionState is CorsairSessionState.Connecting or CorsairSessionState.Timeout) return CorsairError.Success;
230188
if (IsConnected) throw new RGBDeviceException("The Corsair-SDK is already connected.");
231189
return _corsairConnectPtr(SESSION_STATE_CHANGED_CALLBACK, 0);
232190
}
@@ -251,6 +209,7 @@ internal static CorsairError CorsairGetSessionDetails(out _CorsairSessionDetails
251209

252210
internal static CorsairError CorsairDisconnect()
253211
{
212+
if (!IsConnected) throw new RGBDeviceException("The Corsair-SDK is not connected.");
254213
return _corsairDisconnect();
255214
}
256215

@@ -273,12 +232,10 @@ internal static CorsairError CorsairGetDevices(_CorsairDeviceFilter filter, out
273232
}
274233
}
275234

276-
internal static CorsairError CorsairGetDeviceInfo(string deviceId, out _CorsairDeviceInfo deviceInfo)
235+
internal static CorsairError CorsairGetDeviceInfo(string deviceId, _CorsairDeviceInfo deviceInfo)
277236
{
278237
if (!IsConnected) throw new RGBDeviceException("The Corsair-SDK is not connected.");
279-
280-
deviceInfo = new _CorsairDeviceInfo();
281-
return _corsairGetDeviceInfo(deviceId, ref deviceInfo);
238+
return _corsairGetDeviceInfo(deviceId, deviceInfo);
282239
}
283240

284241
internal static CorsairError CorsairGetLedPositions(string deviceId, out _CorsairLedPosition[] ledPositions)

RGB.NET.Devices.Corsair/Native/_CorsairDeviceConnectionStatusChangedEvent.cs

Lines changed: 0 additions & 19 deletions
This file was deleted.

RGB.NET.Devices.Corsair/Native/_CorsairDeviceInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ namespace RGB.NET.Devices.Corsair.Native;
1212
/// iCUE-SDK: contains information about device
1313
/// </summary>
1414
[StructLayout(LayoutKind.Sequential)]
15-
internal struct _CorsairDeviceInfo
15+
internal sealed class _CorsairDeviceInfo
1616
{
1717
/// <summary>
1818
/// iCUE-SDK: enum describing device type

RGB.NET.Devices.Corsair/Native/_CorsairEvent.cs

Lines changed: 0 additions & 22 deletions
This file was deleted.

0 commit comments

Comments
 (0)