@@ -23,13 +23,13 @@ bool DownloadProgress::Connect(const std::string& host, int port) {
2323
2424bool DownloadProgress::Handle (const std::string& id) {
2525 assert (!!ws_);
26- uint64_t total = std::numeric_limits< uint64_t >:: max () ;
26+ std::unordered_map<std::string, uint64_t > totals ;
2727 status_ = DownloadStatus::DownloadStarted;
2828 std::unique_ptr<indicators::DynamicProgress<indicators::ProgressBar>> bars;
2929
3030 std::vector<std::unique_ptr<indicators::ProgressBar>> items;
3131 indicators::show_console_cursor (false );
32- auto handle_message = [this , &bars, &items, &total ,
32+ auto handle_message = [this , &bars, &items, &totals ,
3333 id](const std::string& message) {
3434 CTL_INF (message);
3535
@@ -72,23 +72,26 @@ bool DownloadProgress::Handle(const std::string& id) {
7272 for (int i = 0 ; i < ev.download_task_ .items .size (); i++) {
7373 auto & it = ev.download_task_ .items [i];
7474 uint64_t downloaded = it.downloadedBytes .value_or (0 );
75- if (total == 0 || total == std::numeric_limits< uint64_t >:: max ()) {
76- total = it.bytes .value_or (std::numeric_limits<uint64_t >::max ());
77- CTL_INF (" Updated - total: " << total );
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 ] );
7878 }
79- if (ev.type_ == DownloadStatus::DownloadUpdated) {
79+
80+ if (ev.type_ == DownloadStatus::DownloadStarted ||
81+ ev.type_ == DownloadStatus::DownloadUpdated) {
8082 (*bars)[i].set_option (indicators::option::PrefixText{
8183 pad_string (it.id ) +
82- std::to_string (int (static_cast <double >(downloaded) / total * 100 )) +
84+ std::to_string (
85+ int (static_cast <double >(downloaded) / totals[it.id ] * 100 )) +
8386 ' %' });
8487 (*bars)[i].set_progress (
85- int (static_cast <double >(downloaded) / total * 100 ));
88+ int (static_cast <double >(downloaded) / totals[it. id ] * 100 ));
8689 (*bars)[i].set_option (indicators::option::PostfixText{
8790 format_utils::BytesToHumanReadable (downloaded) + " /" +
88- format_utils::BytesToHumanReadable (total )});
91+ format_utils::BytesToHumanReadable (totals[it. id ] )});
8992 } else if (ev.type_ == DownloadStatus::DownloadSuccess) {
9093 (*bars)[i].set_progress (100 );
91- auto total_str = format_utils::BytesToHumanReadable (total );
94+ auto total_str = format_utils::BytesToHumanReadable (totals[it. id ] );
9295 (*bars)[i].set_option (
9396 indicators::option::PostfixText{total_str + " /" + total_str});
9497 (*bars)[i].set_option (
0 commit comments