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:
parent
1af93658f9
commit
cdace494bc
@ -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
|
||||
|
||||
|
||||
@ -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;
|
||||
|
||||
@ -253,6 +253,10 @@ namespace RGB.NET.Devices.Asus
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -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 */}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -128,6 +128,10 @@ namespace RGB.NET.Devices.Msi
|
||||
//TODO DarthAffe 11.11.2017: Implement
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -110,6 +110,10 @@ namespace RGB.NET.Devices.Novation
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void Dispose()
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user