@@ -23,12 +23,14 @@ bool DownloadProgress::Connect(const std::string& host, int port) {
2323
2424bool DownloadProgress::Handle (const std::string& id) {
2525 assert (!!ws_);
26+ std::unordered_map<std::string, uint64_t > totals;
2627 status_ = DownloadStatus::DownloadStarted;
2728 std::unique_ptr<indicators::DynamicProgress<indicators::ProgressBar>> bars;
2829
2930 std::vector<std::unique_ptr<indicators::ProgressBar>> items;
3031 indicators::show_console_cursor (false );
31- auto handle_message = [this , &bars, &items, id](const std::string& message) {
32+ auto handle_message = [this , &bars, &items, &totals,
33+ id](const std::string& message) {
3234 CTL_INF (message);
3335
3436 auto pad_string = [](const std::string& str,
@@ -70,20 +72,26 @@ bool DownloadProgress::Handle(const std::string& id) {
7072 for (int i = 0 ; i < ev.download_task_ .items .size (); i++) {
7173 auto & it = ev.download_task_ .items [i];
7274 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+ if (totals.find (it.id ) == totals.end ()) {
76+ totals[it.id ] = it.bytes .value_or (std::numeric_limits<uint64_t >::max ());
77+ CTL_INF (" Updated " << it.id << " - total: " << totals[it.id ]);
78+ }
79+
80+ if (ev.type_ == DownloadStatus::DownloadStarted ||
81+ ev.type_ == DownloadStatus::DownloadUpdated) {
7582 (*bars)[i].set_option (indicators::option::PrefixText{
7683 pad_string (it.id ) +
77- std::to_string (int (static_cast <double >(downloaded) / total * 100 )) +
84+ std::to_string (
85+ int (static_cast <double >(downloaded) / totals[it.id ] * 100 )) +
7886 ' %' });
7987 (*bars)[i].set_progress (
80- int (static_cast <double >(downloaded) / total * 100 ));
88+ int (static_cast <double >(downloaded) / totals[it. id ] * 100 ));
8189 (*bars)[i].set_option (indicators::option::PostfixText{
8290 format_utils::BytesToHumanReadable (downloaded) + " /" +
83- format_utils::BytesToHumanReadable (total )});
91+ format_utils::BytesToHumanReadable (totals[it. id ] )});
8492 } else if (ev.type_ == DownloadStatus::DownloadSuccess) {
8593 (*bars)[i].set_progress (100 );
86- auto total_str = format_utils::BytesToHumanReadable (total );
94+ auto total_str = format_utils::BytesToHumanReadable (totals[it. id ] );
8795 (*bars)[i].set_option (
8896 indicators::option::PostfixText{total_str + " /" + total_str});
8997 (*bars)[i].set_option (
0 commit comments