Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downloading soundpacks sometimes doesn't show known total file size #81

Merged
merged 2 commits into from
Jan 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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