From 8251db22d22011ac34f1a928f0333fdd1fab4bf9 Mon Sep 17 00:00:00 2001 From: derrod Date: Tue, 28 Apr 2020 15:32:38 +0200 Subject: [PATCH] [cli/core] Allow overriding platform and UE filter in list-games --- legendary/cli.py | 15 +++++++++++---- legendary/core.py | 24 +++++++++++++++++------- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/legendary/cli.py b/legendary/cli.py index c4a6eba..5f95334 100644 --- a/legendary/cli.py +++ b/legendary/cli.py @@ -84,13 +84,15 @@ class LegendaryCLI: else: logger.error('Login attempt failed, please see log for details.') - def list_games(self): + def list_games(self, args): logger.info('Logging in...') if not self.core.login(): logger.error('Login failed, cannot continue!') exit(1) logger.info('Getting game list... (this may take a while)') - games, dlc_list = self.core.get_game_and_dlc_list() + games, dlc_list = self.core.get_game_and_dlc_list( + platform_override=args.platform_override, skip_ue=not args.include_ue + ) print('\nAvailable games:') for game in sorted(games, key=lambda x: x.app_title): @@ -340,7 +342,7 @@ def main(): uninstall_parser = subparsers.add_parser('uninstall', help='Uninstall (delete) a game') launch_parser = subparsers.add_parser('launch', help='Launch a game', usage='%(prog)s [options]', description='Note: additional arguments are passed to the game') - _ = subparsers.add_parser('list-games', help='List available (installable) games') + list_parser = subparsers.add_parser('list-games', help='List available (installable) games') listi_parser = subparsers.add_parser('list-installed', help='List installed games') install_parser.add_argument('app_name', help='Name of the app', metavar='') @@ -388,6 +390,11 @@ def main(): launch_parser.add_argument('--dry-run', dest='dry_run', action='store_true', help='Print the command line that would have been used to launch the game and exit') + list_parser.add_argument('--platform', dest='platform_override', action='store', metavar='', + type=str, help='Override platform that games are shown for') + list_parser.add_argument('--include-ue', dest='include_ue', action='store_true', + help='Also include Unreal Engine content in list') + listi_parser.add_argument('--check-updates', dest='check_updates', action='store_true', help='Check for updates when listing installed games') @@ -424,7 +431,7 @@ def main(): if args.subparser_name == 'auth': cli.auth(args) elif args.subparser_name == 'list-games': - cli.list_games() + cli.list_games(args) elif args.subparser_name == 'list-installed': cli.list_installed(args) elif args.subparser_name == 'launch': diff --git a/legendary/core.py b/legendary/core.py index 463b96b..0a14f41 100644 --- a/legendary/core.py +++ b/legendary/core.py @@ -126,7 +126,12 @@ class LegendaryCore: self.lgd.userdata = userdata return True - def get_assets(self, update_assets=False) -> List[GameAsset]: + def get_assets(self, update_assets=False, platform_override=None) -> List[GameAsset]: + # do not save and always fetch list when platform is overriden + if platform_override: + return [GameAsset.from_egs_json(a) for a in + self.egs.get_game_assets(platform=platform_override)] + if not self.lgd.assets or update_assets: self.lgd.assets = [GameAsset.from_egs_json(a) for a in self.egs.get_game_assets()] @@ -146,23 +151,28 @@ class LegendaryCore: def get_game_list(self, update_assets=True) -> List[Game]: return self.get_game_and_dlc_list(update_assets=update_assets)[0] - def get_game_and_dlc_list(self, update_assets=True) -> (List[Game], Dict[str, Game]): + def get_game_and_dlc_list(self, update_assets=True, + platform_override=None, + skip_ue=True) -> (List[Game], Dict[str, Game]): _ret = [] _dlc = defaultdict(list) - for ga in self.get_assets(update_assets=update_assets): - if ga.namespace == 'ue': # skip UE demo content + for ga in self.get_assets(update_assets=update_assets, + platform_override=platform_override): + if ga.namespace == 'ue' and skip_ue: continue game = self.lgd.get_game_meta(ga.app_name) - if not game or (game and game.app_version != ga.build_version): - if game and game.app_version != ga.build_version: + if not game or (game and game.app_version != ga.build_version and not platform_override): + if game and game.app_version != ga.build_version and not platform_override: self.log.info(f'Updating meta for {game.app_name} due to build version mismatch') eg_meta = self.egs.get_game_info(ga.namespace, ga.catalog_item_id) game = Game(app_name=ga.app_name, app_version=ga.build_version, app_title=eg_meta['title'], asset_info=ga, metadata=eg_meta) - self.lgd.set_game_meta(game.app_name, game) + + if not platform_override: + self.lgd.set_game_meta(game.app_name, game) if game.is_dlc: _dlc[game.metadata['mainGameItem']['id']].append(game)