From 54409b01f51a406904cbb361eb9d2b39d9d9caa9 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Mon, 7 Oct 2024 11:36:00 +0200 Subject: [PATCH] fix file selector month and seconds remaining overflowing --- src/chat_gui/file_selector.cpp | 2 +- src/chat_gui4.cpp | 26 +++++++++++++------------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/src/chat_gui/file_selector.cpp b/src/chat_gui/file_selector.cpp index e512a16a..c78e920c 100644 --- a/src/chat_gui/file_selector.cpp +++ b/src/chat_gui/file_selector.cpp @@ -198,7 +198,7 @@ void FileSelector::render(void) { const auto ctime = std::chrono::system_clock::to_time_t(file_time_converted); const auto ltime = std::localtime(&ctime); - ImGui::TextDisabled("%2d.%2d.%2d - %2d:%2d", ltime->tm_mday, ltime->tm_mon, ltime->tm_year + 1900, ltime->tm_hour, ltime->tm_min); + ImGui::TextDisabled("%2d.%2d.%2d - %2d:%2d", ltime->tm_mday, ltime->tm_mon + 1, ltime->tm_year + 1900, ltime->tm_hour, ltime->tm_min); } } diff --git a/src/chat_gui4.cpp b/src/chat_gui4.cpp index 0786556b..cfb6b2c9 100644 --- a/src/chat_gui4.cpp +++ b/src/chat_gui4.cpp @@ -1118,38 +1118,38 @@ void ChatGui4::renderMessageBodyFile(Message3Registry& reg, const Message3 e) { // hacky const auto* fts = o.try_get(); if (fts != nullptr && o.any_of()) { - const auto total_size = + const int64_t total_size = o.all_of() ? o.get().file_size : o.get().total_size ; - uint64_t total {0u}; - float rate {0.f}; + int64_t transfer_total {0u}; + float transfer_rate {0.f}; if (o.all_of() && fts->total_down <= 0) { // if have all AND no dl -> show upload progress ImGui::TextUnformatted(" up"); - total = fts->total_up; - rate = fts->rate_up; + transfer_total = fts->total_up; + transfer_rate = fts->rate_up; } else { // else show download progress ImGui::TextUnformatted("down"); - total = fts->total_down; - rate = fts->rate_down; + transfer_total = fts->total_down; + transfer_rate = fts->rate_down; } ImGui::SameLine(); - float fraction = float(total) / total_size; + float fraction = float(transfer_total) / total_size; char overlay_buf[64]; - if (rate > 0.000001f) { + if (transfer_rate > 0.000001f) { const char* byte_suffix = "???"; - int64_t byte_divider = sizeToHumanReadable(rate, byte_suffix); - int64_t seconds_remaining = (total_size - total) / rate; + int64_t byte_divider = sizeToHumanReadable(transfer_rate, byte_suffix); + int64_t seconds_remaining = (total_size - transfer_total) / transfer_rate; if (seconds_remaining > 0) { - std::snprintf(overlay_buf, sizeof(overlay_buf), "%.1f%% @ %.1f%s/s %lds ", fraction * 100 + 0.01f, rate/byte_divider, byte_suffix, seconds_remaining); + std::snprintf(overlay_buf, sizeof(overlay_buf), "%.1f%% @ %.1f%s/s %lds ", fraction * 100 + 0.01f, transfer_rate/byte_divider, byte_suffix, seconds_remaining); } else { - std::snprintf(overlay_buf, sizeof(overlay_buf), "%.1f%% @ %.1f%s/s", fraction * 100 + 0.01f, rate/byte_divider, byte_suffix); + std::snprintf(overlay_buf, sizeof(overlay_buf), "%.1f%% @ %.1f%s/s", fraction * 100 + 0.01f, transfer_rate/byte_divider, byte_suffix); } } else { std::snprintf(overlay_buf, sizeof(overlay_buf), "%.1f%%", fraction * 100 + 0.01f);