1
0
Fork 0
mirror of https://github.com/HamletDuFromage/aio-switch-updater.git synced 2024-12-01 05:42:02 +00:00

don't divide by 0

This commit is contained in:
flb 2023-07-12 12:54:32 +02:00
parent 6a12ffc829
commit 9a7863504d
2 changed files with 13 additions and 14 deletions

View file

@ -212,9 +212,7 @@
}, },
"worker": { "worker": {
"of": "of", "of": "of",
"remaining": "Time remaining", "download_progress": "({:.1f} MB of {:.1f} MB - {:.1f} MB/s)",
"hours": "hours", "time_left": "({} left)"
"minutes": "minutes",
"seconds": "seconds"
} }
} }

View file

@ -33,27 +33,28 @@ WorkerPage::WorkerPage(brls::StagedAppletFrame* frame, const std::string& text,
this->registerAction("", brls::Key::PLUS, [this] { return true; }); this->registerAction("", brls::Key::PLUS, [this] { return true; });
} }
std::string formatLabelText( double speed, double fileSizeCurrent, double fileSizeFinal) std::string formatLabelText(double speed, double fileSizeCurrent, double fileSizeFinal)
{ {
double fileSizeCurrentMB = fileSizeCurrent / 0x100000; double fileSizeCurrentMB = fileSizeCurrent / 0x100000;
double fileSizeFinalMB = fileSizeFinal / 0x100000; double fileSizeFinalMB = fileSizeFinal / 0x100000;
double speedMB = speed / 0x100000; double speedMB = speed / 0x100000;
// Calcul du temps restant
double timeRemaining = (fileSizeFinal - fileSizeCurrent) / speed; double timeRemaining = (fileSizeFinal - fileSizeCurrent) / speed;
int hours = static_cast<int>(timeRemaining / 3600); int hours = static_cast<int>(timeRemaining / 3600);
int minutes = static_cast<int>((timeRemaining - hours * 3600) / 60); int minutes = static_cast<int>((timeRemaining - hours * 3600) / 60);
int seconds = static_cast<int>(timeRemaining - hours * 3600 - minutes * 60); int seconds = static_cast<int>(timeRemaining - hours * 3600 - minutes * 60);
std::string labelText = fmt::format("({:.1f} MB {} {:.1f} MB - {:.1f} MB/s) - {}: ", std::string labelText = fmt::format("menus/worker/download_progress"_i18n, fileSizeCurrentMB, fileSizeFinalMB, speedMB);
fileSizeCurrentMB, "menus/worker/of"_i18n, fileSizeFinalMB, speedMB, "menus/worker/remaining"_i18n); if (speedMB > 0) {
std::string eta;
if (hours > 0) if (hours > 0)
labelText += fmt::format("{}{} ", hours, "menus/worker/hours"_i18n); eta += fmt::format("{}h ", hours);
if (minutes > 0) if (minutes > 0)
labelText += fmt::format("{}{} ", minutes, "menus/worker/minutes"_i18n); eta += fmt::format("{}m ", minutes);
labelText += fmt::format("{}{}", seconds, "menus/worker/seconds"_i18n); eta += fmt::format("{}s", seconds);
labelText += "\n" + fmt::format("menus/worker/time_left"_i18n, eta);
}
return labelText; return labelText;
} }