From 3dafde145a64f26a8d3dc6c4aefe4244a5b78ae8 Mon Sep 17 00:00:00 2001 From: langp11 <77873080+langp11@users.noreply.github.com> Date: Wed, 25 Jan 2023 01:10:11 +1100 Subject: [PATCH] Downloading soundpacks sometimes doesn't show known total file size (#81) Fixes https://github.com/remyroy/CDDA-Game-Launcher/issues/660 --- cddagl/ui/views/soundpacks.py | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/cddagl/ui/views/soundpacks.py b/cddagl/ui/views/soundpacks.py index 7510c9d3..f05fc5d0 100644 --- a/cddagl/ui/views/soundpacks.py +++ b/cddagl/ui/views/soundpacks.py @@ -51,6 +51,7 @@ def __init__(self): self.soundpacks = [] self.soundpacks_model = None + self.selected_size = -1 self.installing_new_soundpack = False self.downloading_new_soundpack = False @@ -389,6 +390,11 @@ def install_new(self): self.downloading_progress_bar = progress_bar progress_bar.setMinimum(0) + self.selected_size = -1 + if 'size' in selected_info: + self.selected_size = selected_info['size'] + self.downloading_progress_bar.setMaximum(self.selected_size) + self.download_last_read = datetime.utcnow() self.download_last_bytes_read = 0 self.download_speed_count = 0 @@ -684,14 +690,19 @@ def download_http_ready_read(self): self.downloading_file.write(self.download_http_reply.readAll()) def download_dl_progress(self, bytes_read, total_bytes): - self.downloading_progress_bar.setMaximum(total_bytes) + if total_bytes != -1: + self.downloading_progress_bar.setMaximum(total_bytes) self.downloading_progress_bar.setValue(bytes_read) self.download_speed_count += 1 + if total_bytes == -1: + size = self.selected_size + else: + size = total_bytes self.downloading_size_label.setText( '{bytes_read}/{total_bytes}' - .format(bytes_read=sizeof_fmt(bytes_read), total_bytes=sizeof_fmt(total_bytes)) + .format(bytes_read=sizeof_fmt(bytes_read), total_bytes=sizeof_fmt(size)) ) if self.download_speed_count % 5 == 0: