Added PrettyBytes function to Utils class

This commit is contained in:
Vladyslav Baranovskyi
2024-06-11 14:02:08 +03:00
parent e90056c5a6
commit 41edc4e45f
2 changed files with 43 additions and 0 deletions

View File

@@ -74,4 +74,46 @@ namespace OpenVulkano
file.close();
return data;
}
std::string Utils::PrettyBytes(uint64_t bytes)
{
static const uint64_t TERABYTES = 1024ULL*1024*1024*1024;
static const uint64_t GIGABYTES = 1024ULL*1024*1024;
static const uint64_t MEGABYTES = 1024*1024;
static const uint64_t KILOBYTES = 1024;
int TB, GB, MB, KB;
TB = bytes / TERABYTES;
bytes -= TB * TERABYTES;
GB = bytes / GIGABYTES;
bytes -= GB * GIGABYTES;
MB = bytes / MEGABYTES;
bytes -= MB * MEGABYTES;
KB = bytes / KILOBYTES;
bytes -= KB * KILOBYTES;
std::string result;
if(TB)
{
result = std::to_string(TB) + " TB";
}
else if(GB)
{
result = std::to_string(GB) + " GB";
}
else if(MB)
{
result = std::to_string(MB) + " MB";
}
else if(KB)
{
result = std::to_string(KB) + " KB";
}
else
{
result = std::to_string(bytes) + " B";
}
return result;
}
}