2022-09-05 05:38:24 +12:00
|
|
|
import configparser
|
|
|
|
import os
|
2023-03-05 00:23:18 +13:00
|
|
|
import time
|
2022-09-05 05:38:24 +12:00
|
|
|
from argparse import Namespace
|
2023-01-05 09:38:05 +13:00
|
|
|
from itertools import chain
|
2022-09-05 05:38:24 +12:00
|
|
|
from logging import getLogger
|
2023-12-17 02:40:01 +13:00
|
|
|
from typing import Dict, Iterator, Callable, Optional, List, Union, Iterable, Tuple, Set
|
2022-09-05 05:38:24 +12:00
|
|
|
|
2023-03-12 23:44:43 +13:00
|
|
|
from PyQt5.QtCore import QObject, pyqtSignal, QSettings, pyqtSlot, QThreadPool, QRunnable, QTimer
|
2023-01-21 13:15:06 +13:00
|
|
|
from legendary.lfs.eos import EOSOverlayApp
|
2023-03-13 00:09:09 +13:00
|
|
|
from legendary.models.game import Game, SaveGameFile
|
2023-09-11 04:08:47 +12:00
|
|
|
from requests.exceptions import HTTPError, ConnectionError
|
2022-09-05 05:38:24 +12:00
|
|
|
|
|
|
|
from rare.lgndr.core import LegendaryCore
|
2023-03-11 08:28:37 +13:00
|
|
|
from rare.models.base_game import RareSaveGame
|
2023-02-19 04:27:18 +13:00
|
|
|
from rare.models.game import RareGame, RareEosOverlay
|
2022-09-05 05:38:24 +12:00
|
|
|
from rare.models.signals import GlobalSignals
|
2023-09-11 04:08:47 +12:00
|
|
|
from rare.utils.metrics import timelogger
|
2023-09-15 09:40:28 +12:00
|
|
|
from rare.utils import config_helper
|
2022-09-05 05:38:24 +12:00
|
|
|
from .image_manager import ImageManager
|
2023-03-05 00:23:18 +13:00
|
|
|
from .workers import (
|
|
|
|
QueueWorker,
|
|
|
|
VerifyWorker,
|
|
|
|
MoveWorker,
|
2023-03-08 04:10:40 +13:00
|
|
|
FetchWorker,
|
2023-09-15 09:40:28 +12:00
|
|
|
GamesDlcsWorker,
|
|
|
|
EntitlementsWorker,
|
2023-03-08 09:53:18 +13:00
|
|
|
OriginWineWorker,
|
2023-03-05 00:23:18 +13:00
|
|
|
)
|
|
|
|
from .workers.uninstall import uninstall_game
|
2023-02-16 21:50:53 +13:00
|
|
|
from .workers.worker import QueueWorkerInfo, QueueWorkerState
|
2023-09-20 10:39:15 +12:00
|
|
|
from .wrappers import Wrappers
|
2022-09-05 05:38:24 +12:00
|
|
|
|
|
|
|
logger = getLogger("RareCore")
|
|
|
|
|
|
|
|
|
|
|
|
class RareCore(QObject):
|
2023-03-05 00:23:18 +13:00
|
|
|
progress = pyqtSignal(int, str)
|
|
|
|
completed = pyqtSignal()
|
2023-03-13 00:19:24 +13:00
|
|
|
# lk: these are unused but remain if case they are become relevant
|
|
|
|
# completed_saves = pyqtSignal()
|
|
|
|
# completed_origin = pyqtSignal()
|
|
|
|
# completed_entitlements = pyqtSignal()
|
2023-03-05 00:23:18 +13:00
|
|
|
|
|
|
|
# lk: special case class attribute, this has to be here
|
2023-02-06 06:12:50 +13:00
|
|
|
__instance: Optional['RareCore'] = None
|
2022-09-05 05:38:24 +12:00
|
|
|
|
|
|
|
def __init__(self, args: Namespace):
|
2023-02-06 06:12:50 +13:00
|
|
|
if self.__instance is not None:
|
2022-09-05 05:38:24 +12:00
|
|
|
raise RuntimeError("RareCore already initialized")
|
|
|
|
super(RareCore, self).__init__()
|
2023-01-21 13:15:06 +13:00
|
|
|
self.__args: Optional[Namespace] = None
|
|
|
|
self.__signals: Optional[GlobalSignals] = None
|
|
|
|
self.__core: Optional[LegendaryCore] = None
|
|
|
|
self.__image_manager: Optional[ImageManager] = None
|
2023-09-20 10:39:15 +12:00
|
|
|
self.__settings: Optional[QSettings] = None
|
|
|
|
self.__wrappers: Optional[Wrappers] = None
|
2023-03-05 00:23:18 +13:00
|
|
|
|
2023-09-11 04:08:47 +12:00
|
|
|
self.__start_time = time.perf_counter()
|
2022-09-05 05:38:24 +12:00
|
|
|
|
|
|
|
self.args(args)
|
|
|
|
self.signals(init=True)
|
|
|
|
self.core(init=True)
|
2023-12-16 03:57:32 +13:00
|
|
|
config_helper.init_config_handler(self.__core)
|
2022-09-05 05:38:24 +12:00
|
|
|
self.image_manager(init=True)
|
2023-09-20 10:39:15 +12:00
|
|
|
self.__settings = QSettings(self)
|
|
|
|
self.__wrappers = Wrappers()
|
2023-03-05 00:23:18 +13:00
|
|
|
|
2023-02-01 02:43:26 +13:00
|
|
|
self.queue_workers: List[QueueWorker] = []
|
|
|
|
self.queue_threadpool = QThreadPool()
|
|
|
|
self.queue_threadpool.setMaxThreadCount(2)
|
|
|
|
|
2023-03-12 23:22:44 +13:00
|
|
|
self.__library: Dict[str, RareGame] = {}
|
|
|
|
self.__eos_overlay = RareEosOverlay(self.__core, EOSOverlayApp)
|
2023-09-09 04:38:39 +12:00
|
|
|
self.__eos_overlay.signals.game.install.connect(self.__signals.game.install)
|
|
|
|
self.__eos_overlay.signals.game.uninstall.connect(self.__signals.game.uninstall)
|
2023-01-21 13:15:06 +13:00
|
|
|
|
2023-09-15 09:40:28 +12:00
|
|
|
self.__fetch_progress: int = 0
|
|
|
|
self.__fetched_games_dlcs: bool = False
|
|
|
|
self.__fetched_entitlements: bool = False
|
|
|
|
|
2023-02-06 06:12:50 +13:00
|
|
|
RareCore.__instance = self
|
2022-09-05 05:38:24 +12:00
|
|
|
|
2023-02-01 02:43:26 +13:00
|
|
|
def enqueue_worker(self, rgame: RareGame, worker: QueueWorker):
|
|
|
|
if isinstance(worker, VerifyWorker):
|
|
|
|
rgame.state = RareGame.State.VERIFYING
|
|
|
|
if isinstance(worker, MoveWorker):
|
|
|
|
rgame.state = RareGame.State.MOVING
|
2023-02-03 21:55:56 +13:00
|
|
|
rgame.set_worker(worker)
|
|
|
|
worker.feedback.started.connect(self.__signals.application.update_statusbar)
|
|
|
|
worker.feedback.finished.connect(lambda: rgame.set_worker(None))
|
2023-02-01 02:43:26 +13:00
|
|
|
worker.feedback.finished.connect(lambda: self.queue_workers.remove(worker))
|
2023-02-03 21:55:56 +13:00
|
|
|
worker.feedback.finished.connect(self.__signals.application.update_statusbar)
|
2023-02-01 02:43:26 +13:00
|
|
|
self.queue_workers.append(worker)
|
2023-02-03 21:55:56 +13:00
|
|
|
self.queue_threadpool.start(worker, priority=0)
|
|
|
|
self.__signals.application.update_statusbar.emit()
|
2023-02-01 02:43:26 +13:00
|
|
|
|
2023-02-17 04:07:02 +13:00
|
|
|
def dequeue_worker(self, worker: QueueWorker):
|
2023-03-12 23:22:44 +13:00
|
|
|
rgame = self.__library[worker.worker_info().app_name]
|
2023-02-17 04:07:02 +13:00
|
|
|
rgame.set_worker(None)
|
|
|
|
self.queue_workers.remove(worker)
|
|
|
|
self.__signals.application.update_statusbar.emit()
|
|
|
|
|
2023-05-02 00:25:30 +12:00
|
|
|
def active_workers(self) -> Iterable[QueueWorker]:
|
2024-02-13 05:30:23 +13:00
|
|
|
# return list(filter(lambda w: w.state == QueueWorkerState.ACTIVE, self.queue_workers))
|
|
|
|
yield from filter(lambda w: w.state == QueueWorkerState.ACTIVE, self.queue_workers)
|
2023-02-16 21:50:53 +13:00
|
|
|
|
2023-05-02 00:25:30 +12:00
|
|
|
def queued_workers(self) -> Iterable[QueueWorker]:
|
2024-02-13 05:30:23 +13:00
|
|
|
# return list(filter(lambda w: w.state == QueueWorkerState.QUEUED, self.queue_workers))
|
|
|
|
yield from filter(lambda w: w.state == QueueWorkerState.QUEUED, self.queue_workers)
|
2023-02-16 21:50:53 +13:00
|
|
|
|
2024-02-13 05:30:23 +13:00
|
|
|
def queue_info(self) -> Iterable[QueueWorkerInfo]:
|
|
|
|
# return (w.worker_info() for w in self.queue_workers)
|
|
|
|
for w in self.queue_workers:
|
|
|
|
yield w.worker_info()
|
2023-02-01 02:43:26 +13:00
|
|
|
|
2022-09-05 05:38:24 +12:00
|
|
|
@staticmethod
|
|
|
|
def instance() -> 'RareCore':
|
2023-02-06 06:12:50 +13:00
|
|
|
if RareCore.__instance is None:
|
2022-09-05 05:38:24 +12:00
|
|
|
raise RuntimeError("Uninitialized use of RareCore")
|
2023-02-06 06:12:50 +13:00
|
|
|
return RareCore.__instance
|
2022-09-05 05:38:24 +12:00
|
|
|
|
|
|
|
def signals(self, init: bool = False) -> GlobalSignals:
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.__signals is None and not init:
|
2022-09-05 05:38:24 +12:00
|
|
|
raise RuntimeError("Uninitialized use of GlobalSignalsSingleton")
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.__signals is not None and init:
|
2022-09-05 05:38:24 +12:00
|
|
|
raise RuntimeError("GlobalSignals already initialized")
|
|
|
|
if init:
|
2023-01-21 13:15:06 +13:00
|
|
|
self.__signals = GlobalSignals()
|
|
|
|
return self.__signals
|
2022-09-05 05:38:24 +12:00
|
|
|
|
|
|
|
def args(self, args: Namespace = None) -> Optional[Namespace]:
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.__args is None and args is None:
|
2022-09-05 05:38:24 +12:00
|
|
|
raise RuntimeError("Uninitialized use of ArgumentsSingleton")
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.__args is not None and args is not None:
|
2022-09-05 05:38:24 +12:00
|
|
|
raise RuntimeError("Arguments already initialized")
|
|
|
|
if args is not None:
|
2023-01-21 13:15:06 +13:00
|
|
|
self.__args = args
|
|
|
|
return self.__args
|
2022-09-05 05:38:24 +12:00
|
|
|
|
|
|
|
def core(self, init: bool = False) -> LegendaryCore:
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.__core is None and not init:
|
2022-09-05 05:38:24 +12:00
|
|
|
raise RuntimeError("Uninitialized use of LegendaryCoreSingleton")
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.__core is not None and init:
|
2022-09-05 05:38:24 +12:00
|
|
|
raise RuntimeError("LegendaryCore already initialized")
|
|
|
|
if init:
|
|
|
|
try:
|
2023-01-21 13:15:06 +13:00
|
|
|
self.__core = LegendaryCore()
|
2022-09-05 05:38:24 +12:00
|
|
|
except configparser.MissingSectionHeaderError as e:
|
2023-12-17 00:52:06 +13:00
|
|
|
logger.warning("Config is corrupt: %s", e)
|
2023-12-16 11:39:00 +13:00
|
|
|
if config_path := os.environ.get('LEGENDARY_CONFIG_PATH'):
|
|
|
|
path = config_path
|
|
|
|
elif config_path := os.environ.get('XDG_CONFIG_HOME'):
|
|
|
|
path = os.path.join(config_path, 'legendary')
|
2022-09-05 05:38:24 +12:00
|
|
|
else:
|
2023-12-16 11:39:00 +13:00
|
|
|
path = os.path.expanduser('~/.config/legendary')
|
2023-12-17 00:52:06 +13:00
|
|
|
logger.info("Creating config in path: %s", config_path)
|
2022-09-05 05:38:24 +12:00
|
|
|
with open(os.path.join(path, "config.ini"), "w") as config_file:
|
|
|
|
config_file.write("[Legendary]")
|
2023-01-21 13:15:06 +13:00
|
|
|
self.__core = LegendaryCore()
|
2023-12-17 02:40:01 +13:00
|
|
|
|
|
|
|
# Initialize sections if they don't exist
|
2023-06-11 22:23:43 +12:00
|
|
|
for section in ["Legendary", "default", "default.env"]:
|
|
|
|
if section not in self.__core.lgd.config.sections():
|
|
|
|
self.__core.lgd.config.add_section(section)
|
2023-12-17 02:40:01 +13:00
|
|
|
|
|
|
|
# Set some platform defaults if unset
|
|
|
|
def check_config(option: str, accepted: Set = None) -> bool:
|
|
|
|
_exists = self.__core.lgd.config.has_option("Legendary", option)
|
|
|
|
_value = self.__core.lgd.config.get("Legendary", option, fallback="")
|
|
|
|
_accepted = _value in accepted if accepted is not None else True
|
|
|
|
return _exists and bool(_value) and _accepted
|
|
|
|
|
|
|
|
if not check_config("default_platform", {"Windows", "Win32", "Mac"}):
|
|
|
|
self.__core.lgd.config.set("Legendary", "default_platform", self.__core.default_platform)
|
|
|
|
if not check_config("install_dir"):
|
|
|
|
self.__core.lgd.config.set(
|
|
|
|
"Legendary", "install_dir", self.__core.get_default_install_dir()
|
|
|
|
)
|
|
|
|
if not check_config("mac_install_dir"):
|
|
|
|
self.__core.lgd.config.set(
|
|
|
|
"Legendary", "mac_install_dir", self.__core.get_default_install_dir(self.__core.default_platform)
|
|
|
|
)
|
2023-12-23 23:16:57 +13:00
|
|
|
|
2023-12-17 03:23:58 +13:00
|
|
|
# Always set these options
|
2023-12-23 23:16:57 +13:00
|
|
|
# Avoid implicitly falling back to Windows games on macOS
|
|
|
|
self.__core.lgd.config.set("Legendary", "install_platform_fallback", str(False))
|
|
|
|
# Force-disable automatic use of crossover on macOS (remove this when we support crossover)
|
|
|
|
self.__core.lgd.config.set("Legendary", "disable_auto_crossover", str(True))
|
|
|
|
# Force-disable automatic sync with EGL, it seems to have issues
|
|
|
|
self.__core.lgd.config.set("Legendary", "egl_sync", str(False))
|
2023-12-17 02:40:01 +13:00
|
|
|
|
2022-09-05 05:38:24 +12:00
|
|
|
# workaround if egl sync enabled, but no programdata_path
|
|
|
|
# programdata_path might be unset if logging in through the browser
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.__core.egl_sync_enabled:
|
|
|
|
if self.__core.egl.programdata_path is None:
|
|
|
|
self.__core.lgd.config.remove_option("Legendary", "egl_sync")
|
2022-09-05 05:38:24 +12:00
|
|
|
else:
|
2023-01-21 13:15:06 +13:00
|
|
|
if not os.path.exists(self.__core.egl.programdata_path):
|
|
|
|
self.__core.lgd.config.remove_option("Legendary", "egl_sync")
|
2023-12-17 02:40:01 +13:00
|
|
|
|
2023-06-11 22:23:43 +12:00
|
|
|
self.__core.lgd.save_config()
|
2023-01-21 13:15:06 +13:00
|
|
|
return self.__core
|
2022-09-05 05:38:24 +12:00
|
|
|
|
|
|
|
def image_manager(self, init: bool = False) -> ImageManager:
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.__image_manager is None and not init:
|
2022-09-05 05:38:24 +12:00
|
|
|
raise RuntimeError("Uninitialized use of ImageManagerSingleton")
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.__image_manager is not None and init:
|
2022-09-05 05:38:24 +12:00
|
|
|
raise RuntimeError("ImageManager already initialized")
|
2023-01-21 13:15:06 +13:00
|
|
|
if self.__image_manager is None:
|
|
|
|
self.__image_manager = ImageManager(self.signals(), self.core())
|
|
|
|
return self.__image_manager
|
2022-09-05 05:38:24 +12:00
|
|
|
|
2023-09-20 10:39:15 +12:00
|
|
|
def wrappers(self) -> Wrappers:
|
|
|
|
return self.__wrappers
|
|
|
|
|
|
|
|
def settings(self) -> QSettings:
|
|
|
|
return self.__settings
|
|
|
|
|
2022-09-05 05:38:24 +12:00
|
|
|
def deleteLater(self) -> None:
|
2023-01-21 13:15:06 +13:00
|
|
|
self.__image_manager.deleteLater()
|
|
|
|
del self.__image_manager
|
|
|
|
self.__image_manager = None
|
2022-09-05 05:38:24 +12:00
|
|
|
|
2023-01-21 13:15:06 +13:00
|
|
|
self.__core.exit()
|
|
|
|
del self.__core
|
|
|
|
self.__core = None
|
2022-09-05 05:38:24 +12:00
|
|
|
|
2023-01-21 13:15:06 +13:00
|
|
|
self.__signals.deleteLater()
|
|
|
|
del self.__signals
|
|
|
|
self.__signals = None
|
2022-09-05 05:38:24 +12:00
|
|
|
|
2023-01-21 13:15:06 +13:00
|
|
|
del self.__args
|
|
|
|
self.__args = None
|
2022-09-05 05:38:24 +12:00
|
|
|
|
2023-12-18 06:34:08 +13:00
|
|
|
# del self.__eos_overlay
|
|
|
|
self.__eos_overlay = None
|
|
|
|
|
2023-02-06 06:12:50 +13:00
|
|
|
RareCore.__instance = None
|
2022-09-05 05:38:24 +12:00
|
|
|
super(RareCore, self).deleteLater()
|
|
|
|
|
2023-03-13 11:04:11 +13:00
|
|
|
def __validate_install(self, rgame: RareGame):
|
2023-03-13 05:59:58 +13:00
|
|
|
if not os.path.exists(rgame.igame.install_path):
|
|
|
|
# lk: since install_path is lost anyway, set keep_files to True
|
|
|
|
# lk: to avoid spamming the log with "file not found" errors
|
|
|
|
for dlc in rgame.owned_dlcs:
|
|
|
|
if dlc.is_installed:
|
|
|
|
logger.info(f'Uninstalling DLC "{dlc.app_name}" ({dlc.app_title})...')
|
2023-09-09 04:38:39 +12:00
|
|
|
uninstall_game(self.__core, dlc, keep_files=True, keep_config=True)
|
2023-03-13 05:59:58 +13:00
|
|
|
dlc.igame = None
|
|
|
|
logger.info(
|
|
|
|
f'Removing "{rgame.app_title}" because "{rgame.igame.install_path}" does not exist...'
|
2023-03-05 00:23:18 +13:00
|
|
|
)
|
2023-09-09 04:38:39 +12:00
|
|
|
uninstall_game(self.__core, rgame, keep_files=True, keep_config=True)
|
2023-03-13 05:59:58 +13:00
|
|
|
logger.info(f"Uninstalled {rgame.app_title}, because no game files exist")
|
|
|
|
rgame.igame = None
|
|
|
|
return
|
|
|
|
# lk: games that don't have an override and can't find their executable due to case sensitivity
|
|
|
|
# lk: will still erroneously require verification. This might need to be removed completely
|
|
|
|
# lk: or be decoupled from the verification requirement
|
|
|
|
if override_exe := self.__core.lgd.config.get(rgame.app_name, "override_exe", fallback=""):
|
|
|
|
igame_executable = override_exe
|
|
|
|
else:
|
|
|
|
igame_executable = rgame.igame.executable
|
|
|
|
# lk: Case-insensitive search for the game's executable (example: Brothers - A Tale of two Sons)
|
|
|
|
executable_path = os.path.join(rgame.igame.install_path, igame_executable.replace("\\", "/").lstrip("/"))
|
|
|
|
file_list = map(str.lower, os.listdir(os.path.dirname(executable_path)))
|
|
|
|
if not os.path.basename(executable_path).lower() in file_list:
|
|
|
|
rgame.igame.needs_verification = True
|
|
|
|
self.__core.lgd.set_installed_game(rgame.app_name, rgame.igame)
|
|
|
|
rgame.update_igame()
|
|
|
|
logger.info(f"{rgame.app_title} needs verification")
|
2023-03-05 00:23:18 +13:00
|
|
|
|
2023-02-19 04:27:18 +13:00
|
|
|
def get_game(self, app_name: str) -> Union[RareEosOverlay, RareGame]:
|
2023-01-21 13:15:06 +13:00
|
|
|
if app_name == EOSOverlayApp.app_name:
|
2023-03-12 23:22:44 +13:00
|
|
|
return self.__eos_overlay
|
|
|
|
return self.__library[app_name]
|
2023-01-05 09:38:05 +13:00
|
|
|
|
2023-09-09 04:38:39 +12:00
|
|
|
def get_overlay(self):
|
|
|
|
return self.get_game(EOSOverlayApp.app_name)
|
|
|
|
|
2023-03-05 00:23:18 +13:00
|
|
|
def __add_game(self, rgame: RareGame) -> None:
|
2023-01-27 15:11:10 +13:00
|
|
|
rgame.signals.download.enqueue.connect(self.__signals.download.enqueue)
|
|
|
|
rgame.signals.download.dequeue.connect(self.__signals.download.dequeue)
|
2023-01-21 13:15:06 +13:00
|
|
|
rgame.signals.game.install.connect(self.__signals.game.install)
|
|
|
|
rgame.signals.game.installed.connect(self.__signals.game.installed)
|
2023-01-27 15:11:10 +13:00
|
|
|
rgame.signals.game.uninstall.connect(self.__signals.game.uninstall)
|
2023-01-21 13:15:06 +13:00
|
|
|
rgame.signals.game.uninstalled.connect(self.__signals.game.uninstalled)
|
|
|
|
rgame.signals.game.finished.connect(self.__signals.application.update_tray)
|
|
|
|
rgame.signals.game.finished.connect(lambda: self.__signals.discord_rpc.set_title.emit(""))
|
2023-03-12 23:22:44 +13:00
|
|
|
self.__library[rgame.app_name] = rgame
|
2023-01-05 09:38:05 +13:00
|
|
|
|
|
|
|
def __filter_games(self, condition: Callable[[RareGame], bool]) -> Iterator[RareGame]:
|
2023-03-12 23:22:44 +13:00
|
|
|
return filter(condition, self.__library.values())
|
2023-01-05 09:38:05 +13:00
|
|
|
|
2023-03-05 00:23:18 +13:00
|
|
|
def __create_or_update_rgame(self, game: Game) -> RareGame:
|
2023-03-12 23:22:44 +13:00
|
|
|
if rgame := self.__library.get(game.app_name, False):
|
2023-03-05 00:23:18 +13:00
|
|
|
logger.warning(f"{rgame.app_name} already present in {type(self).__name__}")
|
|
|
|
logger.info(f"Updating Game for {rgame.app_name}")
|
|
|
|
rgame.update_rgame()
|
|
|
|
else:
|
|
|
|
rgame = RareGame(self.__core, self.__image_manager, game)
|
2023-11-21 01:59:49 +13:00
|
|
|
self.__add_game(rgame)
|
2023-03-05 00:23:18 +13:00
|
|
|
return rgame
|
|
|
|
|
|
|
|
def __add_games_and_dlcs(self, games: List[Game], dlcs_dict: Dict[str, List]) -> None:
|
2023-03-13 11:04:11 +13:00
|
|
|
length = len(games)
|
|
|
|
for idx, game in enumerate(games):
|
2023-03-05 00:23:18 +13:00
|
|
|
rgame = self.__create_or_update_rgame(game)
|
|
|
|
if game_dlcs := dlcs_dict.get(rgame.game.catalog_item_id, False):
|
|
|
|
for dlc in game_dlcs:
|
|
|
|
rdlc = self.__create_or_update_rgame(dlc)
|
2023-11-21 01:59:49 +13:00
|
|
|
if rdlc not in rgame.owned_dlcs:
|
|
|
|
rgame.add_dlc(rdlc)
|
2023-06-14 02:12:58 +12:00
|
|
|
# lk: since loading has to know about game state,
|
|
|
|
# validate installation just adding each RareGamesu
|
|
|
|
# TODO: this should probably be moved into RareGame
|
|
|
|
if rgame.is_installed and not (rgame.is_dlc or rgame.is_non_asset):
|
2023-11-21 01:59:49 +13:00
|
|
|
try:
|
|
|
|
self.__validate_install(rgame)
|
|
|
|
except FileNotFoundError as e:
|
|
|
|
logger.info(f'Marking "{rgame.app_title}" as not installed because an exception has occurred...')
|
|
|
|
logger.error(e)
|
|
|
|
rgame.set_installed(False)
|
2023-09-15 09:40:28 +12:00
|
|
|
progress = int(idx/length * self.__fetch_progress) + (100 - self.__fetch_progress)
|
|
|
|
self.progress.emit(progress, self.tr("Loaded <b>{}</b>").format(rgame.app_title))
|
|
|
|
|
|
|
|
@pyqtSlot(int, str)
|
|
|
|
def __on_fetch_progress(self, increment: int, message: str):
|
|
|
|
self.__fetch_progress += increment
|
|
|
|
self.progress.emit(self.__fetch_progress, message)
|
2023-03-05 00:23:18 +13:00
|
|
|
|
|
|
|
@pyqtSlot(object, int)
|
2023-09-15 09:40:28 +12:00
|
|
|
def __on_fetch_result(self, result: Tuple, result_type: int):
|
|
|
|
if result_type == FetchWorker.Result.GAMESDLCS:
|
|
|
|
self.__add_games_and_dlcs(*result)
|
|
|
|
self.__fetched_games_dlcs = True
|
|
|
|
|
|
|
|
if result_type == FetchWorker.Result.ENTITLEMENTS:
|
|
|
|
self.__core.lgd.entitlements = result
|
|
|
|
self.__fetched_entitlements = True
|
|
|
|
|
2023-09-20 10:39:15 +12:00
|
|
|
logger.info("Acquired data from %s worker", FetchWorker.Result(result_type).name)
|
2023-09-15 09:40:28 +12:00
|
|
|
|
|
|
|
if all([self.__fetched_games_dlcs, self.__fetched_entitlements]):
|
2023-09-20 10:39:15 +12:00
|
|
|
logger.debug("Fetch time %s seconds", time.perf_counter() - self.__start_time)
|
|
|
|
self.__wrappers.import_wrappers(
|
|
|
|
self.__core, self.__settings, [rgame.app_name for rgame in self.games]
|
|
|
|
)
|
2023-09-15 09:40:28 +12:00
|
|
|
self.progress.emit(100, self.tr("Launching Rare"))
|
|
|
|
self.completed.emit()
|
|
|
|
QTimer.singleShot(100, self.__post_init)
|
2023-03-05 00:23:18 +13:00
|
|
|
|
|
|
|
def fetch(self):
|
2023-09-11 04:08:47 +12:00
|
|
|
self.__start_time = time.perf_counter()
|
2023-09-15 09:40:28 +12:00
|
|
|
|
|
|
|
games_dlcs_worker = GamesDlcsWorker(self.__core, self.__args)
|
|
|
|
games_dlcs_worker.signals.progress.connect(self.__on_fetch_progress)
|
|
|
|
games_dlcs_worker.signals.result.connect(self.__on_fetch_result)
|
|
|
|
|
|
|
|
entitlements_worker = EntitlementsWorker(self.__core, self.__args)
|
|
|
|
entitlements_worker.signals.progress.connect(self.__on_fetch_progress)
|
|
|
|
entitlements_worker.signals.result.connect(self.__on_fetch_result)
|
|
|
|
|
|
|
|
QThreadPool.globalInstance().start(games_dlcs_worker)
|
|
|
|
QThreadPool.globalInstance().start(entitlements_worker)
|
2023-03-05 00:23:18 +13:00
|
|
|
|
2023-03-13 00:09:09 +13:00
|
|
|
def fetch_saves(self):
|
2023-03-14 12:20:13 +13:00
|
|
|
def __fetch() -> None:
|
2023-03-13 00:09:09 +13:00
|
|
|
saves_dict: Dict[str, List[SaveGameFile]] = {}
|
|
|
|
try:
|
2023-09-11 04:08:47 +12:00
|
|
|
with timelogger(logger, "Request saves"):
|
|
|
|
saves_list = self.__core.get_save_games()
|
2023-03-13 00:09:09 +13:00
|
|
|
for s in saves_list:
|
2023-03-17 12:26:49 +13:00
|
|
|
if s.app_name not in saves_dict.keys():
|
2023-03-13 00:09:09 +13:00
|
|
|
saves_dict[s.app_name] = [s]
|
|
|
|
else:
|
|
|
|
saves_dict[s.app_name].append(s)
|
|
|
|
for app_name, saves in saves_dict.items():
|
2023-03-17 12:26:49 +13:00
|
|
|
if app_name not in self.__library.keys():
|
|
|
|
continue
|
2023-03-13 00:09:09 +13:00
|
|
|
self.__library[app_name].load_saves(saves)
|
|
|
|
except (HTTPError, ConnectionError) as e:
|
2023-09-20 10:39:15 +12:00
|
|
|
logger.error("Exception while fetching saves from EGS.")
|
2023-09-11 04:08:47 +12:00
|
|
|
logger.error(e)
|
2023-03-13 00:09:09 +13:00
|
|
|
return
|
2023-09-11 04:08:47 +12:00
|
|
|
logger.info(f"Saves: {len(saves_dict)}")
|
2023-03-13 00:09:09 +13:00
|
|
|
|
2023-03-14 12:20:13 +13:00
|
|
|
saves_worker = QRunnable.create(__fetch)
|
2023-03-13 00:09:09 +13:00
|
|
|
QThreadPool.globalInstance().start(saves_worker)
|
|
|
|
|
2023-03-12 23:44:43 +13:00
|
|
|
def resolve_origin(self) -> None:
|
|
|
|
origin_worker = OriginWineWorker(self.__core, list(self.origin_games))
|
|
|
|
QThreadPool.globalInstance().start(origin_worker)
|
|
|
|
|
|
|
|
def __post_init(self) -> None:
|
2023-04-17 05:38:26 +12:00
|
|
|
if not self.__args.offline:
|
|
|
|
self.fetch_saves()
|
2023-03-13 00:09:09 +13:00
|
|
|
self.resolve_origin()
|
2023-03-05 00:23:18 +13:00
|
|
|
|
2023-01-05 09:38:05 +13:00
|
|
|
@property
|
|
|
|
def games_and_dlcs(self) -> Iterator[RareGame]:
|
2023-03-12 23:22:44 +13:00
|
|
|
for app_name in self.__library:
|
|
|
|
yield self.__library[app_name]
|
2023-01-05 09:38:05 +13:00
|
|
|
|
|
|
|
@property
|
|
|
|
def games(self) -> Iterator[RareGame]:
|
2024-01-01 04:51:13 +13:00
|
|
|
return self.__filter_games(lambda game: not game.is_dlc or game.is_launchable_addon)
|
2023-01-05 09:38:05 +13:00
|
|
|
|
|
|
|
@property
|
|
|
|
def installed_games(self) -> Iterator[RareGame]:
|
|
|
|
return self.__filter_games(lambda game: game.is_installed and not game.is_dlc)
|
|
|
|
|
2023-02-02 01:17:51 +13:00
|
|
|
@property
|
|
|
|
def origin_games(self) -> Iterator[RareGame]:
|
|
|
|
return self.__filter_games(lambda game: game.is_origin and not game.is_dlc)
|
|
|
|
|
2023-09-05 06:05:40 +12:00
|
|
|
@property
|
|
|
|
def ubisoft_games(self) -> Iterator[RareGame]:
|
|
|
|
return self.__filter_games(lambda game: game.is_ubisoft and not game.is_dlc)
|
|
|
|
|
2023-01-05 09:38:05 +13:00
|
|
|
@property
|
|
|
|
def game_list(self) -> Iterator[Game]:
|
|
|
|
for game in self.games:
|
|
|
|
yield game.game
|
|
|
|
|
|
|
|
@property
|
2023-12-16 03:57:32 +13:00
|
|
|
def dlcs(self) -> Dict[str, set[RareGame]]:
|
2023-01-05 09:38:05 +13:00
|
|
|
"""!
|
|
|
|
RareGames that ARE DLCs themselves
|
|
|
|
"""
|
|
|
|
return {game.game.catalog_item_id: game.owned_dlcs for game in self.has_dlcs}
|
|
|
|
# return self.__filter_games(lambda game: game.is_dlc)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def has_dlcs(self) -> Iterator[RareGame]:
|
|
|
|
"""!
|
|
|
|
RareGames that HAVE DLCs associated with them
|
|
|
|
"""
|
|
|
|
return self.__filter_games(lambda game: bool(game.owned_dlcs))
|
|
|
|
|
|
|
|
@property
|
|
|
|
def bit32_games(self) -> Iterator[RareGame]:
|
|
|
|
return self.__filter_games(lambda game: game.is_win32)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def mac_games(self) -> Iterator[RareGame]:
|
|
|
|
return self.__filter_games(lambda game: game.is_mac)
|
|
|
|
|
|
|
|
@property
|
2023-02-02 01:17:51 +13:00
|
|
|
def non_asset_games(self) -> Iterator[RareGame]:
|
2023-01-05 09:38:05 +13:00
|
|
|
return self.__filter_games(lambda game: game.is_non_asset)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def unreal_engine(self) -> Iterator[RareGame]:
|
|
|
|
return self.__filter_games(lambda game: game.is_unreal)
|
|
|
|
|
|
|
|
@property
|
|
|
|
def updates(self) -> Iterator[RareGame]:
|
|
|
|
return self.__filter_games(lambda game: game.has_update)
|
|
|
|
|
|
|
|
@property
|
2023-03-11 03:55:31 +13:00
|
|
|
def saves(self) -> Iterator[RareSaveGame]:
|
2023-01-05 09:38:05 +13:00
|
|
|
"""!
|
|
|
|
SaveGameFiles across games
|
|
|
|
"""
|
2023-02-06 11:28:42 +13:00
|
|
|
return chain.from_iterable([game.saves for game in self.has_saves])
|
2023-01-05 09:38:05 +13:00
|
|
|
|
|
|
|
@property
|
|
|
|
def has_saves(self) -> Iterator[RareGame]:
|
|
|
|
"""!
|
|
|
|
RareGames that have SaveGameFiles associated with them
|
|
|
|
"""
|
2023-02-06 11:28:42 +13:00
|
|
|
return self.__filter_games(lambda game: bool(game.saves))
|
2023-01-05 09:38:05 +13:00
|
|
|
|