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

Changed device-providers to be disposable

This commit is contained in:
Darth Affe 2018-01-29 12:41:43 +01:00
parent 1af93658f9
commit cdace494bc
10 changed files with 58 additions and 20 deletions

View File

@ -1,11 +1,12 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;
namespace RGB.NET.Core
{
/// <summary>
/// Represents a generic device provider.
/// </summary>
public interface IRGBDeviceProvider
public interface IRGBDeviceProvider : IDisposable
{
#region Properties & Fields

View File

@ -112,6 +112,10 @@ namespace RGB.NET.Core
try { device.Dispose(); }
catch { /* We do what we can */ }
foreach (IRGBDeviceProvider deviceProvider in _deviceProvider)
try { deviceProvider.Dispose(); }
catch { /* We do what we can */ }
_ledGroups.Clear();
_devices = null;
_deviceProvider = null;

View File

@ -253,6 +253,10 @@ namespace RGB.NET.Devices.Asus
}
}
/// <inheritdoc />
public void Dispose()
{ }
#endregion
}
}

View File

@ -144,19 +144,32 @@ namespace RGB.NET.Devices.CoolerMaster
public void ResetDevices()
{
if (IsInitialized)
try
foreach (IRGBDevice device in Devices)
{
foreach (IRGBDevice device in Devices)
try
{
CoolerMasterRGBDeviceInfo deviceInfo = (CoolerMasterRGBDeviceInfo)device.DeviceInfo;
_CoolerMasterSDK.SetControlDevice(deviceInfo.DeviceIndex);
_CoolerMasterSDK.EnableLedControl(false);
_CoolerMasterSDK.EnableLedControl(true);
}
catch {/* shit happens */}
}
catch
}
/// <inheritdoc />
public void Dispose()
{
if (IsInitialized)
foreach (IRGBDevice device in Devices)
{
// shit happens ...
try
{
CoolerMasterRGBDeviceInfo deviceInfo = (CoolerMasterRGBDeviceInfo)device.DeviceInfo;
_CoolerMasterSDK.SetControlDevice(deviceInfo.DeviceIndex);
_CoolerMasterSDK.EnableLedControl(false);
}
catch {/* shit happens */}
}
}

View File

@ -195,10 +195,7 @@ namespace RGB.NET.Devices.Corsair
{
_CUESDK.Reload();
}
catch
{
// shit happens ...
}
catch {/* shit happens */}
}
private void Reset()
@ -209,6 +206,10 @@ namespace RGB.NET.Devices.Corsair
IsInitialized = false;
}
/// <inheritdoc />
public void Dispose()
{ }
#endregion
}
}

View File

@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using RGB.NET.Core;
namespace RGB.NET.Devices.Debug
@ -73,7 +74,6 @@ namespace RGB.NET.Devices.Debug
try
{
HasExclusiveAccess = exclusiveAccessIfPossible;
IsInitialized = true;
List<IRGBDevice> devices = new List<IRGBDevice>();
foreach ((string layout, string imageLayout, Func<Dictionary<LedId, Color>> syncBackFunc, Action<IEnumerable<Led>> updateLedsAction) in _fakeDeviceDefinitions)
@ -83,7 +83,8 @@ namespace RGB.NET.Devices.Debug
devices.Add(device);
}
Devices = devices;
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
IsInitialized = true;
return true;
}
@ -98,6 +99,12 @@ namespace RGB.NET.Devices.Debug
public void ResetDevices()
{ }
/// <inheritdoc />
public void Dispose()
{
_fakeDeviceDefinitions.Clear();
}
#endregion
}
}

View File

@ -140,10 +140,10 @@ namespace RGB.NET.Devices.Logitech
}
/// <inheritdoc />
public void ResetDevices()
{
_LogitechGSDK.LogiLedRestoreLighting();
}
public void ResetDevices() => _LogitechGSDK.LogiLedRestoreLighting();
/// <inheritdoc />
public void Dispose() => _LogitechGSDK.LogiLedRestoreLighting();
#endregion
}

View File

@ -128,6 +128,10 @@ namespace RGB.NET.Devices.Msi
//TODO DarthAffe 11.11.2017: Implement
}
/// <inheritdoc />
public void Dispose()
{ }
#endregion
}
}

View File

@ -110,6 +110,10 @@ namespace RGB.NET.Devices.Novation
}
}
/// <inheritdoc />
public void Dispose()
{ }
#endregion
}
}

View File

@ -206,13 +206,13 @@ namespace RGB.NET.Devices.Razer
private void TryUnInit()
{
try
{
_RazerSDK.UnInit();
}
try { _RazerSDK.UnInit(); }
catch { /* We tried our best */ }
}
/// <inheritdoc />
public void Dispose() => TryUnInit();
#endregion
}
}