Only update progress display when the percentage has changed.

This commit is contained in:
Steven Smith 2015-04-24 15:18:33 -07:00
parent a4615c95a4
commit f90bc8b620

View File

@ -73,7 +73,7 @@ int main(int argc, char **argv) {
} }
std::stringstream stream; std::stringstream stream;
stream << "FBI v1.3.5" << "\n"; stream << "FBI v1.3.6" << "\n";
stream << "Free Space: " << freeSpace << " bytes (" << std::fixed << std::setprecision(2) << freeSpace / 1024.0f / 1024.0f << "MB)" << "\n"; stream << "Free Space: " << freeSpace << " bytes (" << std::fixed << std::setprecision(2) << freeSpace / 1024.0f / 1024.0f << "MB)" << "\n";
stream << "Destination: " << (destination == NAND ? "NAND" : "SD") << ", Mode: " << (mode == INSTALL_CIA ? "Install CIA" : mode == DELETE_CIA ? "Delete CIA" : mode == DELETE_TITLE ? "Delete Title" : "Launch Title") << "\n"; stream << "Destination: " << (destination == NAND ? "NAND" : "SD") << ", Mode: " << (mode == INSTALL_CIA ? "Install CIA" : mode == DELETE_CIA ? "Delete CIA" : mode == DELETE_TITLE ? "Delete Title" : "Launch Title") << "\n";
stream << "L - Switch Destination, R - Switch Mode" << "\n"; stream << "L - Switch Destination, R - Switch Mode" << "\n";
@ -96,13 +96,19 @@ int main(int argc, char **argv) {
std::string batchInfo = ""; std::string batchInfo = "";
int prevProgress = -1;
auto onProgress = [&](u64 pos, u64 totalSize) { auto onProgress = [&](u64 pos, u64 totalSize) {
std::stringstream details; u32 progress = (u32) ((pos * 100) / totalSize);
details << batchInfo; if(prevProgress != (int) progress) {
details << "(" << pos << " / " << totalSize << ")" << "\n"; prevProgress = (int) progress;
details << "Press B to cancel.";
std::stringstream details;
details << batchInfo;
details << "Press B to cancel.";
uiDisplayProgress(TOP_SCREEN, "Installing", details.str(), true, progress);
}
uiDisplayProgress(TOP_SCREEN, "Installing", details.str(), true, (u32) ((pos * 100) / totalSize));
inputPoll(); inputPoll();
return !inputIsPressed(BUTTON_B); return !inputIsPressed(BUTTON_B);
}; };
@ -136,6 +142,7 @@ int main(int argc, char **argv) {
confirmStream << "Size: " << file.fileSize << " bytes (" << std::fixed << std::setprecision(2) << file.fileSize / 1024.0f / 1024.0f << "MB)" << "\n"; confirmStream << "Size: " << file.fileSize << " bytes (" << std::fixed << std::setprecision(2) << file.fileSize / 1024.0f / 1024.0f << "MB)" << "\n";
if(!showNetworkPrompts || uiPrompt(TOP_SCREEN, confirmStream.str(), true)) { if(!showNetworkPrompts || uiPrompt(TOP_SCREEN, confirmStream.str(), true)) {
AppResult ret = appInstall(destination, file.fd, file.fileSize, onProgress); AppResult ret = appInstall(destination, file.fd, file.fileSize, onProgress);
prevProgress = -1;
if(showNetworkPrompts || ret != APP_SUCCESS) { if(showNetworkPrompts || ret != APP_SUCCESS) {
std::stringstream resultMsg; std::stringstream resultMsg;
resultMsg << "Install "; resultMsg << "Install ";
@ -178,6 +185,7 @@ int main(int argc, char **argv) {
batchInfo = batchInstallStream.str(); batchInfo = batchInstallStream.str();
AppResult ret = appInstallFile(destination, path, onProgress); AppResult ret = appInstallFile(destination, path, onProgress);
prevProgress = -1;
batchInfo = ""; batchInfo = "";
if(ret != APP_SUCCESS) { if(ret != APP_SUCCESS) {
Error error = platformGetError(); Error error = platformGetError();
@ -244,6 +252,7 @@ int main(int argc, char **argv) {
if(mode == INSTALL_CIA) { if(mode == INSTALL_CIA) {
AppResult ret = appInstallFile(destination, path, onProgress); AppResult ret = appInstallFile(destination, path, onProgress);
prevProgress = -1;
if(ret == APP_SUCCESS) { if(ret == APP_SUCCESS) {
resultMsg << "succeeded!"; resultMsg << "succeeded!";
} else { } else {