From fbd0df1ecc70c3178a72fe8cca37b6dff005e414 Mon Sep 17 00:00:00 2001 From: derrod Date: Fri, 10 Sep 2021 20:23:16 +0200 Subject: [PATCH] [cli/core] Include DLCs in installed games list This should be replaced later on by including information about the main game in the InstalledGame metadata. --- legendary/cli.py | 16 +++++++++++++++- legendary/core.py | 11 +++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/legendary/cli.py b/legendary/cli.py index 6e96708..3ce8ff5 100644 --- a/legendary/cli.py +++ b/legendary/cli.py @@ -11,6 +11,7 @@ import subprocess import time import webbrowser +from collections import defaultdict from distutils.util import strtobool from logging.handlers import QueueListener from multiprocessing import freeze_support, Queue as MPQueue @@ -216,7 +217,7 @@ class LegendaryCLI: else: self.core.get_assets(True) - games = sorted(self.core.get_installed_list(), + games = sorted(self.core.get_installed_list(include_dlc=True), key=lambda x: x.title.lower()) versions = dict() @@ -241,6 +242,15 @@ class LegendaryCLI: print(json.dumps([vars(g) for g in games], indent=2, sort_keys=True)) return + installed_dlcs = defaultdict(list) + for game in games.copy(): + if not game.is_dlc: + continue + games.remove(game) + dlc = self.core.get_game(game.app_name) + main_app_name = dlc.metadata['mainGameItem']['releaseInfo'][0]['appId'] + installed_dlcs[main_app_name].append(game) + print('\nInstalled games:') for game in games: if game.install_size == 0: @@ -257,6 +267,10 @@ class LegendaryCLI: print(f' ! Game does no longer appear to be installed (directory "{game.install_path}" missing)!') elif game.app_name in versions and versions[game.app_name] != game.version: print(f' -> Update available! Installed: {game.version}, Latest: {versions[game.app_name]}') + for dlc in installed_dlcs[game.app_name]: + print(f' + {dlc.title} (App name: {dlc.app_name} | Version: {dlc.version})') + if dlc.app_name in versions and versions[dlc.app_name] != dlc.version: + print(f' -> Update available! Installed: {dlc.version}, Latest: {versions[dlc.app_name]}') print(f'\nTotal: {len(games)}') diff --git a/legendary/core.py b/legendary/core.py index 5f7bfca..3377725 100644 --- a/legendary/core.py +++ b/legendary/core.py @@ -387,15 +387,18 @@ class LegendaryCore: _, dlcs = self.get_game_and_dlc_list(update_assets=False) return dlcs[game.asset_info.catalog_item_id] - def get_installed_list(self) -> List[InstalledGame]: + def get_installed_list(self, include_dlc=False) -> List[InstalledGame]: if self.egl_sync_enabled: self.log.debug('Running EGL sync...') self.egl_sync() - return self._get_installed_list() + return self._get_installed_list(include_dlc) - def _get_installed_list(self) -> List[InstalledGame]: - return [g for g in self.lgd.get_installed_list() if not g.is_dlc] + def _get_installed_list(self, include_dlc=False) -> List[InstalledGame]: + if include_dlc: + return self.lgd.get_installed_list() + else: + return [g for g in self.lgd.get_installed_list() if not g.is_dlc] def get_installed_dlc_list(self) -> List[InstalledGame]: return [g for g in self.lgd.get_installed_list() if g.is_dlc]