2020-04-14 12:47:46 +00:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# coding: utf-8
|
|
|
|
|
|
|
|
import argparse
|
2020-04-30 09:12:26 +00:00
|
|
|
import csv
|
2020-04-14 12:47:46 +00:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import shlex
|
|
|
|
import subprocess
|
|
|
|
import time
|
|
|
|
import webbrowser
|
|
|
|
|
2020-04-29 08:56:47 +00:00
|
|
|
from logging.handlers import QueueListener
|
2020-04-26 11:19:28 +00:00
|
|
|
from multiprocessing import freeze_support, Queue as MPQueue
|
2020-04-30 09:12:26 +00:00
|
|
|
from sys import exit, stdout
|
2020-04-14 12:47:46 +00:00
|
|
|
|
2020-04-28 04:14:17 +00:00
|
|
|
from legendary import __version__, __codename__
|
2020-04-14 12:47:46 +00:00
|
|
|
from legendary.core import LegendaryCore
|
|
|
|
from legendary.models.exceptions import InvalidCredentialsError
|
2020-05-19 16:19:15 +00:00
|
|
|
from legendary.models.game import SaveGameStatus, VerifyResult
|
2020-05-04 12:21:25 +00:00
|
|
|
from legendary.utils.custom_parser import AliasedSubParsersAction
|
2020-05-19 16:19:15 +00:00
|
|
|
from legendary.utils.lfs import validate_files
|
2020-04-14 12:47:46 +00:00
|
|
|
|
2020-04-26 11:19:28 +00:00
|
|
|
# todo custom formatter for cli logger (clean info, highlighted error/warning)
|
2020-04-14 12:47:46 +00:00
|
|
|
logging.basicConfig(
|
2020-04-26 11:19:28 +00:00
|
|
|
format='[%(name)s] %(levelname)s: %(message)s',
|
2020-04-14 12:47:46 +00:00
|
|
|
level=logging.INFO
|
|
|
|
)
|
|
|
|
logger = logging.getLogger('cli')
|
|
|
|
|
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
class LegendaryCLI:
|
|
|
|
def __init__(self):
|
|
|
|
self.core = LegendaryCore()
|
|
|
|
self.logger = logging.getLogger('cli')
|
2020-04-26 11:19:28 +00:00
|
|
|
self.logging_queue = None
|
|
|
|
|
|
|
|
def setup_threaded_logging(self):
|
|
|
|
self.logging_queue = MPQueue(-1)
|
|
|
|
shandler = logging.StreamHandler()
|
2020-05-22 12:31:59 +00:00
|
|
|
sformatter = logging.Formatter('[%(name)s] %(levelname)s: %(message)s')
|
2020-04-26 11:19:28 +00:00
|
|
|
shandler.setFormatter(sformatter)
|
|
|
|
ql = QueueListener(self.logging_queue, shandler)
|
|
|
|
ql.start()
|
|
|
|
return ql
|
2020-04-14 12:47:46 +00:00
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
def auth(self, args):
|
2020-05-12 18:01:25 +00:00
|
|
|
if args.auth_delete:
|
|
|
|
self.core.lgd.invalidate_userdata()
|
|
|
|
return
|
|
|
|
|
2020-04-14 12:47:46 +00:00
|
|
|
try:
|
|
|
|
logger.info('Testing existing login data if present...')
|
2020-04-25 10:20:14 +00:00
|
|
|
if self.core.login():
|
2020-05-12 18:01:25 +00:00
|
|
|
logger.info('Stored credentials are still valid, if you wish to switch to a different '
|
|
|
|
'account, run "legendary auth --delete" and try again.')
|
2020-04-14 12:47:46 +00:00
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
except InvalidCredentialsError:
|
|
|
|
logger.error('Stored credentials were found but were no longer valid. Continuing with login...')
|
2020-04-25 10:20:14 +00:00
|
|
|
self.core.lgd.invalidate_userdata()
|
2020-04-14 12:47:46 +00:00
|
|
|
|
|
|
|
if os.name == 'nt' and args.import_egs_auth:
|
|
|
|
logger.info('Importing login session from the Epic Launcher...')
|
|
|
|
try:
|
2020-04-25 10:20:14 +00:00
|
|
|
if self.core.auth_import():
|
2020-04-14 12:47:46 +00:00
|
|
|
logger.info('Successfully imported login session from EGS!')
|
2020-04-25 10:20:14 +00:00
|
|
|
logger.info(f'Now logged in as user "{self.core.lgd.userdata["displayName"]}"')
|
2020-04-14 12:47:46 +00:00
|
|
|
exit(0)
|
|
|
|
else:
|
|
|
|
logger.warning('Login session from EGS seems to no longer be valid.')
|
|
|
|
exit(1)
|
|
|
|
except ValueError:
|
|
|
|
logger.error('No EGS login session found, please login normally.')
|
|
|
|
exit(1)
|
|
|
|
|
2020-05-12 18:01:25 +00:00
|
|
|
if not args.auth_code:
|
|
|
|
# unfortunately the captcha stuff makes a complete CLI login flow kinda impossible right now...
|
|
|
|
print('Please login via the epic web login!')
|
|
|
|
webbrowser.open(
|
|
|
|
'https://www.epicgames.com/id/login?redirectUrl=https%3A%2F%2Fwww.epicgames.com%2Fid%2Fapi%2Fexchange'
|
|
|
|
)
|
|
|
|
print('If web page did not open automatically, please navigate '
|
|
|
|
'to https://www.epicgames.com/id/login in your web browser')
|
|
|
|
print('- In case you opened the link manually; please open https://www.epicgames.com/id/api/exchange '
|
|
|
|
'in your web browser after you have finished logging in.')
|
|
|
|
exchange_code = input('Please enter code from JSON response: ')
|
|
|
|
exchange_token = exchange_code.strip().strip('"')
|
|
|
|
else:
|
|
|
|
exchange_token = args.auth_code
|
2020-04-14 12:47:46 +00:00
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
if self.core.auth_code(exchange_token):
|
|
|
|
logger.info(f'Successfully logged in as "{self.core.lgd.userdata["displayName"]}"')
|
2020-04-14 12:47:46 +00:00
|
|
|
else:
|
|
|
|
logger.error('Login attempt failed, please see log for details.')
|
|
|
|
|
2020-04-28 13:32:38 +00:00
|
|
|
def list_games(self, args):
|
2020-04-14 12:47:46 +00:00
|
|
|
logger.info('Logging in...')
|
2020-04-25 10:20:14 +00:00
|
|
|
if not self.core.login():
|
2020-04-14 12:47:46 +00:00
|
|
|
logger.error('Login failed, cannot continue!')
|
|
|
|
exit(1)
|
2020-04-18 00:11:58 +00:00
|
|
|
logger.info('Getting game list... (this may take a while)')
|
2020-04-28 13:32:38 +00:00
|
|
|
games, dlc_list = self.core.get_game_and_dlc_list(
|
|
|
|
platform_override=args.platform_override, skip_ue=not args.include_ue
|
|
|
|
)
|
2020-04-30 10:03:23 +00:00
|
|
|
# sort games and dlc by name
|
|
|
|
games = sorted(games, key=lambda x: x.app_title)
|
|
|
|
for citem_id in dlc_list.keys():
|
|
|
|
dlc_list[citem_id] = sorted(dlc_list[citem_id], key=lambda d: d.app_title)
|
|
|
|
|
|
|
|
if args.csv or args.tsv:
|
|
|
|
writer = csv.writer(stdout, dialect='excel-tab' if args.tsv else 'excel')
|
|
|
|
writer.writerow(['App name', 'App title', 'Version', 'Is DLC'])
|
|
|
|
for game in games:
|
|
|
|
writer.writerow((game.app_name, game.app_title, game.app_version, False))
|
|
|
|
for dlc in dlc_list[game.asset_info.catalog_item_id]:
|
|
|
|
writer.writerow((dlc.app_name, dlc.app_title, dlc.app_version, True))
|
|
|
|
return
|
2020-04-14 12:47:46 +00:00
|
|
|
|
|
|
|
print('\nAvailable games:')
|
2020-04-30 10:03:23 +00:00
|
|
|
for game in games:
|
|
|
|
print(f' * {game.app_title} (App name: {game.app_name}, version: {game.app_version})')
|
|
|
|
for dlc in dlc_list[game.asset_info.catalog_item_id]:
|
|
|
|
print(f' + {dlc.app_title} (App name: {dlc.app_name}, version: {dlc.app_version})')
|
2020-04-14 12:47:46 +00:00
|
|
|
|
|
|
|
print(f'\nTotal: {len(games)}')
|
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
def list_installed(self, args):
|
2020-04-14 12:47:46 +00:00
|
|
|
if args.check_updates:
|
|
|
|
logger.info('Logging in to check for updates...')
|
2020-04-25 10:20:14 +00:00
|
|
|
if not self.core.login():
|
2020-04-14 12:47:46 +00:00
|
|
|
logger.error('Login failed! Not checking for updates.')
|
|
|
|
else:
|
2020-04-25 10:20:14 +00:00
|
|
|
self.core.get_assets(True)
|
2020-04-14 12:47:46 +00:00
|
|
|
|
2020-04-30 10:03:23 +00:00
|
|
|
games = sorted(self.core.get_installed_list(),
|
|
|
|
key=lambda x: x.title)
|
|
|
|
|
|
|
|
versions = dict()
|
|
|
|
for game in games:
|
|
|
|
versions[game.app_name] = self.core.get_asset(game.app_name).build_version
|
|
|
|
|
|
|
|
if args.csv or args.tsv:
|
|
|
|
writer = csv.writer(stdout, dialect='excel-tab' if args.tsv else 'excel')
|
|
|
|
writer.writerow(['App name', 'App title', 'Installed version', 'Available version', 'Update available'])
|
|
|
|
writer.writerows((game.app_name, game.title, game.version, versions[game.app_name],
|
|
|
|
versions[game.app_name] != game.version) for game in games)
|
|
|
|
return
|
|
|
|
|
2020-04-14 12:47:46 +00:00
|
|
|
print('\nInstalled games:')
|
2020-04-30 10:03:23 +00:00
|
|
|
for game in games:
|
|
|
|
print(f' * {game.title} (App name: {game.app_name}, version: {game.version})')
|
|
|
|
if versions[game.app_name] != game.version:
|
|
|
|
print(f' -> Update available! Installed: {game.version}, Latest: {versions[game.app_name]}')
|
2020-04-14 12:47:46 +00:00
|
|
|
|
|
|
|
print(f'\nTotal: {len(games)}')
|
|
|
|
|
2020-04-30 09:12:26 +00:00
|
|
|
def list_files(self, args):
|
|
|
|
if args.platform_override:
|
|
|
|
args.force_download = True
|
|
|
|
|
2020-04-30 10:31:23 +00:00
|
|
|
if not args.override_manifest and not args.app_name:
|
|
|
|
print('You must provide either a manifest url/path or app name!')
|
|
|
|
return
|
|
|
|
|
2020-04-30 09:12:26 +00:00
|
|
|
# check if we even need to log in
|
|
|
|
if args.override_manifest:
|
|
|
|
logger.info(f'Loading manifest from "{args.override_manifest}"')
|
2020-04-30 09:42:09 +00:00
|
|
|
manifest_data, _ = self.core.get_uri_manfiest(args.override_manifest)
|
2020-04-30 09:12:26 +00:00
|
|
|
elif self.core.is_installed(args.app_name) and not args.force_download:
|
|
|
|
logger.info(f'Loading installed manifest for "{args.app_name}"')
|
2020-04-30 09:42:09 +00:00
|
|
|
manifest_data, _ = self.core.get_installed_manifest(args.app_name)
|
2020-04-30 09:12:26 +00:00
|
|
|
else:
|
|
|
|
logger.info(f'Logging in and downloading manifest for {args.app_name}')
|
|
|
|
if not self.core.login():
|
|
|
|
logger.error('Login failed! Cannot continue with download process.')
|
|
|
|
exit(1)
|
|
|
|
game = self.core.get_game(args.app_name, update_meta=True)
|
2020-04-30 09:42:09 +00:00
|
|
|
manifest_data, _ = self.core.get_cdn_manifest(game, platform_override=args.platform_override)
|
2020-04-30 09:12:26 +00:00
|
|
|
|
2020-04-30 09:42:09 +00:00
|
|
|
manifest = self.core.load_manfiest(manifest_data)
|
2020-04-30 09:12:26 +00:00
|
|
|
files = sorted(manifest.file_manifest_list.elements,
|
|
|
|
key=lambda a: a.filename.lower())
|
|
|
|
|
2020-05-01 12:34:34 +00:00
|
|
|
if args.install_tag:
|
|
|
|
files = [fm for fm in files if args.install_tag in fm.install_tags]
|
|
|
|
|
2020-04-30 09:12:26 +00:00
|
|
|
if args.hashlist:
|
|
|
|
for fm in files:
|
|
|
|
print(f'{fm.hash.hex()} *{fm.filename}')
|
2020-05-01 12:34:34 +00:00
|
|
|
elif args.csv or args.tsv:
|
|
|
|
writer = csv.writer(stdout, dialect='excel-tab' if args.tsv else 'excel')
|
|
|
|
writer.writerow(['path', 'hash', 'size', 'install_tags'])
|
|
|
|
writer.writerows((fm.filename, fm.hash.hex(), fm.file_size, '|'.join(fm.install_tags))for fm in files)
|
2020-04-30 09:12:26 +00:00
|
|
|
else:
|
2020-05-01 12:34:34 +00:00
|
|
|
install_tags = set()
|
2020-04-30 09:12:26 +00:00
|
|
|
for fm in files:
|
|
|
|
print(fm.filename)
|
2020-05-01 12:34:34 +00:00
|
|
|
for t in fm.install_tags:
|
|
|
|
install_tags.add(t)
|
2020-05-01 12:36:50 +00:00
|
|
|
if install_tags:
|
|
|
|
# use the log output so this isn't included when piping file list into file
|
|
|
|
logger.info(f'Install tags: {", ".join(sorted(install_tags))}')
|
2020-04-30 09:12:26 +00:00
|
|
|
|
2020-05-06 13:40:04 +00:00
|
|
|
def list_saves(self, args):
|
|
|
|
if not self.core.login():
|
|
|
|
logger.error('Login failed! Cannot continue with download process.')
|
|
|
|
exit(1)
|
|
|
|
# update game metadata
|
|
|
|
logger.debug('Refreshing games list...')
|
|
|
|
_ = self.core.get_game_and_dlc_list(update_assets=True)
|
|
|
|
# then get the saves
|
|
|
|
logger.info('Getting list of saves...')
|
|
|
|
saves = self.core.get_save_games(args.app_name)
|
|
|
|
last_app = ''
|
|
|
|
print('Save games:')
|
2020-05-12 00:22:10 +00:00
|
|
|
for save in sorted(saves, key=lambda a: a.app_name + a.manifest_name):
|
2020-05-06 13:40:04 +00:00
|
|
|
if save.app_name != last_app:
|
|
|
|
game_title = self.core.get_game(save.app_name).app_title
|
|
|
|
last_app = save.app_name
|
|
|
|
print(f'- {game_title} ("{save.app_name}")')
|
|
|
|
print(' +', save.manifest_name)
|
|
|
|
|
|
|
|
def download_saves(self, args):
|
|
|
|
if not self.core.login():
|
|
|
|
logger.error('Login failed! Cannot continue with download process.')
|
|
|
|
exit(1)
|
|
|
|
logger.info(f'Downloading saves to "{self.core.get_default_install_dir()}"')
|
2020-05-14 12:52:33 +00:00
|
|
|
self.core.download_saves(args.app_name)
|
|
|
|
|
|
|
|
def sync_saves(self, args):
|
|
|
|
if not self.core.login():
|
|
|
|
logger.error('Login failed! Cannot continue with download process.')
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
igames = self.core.get_installed_list()
|
|
|
|
if args.app_name:
|
|
|
|
igame = self.core.get_installed_game(args.app_name)
|
|
|
|
if not igame:
|
|
|
|
logger.fatal(f'Game not installed: {args.app_name}')
|
|
|
|
exit(1)
|
|
|
|
igames = [igame]
|
|
|
|
|
|
|
|
# check available saves
|
|
|
|
saves = self.core.get_save_games()
|
|
|
|
latest_save = dict()
|
|
|
|
|
|
|
|
for save in sorted(saves, key=lambda a: a.datetime):
|
|
|
|
latest_save[save.app_name] = save
|
|
|
|
|
|
|
|
logger.info(f'Got {len(latest_save)} remote save game(s)')
|
|
|
|
|
|
|
|
# evaluate current save state for each game.
|
|
|
|
for igame in igames:
|
|
|
|
game = self.core.get_game(igame.app_name)
|
2020-05-19 14:14:20 +00:00
|
|
|
if not game or not game.supports_cloud_saves:
|
2020-05-16 10:50:28 +00:00
|
|
|
if igame.app_name in latest_save:
|
|
|
|
# this should never happen unless cloud save support was removed from a game
|
|
|
|
logger.warning(f'{igame.app_name} has remote save(s) but does not support cloud saves?!')
|
2020-05-14 12:52:33 +00:00
|
|
|
continue
|
|
|
|
|
2020-05-16 10:50:28 +00:00
|
|
|
logger.info(f'Checking "{igame.title}" ({igame.app_name})')
|
2020-05-14 12:52:33 +00:00
|
|
|
# override save path only if app name is specified
|
|
|
|
if args.app_name and args.save_path:
|
|
|
|
logger.info(f'Overriding save path with "{args.save_path}"...')
|
|
|
|
igame.save_path = args.save_path
|
|
|
|
self.core.lgd.set_installed_game(igame.app_name, igame)
|
|
|
|
|
|
|
|
# if there is no saved save path, try to get one
|
|
|
|
if not igame.save_path:
|
|
|
|
save_path = self.core.get_save_path(igame.app_name)
|
|
|
|
|
|
|
|
# ask user if path is correct if computing for the first time
|
|
|
|
logger.info(f'Computed save path: "{save_path}"')
|
|
|
|
|
|
|
|
if '%' in save_path or '{' in save_path:
|
|
|
|
logger.warning('Path contains unprocessed variables, please enter the correct path manually.')
|
|
|
|
yn = 'n'
|
|
|
|
else:
|
|
|
|
yn = input('Is this correct? [Y/n] ')
|
|
|
|
|
|
|
|
if yn and yn.lower()[0] != 'y':
|
|
|
|
save_path = input('Please enter the correct path (leave empty to skip): ')
|
|
|
|
if not save_path:
|
|
|
|
logger.info('Empty input, skipping...')
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not os.path.exists(save_path):
|
|
|
|
os.makedirs(save_path)
|
|
|
|
igame.save_path = save_path
|
|
|
|
self.core.lgd.set_installed_game(igame.app_name, igame)
|
|
|
|
|
2020-05-16 10:50:28 +00:00
|
|
|
res, (dt_l, dt_r) = self.core.check_savegame_state(igame.save_path, latest_save.get(igame.app_name))
|
|
|
|
|
|
|
|
if res == SaveGameStatus.NO_SAVE:
|
|
|
|
logger.info('No cloud or local savegame found.')
|
|
|
|
continue
|
2020-05-14 12:52:33 +00:00
|
|
|
|
|
|
|
if res == SaveGameStatus.SAME_AGE and not (args.force_upload or args.force_download):
|
|
|
|
logger.info(f'Save game for "{igame.title}" is up to date, skipping...')
|
|
|
|
continue
|
|
|
|
|
|
|
|
if (res == SaveGameStatus.REMOTE_NEWER and not args.force_upload) or args.force_download:
|
|
|
|
if res == SaveGameStatus.REMOTE_NEWER: # only print this info if not forced
|
|
|
|
logger.info(f'Cloud save for "{igame.title}" is newer:')
|
2020-05-16 10:50:28 +00:00
|
|
|
logger.info(f'- Cloud save date: {dt_r.strftime("%Y-%m-%d %H:%M:%S")}')
|
|
|
|
if dt_l:
|
|
|
|
logger.info(f'- Local save date: {dt_l.strftime("%Y-%m-%d %H:%M:%S")}')
|
|
|
|
else:
|
|
|
|
logger.info('- Local save date: N/A')
|
2020-05-14 12:52:33 +00:00
|
|
|
|
|
|
|
if args.upload_only:
|
|
|
|
logger.info('Save game downloading is disabled, skipping...')
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not args.yes and not args.force_download:
|
|
|
|
choice = input(f'Download cloud save? [Y/n]: ')
|
|
|
|
if choice and choice.lower()[0] != 'y':
|
|
|
|
logger.info('Not downloading...')
|
|
|
|
continue
|
|
|
|
|
|
|
|
logger.info('Downloading remote savegame...')
|
|
|
|
self.core.download_saves(igame.app_name, save_dir=igame.save_path, clean_dir=True,
|
|
|
|
manifest_name=latest_save[igame.app_name].manifest_name)
|
|
|
|
elif res == SaveGameStatus.LOCAL_NEWER or args.force_upload:
|
|
|
|
if res == SaveGameStatus.LOCAL_NEWER:
|
|
|
|
logger.info(f'Local save for "{igame.title}" is newer')
|
2020-05-16 10:50:28 +00:00
|
|
|
if dt_r:
|
|
|
|
logger.info(f'- Cloud save date: {dt_r.strftime("%Y-%m-%d %H:%M:%S")}')
|
|
|
|
else:
|
|
|
|
logger.info('- Cloud save date: N/A')
|
|
|
|
logger.info(f'- Local save date: {dt_l.strftime("%Y-%m-%d %H:%M:%S")}')
|
2020-05-14 12:52:33 +00:00
|
|
|
|
|
|
|
if args.download_only:
|
|
|
|
logger.info('Save game uploading is disabled, skipping...')
|
|
|
|
continue
|
|
|
|
|
|
|
|
if not args.yes and not args.force_upload:
|
|
|
|
choice = input(f'Upload local save? [Y/n]: ')
|
|
|
|
if choice and choice.lower()[0] != 'y':
|
|
|
|
logger.info('Not uploading...')
|
|
|
|
continue
|
|
|
|
logger.info('Uploading local savegame...')
|
2020-05-16 10:19:44 +00:00
|
|
|
self.core.upload_save(igame.app_name, igame.save_path, dt_l, args.disable_filters)
|
2020-05-06 13:40:04 +00:00
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
def launch_game(self, args, extra):
|
|
|
|
app_name = args.app_name
|
|
|
|
if not self.core.is_installed(app_name):
|
2020-04-14 12:47:46 +00:00
|
|
|
logger.error(f'Game {app_name} is not currently installed!')
|
|
|
|
exit(1)
|
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
if self.core.is_dlc(app_name):
|
2020-04-18 00:11:58 +00:00
|
|
|
logger.error(f'{app_name} is DLC; please launch the base game instead!')
|
|
|
|
exit(1)
|
|
|
|
|
2020-04-26 12:58:09 +00:00
|
|
|
# override with config value
|
2020-04-29 12:05:30 +00:00
|
|
|
args.offline = self.core.is_offline_game(app_name) or args.offline
|
2020-04-26 12:58:09 +00:00
|
|
|
if not args.offline:
|
2020-04-14 12:47:46 +00:00
|
|
|
logger.info('Logging in...')
|
2020-04-25 10:20:14 +00:00
|
|
|
if not self.core.login():
|
2020-04-14 12:47:46 +00:00
|
|
|
logger.error('Login failed, cannot continue!')
|
|
|
|
exit(1)
|
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
if not args.skip_version_check and not self.core.is_noupdate_game(app_name):
|
2020-04-14 12:47:46 +00:00
|
|
|
logger.info('Checking for updates...')
|
2020-04-25 10:20:14 +00:00
|
|
|
installed = self.core.lgd.get_installed_game(app_name)
|
|
|
|
latest = self.core.get_asset(app_name, update=True)
|
2020-04-14 12:47:46 +00:00
|
|
|
if latest.build_version != installed.version:
|
|
|
|
logger.error('Game is out of date, please update or launch with update check skipping!')
|
|
|
|
exit(1)
|
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
params, cwd, env = self.core.get_launch_parameters(app_name=app_name, offline=args.offline,
|
2020-05-12 00:31:01 +00:00
|
|
|
extra_args=extra, user=args.user_name_override,
|
2020-05-18 08:58:23 +00:00
|
|
|
wine_bin=args.wine_bin, wine_pfx=args.wine_pfx,
|
2020-05-23 16:29:43 +00:00
|
|
|
language=args.language, wrapper=args.wrapper,
|
|
|
|
disable_wine=args.no_wine)
|
2020-04-14 12:47:46 +00:00
|
|
|
|
|
|
|
logger.info(f'Launching {app_name}...')
|
|
|
|
if args.dry_run:
|
|
|
|
logger.info(f'Launch parameters: {shlex.join(params)}')
|
|
|
|
logger.info(f'Working directory: {cwd}')
|
|
|
|
if env:
|
|
|
|
logger.info('Environment overrides:', env)
|
|
|
|
else:
|
|
|
|
logger.debug(f'Launch parameters: {shlex.join(params)}')
|
|
|
|
logger.debug(f'Working directory: {cwd}')
|
|
|
|
if env:
|
|
|
|
logger.debug('Environment overrides:', env)
|
|
|
|
|
|
|
|
subprocess.Popen(params, cwd=cwd, env=env)
|
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
def install_game(self, args):
|
2020-05-20 12:06:55 +00:00
|
|
|
if self.core.is_installed(args.app_name):
|
|
|
|
igame = self.core.get_installed_game(args.app_name)
|
|
|
|
if igame.needs_verification and not args.repair_mode:
|
|
|
|
logger.info('Game needs to be verified before updating, switching to repair mode...')
|
|
|
|
args.repair_mode = True
|
|
|
|
|
2020-05-20 10:41:49 +00:00
|
|
|
repair_file = None
|
2020-05-04 12:21:25 +00:00
|
|
|
if args.subparser_name == 'download':
|
2020-05-20 10:41:49 +00:00
|
|
|
logger.info('Setting --no-install flag since "download" command was used')
|
|
|
|
args.no_install = True
|
|
|
|
elif args.subparser_name == 'repair' or args.repair_mode:
|
|
|
|
args.repair_mode = True
|
|
|
|
args.no_install = True
|
|
|
|
repair_file = os.path.join(self.core.lgd.get_tmp_path(), f'{args.app_name}.repair')
|
2020-05-04 12:21:25 +00:00
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
if not self.core.login():
|
2020-04-14 12:47:46 +00:00
|
|
|
logger.error('Login failed! Cannot continue with download process.')
|
|
|
|
exit(1)
|
|
|
|
|
2020-05-01 12:34:34 +00:00
|
|
|
if args.file_prefix or args.file_exclude_prefix or args.install_tag:
|
2020-04-30 09:49:33 +00:00
|
|
|
args.no_install = True
|
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
if args.update_only:
|
|
|
|
if not self.core.is_installed(args.app_name):
|
|
|
|
logger.error(f'Update requested for "{args.app_name}", but app not installed!')
|
2020-04-14 12:47:46 +00:00
|
|
|
exit(1)
|
|
|
|
|
2020-04-28 13:12:17 +00:00
|
|
|
if args.platform_override:
|
|
|
|
args.no_install = True
|
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
game = self.core.get_game(args.app_name, update_meta=True)
|
2020-04-14 12:47:46 +00:00
|
|
|
|
|
|
|
if not game:
|
2020-04-25 10:20:14 +00:00
|
|
|
logger.error(f'Could not find "{args.app_name}" in list of available games,'
|
|
|
|
f'did you type the name correctly?')
|
2020-04-14 12:47:46 +00:00
|
|
|
exit(1)
|
|
|
|
|
2020-04-18 00:11:58 +00:00
|
|
|
if game.is_dlc:
|
|
|
|
logger.info('Install candidate is DLC')
|
|
|
|
app_name = game.metadata['mainGameItem']['releaseInfo'][0]['appId']
|
2020-04-25 10:20:14 +00:00
|
|
|
base_game = self.core.get_game(app_name)
|
2020-04-18 00:11:58 +00:00
|
|
|
# check if base_game is actually installed
|
2020-04-25 10:20:14 +00:00
|
|
|
if not self.core.is_installed(app_name):
|
2020-04-18 00:11:58 +00:00
|
|
|
# download mode doesn't care about whether or not something's installed
|
2020-04-25 10:20:14 +00:00
|
|
|
if not args.no_install:
|
2020-04-18 00:11:58 +00:00
|
|
|
logger.fatal(f'Base game "{app_name}" is not installed!')
|
|
|
|
exit(1)
|
|
|
|
else:
|
|
|
|
base_game = None
|
|
|
|
|
2020-05-20 10:41:49 +00:00
|
|
|
if args.repair_mode:
|
|
|
|
if not self.core.is_installed(game.app_name):
|
|
|
|
logger.error(f'Game "{game.app_title}" ({game.app_name}) is not installed!')
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
if not os.path.exists(repair_file):
|
|
|
|
logger.info('Game has not been verified yet.')
|
|
|
|
if not args.yes:
|
|
|
|
choice = input(f'Verify "{game.app_name}" now (answer "no" will abort repair)? [Y/n]: ')
|
|
|
|
if choice and choice.lower()[0] != 'y':
|
|
|
|
print('Aborting...')
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
self.verify_game(args, print_command=False)
|
|
|
|
else:
|
|
|
|
logger.info(f'Using existing repair file: {repair_file}')
|
|
|
|
|
2020-05-01 17:57:42 +00:00
|
|
|
logger.info('Preparing download...')
|
2020-04-14 12:47:46 +00:00
|
|
|
# todo use status queue to print progress from CLI
|
2020-05-04 11:59:04 +00:00
|
|
|
# This has become a little ridiculous hasn't it?
|
2020-04-25 10:20:14 +00:00
|
|
|
dlm, analysis, igame = self.core.prepare_download(game=game, base_game=base_game, base_path=args.base_path,
|
|
|
|
force=args.force, max_shm=args.shared_memory,
|
|
|
|
max_workers=args.max_workers, game_folder=args.game_folder,
|
|
|
|
disable_patching=args.disable_patching,
|
|
|
|
override_manifest=args.override_manifest,
|
|
|
|
override_old_manifest=args.override_old_manifest,
|
2020-04-28 13:12:17 +00:00
|
|
|
override_base_url=args.override_base_url,
|
2020-04-29 20:08:28 +00:00
|
|
|
platform_override=args.platform_override,
|
2020-05-01 08:43:55 +00:00
|
|
|
file_prefix_filter=args.file_prefix,
|
2020-05-01 12:34:34 +00:00
|
|
|
file_exclude_filter=args.file_exclude_prefix,
|
2020-05-04 11:59:04 +00:00
|
|
|
file_install_tag=args.install_tag,
|
2020-05-04 11:59:57 +00:00
|
|
|
dl_optimizations=args.order_opt,
|
2020-05-20 10:41:49 +00:00
|
|
|
dl_timeout=args.dl_timeout,
|
|
|
|
repair=args.repair_mode)
|
2020-04-14 12:47:46 +00:00
|
|
|
|
|
|
|
# game is either up to date or hasn't changed, so we have nothing to do
|
|
|
|
if not analysis.dl_size:
|
|
|
|
logger.info('Download size is 0, the game is either already up to date or has not changed. Exiting...')
|
2020-05-20 10:41:49 +00:00
|
|
|
if args.repair_mode and os.path.exists(repair_file):
|
2020-05-20 12:06:55 +00:00
|
|
|
igame = self.core.get_installed_game(game.app_name)
|
|
|
|
if igame.needs_verification:
|
|
|
|
igame.needs_verification = False
|
|
|
|
self.core.install_game(igame)
|
|
|
|
|
2020-05-20 10:41:49 +00:00
|
|
|
logger.debug('Removing repair file.')
|
|
|
|
os.remove(repair_file)
|
2020-04-14 12:47:46 +00:00
|
|
|
exit(0)
|
|
|
|
|
|
|
|
logger.info(f'Install size: {analysis.install_size / 1024 / 1024:.02f} MiB')
|
|
|
|
compression = (1 - (analysis.dl_size / analysis.uncompressed_dl_size)) * 100
|
|
|
|
logger.info(f'Download size: {analysis.dl_size / 1024 / 1024:.02f} MiB '
|
|
|
|
f'(Compression savings: {compression:.01f}%)')
|
|
|
|
logger.info(f'Reusable size: {analysis.reuse_size / 1024 / 1024:.02f} MiB (chunks) / '
|
|
|
|
f'{analysis.unchanged / 1024 / 1024:.02f} MiB (unchanged)')
|
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
res = self.core.check_installation_conditions(analysis=analysis, install=igame)
|
2020-04-14 12:47:46 +00:00
|
|
|
|
|
|
|
if res.failures:
|
|
|
|
logger.fatal('Download cannot proceed, the following errors occured:')
|
|
|
|
for msg in sorted(res.failures):
|
|
|
|
logger.fatal(msg)
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
if res.warnings:
|
|
|
|
logger.warning('Installation requirements check returned the following warnings:')
|
|
|
|
for warn in sorted(res.warnings):
|
|
|
|
logger.warning(warn)
|
|
|
|
|
2020-05-22 07:54:12 +00:00
|
|
|
logger.info('Downloads are resumable, you can interrupt the download with '
|
|
|
|
'CTRL-C and resume it using the same command later on.')
|
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
if not args.yes:
|
|
|
|
choice = input(f'Do you wish to install "{igame.title}"? [Y/n]: ')
|
|
|
|
if choice and choice.lower()[0] != 'y':
|
|
|
|
print('Aborting...')
|
|
|
|
exit(0)
|
2020-04-18 00:17:01 +00:00
|
|
|
|
2020-04-14 12:47:46 +00:00
|
|
|
start_t = time.time()
|
|
|
|
|
|
|
|
try:
|
2020-04-26 11:19:28 +00:00
|
|
|
# set up logging stuff (should be moved somewhere else later)
|
|
|
|
dlm.logging_queue = self.logging_queue
|
|
|
|
dlm.proc_debug = args.dlm_debug
|
|
|
|
|
2020-04-14 12:47:46 +00:00
|
|
|
dlm.start()
|
|
|
|
dlm.join()
|
|
|
|
except Exception as e:
|
|
|
|
end_t = time.time()
|
|
|
|
logger.info(f'Installation failed after {end_t - start_t:.02f} seconds.')
|
|
|
|
logger.warning(f'The following exception occured while waiting for the donlowader to finish: {e!r}. '
|
|
|
|
f'Try restarting the process, the resume file will be used to start where it failed. '
|
|
|
|
f'If it continues to fail please open an issue on GitHub.')
|
|
|
|
else:
|
|
|
|
end_t = time.time()
|
2020-04-25 10:20:14 +00:00
|
|
|
if not args.no_install:
|
2020-05-14 14:40:27 +00:00
|
|
|
# Allow setting savegame directory at install time so sync-saves will work immediately
|
|
|
|
if game.supports_cloud_saves and args.save_path:
|
|
|
|
igame.save_path = args.save_path
|
|
|
|
|
2020-05-14 14:04:03 +00:00
|
|
|
postinstall = self.core.install_game(igame)
|
|
|
|
if postinstall:
|
|
|
|
self._handle_postinstall(postinstall, igame, yes=args.yes)
|
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
dlcs = self.core.get_dlc_for_game(game.app_name)
|
2020-04-18 00:11:58 +00:00
|
|
|
if dlcs:
|
|
|
|
print('The following DLCs are available for this game:')
|
|
|
|
for dlc in dlcs:
|
|
|
|
print(f' - {dlc.app_title} (App name: {dlc.app_name}, version: {dlc.app_version})')
|
2020-05-14 14:04:03 +00:00
|
|
|
print('Manually installing DLCs works the same; just use the DLC app name instead.')
|
|
|
|
|
|
|
|
install_dlcs = True
|
|
|
|
if not args.yes:
|
|
|
|
choice = input(f'Do you wish to automatically install DLCs ? [Y/n]: ')
|
|
|
|
if choice and choice.lower()[0] != 'y':
|
|
|
|
install_dlcs = False
|
|
|
|
|
|
|
|
if install_dlcs:
|
|
|
|
_yes, _app_name = args.yes, args.app_name
|
|
|
|
args.yes = True
|
|
|
|
for dlc in dlcs:
|
|
|
|
args.app_name = dlc.app_name
|
|
|
|
self.install_game(args)
|
|
|
|
args.yes, args.app_name = _yes, _app_name
|
|
|
|
|
2020-05-14 14:40:27 +00:00
|
|
|
if game.supports_cloud_saves and not game.is_dlc:
|
2020-05-14 14:04:03 +00:00
|
|
|
# todo option to automatically download saves after the installation
|
|
|
|
# args does not have the required attributes for sync_saves in here,
|
|
|
|
# not sure how to solve that elegantly.
|
2020-05-14 14:40:27 +00:00
|
|
|
logger.info('This game supports cloud saves, syncing is handled by the "sync-saves" command.')
|
|
|
|
logger.info(f'To download saves for this game run "legendary sync-saves {args.app_name}"')
|
2020-04-14 12:47:46 +00:00
|
|
|
|
2020-05-20 10:41:49 +00:00
|
|
|
if args.repair_mode and os.path.exists(repair_file):
|
2020-05-20 12:06:55 +00:00
|
|
|
igame = self.core.get_installed_game(game.app_name)
|
|
|
|
if igame.needs_verification:
|
|
|
|
igame.needs_verification = False
|
|
|
|
self.core.install_game(igame)
|
|
|
|
|
2020-05-20 10:41:49 +00:00
|
|
|
logger.debug('Removing repair file.')
|
|
|
|
os.remove(repair_file)
|
|
|
|
|
2020-04-14 12:47:46 +00:00
|
|
|
logger.info(f'Finished installation process in {end_t - start_t:.02f} seconds.')
|
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
def _handle_postinstall(self, postinstall, igame, yes=False):
|
|
|
|
print('This game lists the following prequisites to be installed:')
|
|
|
|
print(f'- {postinstall["name"]}: {" ".join((postinstall["path"], postinstall["args"]))}')
|
|
|
|
if os.name == 'nt':
|
|
|
|
if yes:
|
|
|
|
c = 'n' # we don't want to launch anything, just silent install.
|
|
|
|
else:
|
|
|
|
choice = input('Do you wish to install the prerequisites? ([y]es, [n]o, [i]gnore): ')
|
|
|
|
c = choice.lower()[0]
|
|
|
|
|
|
|
|
if c == 'i': # just set it to installed
|
|
|
|
print('Marking prerequisites as installed...')
|
|
|
|
self.core.prereq_installed(igame.app_name)
|
|
|
|
elif c == 'y': # set to installed and launch installation
|
|
|
|
print('Launching prerequisite executable..')
|
|
|
|
self.core.prereq_installed(igame.app_name)
|
|
|
|
req_path, req_exec = os.path.split(postinstall['path'])
|
|
|
|
work_dir = os.path.join(igame.install_path, req_path)
|
|
|
|
fullpath = os.path.join(work_dir, req_exec)
|
|
|
|
subprocess.Popen([fullpath, postinstall['args']], cwd=work_dir)
|
|
|
|
else:
|
|
|
|
logger.info('Automatic installation not available on Linux.')
|
|
|
|
|
|
|
|
def uninstall_game(self, args):
|
|
|
|
igame = self.core.get_installed_game(args.app_name)
|
2020-04-14 12:47:46 +00:00
|
|
|
if not igame:
|
2020-04-25 10:20:14 +00:00
|
|
|
logger.error(f'Game {args.app_name} not installed, cannot uninstall!')
|
2020-04-18 00:17:01 +00:00
|
|
|
exit(0)
|
2020-04-18 00:11:58 +00:00
|
|
|
if igame.is_dlc:
|
|
|
|
logger.error('Uninstalling DLC is not supported.')
|
|
|
|
exit(1)
|
2020-04-14 12:47:46 +00:00
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
if not args.yes:
|
|
|
|
choice = input(f'Do you wish to uninstall "{igame.title}"? [y/N]: ')
|
|
|
|
if not choice or choice.lower()[0] != 'y':
|
|
|
|
print('Aborting...')
|
|
|
|
exit(0)
|
2020-04-18 00:17:01 +00:00
|
|
|
|
2020-04-14 12:47:46 +00:00
|
|
|
try:
|
|
|
|
logger.info(f'Removing "{igame.title}" from "{igame.install_path}"...')
|
2020-04-25 10:20:14 +00:00
|
|
|
self.core.uninstall_game(igame)
|
2020-04-18 00:11:58 +00:00
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
# DLCs are already removed once we delete the main game, so this just removes them from the list
|
|
|
|
dlcs = self.core.get_dlc_for_game(igame.app_name)
|
2020-04-18 00:11:58 +00:00
|
|
|
for dlc in dlcs:
|
2020-04-25 10:20:14 +00:00
|
|
|
idlc = self.core.get_installed_game(dlc.app_name)
|
|
|
|
if self.core.is_installed(dlc.app_name):
|
2020-04-18 00:11:58 +00:00
|
|
|
logger.info(f'Uninstalling DLC "{dlc.app_name}"...')
|
2020-04-25 10:20:14 +00:00
|
|
|
self.core.uninstall_game(idlc, delete_files=False)
|
2020-04-18 00:11:58 +00:00
|
|
|
|
2020-04-14 12:47:46 +00:00
|
|
|
logger.info('Game has been uninstalled.')
|
|
|
|
except Exception as e:
|
|
|
|
logger.warning(f'Removing game failed: {e!r}, please remove {igame.install_path} manually.')
|
|
|
|
|
2020-05-20 10:41:49 +00:00
|
|
|
def verify_game(self, args, print_command=True):
|
2020-05-19 16:19:15 +00:00
|
|
|
if not self.core.is_installed(args.app_name):
|
|
|
|
logger.error(f'Game "{args.app_name}" is not installed')
|
|
|
|
return
|
|
|
|
|
|
|
|
logger.info(f'Loading installed manifest for "{args.app_name}"')
|
|
|
|
igame = self.core.get_installed_game(args.app_name)
|
|
|
|
manifest_data, _ = self.core.get_installed_manifest(args.app_name)
|
|
|
|
manifest = self.core.load_manfiest(manifest_data)
|
|
|
|
|
|
|
|
files = sorted(manifest.file_manifest_list.elements,
|
|
|
|
key=lambda a: a.filename.lower())
|
|
|
|
|
|
|
|
# build list of hashes
|
|
|
|
file_list = [(f.filename, f.sha_hash.hex()) for f in files]
|
|
|
|
total = len(file_list)
|
|
|
|
num = 0
|
|
|
|
failed = []
|
|
|
|
missing = []
|
|
|
|
|
2020-05-20 10:41:49 +00:00
|
|
|
logger.info(f'Verifying "{igame.title}" version "{manifest.meta.build_version}"')
|
|
|
|
repair_file = []
|
|
|
|
for result, path, result_hash in validate_files(igame.install_path, file_list):
|
2020-05-19 16:19:15 +00:00
|
|
|
stdout.write(f'Verification progress: {num}/{total} ({num * 100 / total:.01f}%)\t\r')
|
|
|
|
stdout.flush()
|
|
|
|
num += 1
|
|
|
|
|
|
|
|
if result == VerifyResult.HASH_MATCH:
|
2020-05-20 10:41:49 +00:00
|
|
|
repair_file.append(f'{result_hash}:{path}')
|
2020-05-19 16:19:15 +00:00
|
|
|
continue
|
|
|
|
elif result == VerifyResult.HASH_MISMATCH:
|
|
|
|
logger.error(f'File does not match hash: "{path}"')
|
2020-05-20 10:41:49 +00:00
|
|
|
repair_file.append(f'{result_hash}:{path}')
|
2020-05-19 16:19:15 +00:00
|
|
|
failed.append(path)
|
|
|
|
elif result == VerifyResult.FILE_MISSING:
|
|
|
|
logger.error(f'File is missing: "{path}"')
|
|
|
|
missing.append(path)
|
2020-05-23 14:57:06 +00:00
|
|
|
else:
|
|
|
|
logger.error(f'Other failure (see log), treating file as missing: "{path}"')
|
|
|
|
missing.append(path)
|
2020-05-19 16:19:15 +00:00
|
|
|
|
|
|
|
stdout.write(f'Verification progress: {num}/{total} ({num * 100 / total:.01f}%)\t\n')
|
|
|
|
|
2020-05-20 10:41:49 +00:00
|
|
|
# always write repair file, even if all match
|
|
|
|
if repair_file:
|
|
|
|
repair_filename = os.path.join(self.core.lgd.get_tmp_path(), f'{args.app_name}.repair')
|
|
|
|
with open(repair_filename, 'w') as f:
|
|
|
|
f.write('\n'.join(repair_file))
|
|
|
|
logger.debug(f'Written repair file to "{repair_filename}"')
|
|
|
|
|
2020-05-19 16:19:15 +00:00
|
|
|
if not missing and not failed:
|
|
|
|
logger.info('Verification finished successfully.')
|
|
|
|
else:
|
2020-05-20 10:41:49 +00:00
|
|
|
logger.error(f'Verification failed, {len(failed)} file(s) corrupted, {len(missing)} file(s) are missing.')
|
|
|
|
if print_command:
|
|
|
|
logger.info(f'Run "legendary repair {args.app_name}" to repair your game installation.')
|
2020-05-19 16:19:15 +00:00
|
|
|
|
2020-05-20 12:06:55 +00:00
|
|
|
def import_game(self, args):
|
|
|
|
if not os.path.exists(args.app_path):
|
|
|
|
logger.error(f'Specified path "{args.app_path}" does not exist!')
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
if self.core.is_installed(args.app_name):
|
|
|
|
logger.error('Game is already installed!')
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
if not self.core.login():
|
|
|
|
logger.error('Log in failed!')
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
# do some basic checks
|
|
|
|
game = self.core.get_game(args.app_name, update_meta=True)
|
|
|
|
if not game:
|
|
|
|
logger.fatal(f'Did not find game "{args.app_name}" on account.')
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
# todo: if there is an Epic Games Launcher manifest in the install path use that instead
|
|
|
|
# get everything needed for import from core, then run additional checks.
|
|
|
|
manifest, igame = self.core.import_game(game, args.app_path)
|
|
|
|
# check if most files at least exist or if user might have specified the wrong directory
|
|
|
|
total = len(manifest.file_manifest_list.elements)
|
|
|
|
found = sum(os.path.exists(os.path.join(args.app_path, f.filename))
|
|
|
|
for f in manifest.file_manifest_list.elements)
|
|
|
|
if found != total:
|
|
|
|
ratio = found / total
|
|
|
|
if ratio < 0.95:
|
|
|
|
logger.fatal(f'{total-found}/{total} files are missing, cannot import.')
|
|
|
|
exit(1)
|
|
|
|
logger.warning('Some files are missing from the game installation, this may be due to newer updates.')
|
|
|
|
else:
|
|
|
|
logger.info('Game install appears to be complete.')
|
|
|
|
|
|
|
|
self.core.install_game(igame)
|
|
|
|
logger.info(f'NOTE: The game installation will have to be verified before it can be updated with legendary. '
|
|
|
|
f'Run "legendary repair {args.app_name}" to do so.')
|
|
|
|
logger.info('Game has been imported.')
|
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
|
|
|
|
def main():
|
2020-04-28 04:14:17 +00:00
|
|
|
parser = argparse.ArgumentParser(description=f'Legendary v{__version__} - "{__codename__}"')
|
2020-05-04 12:21:25 +00:00
|
|
|
parser.register('action', 'parsers', AliasedSubParsersAction)
|
2020-04-25 10:20:14 +00:00
|
|
|
|
|
|
|
# general arguments
|
|
|
|
parser.add_argument('-v', dest='debug', action='store_true', help='Set loglevel to debug')
|
2020-04-26 11:20:11 +00:00
|
|
|
parser.add_argument('-y', dest='yes', action='store_true', help='Default to yes for all prompts')
|
2020-04-28 04:14:17 +00:00
|
|
|
parser.add_argument('-V', dest='version', action='store_true', help='Print version and exit')
|
2020-04-25 10:20:14 +00:00
|
|
|
|
|
|
|
# all the commands
|
|
|
|
subparsers = parser.add_subparsers(title='Commands', dest='subparser_name')
|
|
|
|
auth_parser = subparsers.add_parser('auth', help='Authenticate with EPIC')
|
2020-05-04 12:21:25 +00:00
|
|
|
install_parser = subparsers.add_parser('install', help='Download a game',
|
2020-05-20 10:41:49 +00:00
|
|
|
aliases=('download', 'update', 'repair'),
|
2020-05-04 12:25:00 +00:00
|
|
|
usage='%(prog)s <App Name> [options]',
|
|
|
|
description='Aliases: download, update')
|
2020-04-25 10:20:14 +00:00
|
|
|
uninstall_parser = subparsers.add_parser('uninstall', help='Uninstall (delete) a game')
|
|
|
|
launch_parser = subparsers.add_parser('launch', help='Launch a game', usage='%(prog)s <App Name> [options]',
|
2020-04-26 11:20:11 +00:00
|
|
|
description='Note: additional arguments are passed to the game')
|
2020-04-28 13:32:38 +00:00
|
|
|
list_parser = subparsers.add_parser('list-games', help='List available (installable) games')
|
2020-04-30 09:12:26 +00:00
|
|
|
list_installed_parser = subparsers.add_parser('list-installed', help='List installed games')
|
|
|
|
list_files_parser = subparsers.add_parser('list-files', help='List files in manifest')
|
2020-05-06 13:40:04 +00:00
|
|
|
list_saves_parser = subparsers.add_parser('list-saves', help='List available cloud saves')
|
|
|
|
download_saves_parser = subparsers.add_parser('download-saves', help='Download all cloud saves')
|
2020-05-14 12:52:33 +00:00
|
|
|
sync_saves_parser = subparsers.add_parser('sync-saves', help='Sync cloud saves')
|
2020-05-19 16:19:15 +00:00
|
|
|
verify_parser = subparsers.add_parser('verify-game', help='Verify a game\'s local files')
|
2020-05-20 12:06:55 +00:00
|
|
|
import_parser = subparsers.add_parser('import-game', help='Import an already installed game')
|
2020-04-25 10:20:14 +00:00
|
|
|
|
|
|
|
install_parser.add_argument('app_name', help='Name of the app', metavar='<App Name>')
|
|
|
|
uninstall_parser.add_argument('app_name', help='Name of the app', metavar='<App Name>')
|
|
|
|
launch_parser.add_argument('app_name', help='Name of the app', metavar='<App Name>')
|
2020-05-06 13:40:04 +00:00
|
|
|
list_files_parser.add_argument('app_name', nargs='?', metavar='<App Name>',
|
|
|
|
help='Name of the app (optional)')
|
|
|
|
list_saves_parser.add_argument('app_name', nargs='?', metavar='<App Name>', default='',
|
|
|
|
help='Name of the app (optional)')
|
2020-05-14 12:52:33 +00:00
|
|
|
download_saves_parser.add_argument('app_name', nargs='?', metavar='<App Name>', default='',
|
|
|
|
help='Name of the app (optional)')
|
|
|
|
sync_saves_parser.add_argument('app_name', nargs='?', metavar='<App Name>', default='',
|
|
|
|
help='Name of the app (optional)')
|
2020-05-20 12:06:55 +00:00
|
|
|
verify_parser.add_argument('app_name', help='Name of the app', metavar='<App Name>')
|
|
|
|
import_parser.add_argument('app_name', help='Name of the app', metavar='<App Name>')
|
|
|
|
import_parser.add_argument('app_path', help='Path where the game is installed',
|
|
|
|
metavar='<Installation directory>')
|
2020-04-25 10:20:14 +00:00
|
|
|
|
|
|
|
# importing only works on Windows right now
|
|
|
|
if os.name == 'nt':
|
|
|
|
auth_parser.add_argument('--import', dest='import_egs_auth', action='store_true',
|
|
|
|
help='Import EGS authentication data')
|
2020-05-12 18:01:25 +00:00
|
|
|
auth_parser.add_argument('--code', dest='auth_code', action='store', metavar='<exchange code>',
|
|
|
|
help='Use specified exchange code instead of interactive authentication.')
|
|
|
|
auth_parser.add_argument('--delete', dest='auth_delete', action='store_true',
|
|
|
|
help='Remove existing authentication data')
|
2020-04-25 10:20:14 +00:00
|
|
|
|
|
|
|
install_parser.add_argument('--base-path', dest='base_path', action='store', metavar='<path>',
|
|
|
|
help='Path for game installations (defaults to ~/legendary)')
|
|
|
|
install_parser.add_argument('--game-folder', dest='game_folder', action='store', metavar='<path>',
|
|
|
|
help='Folder for game installation (defaults to folder in metadata)')
|
|
|
|
install_parser.add_argument('--max-shared-memory', dest='shared_memory', action='store', metavar='<size>',
|
|
|
|
type=int, help='Maximum amount of shared memory to use (in MiB), default: 1 GiB')
|
|
|
|
install_parser.add_argument('--max-workers', dest='max_workers', action='store', metavar='<num>',
|
|
|
|
type=int, help='Maximum amount of download workers, default: 2 * logical CPU')
|
|
|
|
install_parser.add_argument('--manifest', dest='override_manifest', action='store', metavar='<uri>',
|
|
|
|
help='Manifest URL or path to use instead of the CDN one (e.g. for downgrading)')
|
|
|
|
install_parser.add_argument('--old-manifest', dest='override_old_manifest', action='store', metavar='<uri>',
|
|
|
|
help='Manifest URL or path to use as the old one (e.g. for testing patching)')
|
|
|
|
install_parser.add_argument('--base-url', dest='override_base_url', action='store', metavar='<url>',
|
|
|
|
help='Base URL to download from (e.g. to test or switch to a different CDNs)')
|
|
|
|
install_parser.add_argument('--force', dest='force', action='store_true',
|
|
|
|
help='Ignore existing files (overwrite)')
|
|
|
|
install_parser.add_argument('--disable-patching', dest='disable_patching', action='store_true',
|
|
|
|
help='Do not attempt to patch existing installations (download entire changed file)')
|
2020-05-05 14:01:53 +00:00
|
|
|
install_parser.add_argument('--download-only', '--no-install', dest='no_install', action='store_true',
|
2020-04-26 11:20:11 +00:00
|
|
|
help='Do not mark game as intalled and do not run prereq installers after download')
|
|
|
|
install_parser.add_argument('--update-only', dest='update_only', action='store_true',
|
2020-04-25 10:20:14 +00:00
|
|
|
help='Abort if game is not already installed (for automation)')
|
2020-04-26 11:19:28 +00:00
|
|
|
install_parser.add_argument('--dlm-debug', dest='dlm_debug', action='store_true',
|
|
|
|
help='Set download manager and worker processes\' loglevel to debug')
|
2020-04-28 13:12:17 +00:00
|
|
|
install_parser.add_argument('--platform', dest='platform_override', action='store', metavar='<Platform>',
|
|
|
|
type=str, help='Platform override for download (disables install)')
|
2020-05-14 14:32:08 +00:00
|
|
|
install_parser.add_argument('--prefix', dest='file_prefix', action='append', metavar='<prefix>',
|
2020-04-30 10:23:23 +00:00
|
|
|
help='Only fetch files whose path starts with <prefix> (case insensitive)')
|
2020-05-14 14:32:08 +00:00
|
|
|
install_parser.add_argument('--exclude', dest='file_exclude_prefix', action='append', metavar='<prefix>',
|
2020-05-01 08:43:55 +00:00
|
|
|
type=str, help='Exclude files starting with <prefix> (case insensitive)')
|
2020-05-14 14:32:08 +00:00
|
|
|
install_parser.add_argument('--install-tag', dest='install_tag', action='append', metavar='<tag>',
|
2020-05-01 12:34:34 +00:00
|
|
|
type=str, help='Only download files with the specified install tag (testing)')
|
2020-05-04 11:59:04 +00:00
|
|
|
install_parser.add_argument('--enable-reordering', dest='order_opt', action='store_true',
|
|
|
|
help='Enable reordering to attempt to optimize RAM usage during download')
|
2020-05-04 11:59:57 +00:00
|
|
|
install_parser.add_argument('--dl-timeout', dest='dl_timeout', action='store', metavar='<sec>', type=int,
|
|
|
|
help='Connection timeout for downloader (default: 10 seconds)')
|
2020-05-14 14:40:27 +00:00
|
|
|
install_parser.add_argument('--save-path', dest='save_path', action='store', metavar='<path>',
|
|
|
|
help='Set save game path during install.')
|
2020-05-20 10:41:49 +00:00
|
|
|
install_parser.add_argument('--repair', dest='repair_mode', action='store_true',
|
|
|
|
help='Repair already installed game by downloading corrupted/missing files')
|
2020-04-25 10:20:14 +00:00
|
|
|
|
|
|
|
launch_parser.add_argument('--offline', dest='offline', action='store_true',
|
|
|
|
default=False, help='Skip login and launch game without online authentication')
|
|
|
|
launch_parser.add_argument('--skip-version-check', dest='skip_version_check', action='store_true',
|
|
|
|
default=False, help='Skip version check when launching game in online mode')
|
|
|
|
launch_parser.add_argument('--override-username', dest='user_name_override', action='store', metavar='<username>',
|
|
|
|
help='Override username used when launching the game (only works with some titles)')
|
|
|
|
launch_parser.add_argument('--dry-run', dest='dry_run', action='store_true',
|
|
|
|
help='Print the command line that would have been used to launch the game and exit')
|
2020-05-18 08:58:23 +00:00
|
|
|
launch_parser.add_argument('--language', dest='language', action='store', metavar='<two letter language code>',
|
|
|
|
help='Override language for game launch (defaults to system settings)')
|
2020-05-20 10:49:51 +00:00
|
|
|
launch_parser.add_argument('--wrapper', dest='wrapper', action='store', metavar='<wrapper command>',
|
|
|
|
help='Wrapper command to launch game with')
|
|
|
|
|
2020-05-12 00:31:01 +00:00
|
|
|
if os.name != 'nt':
|
|
|
|
launch_parser.add_argument('--wine', dest='wine_bin', action='store', metavar='<wine binary>',
|
|
|
|
default=os.environ.get('LGDRY_WINE_BINARY', None),
|
|
|
|
help='Override WINE binary being used to launch the game')
|
|
|
|
launch_parser.add_argument('--wine-prefix', dest='wine_pfx', action='store', metavar='<wine pfx path>',
|
|
|
|
default=os.environ.get('LGDRY_WINE_PREFIX', None),
|
|
|
|
help='Override WINE prefix used.')
|
2020-05-23 16:29:43 +00:00
|
|
|
launch_parser.add_argument('--no-wine', dest='no_wine', action='store_true',
|
|
|
|
default=os.environ.get('LGDRY_NO_WINE', None),
|
|
|
|
help='Do not use WINE (e.g. if a wrapper is being used)')
|
2020-05-16 11:57:57 +00:00
|
|
|
else:
|
|
|
|
# hidden arguments to not break this on Windows
|
|
|
|
launch_parser.add_argument('--wine', help=argparse.SUPPRESS, dest='wine_bin')
|
|
|
|
launch_parser.add_argument('--wine-prefix', help=argparse.SUPPRESS, dest='wine_pfx')
|
2020-05-23 16:29:43 +00:00
|
|
|
launch_parser.add_argument('--no-wine', dest='no_wine', help=argparse.SUPPRESS,
|
|
|
|
action='store_true', default=True)
|
2020-04-25 10:20:14 +00:00
|
|
|
|
2020-04-28 13:32:38 +00:00
|
|
|
list_parser.add_argument('--platform', dest='platform_override', action='store', metavar='<Platform>',
|
|
|
|
type=str, help='Override platform that games are shown for')
|
|
|
|
list_parser.add_argument('--include-ue', dest='include_ue', action='store_true',
|
|
|
|
help='Also include Unreal Engine content in list')
|
2020-04-30 10:03:23 +00:00
|
|
|
list_parser.add_argument('--csv', dest='csv', action='store_true', help='List games in CSV format')
|
|
|
|
list_parser.add_argument('--tsv', dest='tsv', action='store_true', help='List games in TSV format')
|
2020-04-28 13:32:38 +00:00
|
|
|
|
2020-04-30 09:12:26 +00:00
|
|
|
list_installed_parser.add_argument('--check-updates', dest='check_updates', action='store_true',
|
|
|
|
help='Check for updates when listing installed games')
|
2020-04-30 10:03:23 +00:00
|
|
|
list_installed_parser.add_argument('--csv', dest='csv', action='store_true',
|
|
|
|
help='List games in CSV format')
|
|
|
|
list_installed_parser.add_argument('--tsv', dest='tsv', action='store_true',
|
|
|
|
help='List games in TSV format')
|
2020-04-30 09:12:26 +00:00
|
|
|
|
|
|
|
list_files_parser.add_argument('--force-download', dest='force_download', action='store_true',
|
|
|
|
help='Always download instead of using on-disk manifest')
|
|
|
|
list_files_parser.add_argument('--platform', dest='platform_override', action='store', metavar='<Platform>',
|
|
|
|
type=str, help='Platform override for download (disables install)')
|
|
|
|
list_files_parser.add_argument('--manifest', dest='override_manifest', action='store', metavar='<uri>',
|
|
|
|
help='Manifest URL or path to use instead of the CDN one')
|
|
|
|
list_files_parser.add_argument('--csv', dest='csv', action='store_true', help='Output in CSV format')
|
2020-05-01 12:34:34 +00:00
|
|
|
list_files_parser.add_argument('--tsv', dest='tsv', action='store_true', help='Output in TSV format')
|
2020-04-30 09:12:26 +00:00
|
|
|
list_files_parser.add_argument('--hashlist', dest='hashlist', action='store_true',
|
|
|
|
help='Output file hash list in hashcheck/sha1sum compatible format')
|
2020-05-01 13:08:48 +00:00
|
|
|
list_files_parser.add_argument('--install-tag', dest='install_tag', action='store', metavar='<tag>',
|
2020-05-01 12:34:34 +00:00
|
|
|
type=str, help='Show only files with specified install tag')
|
2020-04-25 10:20:14 +00:00
|
|
|
|
2020-05-14 12:52:33 +00:00
|
|
|
sync_saves_parser.add_argument('--skip-upload', dest='download_only', action='store_true',
|
|
|
|
help='Only download new saves from cloud, don\'t upload')
|
|
|
|
sync_saves_parser.add_argument('--skip-download', dest='upload_only', action='store_true',
|
|
|
|
help='Only upload new saves from cloud, don\'t download')
|
|
|
|
sync_saves_parser.add_argument('--force-upload', dest='force_upload', action='store_true',
|
|
|
|
help='Force upload even if local saves are older')
|
|
|
|
sync_saves_parser.add_argument('--force-download', dest='force_download', action='store_true',
|
|
|
|
help='Force download even if local saves are newer')
|
2020-05-14 14:32:08 +00:00
|
|
|
sync_saves_parser.add_argument('--save-path', dest='save_path', action='store', metavar='<path>',
|
2020-05-14 12:52:33 +00:00
|
|
|
help='Override savegame path (only if app name is specified)')
|
2020-05-16 10:19:44 +00:00
|
|
|
sync_saves_parser.add_argument('--disable-filters', dest='disable_filters', action='store_true',
|
|
|
|
help='Disable save game file filtering (in case it breaks)')
|
2020-05-14 12:52:33 +00:00
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
args, extra = parser.parse_known_args()
|
|
|
|
|
2020-04-28 04:14:17 +00:00
|
|
|
if args.version:
|
|
|
|
print(f'legendary version "{__version__}", codename "{__codename__}"')
|
|
|
|
exit(0)
|
|
|
|
|
2020-04-30 09:12:26 +00:00
|
|
|
if args.subparser_name not in ('auth', 'list-games', 'list-installed', 'list-files',
|
2020-05-06 13:40:04 +00:00
|
|
|
'launch', 'download', 'uninstall', 'install', 'update',
|
2020-05-20 10:41:49 +00:00
|
|
|
'repair', 'list-saves', 'download-saves', 'sync-saves',
|
2020-05-20 12:06:55 +00:00
|
|
|
'verify-game', 'import-game'):
|
2020-04-25 10:20:14 +00:00
|
|
|
print(parser.format_help())
|
|
|
|
|
|
|
|
# Print the main help *and* the help for all of the subcommands. Thanks stackoverflow!
|
|
|
|
print('Individual command help:')
|
|
|
|
subparsers = next(a for a in parser._actions if isinstance(a, argparse._SubParsersAction))
|
|
|
|
for choice, subparser in subparsers.choices.items():
|
2020-05-22 12:39:01 +00:00
|
|
|
if choice in ('download', 'update', 'repair'):
|
2020-05-04 12:21:25 +00:00
|
|
|
continue
|
2020-04-25 10:20:14 +00:00
|
|
|
print(f'\nCommand: {choice}')
|
|
|
|
print(subparser.format_help())
|
|
|
|
return
|
|
|
|
|
|
|
|
cli = LegendaryCLI()
|
2020-04-26 11:19:28 +00:00
|
|
|
ql = cli.setup_threaded_logging()
|
2020-04-25 10:20:14 +00:00
|
|
|
|
|
|
|
config_ll = cli.core.lgd.config.get('Legendary', 'log_level', fallback='info')
|
|
|
|
if config_ll == 'debug' or args.debug:
|
|
|
|
logging.getLogger().setLevel(level=logging.DEBUG)
|
|
|
|
# keep requests quiet
|
|
|
|
logging.getLogger('requests').setLevel(logging.WARNING)
|
|
|
|
logging.getLogger('urllib3').setLevel(logging.WARNING)
|
|
|
|
|
|
|
|
# technically args.func() with setdefaults could work (see docs on subparsers)
|
|
|
|
# but that would require all funcs to accept args and extra...
|
2020-04-26 11:19:28 +00:00
|
|
|
try:
|
|
|
|
if args.subparser_name == 'auth':
|
|
|
|
cli.auth(args)
|
|
|
|
elif args.subparser_name == 'list-games':
|
2020-04-28 13:32:38 +00:00
|
|
|
cli.list_games(args)
|
2020-04-26 11:19:28 +00:00
|
|
|
elif args.subparser_name == 'list-installed':
|
|
|
|
cli.list_installed(args)
|
|
|
|
elif args.subparser_name == 'launch':
|
|
|
|
cli.launch_game(args, extra)
|
2020-05-20 10:41:49 +00:00
|
|
|
elif args.subparser_name in ('download', 'install', 'update', 'repair'):
|
2020-04-26 11:19:28 +00:00
|
|
|
cli.install_game(args)
|
|
|
|
elif args.subparser_name == 'uninstall':
|
|
|
|
cli.uninstall_game(args)
|
2020-04-30 09:12:26 +00:00
|
|
|
elif args.subparser_name == 'list-files':
|
|
|
|
cli.list_files(args)
|
2020-05-06 13:40:04 +00:00
|
|
|
elif args.subparser_name == 'list-saves':
|
|
|
|
cli.list_saves(args)
|
|
|
|
elif args.subparser_name == 'download-saves':
|
|
|
|
cli.download_saves(args)
|
2020-05-14 12:52:33 +00:00
|
|
|
elif args.subparser_name == 'sync-saves':
|
|
|
|
cli.sync_saves(args)
|
2020-05-19 16:19:15 +00:00
|
|
|
elif args.subparser_name == 'verify-game':
|
|
|
|
cli.verify_game(args)
|
2020-05-20 12:06:55 +00:00
|
|
|
elif args.subparser_name == 'import-game':
|
|
|
|
cli.import_game(args)
|
2020-04-26 11:19:28 +00:00
|
|
|
except KeyboardInterrupt:
|
|
|
|
logger.info('Command was aborted via KeyboardInterrupt, cleaning up...')
|
2020-04-25 10:20:14 +00:00
|
|
|
|
|
|
|
cli.core.exit()
|
2020-04-26 11:19:28 +00:00
|
|
|
ql.stop()
|
2020-04-14 12:47:46 +00:00
|
|
|
exit(0)
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2020-04-26 11:19:28 +00:00
|
|
|
# required for pyinstaller on Windows, does nothing on other platforms.
|
|
|
|
freeze_support()
|
2020-04-14 12:47:46 +00:00
|
|
|
main()
|