Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#5108: Add file size to FileSystemView.
- Loading branch information
1 parent
d110939
commit c438870
Showing
6 changed files
with
50 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#pragma once | ||
|
||
#include <fmt/format.h> | ||
|
||
namespace os | ||
{ | ||
|
||
// Formats the given number in bytes/kB/MB/GB | ||
inline std::string getFormattedFileSize(std::size_t size) | ||
{ | ||
if (size > 1024 * 1024 * 1024) | ||
{ | ||
return fmt::format("{0:0.2f} GB", (static_cast<double>(size) / (1024 * 1024 * 1024))); | ||
} | ||
else if (size > 1024 * 1024) | ||
{ | ||
return fmt::format("{0:0.1f} MB", (static_cast<double>(size) / (1024 * 1024))); | ||
} | ||
else if (size > 1024) | ||
{ | ||
return fmt::format("{0:0.0f} kB", (static_cast<double>(size) / 1024)); | ||
} | ||
else | ||
{ | ||
return fmt::format("{0:d} bytes", size); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters