|
1 | 1 | #include "download_progress.h" |
2 | 2 | #include <chrono> |
| 3 | +#include <limits> |
3 | 4 | #include "common/event.h" |
4 | 5 | #include "indicators/dynamic_progress.hpp" |
5 | 6 | #include "indicators/progress_bar.hpp" |
@@ -65,35 +66,34 @@ bool DownloadProgress::Handle(const std::string& id) { |
65 | 66 | indicators::option::ShowRemainingTime{true})); |
66 | 67 | bars->push_back(*(items.back())); |
67 | 68 | } |
68 | | - } else { |
69 | | - for (int i = 0; i < ev.download_task_.items.size(); i++) { |
70 | | - auto& it = ev.download_task_.items[i]; |
71 | | - uint64_t downloaded = it.downloadedBytes.value_or(0); |
72 | | - uint64_t total = it.bytes.value_or(9999); |
73 | | - if (ev.type_ == DownloadStatus::DownloadUpdated) { |
74 | | - (*bars)[i].set_option(indicators::option::PrefixText{ |
75 | | - pad_string(it.id) + |
76 | | - std::to_string( |
77 | | - int(static_cast<double>(downloaded) / total * 100)) + |
78 | | - '%'}); |
79 | | - (*bars)[i].set_progress( |
80 | | - int(static_cast<double>(downloaded) / total * 100)); |
81 | | - (*bars)[i].set_option(indicators::option::PostfixText{ |
82 | | - format_utils::BytesToHumanReadable(downloaded) + "/" + |
83 | | - format_utils::BytesToHumanReadable(total)}); |
84 | | - } else if (ev.type_ == DownloadStatus::DownloadSuccess) { |
85 | | - (*bars)[i].set_progress(100); |
86 | | - auto total_str = format_utils::BytesToHumanReadable(total); |
87 | | - (*bars)[i].set_option( |
88 | | - indicators::option::PostfixText{total_str + "/" + total_str}); |
89 | | - (*bars)[i].set_option( |
90 | | - indicators::option::PrefixText{pad_string(it.id) + "100%"}); |
91 | | - (*bars)[i].set_progress(100); |
| 69 | + } |
| 70 | + for (int i = 0; i < ev.download_task_.items.size(); i++) { |
| 71 | + auto& it = ev.download_task_.items[i]; |
| 72 | + uint64_t downloaded = it.downloadedBytes.value_or(0); |
| 73 | + uint64_t total = it.bytes.value_or(std::numeric_limits<uint64_t>::max()); |
| 74 | + if (ev.type_ == DownloadStatus::DownloadUpdated) { |
| 75 | + (*bars)[i].set_option(indicators::option::PrefixText{ |
| 76 | + pad_string(it.id) + |
| 77 | + std::to_string(int(static_cast<double>(downloaded) / total * 100)) + |
| 78 | + '%'}); |
| 79 | + (*bars)[i].set_progress( |
| 80 | + int(static_cast<double>(downloaded) / total * 100)); |
| 81 | + (*bars)[i].set_option(indicators::option::PostfixText{ |
| 82 | + format_utils::BytesToHumanReadable(downloaded) + "/" + |
| 83 | + format_utils::BytesToHumanReadable(total)}); |
| 84 | + } else if (ev.type_ == DownloadStatus::DownloadSuccess) { |
| 85 | + (*bars)[i].set_progress(100); |
| 86 | + auto total_str = format_utils::BytesToHumanReadable(total); |
| 87 | + (*bars)[i].set_option( |
| 88 | + indicators::option::PostfixText{total_str + "/" + total_str}); |
| 89 | + (*bars)[i].set_option( |
| 90 | + indicators::option::PrefixText{pad_string(it.id) + "100%"}); |
| 91 | + (*bars)[i].set_progress(100); |
92 | 92 |
|
93 | | - CTL_INF("Download success"); |
94 | | - } |
| 93 | + CTL_INF("Download success"); |
95 | 94 | } |
96 | 95 | } |
| 96 | + |
97 | 97 | status_ = ev.type_; |
98 | 98 | }; |
99 | 99 |
|
|
0 commit comments