mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 01:58:30 +00:00
Changed device-providers to be disposable
This commit is contained in:
parent
1af93658f9
commit
cdace494bc
@ -1,11 +1,12 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
|
||||||
namespace RGB.NET.Core
|
namespace RGB.NET.Core
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Represents a generic device provider.
|
/// Represents a generic device provider.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public interface IRGBDeviceProvider
|
public interface IRGBDeviceProvider : IDisposable
|
||||||
{
|
{
|
||||||
#region Properties & Fields
|
#region Properties & Fields
|
||||||
|
|
||||||
|
|||||||
@ -112,6 +112,10 @@ namespace RGB.NET.Core
|
|||||||
try { device.Dispose(); }
|
try { device.Dispose(); }
|
||||||
catch { /* We do what we can */ }
|
catch { /* We do what we can */ }
|
||||||
|
|
||||||
|
foreach (IRGBDeviceProvider deviceProvider in _deviceProvider)
|
||||||
|
try { deviceProvider.Dispose(); }
|
||||||
|
catch { /* We do what we can */ }
|
||||||
|
|
||||||
_ledGroups.Clear();
|
_ledGroups.Clear();
|
||||||
_devices = null;
|
_devices = null;
|
||||||
_deviceProvider = null;
|
_deviceProvider = null;
|
||||||
|
|||||||
@ -253,6 +253,10 @@ namespace RGB.NET.Devices.Asus
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Dispose()
|
||||||
|
{ }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -144,19 +144,32 @@ namespace RGB.NET.Devices.CoolerMaster
|
|||||||
public void ResetDevices()
|
public void ResetDevices()
|
||||||
{
|
{
|
||||||
if (IsInitialized)
|
if (IsInitialized)
|
||||||
try
|
foreach (IRGBDevice device in Devices)
|
||||||
{
|
{
|
||||||
foreach (IRGBDevice device in Devices)
|
try
|
||||||
{
|
{
|
||||||
CoolerMasterRGBDeviceInfo deviceInfo = (CoolerMasterRGBDeviceInfo)device.DeviceInfo;
|
CoolerMasterRGBDeviceInfo deviceInfo = (CoolerMasterRGBDeviceInfo)device.DeviceInfo;
|
||||||
_CoolerMasterSDK.SetControlDevice(deviceInfo.DeviceIndex);
|
_CoolerMasterSDK.SetControlDevice(deviceInfo.DeviceIndex);
|
||||||
_CoolerMasterSDK.EnableLedControl(false);
|
_CoolerMasterSDK.EnableLedControl(false);
|
||||||
_CoolerMasterSDK.EnableLedControl(true);
|
_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 */}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -195,10 +195,7 @@ namespace RGB.NET.Devices.Corsair
|
|||||||
{
|
{
|
||||||
_CUESDK.Reload();
|
_CUESDK.Reload();
|
||||||
}
|
}
|
||||||
catch
|
catch {/* shit happens */}
|
||||||
{
|
|
||||||
// shit happens ...
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Reset()
|
private void Reset()
|
||||||
@ -209,6 +206,10 @@ namespace RGB.NET.Devices.Corsair
|
|||||||
IsInitialized = false;
|
IsInitialized = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Dispose()
|
||||||
|
{ }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.Collections.ObjectModel;
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
|
|
||||||
namespace RGB.NET.Devices.Debug
|
namespace RGB.NET.Devices.Debug
|
||||||
@ -73,7 +74,6 @@ namespace RGB.NET.Devices.Debug
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
HasExclusiveAccess = exclusiveAccessIfPossible;
|
HasExclusiveAccess = exclusiveAccessIfPossible;
|
||||||
IsInitialized = true;
|
|
||||||
|
|
||||||
List<IRGBDevice> devices = new List<IRGBDevice>();
|
List<IRGBDevice> devices = new List<IRGBDevice>();
|
||||||
foreach ((string layout, string imageLayout, Func<Dictionary<LedId, Color>> syncBackFunc, Action<IEnumerable<Led>> updateLedsAction) in _fakeDeviceDefinitions)
|
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.Add(device);
|
||||||
}
|
}
|
||||||
|
|
||||||
Devices = devices;
|
Devices = new ReadOnlyCollection<IRGBDevice>(devices);
|
||||||
|
IsInitialized = true;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -98,6 +99,12 @@ namespace RGB.NET.Devices.Debug
|
|||||||
public void ResetDevices()
|
public void ResetDevices()
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
_fakeDeviceDefinitions.Clear();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -140,10 +140,10 @@ namespace RGB.NET.Devices.Logitech
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public void ResetDevices()
|
public void ResetDevices() => _LogitechGSDK.LogiLedRestoreLighting();
|
||||||
{
|
|
||||||
_LogitechGSDK.LogiLedRestoreLighting();
|
/// <inheritdoc />
|
||||||
}
|
public void Dispose() => _LogitechGSDK.LogiLedRestoreLighting();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -128,6 +128,10 @@ namespace RGB.NET.Devices.Msi
|
|||||||
//TODO DarthAffe 11.11.2017: Implement
|
//TODO DarthAffe 11.11.2017: Implement
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Dispose()
|
||||||
|
{ }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -110,6 +110,10 @@ namespace RGB.NET.Devices.Novation
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Dispose()
|
||||||
|
{ }
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -206,13 +206,13 @@ namespace RGB.NET.Devices.Razer
|
|||||||
|
|
||||||
private void TryUnInit()
|
private void TryUnInit()
|
||||||
{
|
{
|
||||||
try
|
try { _RazerSDK.UnInit(); }
|
||||||
{
|
|
||||||
_RazerSDK.UnInit();
|
|
||||||
}
|
|
||||||
catch { /* We tried our best */ }
|
catch { /* We tried our best */ }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
public void Dispose() => TryUnInit();
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user