33using System . Drawing . Drawing2D ;
44using System . Drawing . Imaging ;
55using System . Drawing . Text ;
6+ using System . Linq ;
67using System . Runtime . InteropServices ;
78using System . Windows . Forms ;
89using OpenHardwareMonitor . Hardware ;
@@ -184,9 +185,10 @@ private string GetString()
184185 case SensorType . Current :
185186 case SensorType . SmallData :
186187 case SensorType . Factor :
187- case SensorType . Throughput :
188188 case SensorType . Conductivity :
189189 return $ "{ Sensor . Value : F1} ";
190+ case SensorType . Throughput :
191+ return GetThroughputValue ( Sensor . Value ?? 0 ) ;
190192 case SensorType . Control :
191193 case SensorType . Frequency :
192194 case SensorType . Level :
@@ -205,6 +207,24 @@ private string GetString()
205207 }
206208 }
207209
210+ private static string GetThroughputValue ( float byteCount , byte preferredSufNum = 1 , bool addSuffix = false )
211+ {
212+ string [ ] suf = { " B" , " KB" , " MB" , " GB" } ;
213+ if ( byteCount == 0 )
214+ return addSuffix ? "0" + suf [ 0 ] : "0" ;
215+ long bytes = Math . Abs ( ( long ) byteCount ) ;
216+ int place = Convert . ToInt32 ( Math . Floor ( Math . Log ( bytes , 1024 ) ) ) ;
217+ if ( place < preferredSufNum )
218+ place = preferredSufNum ;
219+ double num = Math . Round ( bytes / Math . Pow ( 1024 , place ) , 1 ) ;
220+ if ( num >= 10 )
221+ num = Math . Round ( num , 0 ) ;
222+ var result = ( Math . Sign ( byteCount ) * num ) . ToString ( ) ;
223+ if ( addSuffix )
224+ return result + suf [ place ] ;
225+ return new string ( result . Take ( 3 ) . ToArray ( ) ) ;
226+ }
227+
208228 private bool IsFontInstalled ( string fontName , float fontSize = 12 )
209229 {
210230 using ( Font fontTester = new Font ( fontName , fontSize , FontStyle . Regular , GraphicsUnit . Pixel ) )
@@ -365,6 +385,10 @@ public void Update()
365385 format = "\n {0}: {1:F1} °F" ;
366386 formattedValue = string . Format ( format , Sensor . Name , UnitManager . CelsiusToFahrenheit ( Sensor . Value ) ) ;
367387 }
388+ else if ( Sensor . SensorType == SensorType . Throughput && ! "Connection Speed" . Equals ( Sensor . Name ) )
389+ {
390+ formattedValue = $ "\n { Sensor . Name } : { GetThroughputValue ( Sensor . Value ?? 0 , 0 , true ) } /s";
391+ }
368392
369393 string hardwareName = Sensor . Hardware . Name ;
370394 hardwareName = hardwareName . Substring ( 0 , Math . Min ( 63 - formattedValue . Length , hardwareName . Length ) ) ;
0 commit comments