Skip to content

Commit

Permalink
Show bytes suffix when data is less than 1kb
Browse files Browse the repository at this point in the history
  • Loading branch information
sandermvanvliet committed Dec 1, 2021
1 parent 1761d75 commit 153923c
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

3 comments on commit 153923c

@abbaye
Copy link
Owner

@abbaye abbaye commented on 153923c Dec 2, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank for this pull request 👌😁

I have never see this little bug. Probably because I am testing over large files.

@sandermvanvliet
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I’m working with small Protobuf payloads and it became obvious quite quickly there 😜

Thanks for building a great control, I really like it 👍

@abbaye
Copy link
Owner

@abbaye abbaye commented on 153923c Dec 2, 2021 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.