[cli] Make it possible to uninstall DLC

This commit is contained in:
derrod 2021-10-10 17:08:05 +02:00
parent 205f960ed4
commit 6d3a8af70b

View file

@ -958,9 +958,6 @@ class LegendaryCLI:
if not igame: if not igame:
logger.error(f'Game {args.app_name} not installed, cannot uninstall!') logger.error(f'Game {args.app_name} not installed, cannot uninstall!')
exit(0) exit(0)
if igame.is_dlc:
logger.error('Uninstalling DLC is not supported.')
exit(1)
if not args.yes: if not args.yes:
if not get_boolean_choice(f'Do you wish to uninstall "{igame.title}"?', default=False): if not get_boolean_choice(f'Do you wish to uninstall "{igame.title}"?', default=False):
@ -968,15 +965,17 @@ class LegendaryCLI:
exit(0) exit(0)
try: try:
# Remove DLC first so directory is empty when game uninstall runs if not igame.is_dlc:
dlcs = self.core.get_dlc_for_game(igame.app_name) # Remove DLC first so directory is empty when game uninstall runs
for dlc in dlcs: dlcs = self.core.get_dlc_for_game(igame.app_name)
if (idlc := self.core.get_installed_game(dlc.app_name)) is not None: for dlc in dlcs:
logger.info(f'Uninstalling DLC "{dlc.app_name}"...') if (idlc := self.core.get_installed_game(dlc.app_name)) is not None:
self.core.uninstall_game(idlc, delete_files=not args.keep_files) logger.info(f'Uninstalling DLC "{dlc.app_name}"...')
self.core.uninstall_game(idlc, delete_files=not args.keep_files)
logger.info(f'Removing "{igame.title}" from "{igame.install_path}"...') logger.info(f'Removing "{igame.title}" from "{igame.install_path}"...')
self.core.uninstall_game(igame, delete_files=not args.keep_files, delete_root_directory=True) self.core.uninstall_game(igame, delete_files=not args.keep_files,
delete_root_directory=not igame.is_dlc)
logger.info('Game has been uninstalled.') logger.info('Game has been uninstalled.')
except Exception as e: except Exception as e:
logger.warning(f'Removing game failed: {e!r}, please remove {igame.install_path} manually.') logger.warning(f'Removing game failed: {e!r}, please remove {igame.install_path} manually.')