1
0
mirror of https://github.com/DarthAffe/CUE.NET.git synced 2025-12-12 16:58:29 +00:00

Fixed an issue that prevents further reinitializing if an exception was thrown earlier

This commit is contained in:
Darth Affe 2017-08-13 08:22:18 +02:00
parent c786710b65
commit 220953bfe7

View File

@ -166,7 +166,7 @@ namespace CUE.NET
CorsairError error = LastError; CorsairError error = LastError;
if (error != CorsairError.Success) if (error != CorsairError.Success)
Throw(error); Throw(error, true);
if (ProtocolDetails.BreakingChanges) if (ProtocolDetails.BreakingChanges)
throw new WrapperException("The SDK currently used isn't compatible with the installed version of CUE.\r\n" throw new WrapperException("The SDK currently used isn't compatible with the installed version of CUE.\r\n"
@ -176,7 +176,7 @@ namespace CUE.NET
if (exclusiveAccess) if (exclusiveAccess)
{ {
if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl)) if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
Throw(LastError); Throw(LastError, true);
HasExclusiveAccess = true; HasExclusiveAccess = true;
} }
@ -216,7 +216,7 @@ namespace CUE.NET
error = LastError; error = LastError;
if (error != CorsairError.Success) if (error != CorsairError.Success)
Throw(error); Throw(error, true);
} }
InitializedDevices = new ReadOnlyCollection<ICueDevice>(devices); InitializedDevices = new ReadOnlyCollection<ICueDevice>(devices);
@ -252,7 +252,7 @@ namespace CUE.NET
CorsairError error = LastError; CorsairError error = LastError;
if (error != CorsairError.Success) if (error != CorsairError.Success)
Throw(error); Throw(error, false);
if (ProtocolDetails.BreakingChanges) if (ProtocolDetails.BreakingChanges)
throw new WrapperException("The SDK currently used isn't compatible with the installed version of CUE.\r\n" throw new WrapperException("The SDK currently used isn't compatible with the installed version of CUE.\r\n"
@ -261,7 +261,7 @@ namespace CUE.NET
if (exclusiveAccess) if (exclusiveAccess)
if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl)) if (!_CUESDK.CorsairRequestControl(CorsairAccessMode.ExclusiveLightingControl))
Throw(LastError); Throw(LastError, false);
HasExclusiveAccess = exclusiveAccess; HasExclusiveAccess = exclusiveAccess;
int deviceCount = _CUESDK.CorsairGetDeviceCount(); int deviceCount = _CUESDK.CorsairGetDeviceCount();
@ -276,7 +276,7 @@ namespace CUE.NET
error = LastError; error = LastError;
if (error != CorsairError.Success) if (error != CorsairError.Success)
Throw(error); Throw(error, false);
} }
if (KeyboardSDK != null) if (KeyboardSDK != null)
@ -299,15 +299,18 @@ namespace CUE.NET
IsInitialized = true; IsInitialized = true;
} }
private static void Throw(CorsairError error) private static void Throw(CorsairError error, bool reset)
{ {
ProtocolDetails = null; if (reset)
HasExclusiveAccess = false; {
KeyboardSDK = null; ProtocolDetails = null;
MouseSDK = null; HasExclusiveAccess = false;
HeadsetSDK = null; KeyboardSDK = null;
MousematSDK = null; MouseSDK = null;
IsInitialized = false; HeadsetSDK = null;
MousematSDK = null;
IsInitialized = false;
}
throw new CUEException(error); throw new CUEException(error);
} }