diff --git a/rare/components/tabs/games/__init__.py b/rare/components/tabs/games/__init__.py index a2f44830..03046ec2 100644 --- a/rare/components/tabs/games/__init__.py +++ b/rare/components/tabs/games/__init__.py @@ -157,10 +157,9 @@ class GamesTab(QStackedWidget): self.update_count_games_label() if platform.system() != "Windows": - worker = OriginWineWorker(self.rcore.origin_games, self.core) + worker = OriginWineWorker(self.core, self.rcore.origin_games) QThreadPool.globalInstance().start(worker) - def add_library_widget(self, rgame: RareGame): try: icon_widget, list_widget = self.library_controller.add_game(rgame) diff --git a/rare/models/game.py b/rare/models/game.py index 1606a1cb..bc7a190b 100644 --- a/rare/models/game.py +++ b/rare/models/game.py @@ -19,11 +19,6 @@ from rare.shared.image_manager import ImageManager from rare.utils.paths import data_dir, get_rare_executable from rare.utils.steam_grades import get_rating -if platform.system() == "Windows": - # noinspection PyUnresolvedReferences - import winreg # pylint: disable=E0401 - from legendary.lfs import windows_helpers - logger = getLogger("RareGame") @@ -201,6 +196,7 @@ class RareGame(RareGameSlim): def __init__(self, legendary_core: LegendaryCore, image_manager: ImageManager, game: Game): super(RareGame, self).__init__(legendary_core, game) self.__origin_install_path: Optional[str] = None + self.__origin_install_size: Optional[int] = None self.__steam_grade: Optional[str] = None self.image_manager = image_manager @@ -229,16 +225,6 @@ class RareGame(RareGameSlim): if self.is_installed and not self.is_dlc: self.game_process.connect_to_server(on_startup=True) - if platform.system() == "Windows" and self.is_origin: - reg_path: str = self.game.metadata \ - .get("customAttributes", {}) \ - .get("RegistryPath", {}).get("value", None) - if not reg_path: - return - install_dir = windows_helpers.query_registry_value(winreg.HKEY_LOCAL_MACHINE, reg_path, "Install Dir") - self.__origin_install_path = install_dir - self.set_origin_attributes(install_dir) - def __on_progress_update(self, progress: int): self.progress = progress @@ -328,6 +314,8 @@ class RareGame(RareGameSlim): @return int The size of the installation """ + if self.is_origin: + return self.__origin_install_size if self.__origin_install_size is not None else 0 return self.igame.install_size if self.igame is not None else 0 @property @@ -617,9 +605,10 @@ class RareGame(RareGameSlim): ) return True - def set_origin_attributes(self, path: str) -> None: + def set_origin_attributes(self, path: str, size: int = 0) -> None: self.__origin_install_path = path - if self.install_path: + self.__origin_install_size = size + if self.install_path and self.install_size: self.signals.game.installed.emit(self.app_name) else: self.signals.game.uninstalled.emit(self.app_name) diff --git a/rare/shared/workers/wine_resolver.py b/rare/shared/workers/wine_resolver.py index 08021726..9cb79171 100644 --- a/rare/shared/workers/wine_resolver.py +++ b/rare/shared/workers/wine_resolver.py @@ -1,4 +1,5 @@ import os +import platform import subprocess import time from configparser import ConfigParser @@ -13,6 +14,11 @@ from rare.models.pathspec import PathSpec from rare.utils.misc import read_registry from .worker import Worker +if platform.system() == "Windows": + # noinspection PyUnresolvedReferences + import winreg # pylint: disable=E0401 + from legendary.lfs import windows_helpers + logger = getLogger("WineResolver") @@ -77,7 +83,7 @@ class WineResolver(Worker): class OriginWineWorker(QRunnable): - def __init__(self, games: Union[Iterator[RareGame], RareGame], core: LegendaryCore): + def __init__(self, core: LegendaryCore, games: Union[Iterator[RareGame], RareGame]): super().__init__() self.setAutoDelete(True) @@ -100,17 +106,21 @@ class OriginWineWorker(QRunnable): if not reg_path: continue - wine_prefix = self.core.lgd.config.get(rgame.app_name, "wine_prefix", - fallback=os.path.expanduser("~/.wine")) - reg = self.__cache.get(wine_prefix) or read_registry("system.reg", wine_prefix) - self.__cache[wine_prefix] = reg + if platform.system() == "Windows": + install_dir = windows_helpers.query_registry_value(winreg.HKEY_LOCAL_MACHINE, reg_path, "Install Dir") + else: + wine_prefix = self.core.lgd.config.get(rgame.app_name, "wine_prefix", + fallback=os.path.expanduser("~/.wine")) + reg = self.__cache.get(wine_prefix) or read_registry("system.reg", wine_prefix) + self.__cache[wine_prefix] = reg - # TODO: find a better solution - reg_path = reg_path.replace("\\", "\\\\")\ - .replace("SOFTWARE", "Software").replace("WOW6432Node", "Wow6432Node") + # TODO: find a better solution + reg_path = reg_path.replace("\\", "\\\\")\ + .replace("SOFTWARE", "Software").replace("WOW6432Node", "Wow6432Node") - install_dir = reg.get(reg_path, '"Install Dir"', fallback=None) + install_dir = reg.get(reg_path, '"Install Dir"', fallback=None) if install_dir: + size = sum(os.path.getsize(f) for f in os.listdir(install_dir) if os.path.isfile(f)) logger.debug(f"Found install path for {rgame.title}: {install_dir}") - rgame.set_origin_attributes(install_dir) + rgame.set_origin_attributes(install_dir, size) logger.info(f"Origin registry worker finished in {time.time() - t}s")