Skip to content

Commit

Permalink
Downloading soundpacks sometimes doesn't show known total file size (#81
Browse files Browse the repository at this point in the history
)

Fixes remyroy#660
  • Loading branch information
langp11 authored Jan 24, 2023
1 parent 9f5a9c5 commit 3dafde1
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions cddagl/ui/views/soundpacks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand Down

0 comments on commit 3dafde1

Please sign in to comment.