@@ -55,10 +55,15 @@ public class _HWiNFO_SENSOR
5555 {
5656 public uint SensorId ;
5757 public uint SensorInstance ;
58- [ MarshalAs ( UnmanagedType . ByValTStr , SizeConst = HWINFO_SENSORS_STRING_LEN ) ]
59- public string SensorNameOrig ;
60- [ MarshalAs ( UnmanagedType . ByValTStr , SizeConst = HWINFO_SENSORS_STRING_LEN ) ]
61- public string SensorNameUser ;
58+ [ MarshalAs ( UnmanagedType . ByValArray , SizeConst = HWINFO_SENSORS_STRING_LEN ) ]
59+ public byte [ ] SensorNameOrig ;
60+ [ MarshalAs ( UnmanagedType . ByValArray , SizeConst = HWINFO_SENSORS_STRING_LEN ) ]
61+ public byte [ ] SensorNameUser ;
62+
63+ // Version 2+ new:
64+ [ MarshalAs ( UnmanagedType . ByValArray , SizeConst = HWINFO_SENSORS_STRING_LEN ) ]
65+ public byte [ ] UtfSensorNameUser ; // Sensor name displayed, which might be translated or renamed by user [UTF-8 string]
66+
6267 }
6368
6469 [ StructLayout ( LayoutKind . Sequential , Pack = 1 ) ]
@@ -67,16 +72,22 @@ public class _HWiNFO_ELEMENT
6772 public SENSOR_TYPE SensorType ;
6873 public uint SensorIndex ;
6974 public uint ElementId ;
70- [ MarshalAs ( UnmanagedType . ByValTStr , SizeConst = HWINFO_SENSORS_STRING_LEN ) ]
71- public string LabelOrig ;
72- [ MarshalAs ( UnmanagedType . ByValTStr , SizeConst = HWINFO_SENSORS_STRING_LEN ) ]
73- public string LabelUser ;
74- [ MarshalAs ( UnmanagedType . ByValTStr , SizeConst = HWINFO_UNIT_STRING_LEN ) ]
75- public string Unit ;
75+ [ MarshalAs ( UnmanagedType . ByValArray , SizeConst = HWINFO_SENSORS_STRING_LEN ) ]
76+ public byte [ ] LabelOrig ;
77+ [ MarshalAs ( UnmanagedType . ByValArray , SizeConst = HWINFO_SENSORS_STRING_LEN ) ]
78+ public byte [ ] LabelUser ;
79+ [ MarshalAs ( UnmanagedType . ByValArray , SizeConst = HWINFO_UNIT_STRING_LEN ) ]
80+ public byte [ ] Unit ;
7681 public double Value ;
7782 public double ValueMin ;
7883 public double ValueMax ;
7984 public double ValueAvg ;
85+
86+ // Version 2+ new:
87+ [ MarshalAs ( UnmanagedType . ByValArray , SizeConst = HWINFO_SENSORS_STRING_LEN ) ]
88+ public byte [ ] UtfLabelUser ; // Label displayed, which might be translated or renamed by user [UTF-8 string]
89+ [ MarshalAs ( UnmanagedType . ByValArray , SizeConst = HWINFO_UNIT_STRING_LEN ) ]
90+ public byte [ ] UtfUnit ; // e.g. "RPM" [UTF-8 string]
8091 }
8192
8293 public class ElementObj
@@ -141,7 +152,16 @@ public static string NumberFormat(SENSOR_TYPE sensorType, string unit, double va
141152 valstr = value . ToString ( "N3" ) ;
142153 break ;
143154 case SENSOR_TYPE . SENSOR_TYPE_POWER :
144- valstr = value . ToString ( "N3" ) ;
155+
156+ if ( unit == "W" )
157+ {
158+ valstr = value . ToString ( "N1" ) ;
159+ }
160+ else
161+ {
162+ valstr = value . ToString ( "N3" ) ;
163+ }
164+
145165 break ;
146166
147167 case SENSOR_TYPE . SENSOR_TYPE_CLOCK :
@@ -190,6 +210,75 @@ public static string NumberFormat(SENSOR_TYPE sensorType, string unit, double va
190210 return ( valstr + " " + unit ) . Trim ( ) ;
191211 }
192212
213+
214+ public static double RoundValue ( SENSOR_TYPE sensorType , string unit , double value )
215+ {
216+ double val = value ;
217+
218+ switch ( sensorType )
219+ {
220+ case SENSOR_TYPE . SENSOR_TYPE_VOLT :
221+ val = Math . Round ( value , 3 ) ;
222+ break ;
223+ case SENSOR_TYPE . SENSOR_TYPE_CURRENT :
224+ val = Math . Round ( value , 3 ) ;
225+ break ;
226+ case SENSOR_TYPE . SENSOR_TYPE_POWER :
227+
228+ if ( unit == "W" )
229+ {
230+ val = Math . Round ( value , 1 ) ;
231+ }
232+ else
233+ {
234+ val = Math . Round ( value , 3 ) ;
235+ }
236+
237+ break ;
238+
239+ case SENSOR_TYPE . SENSOR_TYPE_CLOCK :
240+ val = Math . Round ( value , 1 ) ;
241+ break ;
242+ case SENSOR_TYPE . SENSOR_TYPE_USAGE :
243+ val = Math . Round ( value , 1 ) ;
244+ break ;
245+ case SENSOR_TYPE . SENSOR_TYPE_TEMP :
246+ val = Math . Round ( value , 1 ) ;
247+ break ;
248+
249+ case SENSOR_TYPE . SENSOR_TYPE_FAN :
250+ val = Math . Round ( value , 0 ) ;
251+ break ;
252+
253+ case SENSOR_TYPE . SENSOR_TYPE_OTHER :
254+
255+ if ( unit == "Yes/No" )
256+ {
257+
258+ }
259+ else if ( unit . EndsWith ( "GT/s" ) || unit == "x" || unit == "%" )
260+ {
261+ val = Math . Round ( value , 1 ) ;
262+ }
263+ else if ( unit . EndsWith ( "/s" ) )
264+ {
265+ val = Math . Round ( value , 3 ) ;
266+ }
267+ else if ( unit . EndsWith ( "MB" ) || unit . EndsWith ( "GB" ) || unit == "T" || unit == "FPS" )
268+ {
269+ val = Math . Round ( value , 0 ) ;
270+ }
271+
272+ break ;
273+
274+ case SENSOR_TYPE . SENSOR_TYPE_NONE :
275+
276+ break ;
277+
278+ }
279+
280+ return val ;
281+ }
193282 public static void ReadMem ( string incPath )
194283 {
195284 lock ( RefreshHWInfoLock )
@@ -239,12 +328,27 @@ private static void ReadSensors(MemoryMappedFile mmf, _HWiNFO_SHARED_MEM hWiNFOM
239328
240329 if ( ! FullSensorData . ContainsKey ( index ) )
241330 {
331+ //var sensorNameOrig = Encoding.GetEncoding(1252).GetString(structure.SensorNameOrig).TrimEnd((char)0);
332+ var sensorNameOrig = Encoding . UTF8 . GetString ( structure . SensorNameOrig ) . TrimEnd ( ( char ) 0 ) ;
333+
334+ var sensorName = "" ;
335+
336+ if ( hWiNFOMemory . Version > 1 )
337+ {
338+ sensorName = Encoding . UTF8 . GetString ( structure . UtfSensorNameUser ) . TrimEnd ( ( char ) 0 ) ;
339+ }
340+ else
341+ {
342+ //sensorName = Encoding.GetEncoding(1252).GetString(structure.SensorNameUser).TrimEnd((char)0);
343+ sensorName = Encoding . UTF8 . GetString ( structure . SensorNameUser ) . TrimEnd ( ( char ) 0 ) ;
344+ }
345+
242346 var sensor = new SensorObj
243347 {
244348 SensorId = structure . SensorId ,
245349 SensorInstance = structure . SensorInstance ,
246- SensorNameOrig = structure . SensorNameOrig ,
247- SensorNameUser = structure . SensorNameUser ,
350+ SensorNameOrig = sensorNameOrig ,
351+ SensorNameUser = sensorName ,
248352 Elements = new Dictionary < string , ElementObj > ( )
249353 } ;
250354
@@ -273,20 +377,46 @@ private static void ReadElements(MemoryMappedFile mmf, _HWiNFO_SHARED_MEM hWiNFO
273377
274378 var elementKey = sensor . SensorId + "-" + sensor . SensorInstance + "-" + structure . ElementId ;
275379
380+ //var labelOrig = Encoding.GetEncoding(1252).GetString(structure.LabelOrig).TrimEnd((char)0);
381+ var labelOrig = Encoding . UTF8 . GetString ( structure . LabelOrig ) . TrimEnd ( ( char ) 0 ) ;
382+
383+ var unit = "" ;
384+
385+ if ( hWiNFOMemory . Version > 1 )
386+ {
387+ unit = Encoding . UTF8 . GetString ( structure . UtfUnit ) . TrimEnd ( ( char ) 0 ) ;
388+ } else
389+ {
390+ //unit = Encoding.GetEncoding(1252).GetString(structure.Unit).TrimEnd((char)0);
391+ unit = Encoding . UTF8 . GetString ( structure . Unit ) . TrimEnd ( ( char ) 0 ) ;
392+ }
393+
394+ var label = "?" ;
395+
396+ if ( hWiNFOMemory . Version > 1 )
397+ {
398+ label = Encoding . UTF8 . GetString ( structure . UtfLabelUser ) . TrimEnd ( ( char ) 0 ) ;
399+ }
400+ else
401+ {
402+ //label = System.Text.Encoding.GetEncoding(1252).GetString(structure.LabelUser).TrimEnd((char)0);
403+ label = System . Text . Encoding . UTF8 . GetString ( structure . LabelUser ) . TrimEnd ( ( char ) 0 ) ;
404+ }
405+
276406 var element = new ElementObj
277407 {
278408 ElementKey = elementKey ,
279409
280410 SensorType = structure . SensorType ,
281411 ElementId = structure . ElementId ,
282- LabelOrig = structure . LabelOrig ,
283- LabelUser = structure . LabelUser ,
284- Unit = structure . Unit ,
285- NumericValue = ( float ) structure . Value ,
286- Value = NumberFormat ( structure . SensorType , structure . Unit , structure . Value ) ,
287- ValueMin = NumberFormat ( structure . SensorType , structure . Unit , structure . ValueMin ) ,
288- ValueMax = NumberFormat ( structure . SensorType , structure . Unit , structure . ValueMax ) ,
289- ValueAvg = NumberFormat ( structure . SensorType , structure . Unit , structure . ValueAvg )
412+ LabelOrig = labelOrig ,
413+ LabelUser = label ,
414+ Unit = unit ,
415+ NumericValue = ( float ) RoundValue ( structure . SensorType , unit , structure . Value ) ,
416+ Value = NumberFormat ( structure . SensorType , unit , structure . Value ) ,
417+ ValueMin = NumberFormat ( structure . SensorType , unit , structure . ValueMin ) ,
418+ ValueMax = NumberFormat ( structure . SensorType , unit , structure . ValueMax ) ,
419+ ValueAvg = NumberFormat ( structure . SensorType , unit , structure . ValueAvg ) ,
290420 } ;
291421
292422 sensor . Elements [ elementKey ] = element ;
@@ -322,7 +452,8 @@ private static void ParseIncFile()
322452 var sensorInstanceStr = IncData [ "Variables" ] [ key . KeyName + "-SensorInstance" ] ;
323453 var elementIdStr = IncData [ "Variables" ] [ key . KeyName + "-EntryId" ] ;
324454
325- if ( sensorIdStr ? . StartsWith ( "0x" ) == true && sensorInstanceStr ? . StartsWith ( "0x" ) == true &&
455+ if ( sensorIdStr ? . StartsWith ( "0x" ) == true &&
456+ sensorInstanceStr ? . StartsWith ( "0x" ) == true &&
326457 elementIdStr ? . StartsWith ( "0x" ) == true )
327458 {
328459 var sensorId = Convert . ToUInt32 ( sensorIdStr . Replace ( "0x" , "" ) , 16 ) ;
@@ -387,7 +518,9 @@ private static void ParseIncFile()
387518
388519 if ( ! SensorTrends . ContainsKey ( elementKey ) )
389520 {
390- SensorTrends . Add ( elementKey , new ChartCircularBuffer ( fullSensorDataElement . SensorType , fullSensorDataElement . Unit ) ) ;
521+ SensorTrends . Add ( elementKey ,
522+ new ChartCircularBuffer ( fullSensorDataElement . SensorType ,
523+ fullSensorDataElement . Unit ) ) ;
391524 }
392525
393526 SensorTrends [ elementKey ] . Put ( fullSensorDataElement . NumericValue ) ;
@@ -406,6 +539,8 @@ public static void SaveDataToFile(string path)
406539 {
407540 path = Path . Combine ( App . ExePath , path ) ;
408541
542+ Directory . CreateDirectory ( Path . GetDirectoryName ( path ) ) ;
543+
409544 using ( var fs = File . Create ( path ) )
410545 {
411546 var json = new UTF8Encoding ( true ) . GetBytes ( JsonConvert . SerializeObject ( FullSensorData , Formatting . Indented ) ) ;
0 commit comments