unifork.old/source/utils/formatting.cpp
Stefan Schnitzler 99e09bd17c simple visual progress bar (#7)
* download files directly to sd instead of a buffer

- this fixes running out of memory while downloading large files

* simple visual download progressbar
2019-11-17 02:30:30 +01:00

19 lines
No EOL
641 B
C++

#include <string>
#include "utils/formatting.hpp"
// adapted from GM9i's byte parsing.
std::string formatBytes(int bytes) {
char out[32];
if(bytes == 1)
snprintf(out, sizeof(out), "%d Byte", bytes);
else if(bytes < 1024)
snprintf(out, sizeof(out), "%d Bytes", bytes);
else if(bytes < 1024 * 1024)
snprintf(out, sizeof(out), "%.1f KB", (float)bytes / 1024);
else if (bytes < 1024 * 1024 * 1024)
snprintf(out, sizeof(out), "%.1f MB", (float)bytes / 1024 / 1024);
else
snprintf(out, sizeof(out), "%.1f GB", (float)bytes / 1024 / 1024 / 1024);
return out;
}