1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-13 01:58:30 +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; }
#endregion
UpdateTrigger?.Start();
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
@ -267,7 +267,10 @@ namespace RGB.NET.Devices.Asus
/// <inheritdoc />
public void Dispose()
{ }
{
try { _AsusSDK.UnloadAsusSDK(); }
catch { /* at least we tried */ }
}
#endregion
}

View File

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

View File

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

View File

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

View File

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

View File

@ -56,7 +56,7 @@ namespace RGB.NET.Devices.Corsair.Native
_corsairGetLastErrorPointer = (CorsairGetLastErrorPointer)Marshal.GetDelegateForFunctionPointer(GetProcAddress(_dllHandle, "CorsairGetLastError"), typeof(CorsairGetLastErrorPointer));
}
private static void UnloadCUESDK()
internal static void UnloadCUESDK()
{
if (_dllHandle == IntPtr.Zero) return;
@ -136,7 +136,7 @@ namespace RGB.NET.Devices.Corsair.Native
#endregion
// ReSharper disable EventExceptionNotDocumented
/// <summary>
/// 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.
@ -151,7 +151,7 @@ namespace RGB.NET.Devices.Corsair.Native
/// This function executes synchronously, if you are concerned about delays consider using CorsairSetLedsColorsFlushBufferAsync
/// </summary>
internal static bool CorsairSetLedsColorsFlushBuffer() => _corsairSetLedsColorsFlushBufferPointer();
/// <summary>
/// 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.
@ -175,7 +175,7 @@ namespace RGB.NET.Devices.Corsair.Native
/// CUE-SDK: returns information about device at provided index.
/// </summary>
internal static IntPtr CorsairGetDeviceInfo(int deviceIndex) => _corsairGetDeviceInfoPointer(deviceIndex);
/// <summary>
/// CUE-SDK: provides list of keyboard or mousepad LEDs with their physical positions.
/// </summary>

View File

@ -182,7 +182,14 @@ namespace RGB.NET.Devices.Logitech
public void ResetDevices() => _LogitechGSDK.LogiLedRestoreLighting();
/// <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
}

View File

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

View File

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

View File

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

View File

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

View File

@ -27,11 +27,11 @@ namespace RGB.NET.Devices.Roccat.Native
/// </summary>
internal static void Reload()
{
UnloadCUESDK();
LoadCUESDK();
UnloadRoccatSDK();
LoadRoccatSDK();
}
private static void LoadCUESDK()
private static void LoadRoccatSDK()
{
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));
}
private static void UnloadCUESDK()
internal static void UnloadRoccatSDK()
{
if (_dllHandle == IntPtr.Zero) return;

View File

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

View File

@ -85,7 +85,9 @@ namespace RGB.NET.Devices.SteelSeries.API
internal static void Dispose()
{
ResetLeds();
if (IsInitialized)
ResetLeds();
_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));
}
private static void UnloadWootingSDK()
internal static void UnloadWootingSDK()
{
if (_dllHandle == IntPtr.Zero) return;
@ -91,13 +91,13 @@ namespace RGB.NET.Devices.Wooting.Native
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate IntPtr GetDeviceInfoPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool KeyboardConnectedPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate bool ResetPointer();
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
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.
/// The first match will be used.
/// </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>
/// Gets a modifiable list of paths used to find the native SDK-dlls for x64 applications.
/// The first match will be used.
/// </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 />
/// <summary>
@ -144,9 +144,10 @@ namespace RGB.NET.Devices.Wooting
public void Dispose()
{
try { _WootingSDK.Reset(); }
catch
{ /* Unlucky.. */
}
catch { /* Unlucky.. */ }
try { _WootingSDK.UnloadWootingSDK(); }
catch { /* at least we tried */ }
}
#endregion