MCPcopy
hub / github.com/legendary-gl/legendary / list_installed

Method list_installed

legendary/cli.py:269–339  ·  view source on GitHub ↗
(self, args)

Source from the content-addressed store, hash-verified

267 print(f'\nTotal: {len(games)}')
268
269 def list_installed(self, args):
270 if args.check_updates:
271 logger.info('Logging in to check for updates...')
272 if not self.core.login():
273 logger.error('Login failed! Not checking for updates.')
274 else:
275 # Update assets for all platforms currently installed
276 for app_platform in self.core.get_installed_platforms():
277 self.core.get_assets(True, platform=app_platform)
278
279 games = sorted(self.core.get_installed_list(include_dlc=True),
280 key=lambda x: x.title.lower())
281
282 versions = dict()
283 for game in games:
284 try:
285 versions[game.app_name] = self.core.get_asset(game.app_name, platform=game.platform).build_version
286 except ValueError:
287 logger.warning(f'Metadata for "{game.app_name}" is missing, the game may have been removed from '
288 f'your account or not be in legendary\'s database yet, try rerunning the command '
289 f'with "--check-updates".')
290
291 if args.csv or args.tsv:
292 writer = csv.writer(stdout, dialect='excel-tab' if args.tsv else 'excel', lineterminator='\n')
293 writer.writerow(['App name', 'App title', 'Installed version', 'Available version',
294 'Update available', 'Install size', 'Install path', 'Platform'])
295 writer.writerows((game.app_name, game.title, game.version, versions[game.app_name],
296 versions[game.app_name] != game.version, game.install_size, game.install_path,
297 game.platform)
298 for game in games if game.app_name in versions)
299 return
300
301 if args.json:
302 return self._print_json([vars(g) for g in games], args.pretty_json)
303
304 installed_dlcs = defaultdict(list)
305 for game in games.copy():
306 if not game.is_dlc:
307 continue
308 games.remove(game)
309 dlc = self.core.get_game(game.app_name)
310 if not dlc or not dlc.metadata:
311 logger.warning(f'DLC "{game.app_name}" is missing metadata for some reason. '
312 f'Running "legendary list-games" may fix this.')
313 continue
314 main_app_name = dlc.metadata['mainGameItem']['releaseInfo'][0]['appId']
315 installed_dlcs[main_app_name].append(game)
316
317 print('\nInstalled games:')
318 for game in games:
319 if game.install_size == 0 and self.core.lgd.lock_installed():
320 logger.debug(f'Updating missing size for {game.app_name}')
321 m = self.core.load_manifest(self.core.get_installed_manifest(game.app_name)[0])
322 game.install_size = sum(fm.file_size for fm in m.file_manifest_list.elements)
323 self.core.install_game(game)
324
325 print(f' * {game.title} (App name: {game.app_name} | Version: {game.version} | '
326 f'Platform: {game.platform} | {game.install_size / (1024 * 1024 * 1024):.02f} GiB)')

Callers 1

mainFunction · 0.95

Calls 12

_print_jsonMethod · 0.95
infoMethod · 0.80
loginMethod · 0.80
get_assetsMethod · 0.80
get_assetMethod · 0.80
get_gameMethod · 0.80
lock_installedMethod · 0.80
get_installed_listMethod · 0.45
load_manifestMethod · 0.45
install_gameMethod · 0.45

Tested by

no test coverage detected