Add safety checks for low SD card space (#90)

* Some attempt.

* Enable some-safety-freespace-work nightlies

* Upload elf with nightly

* *Derp fixes.*

* Bye Bye testing things.

* Revert "Upload elf with nightly"

This reverts commit 303968cd78e466a3fcc010915565d8265acaa76a.

* Add safety checks to fcopy

Co-authored-by: StackZ <47382115+SuperSaiyajinStackZ@users.noreply.github.com>
This commit is contained in:
Pk11 2021-05-26 05:47:51 -05:00 committed by GitHub
commit baa14561eb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 145 additions and 105 deletions

View file

@ -65,14 +65,15 @@ std::string StringUtils::FetchStringsFromVector(const std::vector<std::string> &
/*
adapted from GM9i's byte parsing.
*/
std::string StringUtils::formatBytes(int bytes) {
std::string StringUtils::formatBytes(u64 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 KiB", (float)bytes / 1024);
else if (bytes < 1024 * 1024 * 1024) snprintf(out, sizeof(out), "%.1f MiB", (float)bytes / 1024 / 1024);
else snprintf(out, sizeof(out), "%.1f GiB", (float)bytes / 1024 / 1024 / 1024);
if (bytes == 1) snprintf(out, sizeof(out), "%lld Byte", bytes);
else if (bytes < 1ull << 10) snprintf(out, sizeof(out), "%lld Bytes", bytes);
else if (bytes < 1ull << 20) snprintf(out, sizeof(out), "%.1f KiB", (float)bytes / 1024);
else if (bytes < 1ull << 30) snprintf(out, sizeof(out), "%.1f MiB", (float)bytes / 1024 / 1024);
else if (bytes < 1ull << 40) snprintf(out, sizeof(out), "%.1f GiB", (float)bytes / 1024 / 1024 / 1024);
else snprintf(out, sizeof(out), "%.1f TiB", (float)bytes / 1024 / 1024 / 1024 / 1024);
return out;
}