diff --git a/Source/Editor/Content/Items/ContentItem.cs b/Source/Editor/Content/Items/ContentItem.cs index 259c09481..18c5b6d7b 100644 --- a/Source/Editor/Content/Items/ContentItem.cs +++ b/Source/Editor/Content/Items/ContentItem.cs @@ -388,7 +388,7 @@ namespace FlaxEditor.Content { sb.Append("Type: ").Append(TypeDescription).AppendLine(); if (File.Exists(Path)) - sb.Append("Size: ").Append(Utilities.Utils.FormatBytesCount((int)new FileInfo(Path).Length)).AppendLine(); + sb.Append("Size: ").Append(Utilities.Utils.FormatBytesCount((ulong)new FileInfo(Path).Length)).AppendLine(); sb.Append("Path: ").Append(Utilities.Utils.GetAssetNamePathWithExt(Path)).AppendLine(); } diff --git a/Source/Editor/Utilities/Utils.cs b/Source/Editor/Utilities/Utils.cs index b14d58eb6..1487f1a59 100644 --- a/Source/Editor/Utilities/Utils.cs +++ b/Source/Editor/Utilities/Utils.cs @@ -146,19 +146,14 @@ namespace FlaxEditor.Utilities /// /// Formats the amount of bytes to get a human-readable data size in bytes with abbreviation. Eg. 32 kB + /// [Deprecated in v1.9] /// /// The bytes. /// The formatted amount of bytes. + [Obsolete("Use FormatBytesCount with ulong instead")] public static string FormatBytesCount(int bytes) { - int order = 0; - while (bytes >= 1024 && order < MemorySizePostfixes.Length - 1) - { - order++; - bytes /= 1024; - } - - return string.Format("{0:0.##} {1}", bytes, MemorySizePostfixes[order]); + return FormatBytesCount((ulong)bytes); } /// @@ -169,12 +164,15 @@ namespace FlaxEditor.Utilities public static string FormatBytesCount(ulong bytes) { int order = 0; + ulong bytesPrev = bytes; while (bytes >= 1024 && order < MemorySizePostfixes.Length - 1) { + bytesPrev = bytes; order++; bytes /= 1024; } - + if (order >= 3) // GB or higher use up to 2 decimal places for more precision + return string.Format("{0:0.##} {1}", FlaxEngine.Utils.RoundTo2DecimalPlaces(bytesPrev / 1024.0f), MemorySizePostfixes[order]); return string.Format("{0:0.##} {1}", bytes, MemorySizePostfixes[order]); } diff --git a/Source/Editor/Windows/Assets/AnimationWindow.cs b/Source/Editor/Windows/Assets/AnimationWindow.cs index 2411daf86..f6ca7e1b0 100644 --- a/Source/Editor/Windows/Assets/AnimationWindow.cs +++ b/Source/Editor/Windows/Assets/AnimationWindow.cs @@ -181,7 +181,7 @@ namespace FlaxEditor.Windows.Assets group.Label("Frames: " + info.FramesCount); group.Label("Channels: " + info.ChannelsCount); group.Label("Keyframes: " + info.KeyframesCount); - group.Label("Memory Usage: " + Utilities.Utils.FormatBytesCount(info.MemoryUsage)); + group.Label("Memory Usage: " + Utilities.Utils.FormatBytesCount((ulong)info.MemoryUsage)); } base.Initialize(layout); diff --git a/Source/Editor/Windows/Profiler/Assets.cs b/Source/Editor/Windows/Profiler/Assets.cs index 3cd66e4eb..159392138 100644 --- a/Source/Editor/Windows/Profiler/Assets.cs +++ b/Source/Editor/Windows/Profiler/Assets.cs @@ -52,7 +52,7 @@ namespace FlaxEditor.Windows.Profiler AnchorPreset = AnchorPresets.HorizontalStretchTop, Offsets = Margin.Zero, Height = SingleChart.DefaultHeight, - FormatSample = v => Utilities.Utils.FormatBytesCount((int)v), + FormatSample = v => Utilities.Utils.FormatBytesCount((ulong)v), Parent = mainPanel, }; _memoryUsageChart.SelectedSampleChanged += OnSelectedSampleChanged; diff --git a/Source/Editor/Windows/Profiler/CPU.cs b/Source/Editor/Windows/Profiler/CPU.cs index ff9b0e253..8c6ff5e78 100644 --- a/Source/Editor/Windows/Profiler/CPU.cs +++ b/Source/Editor/Windows/Profiler/CPU.cs @@ -175,7 +175,7 @@ namespace FlaxEditor.Windows.Profiler private string FormatCellBytes(object x) { - return Utilities.Utils.FormatBytesCount((int)x); + return Utilities.Utils.FormatBytesCount((ulong)x); } /// diff --git a/Source/Editor/Windows/Profiler/Memory.cs b/Source/Editor/Windows/Profiler/Memory.cs index 4272bc0ae..8ab279fb8 100644 --- a/Source/Editor/Windows/Profiler/Memory.cs +++ b/Source/Editor/Windows/Profiler/Memory.cs @@ -36,14 +36,14 @@ namespace FlaxEditor.Windows.Profiler _nativeAllocationsChart = new SingleChart { Title = "Native Memory Allocation", - FormatSample = v => Utilities.Utils.FormatBytesCount((int)v), + FormatSample = v => Utilities.Utils.FormatBytesCount((ulong)v), Parent = layout, }; _nativeAllocationsChart.SelectedSampleChanged += OnSelectedSampleChanged; _managedAllocationsChart = new SingleChart { Title = "Managed Memory Allocation", - FormatSample = v => Utilities.Utils.FormatBytesCount((int)v), + FormatSample = v => Utilities.Utils.FormatBytesCount((ulong)v), Parent = layout, }; _managedAllocationsChart.SelectedSampleChanged += OnSelectedSampleChanged; diff --git a/Source/Editor/Windows/Profiler/Network.cs b/Source/Editor/Windows/Profiler/Network.cs index 577387617..fa5701db9 100644 --- a/Source/Editor/Windows/Profiler/Network.cs +++ b/Source/Editor/Windows/Profiler/Network.cs @@ -319,7 +319,7 @@ namespace FlaxEditor.Windows.Profiler private static string FormatCellBytes(object x) { - return Utilities.Utils.FormatBytesCount((int)x); + return Utilities.Utils.FormatBytesCount((ulong)x); } private static int SortRows(Control x, Control y)