diff --git a/Corale.Colore/Core/Chroma.cs b/Corale.Colore/Core/Chroma.cs
index 92ac5f74..539d80b1 100644
--- a/Corale.Colore/Core/Chroma.cs
+++ b/Corale.Colore/Core/Chroma.cs
@@ -57,11 +57,6 @@ public sealed class Chroma : IChroma
///
private static readonly object InitLock = new object();
- ///
- /// Keeps track of whether the SDK has been initialized.
- ///
- private static bool _initialized;
-
///
/// Holds the application-wide instance of the interface.
///
@@ -82,12 +77,7 @@ public sealed class Chroma : IChroma
///
private Chroma()
{
- Log.Info("Chroma is initializing.");
- Log.Debug("Calling SDK Init function");
- NativeWrapper.Init();
- _initialized = true;
- Log.Debug("Resetting _registeredHandle");
- _registeredHandle = IntPtr.Zero;
+ Initialize();
}
///
@@ -98,11 +88,7 @@ private Chroma()
///
~Chroma()
{
- if (!_initialized)
- return;
-
- Unregister();
- NativeWrapper.UnInit();
+ Uninitialize();
}
///
@@ -211,15 +197,10 @@ public IKeypad Keypad
}
///
- /// Gets a value indicating whether the Chroma main class has been initialized or not.
+ /// Gets a value indicating whether the Chroma
+ /// SDK has been initialized or not.
///
- internal static bool Initialized
- {
- get
- {
- return _instance != null;
- }
- }
+ public bool Initialized { get; private set; }
///
/// Checks if the Chroma SDK is available on this system.
@@ -288,6 +269,57 @@ public static bool IsSdkAvailable()
return dllValid && regEnabled;
}
+ ///
+ /// Initializes the SDK if it hasn't already.
+ ///
+ ///
+ /// Manual manipulation of the SDK state is
+ /// not supported by the CoraleStudios team and may
+ /// result in undefined behaviour. Usage of this method is
+ /// at your own risk.
+ ///
+ public void Initialize()
+ {
+ if (Initialized)
+ return;
+
+ Log.Info("Chroma is initializing.");
+ Log.Debug("Calling SDK Init function");
+ NativeWrapper.Init();
+ Initialized = true;
+ Log.Debug("Resetting _registeredHandle");
+ _registeredHandle = IntPtr.Zero;
+ }
+
+ ///
+ /// Uninitializes the SDK if it has been initialized.
+ ///
+ ///
+ /// Manual manipulation of the SDK state is
+ /// not supported by the CoraleStudios team and may
+ /// result in undefined behaviour. Usage of this method is
+ /// at your own risk. Usage of SDK functions while
+ /// the SDK is in an uninitialized state is highly
+ /// advised against and WILL result in catastrophic
+ /// failure. YOU HAVE BEEN WARNED.
+ ///
+ public void Uninitialize()
+ {
+ if (!Initialized)
+ return;
+
+ ((Device)Keyboard).DeleteCurrentEffect();
+ ((Device)Mouse).DeleteCurrentEffect();
+ ((Device)Keypad).DeleteCurrentEffect();
+ ((Device)Mousepad).DeleteCurrentEffect();
+ ((Device)Headset).DeleteCurrentEffect();
+
+ Unregister();
+ NativeWrapper.UnInit();
+
+ Initialized = false;
+ }
+
///
/// Queries the SDK for information regarding a specific device.
///
@@ -428,10 +460,9 @@ public void SetAll(Color color)
///
/// For internal use by singleton accessors in device interface implementations.
///
- internal static void Initialize()
+ internal static void InitInstance()
{
- if (!Initialized)
- _instance = new Chroma();
+ Instance.Initialize();
}
///
diff --git a/Corale.Colore/Core/Device.cs b/Corale.Colore/Core/Device.cs
index 7a14413a..33a14b87 100644
--- a/Corale.Colore/Core/Device.cs
+++ b/Corale.Colore/Core/Device.cs
@@ -62,14 +62,21 @@ public void Clear()
/// GUID to set.
public void SetGuid(Guid guid)
{
- if (CurrentEffectId != Guid.Empty)
- {
- NativeWrapper.DeleteEffect(CurrentEffectId);
- CurrentEffectId = Guid.Empty;
- }
-
+ DeleteCurrentEffect();
NativeWrapper.SetEffect(guid);
CurrentEffectId = guid;
}
+
+ ///
+ /// Deletes the currently set effect.
+ ///
+ internal void DeleteCurrentEffect()
+ {
+ if (CurrentEffectId == Guid.Empty)
+ return;
+
+ NativeWrapper.DeleteEffect(CurrentEffectId);
+ CurrentEffectId = Guid.Empty;
+ }
}
}
diff --git a/Corale.Colore/Core/GenericDevice.cs b/Corale.Colore/Core/GenericDevice.cs
index 35966612..b726288c 100644
--- a/Corale.Colore/Core/GenericDevice.cs
+++ b/Corale.Colore/Core/GenericDevice.cs
@@ -93,7 +93,7 @@ public Guid DeviceId
[PublicAPI]
public static IGenericDevice Get(Guid deviceId)
{
- Chroma.Initialize();
+ Chroma.InitInstance();
if (!Instances.ContainsKey(deviceId))
Instances[deviceId] = new GenericDevice(deviceId);
diff --git a/Corale.Colore/Core/Headset.cs b/Corale.Colore/Core/Headset.cs
index b816cb98..f3bc927b 100644
--- a/Corale.Colore/Core/Headset.cs
+++ b/Corale.Colore/Core/Headset.cs
@@ -55,7 +55,7 @@ public sealed class Headset : Device, IHeadset
private Headset()
{
Log.Info("Headset is initializing");
- Chroma.Initialize();
+ Chroma.InitInstance();
}
///
diff --git a/Corale.Colore/Core/IChroma.cs b/Corale.Colore/Core/IChroma.cs
index 2829c9c2..982a7629 100644
--- a/Corale.Colore/Core/IChroma.cs
+++ b/Corale.Colore/Core/IChroma.cs
@@ -110,6 +110,35 @@ public interface IChroma
[PublicAPI]
IKeypad Keypad { get; }
+ ///
+ /// Gets a value indicating whether the Chroma
+ /// SDK has been initialized or not.
+ ///
+ [PublicAPI]
+ bool Initialized { get; }
+
+ ///
+ /// Initializes the SDK if it hasn't already.
+ ///
+ ///
+ /// Manually modifying the SDK init state is untested
+ /// and may result in undefined behaviour, usage
+ /// is at your own risk.
+ ///
+ [PublicAPI]
+ void Initialize();
+
+ ///
+ /// Uninitializes the SDK if it has been initialized.
+ ///
+ ///
+ /// Manually modifying the SDK init state is untested
+ /// and may result in undefined behaviour, usage
+ /// is at your own risk.
+ ///
+ [PublicAPI]
+ void Uninitialize();
+
///
/// Queries the SDK for information regarding a specific device.
///
diff --git a/Corale.Colore/Core/Keyboard.cs b/Corale.Colore/Core/Keyboard.cs
index 6be0093d..17d2906e 100644
--- a/Corale.Colore/Core/Keyboard.cs
+++ b/Corale.Colore/Core/Keyboard.cs
@@ -73,7 +73,7 @@ private Keyboard()
{
Log.Info("Keyboard initializing...");
- Chroma.Initialize();
+ Chroma.InitInstance();
CurrentEffectId = Guid.Empty;
diff --git a/Corale.Colore/Core/Keypad.cs b/Corale.Colore/Core/Keypad.cs
index 23385e39..4c2b5cc7 100644
--- a/Corale.Colore/Core/Keypad.cs
+++ b/Corale.Colore/Core/Keypad.cs
@@ -67,7 +67,7 @@ public sealed class Keypad : Device, IKeypad
private Keypad()
{
Log.Debug("Keypad is initializing");
- Chroma.Initialize();
+ Chroma.InitInstance();
_custom = Custom.Create();
}
diff --git a/Corale.Colore/Core/Mouse.cs b/Corale.Colore/Core/Mouse.cs
index bb6e0e34..e3b3df11 100644
--- a/Corale.Colore/Core/Mouse.cs
+++ b/Corale.Colore/Core/Mouse.cs
@@ -73,7 +73,7 @@ public sealed class Mouse : Device, IMouse
private Mouse()
{
Log.Info("Mouse is initializing");
- Chroma.Initialize();
+ Chroma.InitInstance();
_custom = Custom.Create();
_customGrid = CustomGrid.Create();
}
diff --git a/Corale.Colore/Core/Mousepad.cs b/Corale.Colore/Core/Mousepad.cs
index 1701f122..2ec1ba6e 100644
--- a/Corale.Colore/Core/Mousepad.cs
+++ b/Corale.Colore/Core/Mousepad.cs
@@ -65,7 +65,7 @@ public sealed class Mousepad : Device, IMousepad
private Mousepad()
{
Log.Debug("Mousepad is initializing.");
- Chroma.Initialize();
+ Chroma.InitInstance();
_custom = Custom.Create();
}