Skip to content
This repository was archived by the owner on Jul 4, 2025. It is now read-only.

Commit 26f3d6f

Browse files
authored
fix: download engine does not show progress (#1592)
* fix: download progress does not show * fix: typo
1 parent 6d553f9 commit 26f3d6f

File tree

1 file changed

+26
-26
lines changed

1 file changed

+26
-26
lines changed

engine/cli/utils/download_progress.cc

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "download_progress.h"
22
#include <chrono>
3+
#include <limits>
34
#include "common/event.h"
45
#include "indicators/dynamic_progress.hpp"
56
#include "indicators/progress_bar.hpp"
@@ -65,35 +66,34 @@ bool DownloadProgress::Handle(const std::string& id) {
6566
indicators::option::ShowRemainingTime{true}));
6667
bars->push_back(*(items.back()));
6768
}
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);
9292

93-
CTL_INF("Download success");
94-
}
93+
CTL_INF("Download success");
9594
}
9695
}
96+
9797
status_ = ev.type_;
9898
};
9999

0 commit comments

Comments
 (0)