[cli/core] Allow overriding platform and UE filter in list-games

This commit is contained in:
derrod 2020-04-28 15:32:38 +02:00
parent e0b4769af2
commit 8251db22d2
2 changed files with 28 additions and 11 deletions

View file

@ -84,13 +84,15 @@ class LegendaryCLI:
else: else:
logger.error('Login attempt failed, please see log for details.') logger.error('Login attempt failed, please see log for details.')
def list_games(self): def list_games(self, args):
logger.info('Logging in...') logger.info('Logging in...')
if not self.core.login(): if not self.core.login():
logger.error('Login failed, cannot continue!') logger.error('Login failed, cannot continue!')
exit(1) exit(1)
logger.info('Getting game list... (this may take a while)') 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:') print('\nAvailable games:')
for game in sorted(games, key=lambda x: x.app_title): 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') uninstall_parser = subparsers.add_parser('uninstall', help='Uninstall (delete) a game')
launch_parser = subparsers.add_parser('launch', help='Launch a game', usage='%(prog)s <App Name> [options]', launch_parser = subparsers.add_parser('launch', help='Launch a game', usage='%(prog)s <App Name> [options]',
description='Note: additional arguments are passed to the game') 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') listi_parser = subparsers.add_parser('list-installed', help='List installed games')
install_parser.add_argument('app_name', help='Name of the app', metavar='<App Name>') install_parser.add_argument('app_name', help='Name of the app', metavar='<App Name>')
@ -388,6 +390,11 @@ def main():
launch_parser.add_argument('--dry-run', dest='dry_run', action='store_true', 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') 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='<Platform>',
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', listi_parser.add_argument('--check-updates', dest='check_updates', action='store_true',
help='Check for updates when listing installed games') help='Check for updates when listing installed games')
@ -424,7 +431,7 @@ def main():
if args.subparser_name == 'auth': if args.subparser_name == 'auth':
cli.auth(args) cli.auth(args)
elif args.subparser_name == 'list-games': elif args.subparser_name == 'list-games':
cli.list_games() cli.list_games(args)
elif args.subparser_name == 'list-installed': elif args.subparser_name == 'list-installed':
cli.list_installed(args) cli.list_installed(args)
elif args.subparser_name == 'launch': elif args.subparser_name == 'launch':

View file

@ -126,7 +126,12 @@ class LegendaryCore:
self.lgd.userdata = userdata self.lgd.userdata = userdata
return True 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: if not self.lgd.assets or update_assets:
self.lgd.assets = [GameAsset.from_egs_json(a) for a in self.egs.get_game_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]: def get_game_list(self, update_assets=True) -> List[Game]:
return self.get_game_and_dlc_list(update_assets=update_assets)[0] 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 = [] _ret = []
_dlc = defaultdict(list) _dlc = defaultdict(list)
for ga in self.get_assets(update_assets=update_assets): for ga in self.get_assets(update_assets=update_assets,
if ga.namespace == 'ue': # skip UE demo content platform_override=platform_override):
if ga.namespace == 'ue' and skip_ue:
continue continue
game = self.lgd.get_game_meta(ga.app_name) game = self.lgd.get_game_meta(ga.app_name)
if not game or (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: 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') 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) 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, game = Game(app_name=ga.app_name, app_version=ga.build_version,
app_title=eg_meta['title'], asset_info=ga, metadata=eg_meta) 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: if game.is_dlc:
_dlc[game.metadata['mainGameItem']['id']].append(game) _dlc[game.metadata['mainGameItem']['id']].append(game)