1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 10:08:31 +00:00

Added native-unload to all deviceprovider-disposes

This commit is contained in:
Darth Affe 2020-03-03 14:30:12 +01:00
parent c98ffd2dbf
commit 1cfdeefde1
17 changed files with 60 additions and 29 deletions

View File

@ -228,7 +228,7 @@ namespace RGB.NET.Devices.Asus
catch { if (throwExceptions) throw; } catch { if (throwExceptions) throw; }
#endregion #endregion
UpdateTrigger?.Start(); UpdateTrigger?.Start();
Devices = new ReadOnlyCollection<IRGBDevice>(devices); Devices = new ReadOnlyCollection<IRGBDevice>(devices);
@ -267,7 +267,10 @@ namespace RGB.NET.Devices.Asus
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public void Dispose()
{ } {
try { _AsusSDK.UnloadAsusSDK(); }
catch { /* at least we tried */ }
}
#endregion #endregion
} }

View File

@ -75,7 +75,7 @@ namespace RGB.NET.Devices.Asus.Native
//_getDramColorPointer = (GetDramColorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "GetDramColor"), typeof(GetDramColorPointer)); //_getDramColorPointer = (GetDramColorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "GetDramColor"), typeof(GetDramColorPointer));
} }
private static void UnloadAsusSDK() internal static void UnloadAsusSDK()
{ {
if (_dllHandle == IntPtr.Zero) return; if (_dllHandle == IntPtr.Zero) return;

View File

@ -108,7 +108,7 @@ namespace RGB.NET.Devices.CoolerMaster
{ {
RGBDeviceType deviceType = index.GetDeviceType(); RGBDeviceType deviceType = index.GetDeviceType();
if (deviceType == RGBDeviceType.None) continue; if (deviceType == RGBDeviceType.None) continue;
if (_CoolerMasterSDK.IsDevicePlugged(index)) if (_CoolerMasterSDK.IsDevicePlugged(index))
{ {
if (!loadFilter.HasFlag(deviceType)) continue; if (!loadFilter.HasFlag(deviceType)) continue;
@ -185,6 +185,9 @@ namespace RGB.NET.Devices.CoolerMaster
} }
catch {/* shit happens */} catch {/* shit happens */}
} }
try { _CoolerMasterSDK.UnloadCMSDK(); }
catch { /* at least we tried */ }
} }
#endregion #endregion

View File

@ -52,7 +52,7 @@ namespace RGB.NET.Devices.CoolerMaster.Native
_setAllLedColorPointer = (SetAllLedColorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "SetAllLedColor"), typeof(SetAllLedColorPointer)); _setAllLedColorPointer = (SetAllLedColorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "SetAllLedColor"), typeof(SetAllLedColorPointer));
} }
private static void UnloadCMSDK() internal static void UnloadCMSDK()
{ {
if (_dllHandle == IntPtr.Zero) return; if (_dllHandle == IntPtr.Zero) return;

View File

@ -292,7 +292,10 @@ namespace RGB.NET.Devices.Corsair
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public void Dispose()
{ } {
try { _CUESDK.UnloadCUESDK(); }
catch { /* at least we tried */ }
}
#endregion #endregion
} }

View File

@ -56,7 +56,7 @@ namespace RGB.NET.Devices.Corsair.Native
_corsairGetLastErrorPointer = (CorsairGetLastErrorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLastError"), typeof(CorsairGetLastErrorPointer)); _corsairGetLastErrorPointer = (CorsairGetLastErrorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLastError"), typeof(CorsairGetLastErrorPointer));
} }
private static void UnloadCUESDK() internal static void UnloadCUESDK()
{ {
if (_dllHandle == IntPtr.Zero) return; if (_dllHandle == IntPtr.Zero) return;
@ -136,7 +136,7 @@ namespace RGB.NET.Devices.Corsair.Native
#endregion #endregion
// ReSharper disable EventExceptionNotDocumented // ReSharper disable EventExceptionNotDocumented
/// <summary> /// <summary>
/// CUE-SDK: set specified LEDs to some colors. /// CUE-SDK: set specified LEDs to some colors.
/// This function set LEDs colors in the buffer which is written to the devices via CorsairSetLedsColorsFlushBuffer or CorsairSetLedsColorsFlushBufferAsync. /// This function set LEDs colors in the buffer which is written to the devices via CorsairSetLedsColorsFlushBuffer or CorsairSetLedsColorsFlushBufferAsync.
@ -151,7 +151,7 @@ namespace RGB.NET.Devices.Corsair.Native
/// This function executes synchronously, if you are concerned about delays consider using CorsairSetLedsColorsFlushBufferAsync /// This function executes synchronously, if you are concerned about delays consider using CorsairSetLedsColorsFlushBufferAsync
/// </summary> /// </summary>
internal static bool CorsairSetLedsColorsFlushBuffer() => _corsairSetLedsColorsFlushBufferPointer(); internal static bool CorsairSetLedsColorsFlushBuffer() => _corsairSetLedsColorsFlushBufferPointer();
/// <summary> /// <summary>
/// CUE-SDK: get current color for the list of requested LEDs. /// CUE-SDK: get current color for the list of requested LEDs.
/// The color should represent the actual state of the hardware LED, which could be a combination of SDK and/or CUE input. /// The color should represent the actual state of the hardware LED, which could be a combination of SDK and/or CUE input.
@ -175,7 +175,7 @@ namespace RGB.NET.Devices.Corsair.Native
/// CUE-SDK: returns information about device at provided index. /// CUE-SDK: returns information about device at provided index.
/// </summary> /// </summary>
internal static IntPtr CorsairGetDeviceInfo(int deviceIndex) => _corsairGetDeviceInfoPointer(deviceIndex); internal static IntPtr CorsairGetDeviceInfo(int deviceIndex) => _corsairGetDeviceInfoPointer(deviceIndex);
/// <summary> /// <summary>
/// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions. /// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions.
/// </summary> /// </summary>

View File

@ -182,7 +182,14 @@ namespace RGB.NET.Devices.Logitech
public void ResetDevices() => _LogitechGSDK.LogiLedRestoreLighting(); public void ResetDevices() => _LogitechGSDK.LogiLedRestoreLighting();
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() => _LogitechGSDK.LogiLedRestoreLighting(); public void Dispose()
{
try { _LogitechGSDK.LogiLedRestoreLighting(); }
catch { /* at least we tried */ }
try { _LogitechGSDK.UnloadLogitechGSDK(); }
catch { /* at least we tried */ }
}
#endregion #endregion
} }

View File

@ -55,7 +55,7 @@ namespace RGB.NET.Devices.Logitech.Native
_logiLedSetLightingForTargetZonePointer = (LogiLedSetLightingForTargetZonePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLightingForTargetZone"), typeof(LogiLedSetLightingForTargetZonePointer)); _logiLedSetLightingForTargetZonePointer = (LogiLedSetLightingForTargetZonePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "LogiLedSetLightingForTargetZone"), typeof(LogiLedSetLightingForTargetZonePointer));
} }
private static void UnloadLogitechGSDK() internal static void UnloadLogitechGSDK()
{ {
if (_dllHandle == IntPtr.Zero) return; if (_dllHandle == IntPtr.Zero) return;

View File

@ -163,7 +163,10 @@ namespace RGB.NET.Devices.Msi
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() public void Dispose()
{ } {
try { _MsiSDK.UnloadMsiSDK(); }
catch { /* at least we tried */ }
}
#endregion #endregion
} }

View File

@ -60,7 +60,7 @@ namespace RGB.NET.Devices.Msi.Native
_getErrorMessagePointer = (GetErrorMessagePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "MLAPI_GetErrorMessage"), typeof(GetErrorMessagePointer)); _getErrorMessagePointer = (GetErrorMessagePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "MLAPI_GetErrorMessage"), typeof(GetErrorMessagePointer));
} }
private static void UnloadMsiSDK() internal static void UnloadMsiSDK()
{ {
if (_dllHandle == IntPtr.Zero) return; if (_dllHandle == IntPtr.Zero) return;

View File

@ -52,7 +52,7 @@ namespace RGB.NET.Devices.Razer.Native
_deleteEffectPointer = (DeleteEffectPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "DeleteEffect"), typeof(DeleteEffectPointer)); _deleteEffectPointer = (DeleteEffectPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "DeleteEffect"), typeof(DeleteEffectPointer));
} }
private static void UnloadRazerSDK() internal static void UnloadRazerSDK()
{ {
if (_dllHandle == IntPtr.Zero) return; if (_dllHandle == IntPtr.Zero) return;

View File

@ -222,7 +222,13 @@ namespace RGB.NET.Devices.Razer
} }
/// <inheritdoc /> /// <inheritdoc />
public void Dispose() => TryUnInit(); public void Dispose()
{
TryUnInit();
try { _RazerSDK.UnloadRazerSDK(); }
catch { /* at least we tried */ }
}
#endregion #endregion
} }

View File

@ -27,11 +27,11 @@ namespace RGB.NET.Devices.Roccat.Native
/// </summary> /// </summary>
internal static void Reload() internal static void Reload()
{ {
UnloadCUESDK(); UnloadRoccatSDK();
LoadCUESDK(); LoadRoccatSDK();
} }
private static void LoadCUESDK() private static void LoadRoccatSDK()
{ {
if (_dllHandle != IntPtr.Zero) return; if (_dllHandle != IntPtr.Zero) return;
@ -57,7 +57,7 @@ namespace RGB.NET.Devices.Roccat.Native
_setAllLedSfxPointer = (SetAllLedSfxPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "Set_all_LEDSFX"), typeof(SetAllLedSfxPointer)); _setAllLedSfxPointer = (SetAllLedSfxPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "Set_all_LEDSFX"), typeof(SetAllLedSfxPointer));
} }
private static void UnloadCUESDK() internal static void UnloadRoccatSDK()
{ {
if (_dllHandle == IntPtr.Zero) return; if (_dllHandle == IntPtr.Zero) return;

View File

@ -114,6 +114,9 @@ namespace RGB.NET.Devices.Roccat
try { _RoccatSDK.UnloadSDK(_sdkHandle); } try { _RoccatSDK.UnloadSDK(_sdkHandle); }
catch { /* We tried our best */} catch { /* We tried our best */}
} }
try { _RoccatSDK.UnloadRoccatSDK(); }
catch { /* at least we tried */ }
} }
#endregion #endregion

View File

@ -85,7 +85,9 @@ namespace RGB.NET.Devices.SteelSeries.API
internal static void Dispose() internal static void Dispose()
{ {
ResetLeds(); if (IsInitialized)
ResetLeds();
_client.Dispose(); _client.Dispose();
} }

View File

@ -52,7 +52,7 @@ namespace RGB.NET.Devices.Wooting.Native
_arraySetSinglePointer = (ArraySetSinglePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_array_set_single"), typeof(ArraySetSinglePointer)); _arraySetSinglePointer = (ArraySetSinglePointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "wooting_rgb_array_set_single"), typeof(ArraySetSinglePointer));
} }
private static void UnloadWootingSDK() internal static void UnloadWootingSDK()
{ {
if (_dllHandle == IntPtr.Zero) return; if (_dllHandle == IntPtr.Zero) return;
@ -91,13 +91,13 @@ namespace RGB.NET.Devices.Wooting.Native
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate IntPtr GetDeviceInfoPointer(); private delegate IntPtr GetDeviceInfoPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool KeyboardConnectedPointer(); private delegate bool KeyboardConnectedPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool ResetPointer(); private delegate bool ResetPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool ArrayUpdateKeyboardPointer(); private delegate bool ArrayUpdateKeyboardPointer();

View File

@ -28,13 +28,13 @@ namespace RGB.NET.Devices.Wooting
/// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x86 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX86NativePaths { get; } = new List<string> {"x86/wooting-rgb-sdk.dll"}; public static List<string> PossibleX86NativePaths { get; } = new List<string> { "x86/wooting-rgb-sdk.dll" };
/// <summary> /// <summary>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications. /// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used. /// The first match will be used.
/// </summary> /// </summary>
public static List<string> PossibleX64NativePaths { get; } = new List<string> {"x64/wooting-rgb-sdk64.dll"}; public static List<string> PossibleX64NativePaths { get; } = new List<string> { "x64/wooting-rgb-sdk64.dll" };
/// <inheritdoc /> /// <inheritdoc />
/// <summary> /// <summary>
@ -144,9 +144,10 @@ namespace RGB.NET.Devices.Wooting
public void Dispose() public void Dispose()
{ {
try { _WootingSDK.Reset(); } try { _WootingSDK.Reset(); }
catch catch { /* Unlucky.. */ }
{ /* Unlucky.. */
} try { _WootingSDK.UnloadWootingSDK(); }
catch { /* at least we tried */ }
} }
#endregion #endregion