From dc2f622013d44b0827bbb4c62edd2adc5d02a139 Mon Sep 17 00:00:00 2001 From: Dummerle Date: Sun, 11 Apr 2021 21:02:56 +0200 Subject: [PATCH] Show size in gb or mb --- rare/app.py | 2 -- rare/components/tabs/downloads/__init__.py | 5 ++++- rare/components/tabs/games/game_info/__init__.py | 4 ++-- rare/utils/utils.py | 7 +++++++ 4 files changed, 13 insertions(+), 5 deletions(-) diff --git a/rare/app.py b/rare/app.py index 0673f28b..e82e2509 100644 --- a/rare/app.py +++ b/rare/app.py @@ -71,8 +71,6 @@ class App(QApplication): self.setStyleSheet(open(style_path + "RareStyle.qss").read()) self.setWindowIcon(QIcon(style_path + "Logo.png")) - # tray icon - # launch app self.launch_dialog = LaunchDialog(self.core) self.launch_dialog.start_app.connect(self.start_app) diff --git a/rare/components/tabs/downloads/__init__.py b/rare/components/tabs/downloads/__init__.py index 29c8483a..9611bf8e 100644 --- a/rare/components/tabs/downloads/__init__.py +++ b/rare/components/tabs/downloads/__init__.py @@ -14,6 +14,7 @@ from custom_legendary.core import LegendaryCore from custom_legendary.models.downloading import UIUpdate from custom_legendary.models.game import Game, InstalledGame from custom_legendary.utils.selective_dl import games +from rare.utils.utils import get_size logger = getLogger("Download") @@ -145,6 +146,7 @@ class DownloadTab(QWidget): self.thread.statistics.connect(self.statistics) self.thread.start() self.kill_button.setDisabled(False) + self.analysis = analysis self.installing_game.setText(self.tr("Installing Game: ") + self.active_game.app_title) def sdl_prompt(self, app_name: str = '', title: str = '') -> list: @@ -242,12 +244,13 @@ class DownloadTab(QWidget): self.time_left.setText("") self.cache_used.setText("") self.downloaded.setText("") + self.analysis = None def statistics(self, ui_update: UIUpdate): self.prog_bar.setValue(ui_update.progress) self.dl_speed.setText(self.tr("Download speed") + f": {ui_update.download_speed / 1024 / 1024:.02f}MB/s") self.cache_used.setText(self.tr("Cache used") + f": {ui_update.cache_usage / 1024 / 1024:.02f}MB") - self.downloaded.setText(self.tr("Downloaded") + f": {ui_update.total_downloaded / 1024 / 1024:.02f}MB") + self.downloaded.setText(self.tr("Downloaded") + f": {get_size(ui_update.total_downloaded)} / {get_size(self.analysis.dl_size)}") self.time_left.setText(self.tr("Time left: ") + self.get_time(ui_update.estimated_time_left)) def get_time(self, seconds: int) -> str: diff --git a/rare/components/tabs/games/game_info/__init__.py b/rare/components/tabs/games/game_info/__init__.py index 304f227e..38233059 100644 --- a/rare/components/tabs/games/game_info/__init__.py +++ b/rare/components/tabs/games/game_info/__init__.py @@ -11,7 +11,7 @@ from rare.components.tabs.games.game_info.game_settings import GameSettings from rare.utils import legendary_utils from rare.utils.legendary_utils import VerifyThread from rare.utils.extra_widgets import SideTabBar -from rare.utils.utils import IMAGE_DIR +from rare.utils.utils import IMAGE_DIR, get_size from custom_legendary.core import LegendaryCore from custom_legendary.models.game import InstalledGame, Game @@ -168,7 +168,7 @@ class GameInfo(QScrollArea): self.version.setText("Version: " + self.game.app_version) self.dev.setText(self.tr("Developer: ") + self.game.metadata["developer"]) self.install_size.setText( - self.tr("Install size: ") + str(round(self.igame.install_size / (1024 ** 3), 2)) + " GB") + self.tr("Install size: ") + get_size(self.igame.install_size)) self.install_path.setText(self.tr("Install path: ") + self.igame.install_path) if len(self.verify_threads.keys()) == 0 or not self.verify_threads.get(app_name): diff --git a/rare/utils/utils.py b/rare/utils/utils.py index 39fce266..f29bc333 100644 --- a/rare/utils/utils.py +++ b/rare/utils/utils.py @@ -124,3 +124,10 @@ def get_latest_version(): resp = requests.get("https://api.github.com/repos/Dummerle/Rare/releases/latest") tag = json.loads(resp.content.decode("utf-8"))["tag_name"] return tag + + +def get_size(b: int) -> str: + for i in ['', 'K', 'M', 'G', 'T', 'P', 'E']: + if b < 1024: + return f"{b:.2f}{i}B" + b /= 1024