1
0
Fork 0
mirror of synced 2024-06-28 11:11:15 +12:00

Enable origin install check on linux and add some performance improvements for linux

Signed-off-by: loathingKernel <142770+loathingKernel@users.noreply.github.com>
This commit is contained in:
lennard 2023-01-08 23:39:41 +02:00 committed by loathingKernel
parent 9733e119c9
commit b926dd112c
No known key found for this signature in database
GPG key ID: CE0C72D0B53821FD

View file

@ -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):