Skip to content

Commit

Permalink
Merge pull request #109 from sandermvanvliet/master
Browse files Browse the repository at this point in the history
Show bytes suffix when data is less than 1kb - thank to @sandermvanvliet
  • Loading branch information
abbaye authored Dec 2, 2021
2 parents 1761d75 + 153923c commit 880b8ba
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 113 deletions.
27 changes: 16 additions & 11 deletions Sources/WPFHexaEditor/HexEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3837,21 +3837,26 @@ private void UpdateStatusBar(bool updateFilelength = true)
#region Show length
if (updateFilelength)
{
var isMegabByte = false;
double length;
string unit;

//is mega bytes ?
double length = _provider.LengthAjusted / 1024;

if (length > 1024)
if (_provider.LengthAjusted < 1024)
{
length = _provider.LengthAjusted;
unit = Properties.Resources.BytesTagString;
}
else if (_provider.LengthAjusted < 1048576) // 1048576 bytes = 1 MiB
{
length = _provider.LengthAjusted / 1024;
unit = Properties.Resources.KBTagString;
}
else
{
length /= 1024;
isMegabByte = true;
length = _provider.LengthAjusted / 1048576;
unit = Properties.Resources.MBTagString;
}

FileLengthKbLabel.Content = Math.Round(length, 2) +
(isMegabByte
? $" {Properties.Resources.MBTagString}"
: $" {Properties.Resources.KBTagString}");
FileLengthKbLabel.Content = Math.Round(length, 2) + " " + unit;
}
#endregion

Expand Down
Loading

0 comments on commit 880b8ba

Please sign in to comment.