@@ -50,13 +50,12 @@ bool DownloadProgress::Handle(const DownloadType& event_type) {
5050 }
5151 }
5252#endif
53- std::unordered_map<std::string, uint64_t > totals;
5453 status_ = DownloadStatus::DownloadStarted;
5554 std::unique_ptr<indicators::DynamicProgress<indicators::ProgressBar>> bars;
5655
5756 std::vector<std::unique_ptr<indicators::ProgressBar>> items;
5857 indicators::show_console_cursor (false );
59- auto handle_message = [this , &bars, &items, &totals,
58+ auto handle_message = [this , &bars, &items,
6059 event_type](const std::string& message) {
6160 CTL_INF (message);
6261
@@ -98,27 +97,24 @@ bool DownloadProgress::Handle(const DownloadType& event_type) {
9897 }
9998 for (int i = 0 ; i < ev.download_task_ .items .size (); i++) {
10099 auto & it = ev.download_task_ .items [i];
101- uint64_t downloaded = it.downloadedBytes .value_or (0 );
102- if (totals.find (it.id ) == totals.end ()) {
103- totals[it.id ] = it.bytes .value_or (std::numeric_limits<uint64_t >::max ());
104- CTL_INF (" Updated " << it.id << " - total: " << totals[it.id ]);
105- }
106-
107- if (ev.type_ == DownloadStatus::DownloadStarted ||
108- ev.type_ == DownloadStatus::DownloadUpdated) {
100+ if (ev.type_ == DownloadStatus::DownloadUpdated) {
101+ uint64_t downloaded = it.downloadedBytes .value_or (0u );
102+ uint64_t total =
103+ it.bytes .value_or (std::numeric_limits<uint64_t >::max ());
109104 (*bars)[i].set_option (indicators::option::PrefixText{
110105 pad_string (Repo2Engine (it.id )) +
111- std::to_string (
112- int (static_cast <double >(downloaded) / totals[it.id ] * 100 )) +
106+ std::to_string (int (static_cast <double >(downloaded) / total * 100 )) +
113107 ' %' });
114108 (*bars)[i].set_progress (
115- int (static_cast <double >(downloaded) / totals[it. id ] * 100 ));
109+ int (static_cast <double >(downloaded) / total * 100 ));
116110 (*bars)[i].set_option (indicators::option::PostfixText{
117111 format_utils::BytesToHumanReadable (downloaded) + " /" +
118- format_utils::BytesToHumanReadable (totals[it. id ] )});
112+ format_utils::BytesToHumanReadable (total )});
119113 } else if (ev.type_ == DownloadStatus::DownloadSuccess) {
114+ uint64_t total =
115+ it.bytes .value_or (std::numeric_limits<uint64_t >::max ());
120116 (*bars)[i].set_progress (100 );
121- auto total_str = format_utils::BytesToHumanReadable (totals[it. id ] );
117+ auto total_str = format_utils::BytesToHumanReadable (total );
122118 (*bars)[i].set_option (
123119 indicators::option::PostfixText{total_str + " /" + total_str});
124120 (*bars)[i].set_option (indicators::option::PrefixText{
0 commit comments