Skip to content

Commit 6536473

Browse files
committed
[cli] Support running uninstaller on Windows
1 parent 6d7909c commit 6536473

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

legendary/cli.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1153,6 +1153,9 @@ def uninstall_game(self, args):
11531153
print('Aborting...')
11541154
exit(0)
11551155

1156+
if os.name == 'nt' and igame.uninstaller and not args.skip_uninstaller:
1157+
self._handle_uninstaller(igame, args.yes)
1158+
11561159
try:
11571160
if not igame.is_dlc:
11581161
# Remove DLC first so directory is empty when game uninstall runs
@@ -1169,6 +1172,32 @@ def uninstall_game(self, args):
11691172
except Exception as e:
11701173
logger.warning(f'Removing game failed: {e!r}, please remove {igame.install_path} manually.')
11711174

1175+
def _handle_uninstaller(self, igame, yes=False):
1176+
uninstaller = igame.uninstaller
1177+
1178+
print('\nThis game lists the following prerequisites to be installed:')
1179+
print(f'- {" ".join((uninstaller["path"], uninstaller["args"]))}\n')
1180+
1181+
# default to yes
1182+
c = 'y'
1183+
if not yes:
1184+
choice = input('Do you wish to run the uninstaller? ([y]es, [n]o): ')
1185+
if choice:
1186+
c = choice.lower()[0]
1187+
1188+
if c == 'y': # set to installed and launch installation
1189+
logger.info('Running uninstaller...')
1190+
req_path, req_exec = os.path.split(uninstaller['path'])
1191+
work_dir = os.path.join(igame.install_path, req_path)
1192+
fullpath = os.path.join(work_dir, req_exec)
1193+
try:
1194+
p = subprocess.Popen([fullpath, uninstaller['args']], cwd=work_dir, shell=True)
1195+
p.wait()
1196+
except Exception as e:
1197+
logger.error(f'Failed to run uninstaller: {e!r}')
1198+
elif c != 'n':
1199+
print('Invalid choice, not running uninstaller...')
1200+
11721201
def verify_game(self, args, print_command=True, repair_mode=False, repair_online=False):
11731202
args.app_name = self._resolve_aliases(args.app_name)
11741203
if not self.core.is_installed(args.app_name):
@@ -2757,6 +2786,8 @@ def main():
27572786

27582787
uninstall_parser.add_argument('--keep-files', dest='keep_files', action='store_true',
27592788
help='Keep files but remove game from Legendary database')
2789+
uninstall_parser.add_argument('--skip-uninstaller', dest='skip_uninstaller', action='store_true',
2790+
help='Skip running the uninstaller')
27602791

27612792
launch_parser.add_argument('--offline', dest='offline', action='store_true',
27622793
default=False, help='Skip login and launch game without online authentication')

0 commit comments

Comments
 (0)