@@ -374,8 +374,7 @@ public static void SyncManager()
374374 long sizeChange = component . Size - oldSize ;
375375 totalSizeChange += sizeChange ;
376376
377- string displayedSize = GetFormattedBytes ( sizeChange ) ;
378- if ( displayedSize [ 0 ] != '-' ) displayedSize = "+" + displayedSize ;
377+ string displayedSize = GetFormattedBytes ( sizeChange , true ) ;
379378
380379 var item = new ListViewItem ( ) ;
381380 item . Text = component . Title ;
@@ -394,7 +393,7 @@ public static void SyncManager()
394393 item . Text = component . Title ;
395394 item . SubItems . Add ( "This component is deprecated and can be deleted." ) ;
396395 item . SubItems . Add ( "" ) ;
397- item . SubItems . Add ( GetFormattedBytes ( - component . Size ) ) ;
396+ item . SubItems . Add ( GetFormattedBytes ( - component . Size , true ) ) ;
398397
399398 Main . UpdateList . Items . Add ( item ) ;
400399 }
@@ -406,7 +405,7 @@ public static void SyncManager()
406405
407406 if ( ComponentTracker . Outdated . Count > 0 || ComponentTracker . Deprecated . Count > 0 )
408407 {
409- Main . UpdateButton . Text += $ " ({ GetFormattedBytes ( totalSizeChange ) } )";
408+ Main . UpdateButton . Text += $ " ({ GetFormattedBytes ( totalSizeChange , true ) } )";
410409 Main . UpdateButton . Enabled = true ;
411410 }
412411 else
@@ -604,18 +603,24 @@ void AddDependencies(string[] depends)
604603 }
605604
606605 // Formats bytes as a human-readable string
607- public static string GetFormattedBytes ( long bytes )
606+ public static string GetFormattedBytes ( long bytes , bool plusSign = false )
608607 {
609608 string [ ] units = new [ ] { " bytes" , "KB" , "MB" , "GB" } ;
610609 int i = units . Length ;
611610
611+ string formattedBytes = "0 bytes" ;
612+
612613 while ( -- i >= 0 )
613614 {
614615 double unitSize = Math . Pow ( 1024 , i ) ;
615- if ( Math . Abs ( bytes ) >= unitSize ) return ( Math . Floor ( bytes / unitSize * 10 ) / 10 ) . ToString ( "N1" ) + units [ i ] ;
616+ if ( Math . Abs ( bytes ) >= unitSize )
617+ {
618+ formattedBytes = ( Math . Round ( bytes / unitSize * 10 ) / 10 ) . ToString ( "N1" ) + units [ i ] ;
619+ break ;
620+ }
616621 }
617622
618- return "0 bytes" ;
623+ return ( plusSign && ! formattedBytes . StartsWith ( "-" ) ? "+" : "" ) + formattedBytes ;
619624 }
620625
621626 // Function for errors unrelated to the component list
0 commit comments