3
3
4
4
using System ;
5
5
using System . Collections . Generic ;
6
+ using System . Linq ;
6
7
using LibreHardwareMonitor . Hardware ;
7
8
8
9
namespace VRCOSC . Game . Providers . Hardware ;
9
10
10
- public class SensorInfoList
11
- {
12
- public readonly List < SensorInfo > InfoList = new ( ) ;
13
-
14
- public SensorInfoList ( SensorType type , params string [ ] names )
15
- {
16
- foreach ( var name in names ) InfoList . Add ( new SensorInfo ( type , name ) ) ;
17
- }
18
- }
11
+ public record SensorPair ( SensorType Type , string Name ) ;
19
12
20
13
public class SensorInfo
21
14
{
22
- public readonly string Name ;
23
- public readonly SensorType Type ;
15
+ public readonly List < SensorPair > Pairs = new ( ) ;
24
16
25
- public SensorInfo ( SensorType type , string name )
17
+ public SensorInfo ( SensorType type , params string [ ] names )
26
18
{
27
- Type = type ;
28
- Name = name ;
19
+ foreach ( var name in names ) Pairs . Add ( new SensorPair ( type , name ) ) ;
29
20
}
30
21
}
31
22
32
23
public abstract class HardwareComponent
33
24
{
34
25
protected virtual SensorInfo LoadInfo => throw new NotImplementedException ( ) ;
35
26
36
- public readonly int Id ;
37
-
38
27
public float Usage { get ; private set ; }
39
28
40
- protected HardwareComponent ( int id )
41
- {
42
- Id = id ;
43
- }
44
-
45
- protected bool GetIntValue ( ISensor sensor , SensorInfoList infoList , out int value )
29
+ protected static bool GetIntValue ( ISensor sensor , SensorInfo info , out int value )
46
30
{
47
- foreach ( var info in infoList . InfoList )
31
+ if ( ! GetFloatValue ( sensor , info , out var floatValue ) )
48
32
{
49
- if ( ! GetIntValue ( sensor , info , out var intValue ) ) continue ;
50
-
51
- value = intValue ;
33
+ value = ( int ) MathF . Round ( floatValue ) ;
52
34
return true ;
53
35
}
54
36
55
37
value = 0 ;
56
38
return false ;
57
39
}
58
40
59
- protected bool GetIntValue ( ISensor sensor , SensorInfo info , out int value )
41
+ protected static bool GetFloatValue ( ISensor sensor , SensorInfo info , out float value )
60
42
{
61
- if ( GetFloatValue ( sensor , info , out var valueFloat ) )
62
- {
63
- value = ( int ) Math . Round ( valueFloat ) ;
64
- return true ;
65
- }
66
-
67
- value = 0 ;
68
- return false ;
69
- }
70
-
71
- protected bool GetFloatValue ( ISensor sensor , SensorInfo info , out float value )
72
- {
73
- if ( sensor . Name == info . Name && sensor . SensorType == info . Type )
43
+ if ( info . Pairs . Any ( pair => sensor . SensorType == pair . Type && sensor . Name == pair . Name ) )
74
44
{
75
45
value = sensor . Value ?? 0f ;
76
46
return true ;
77
47
}
78
48
79
- value = 0f ;
49
+ value = 0 ;
80
50
return false ;
81
51
}
82
52
@@ -90,16 +60,11 @@ public abstract class CPU : HardwareComponent
90
60
{
91
61
protected override SensorInfo LoadInfo => new ( SensorType . Load , "CPU Total" ) ;
92
62
protected virtual SensorInfo PowerInfo => throw new NotImplementedException ( ) ;
93
- protected virtual SensorInfoList TemperatureInfo => throw new NotImplementedException ( ) ;
63
+ protected virtual SensorInfo TemperatureInfo => throw new NotImplementedException ( ) ;
94
64
95
65
public int Power { get ; private set ; }
96
66
public int Temperature { get ; private set ; }
97
67
98
- protected CPU ( int id )
99
- : base ( id )
100
- {
101
- }
102
-
103
68
public override void Update ( ISensor sensor )
104
69
{
105
70
base . Update ( sensor ) ;
@@ -111,24 +76,14 @@ public override void Update(ISensor sensor)
111
76
public class IntelCPU : CPU
112
77
{
113
78
protected override SensorInfo PowerInfo => new ( SensorType . Power , "CPU Package" ) ;
114
- protected override SensorInfoList TemperatureInfo => new ( SensorType . Temperature , "CPU Package" ) ;
115
-
116
- public IntelCPU ( int id )
117
- : base ( id )
118
- {
119
- }
79
+ protected override SensorInfo TemperatureInfo => new ( SensorType . Temperature , "CPU Package" ) ;
120
80
}
121
81
122
82
// ReSharper disable once InconsistentNaming
123
83
public class AMDCPU : CPU
124
84
{
125
85
protected override SensorInfo PowerInfo => new ( SensorType . Power , "Package" ) ;
126
- protected override SensorInfoList TemperatureInfo => new ( SensorType . Temperature , "Core (Tdie)" , "Core (Tctl/Tdie)" , "CPU Cores" ) ;
127
-
128
- public AMDCPU ( int id )
129
- : base ( id )
130
- {
131
- }
86
+ protected override SensorInfo TemperatureInfo => new ( SensorType . Temperature , "Core (Tdie)" , "Core (Tctl/Tdie)" , "CPU Cores" ) ;
132
87
}
133
88
134
89
public class GPU : HardwareComponent
@@ -137,7 +92,7 @@ public class GPU : HardwareComponent
137
92
private readonly SensorInfo powerInfo = new ( SensorType . Power , "GPU Package" ) ;
138
93
private readonly SensorInfo temperatureInfo = new ( SensorType . Temperature , "GPU Core" ) ;
139
94
private readonly SensorInfo memoryFreeInfo = new ( SensorType . SmallData , "GPU Memory Free" ) ;
140
- private readonly SensorInfo memoryUsedINfo = new ( SensorType . SmallData , "GPU Memory Used" ) ;
95
+ private readonly SensorInfo memoryUsedInfo = new ( SensorType . SmallData , "GPU Memory Used" , "D3D Dedicated Memory Used") ;
141
96
private readonly SensorInfo memoryTotalInfo = new ( SensorType . SmallData , "GPU Memory Total" ) ;
142
97
143
98
public int Power { get ; private set ; }
@@ -147,18 +102,13 @@ public class GPU : HardwareComponent
147
102
public float MemoryTotal { get ; private set ; }
148
103
public float MemoryUsage => MemoryUsed / MemoryTotal ;
149
104
150
- public GPU ( int id )
151
- : base ( id )
152
- {
153
- }
154
-
155
105
public override void Update ( ISensor sensor )
156
106
{
157
107
base . Update ( sensor ) ;
158
108
if ( GetIntValue ( sensor , powerInfo , out var powerValue ) ) Power = powerValue ;
159
109
if ( GetIntValue ( sensor , temperatureInfo , out var temperatureValue ) ) Temperature = temperatureValue ;
160
110
if ( GetFloatValue ( sensor , memoryFreeInfo , out var memoryFreeValue ) ) MemoryFree = memoryFreeValue ;
161
- if ( GetFloatValue ( sensor , memoryUsedINfo , out var memoryUsedValue ) ) MemoryUsed = memoryUsedValue ;
111
+ if ( GetFloatValue ( sensor , memoryUsedInfo , out var memoryUsedValue ) ) MemoryUsed = memoryUsedValue ;
162
112
if ( GetFloatValue ( sensor , memoryTotalInfo , out var memoryTotalValue ) ) MemoryTotal = memoryTotalValue ;
163
113
}
164
114
}
@@ -173,11 +123,6 @@ public class RAM : HardwareComponent
173
123
public float Available { get ; private set ; }
174
124
public float Total => Used + Available ;
175
125
176
- public RAM ( )
177
- : base ( 0 )
178
- {
179
- }
180
-
181
126
public override void Update ( ISensor sensor )
182
127
{
183
128
base . Update ( sensor ) ;
0 commit comments