From b926dd112c9e3ceeec2fbaa59c68a3149e4d88d3 Mon Sep 17 00:00:00 2001 From: lennard <44114474+dummerle@users.noreply.github.com> Date: Sun, 8 Jan 2023 23:39:41 +0200 Subject: [PATCH] Enable origin install check on linux and add some performance improvements for linux Signed-off-by: loathingKernel <142770+loathingKernel@users.noreply.github.com> --- rare/models/game.py | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/rare/models/game.py b/rare/models/game.py index d8b63972..fa9d8ba1 100644 --- a/rare/models/game.py +++ b/rare/models/game.py @@ -2,6 +2,7 @@ import json import os import platform from abc import abstractmethod +import time from dataclasses import dataclass, field from datetime import datetime from enum import IntEnum @@ -20,6 +21,11 @@ from rare.utils.misc import read_registry 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") @@ -373,7 +379,7 @@ class RareGame(RareGameSlim): """ return (self.igame is not None) \ or (self.is_origin and self.__origin_install_path() is not None) \ - or (self.is_non_asset and platform.system() != "Windows") # TODO: Remove this line + or (self.is_non_asset and platform.system() != "Windows") # TODO: Remove this line def set_installed(self, installed: bool) -> None: """! @@ -595,31 +601,44 @@ class RareGame(RareGameSlim): ) return True + __origin_install_path_cache = None + def __origin_install_path(self) -> Optional[str]: + if self.__origin_install_path_cache == "err": + return None + elif self.__origin_install_path_cache: + return self.__origin_install_path_cache reg_path: str = self.game.metadata \ .get("customAttributes", {}) \ .get("RegistryPath", {}).get("value", None) if not reg_path: return None - if platform.system() == "Windows": - import winreg - from legendary.lfs import windows_helpers - return windows_helpers.query_registry_value(winreg.HKEY_LOCAL_MACHINE, reg_path, "Install Dir") - return None + if platform.system() == "Windows": + install_dir = windows_helpers.query_registry_value(winreg.HKEY_LOCAL_MACHINE, reg_path, "Install Dir") + self.__origin_install_path_cache = install_dir + return install_dir + # TODO: Do not get install path on non windows, because of performance wine_prefix = self.core.lgd.config.get(self.game.app_name, "wine_prefix", fallback=os.path.expanduser("~/.wine")) # TODO cache this line + t = time.time() reg = read_registry("system.reg", wine_prefix) + print(f"Read reg file {self.app_name}: {time.time() - t}s") # TODO: find a better solution reg_path = reg_path.replace("\\", "\\\\").replace("SOFTWARE", "Software").replace("WOW6432Node", "Wow6432Node") - + t = time.time() install_dir = reg.get(reg_path, '"Install Dir"', fallback=None) + print(f"Get install dir {self.title}: {time.time() - t}s") + if install_dir: - return install_dir.strip('"') + install_dir = install_dir.strip('"') + self.__origin_install_path_cache = install_dir + return install_dir + self.__origin_install_path_cache = "err" return None def repair(self, repair_and_update):