Rare: Add launchable addons as games in the library
This commit is contained in:
parent
ef09354b62
commit
2cbe6cadd9
|
@ -37,9 +37,8 @@ class PreLaunchThread(QRunnable):
|
|||
|
||||
def __init__(self, core: LegendaryCore, args: InitArgs, rgame: RareGameSlim, sync_action=None):
|
||||
super(PreLaunchThread, self).__init__()
|
||||
self.logger = getLogger(type(self).__name__)
|
||||
self.core = core
|
||||
self.signals = self.Signals()
|
||||
self.logger = getLogger(type(self).__name__)
|
||||
self.args = args
|
||||
self.rgame = rgame
|
||||
self.sync_action = sync_action
|
||||
|
@ -60,7 +59,7 @@ class PreLaunchThread(QRunnable):
|
|||
|
||||
def prepare_launch(self, args: InitArgs) -> Optional[LaunchArgs]:
|
||||
try:
|
||||
launch_args = get_launch_args(self.core, args)
|
||||
launch_args = get_launch_args(self.rgame, args)
|
||||
except Exception as e:
|
||||
self.signals.error_occurred.emit(str(e))
|
||||
return None
|
||||
|
|
|
@ -7,10 +7,9 @@ from logging import getLogger
|
|||
from typing import List
|
||||
|
||||
from PyQt5.QtCore import QProcess, QProcessEnvironment
|
||||
from legendary.models.game import InstalledGame, LaunchParameters
|
||||
|
||||
from rare.lgndr.core import LegendaryCore
|
||||
from legendary.models.game import LaunchParameters
|
||||
|
||||
from rare.models.base_game import RareGameSlim
|
||||
|
||||
logger = getLogger("Helper")
|
||||
|
||||
|
@ -55,9 +54,11 @@ class LaunchArgs:
|
|||
return bool(self.executable)
|
||||
|
||||
|
||||
def get_origin_params(core: LegendaryCore, app_name, offline: bool,
|
||||
launch_args: LaunchArgs) -> LaunchArgs:
|
||||
origin_uri = core.get_origin_uri(app_name, offline)
|
||||
def get_origin_params(rgame: RareGameSlim, init_args: InitArgs, launch_args: LaunchArgs) -> LaunchArgs:
|
||||
core = rgame.core
|
||||
app_name = rgame.app_name
|
||||
|
||||
origin_uri = core.get_origin_uri(app_name, init_args.offline)
|
||||
if platform.system() == "Windows":
|
||||
launch_args.executable = origin_uri
|
||||
launch_args.arguments = []
|
||||
|
@ -87,24 +88,25 @@ def get_origin_params(core: LegendaryCore, app_name, offline: bool,
|
|||
return launch_args
|
||||
|
||||
|
||||
def get_game_params(core: LegendaryCore, igame: InstalledGame, args: InitArgs,
|
||||
launch_args: LaunchArgs) -> LaunchArgs:
|
||||
def get_game_params(rgame: RareGameSlim, args: InitArgs, launch_args: LaunchArgs) -> LaunchArgs:
|
||||
if not args.offline: # skip for update
|
||||
if not args.skip_update_check and not core.is_noupdate_game(igame.app_name):
|
||||
# print("Checking for updates...")
|
||||
# check updates
|
||||
if not args.skip_update_check and not rgame.core.is_noupdate_game(rgame.app_name):
|
||||
try:
|
||||
latest = core.get_asset(
|
||||
igame.app_name, igame.platform, update=False
|
||||
)
|
||||
latest = rgame.core.get_asset(rgame.app_name, rgame.igame.platform, update=False)
|
||||
except ValueError:
|
||||
raise GameArgsError("Metadata doesn't exist")
|
||||
else:
|
||||
if latest.build_version != igame.version:
|
||||
if latest.build_version != rgame.igame.version:
|
||||
raise GameArgsError("Game is not up to date. Please update first")
|
||||
|
||||
params: LaunchParameters = core.get_launch_parameters(
|
||||
app_name=igame.app_name, offline=args.offline
|
||||
if (not rgame.igame or not rgame.igame.executable) and rgame.game is not None:
|
||||
# override installed game with base title
|
||||
if rgame.is_launchable_addon:
|
||||
app_name = rgame.game.metadata['mainGameItem']['releaseInfo'][0]['appId']
|
||||
rgame.igame = rgame.core.get_installed_game(app_name)
|
||||
|
||||
params: LaunchParameters = rgame.core.get_launch_parameters(
|
||||
app_name=rgame.game.app_name, offline=args.offline, addon_app_name=rgame.igame.app_name
|
||||
)
|
||||
|
||||
full_params = []
|
||||
|
@ -135,32 +137,30 @@ def get_game_params(core: LegendaryCore, igame: InstalledGame, args: InitArgs,
|
|||
return launch_args
|
||||
|
||||
|
||||
def get_launch_args(core: LegendaryCore, args: InitArgs = None) -> LaunchArgs:
|
||||
game = core.get_game(args.app_name)
|
||||
igame = core.get_installed_game(args.app_name)
|
||||
def get_launch_args(rgame: RareGameSlim, init_args: InitArgs = None) -> LaunchArgs:
|
||||
|
||||
resp = LaunchArgs()
|
||||
|
||||
if not game:
|
||||
raise GameArgsError("Could not find metadata for ")
|
||||
if not rgame.game:
|
||||
raise GameArgsError(f"Could not find metadata for {rgame.app_title}")
|
||||
|
||||
if game.third_party_store == "Origin":
|
||||
args.offline = False
|
||||
if rgame.is_origin:
|
||||
init_args.offline = False
|
||||
else:
|
||||
if not igame:
|
||||
if not rgame.is_installed:
|
||||
raise GameArgsError("Game is not installed or has unsupported format")
|
||||
|
||||
if game.is_dlc:
|
||||
if rgame.is_dlc:
|
||||
raise GameArgsError("Game is a DLC")
|
||||
if not os.path.exists(igame.install_path):
|
||||
if not os.path.exists(rgame.install_path):
|
||||
raise GameArgsError("Game path does not exist")
|
||||
|
||||
if game.third_party_store == "Origin":
|
||||
resp = get_origin_params(core, args.app_name, args.offline, resp)
|
||||
if rgame.is_origin:
|
||||
resp = get_origin_params(rgame, init_args, resp)
|
||||
else:
|
||||
resp = get_game_params(core, igame, args, resp)
|
||||
resp = get_game_params(rgame, init_args, resp)
|
||||
|
||||
pre_cmd, wait = core.get_pre_launch_command(args.app_name)
|
||||
pre_cmd, wait = rgame.core.get_pre_launch_command(init_args.app_name)
|
||||
resp.pre_launch_command, resp.pre_launch_wait = pre_cmd, wait
|
||||
return resp
|
||||
|
||||
|
|
|
@ -160,6 +160,24 @@ class RareGameBase(QObject):
|
|||
def is_overlay(self):
|
||||
return self.app_name == eos.EOSOverlayApp.app_name
|
||||
|
||||
@property
|
||||
def is_dlc(self) -> bool:
|
||||
"""!
|
||||
@brief Property to report if Game is a dlc
|
||||
|
||||
@return bool
|
||||
"""
|
||||
return self.game.is_dlc
|
||||
|
||||
@property
|
||||
def is_launchable_addon(self) -> bool:
|
||||
# lk: the attribute doesn't exist in the currently released version
|
||||
# FIXME: remove after legendary >= 0.20.35
|
||||
try:
|
||||
return self.game.is_launchable_addon
|
||||
except AttributeError:
|
||||
return False
|
||||
|
||||
@property
|
||||
def version(self) -> str:
|
||||
"""!
|
||||
|
@ -190,7 +208,9 @@ class RareGameSlim(RareGameBase):
|
|||
|
||||
@property
|
||||
def is_installed(self) -> bool:
|
||||
return True
|
||||
if self.is_origin:
|
||||
return True
|
||||
return self.igame is not None
|
||||
|
||||
def set_installed(self, installed: bool) -> None:
|
||||
pass
|
||||
|
|
|
@ -376,15 +376,6 @@ class RareGame(RareGameSlim):
|
|||
if not needs and os.path.exists(self.repair_file):
|
||||
os.unlink(self.repair_file)
|
||||
|
||||
@property
|
||||
def is_dlc(self) -> bool:
|
||||
"""!
|
||||
@brief Property to report if Game is a dlc
|
||||
|
||||
@return bool
|
||||
"""
|
||||
return self.game.is_dlc
|
||||
|
||||
@property
|
||||
def is_unreal(self) -> bool:
|
||||
"""!
|
||||
|
|
|
@ -374,7 +374,7 @@ class RareCore(QObject):
|
|||
|
||||
@property
|
||||
def games(self) -> Iterator[RareGame]:
|
||||
return self.__filter_games(lambda game: not game.is_dlc)
|
||||
return self.__filter_games(lambda game: not game.is_dlc or game.is_launchable_addon)
|
||||
|
||||
@property
|
||||
def installed_games(self) -> Iterator[RareGame]:
|
||||
|
|
|
@ -2,8 +2,10 @@ requests
|
|||
PyQt5
|
||||
QtAwesome
|
||||
setuptools
|
||||
legendary-gl>=0.20.33
|
||||
legendary-gl>=0.20.34; platform_system != "Windows" or platform_system != "Darwin"
|
||||
legendary-gl @ git+https://github.com/derrod/legendary@96e07ff ; platform_system == "Windows" or platform_system == "Darwin"
|
||||
orjson
|
||||
vdf; platform_system != "Windows"
|
||||
pywin32; platform_system == "Windows"
|
||||
pywebview[qt]; platform_system == "Linux"
|
||||
pywebview[qt]; platform_system == "FreeBSD"
|
||||
|
|
|
@ -2,7 +2,8 @@ requests
|
|||
PyQt5
|
||||
QtAwesome
|
||||
setuptools
|
||||
legendary-gl>=0.20.34
|
||||
legendary-gl>=0.20.34; platform_system != "Windows" or platform_system != "Darwin"
|
||||
legendary-gl @ git+https://github.com/derrod/legendary@96e07ff ; platform_system == "Windows" or platform_system == "Darwin"
|
||||
orjson
|
||||
vdf; platform_system != "Windows"
|
||||
pywin32; platform_system == "Windows"
|
||||
|
|
Loading…
Reference in a new issue