From 0ef916e9c5c5def15fca517c69c26c91ae3a5748 Mon Sep 17 00:00:00 2001 From: derrod Date: Sat, 16 Oct 2021 19:44:48 +0200 Subject: [PATCH] [cli/lfs] Prune game metadata that's no longer needed --- legendary/core.py | 19 +++++++++++++++++++ legendary/lfs/lgndry.py | 3 +++ 2 files changed, 22 insertions(+) diff --git a/legendary/core.py b/legendary/core.py index 8256f47..92b5214 100644 --- a/legendary/core.py +++ b/legendary/core.py @@ -394,9 +394,28 @@ class LegendaryCore: if not platform_override: self.update_aliases(force=meta_updated) + if meta_updated: + self._prune_metadata() return _ret, _dlc + def _prune_metadata(self): + # compile list of games without assets, then delete their metadata + available_assets = {i.app_name for i in self.get_assets()} + + for app_name in self.lgd.get_game_app_names(): + if app_name in available_assets: + continue + # if metadata is still used by an install hold-off on deleting it + if self.is_installed(app_name): + continue + game = self.get_game(app_name) + # Origin games etc. + if game.third_party_store: + continue + self.log.debug(f'Removing old/unused metadata for "{app_name}"') + self.lgd.delete_game_meta(app_name) + def get_non_asset_library_items(self, force_refresh=False, skip_ue=True) -> (List[Game], Dict[str, List[Game]]): """ diff --git a/legendary/lfs/lgndry.py b/legendary/lfs/lgndry.py index 3dbbcac..7a445d7 100644 --- a/legendary/lfs/lgndry.py +++ b/legendary/lfs/lgndry.py @@ -230,6 +230,9 @@ class LGDLFS: else: raise ValueError(f'Game {app_name} does not exist in metadata DB!') + def get_game_app_names(self): + return sorted(self._game_metadata.keys()) + def get_tmp_path(self): return os.path.join(self.path, 'tmp')