-
Notifications
You must be signed in to change notification settings - Fork 8
/
DellPlugin.cs
95 lines (80 loc) · 3.07 KB
/
DellPlugin.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using FanControl.Plugins;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using DellFanManagement.DellSmbiozBzhLib;
namespace FanControl.DellPlugin
{
public class DellPlugin : IPlugin, IDisposable
{
private const string SYS_FILE = "bzh_dell_smm_io_x64.sys";
private bool _dellInitialized;
private FileInfo _copiedSysFile;
private Boolean m_DisposedValue;
public string Name => "Dell";
public void Close()
{
if (_dellInitialized)
{
DellSmbiosBzh.EnableAutomaticFanControl(true);
DellSmbiosBzh.EnableAutomaticFanControl(false);
DellSmbiosBzh.Shutdown();
_copiedSysFile.Delete();
_copiedSysFile = null;
_dellInitialized = false;
}
}
public void Initialize()
{
var copyLocation = Path.Combine(Directory.GetCurrentDirectory(), SYS_FILE);
if (File.Exists(copyLocation))
File.Delete(copyLocation);
FileInfo sysFile = new FileInfo(typeof(DellSmbiosBzh).Assembly.Location).Directory.GetFiles(SYS_FILE).FirstOrDefault();
_copiedSysFile = sysFile.CopyTo(copyLocation, true);
_dellInitialized = DellSmbiosBzh.Initialize();
}
public void Load(IPluginSensorsContainer _container)
{
if (_dellInitialized)
{
IEnumerable<DellFanManagementControlSensor> fanControls = new[] {
BzhFanIndex.Fan1,
BzhFanIndex.Fan2
}.Select(i => new DellFanManagementControlSensor(i)).ToArray();
IEnumerable<DellFanManagementFanSensor> fanSensors = new[] {
BzhFanIndex.Fan1,
BzhFanIndex.Fan2
}.Select(i => new DellFanManagementFanSensor(i)).ToArray();
_container.ControlSensors.AddRange(fanControls);
_container.FanSensors.AddRange(fanSensors);
}
}
protected virtual void Dispose(Boolean disposing)
{
if (!m_DisposedValue)
{
if (disposing)
{
// TODO: dispose managed state (managed objects)
}
// TODO: free unmanaged resources (unmanaged objects) and override finalizer
// TODO: set large fields to null
Close();
m_DisposedValue = true;
}
}
// // TODO: override finalizer only if 'Dispose(bool disposing)' has code to free unmanaged resources
~DellPlugin()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: false);
}
public void Dispose()
{
// Do not change this code. Put cleanup code in 'Dispose(bool disposing)' method
Dispose(disposing: true);
GC.SuppressFinalize(this);
}
}
}