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-09-08 03:12:14 +00:00
|
|
|
import json
|
2020-04-14 12:47:46 +00:00
|
|
|
import logging
|
|
|
|
import os
|
|
|
|
import shlex
|
|
|
|
import subprocess
|
|
|
|
import time
|
|
|
|
import webbrowser
|
|
|
|
|
2021-10-05 06:41:57 +00:00
|
|
|
from collections import defaultdict, namedtuple
|
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
|
2021-12-01 21:04:30 +00:00
|
|
|
from platform import platform
|
2021-12-02 14:23:16 +00:00
|
|
|
from sys import exit, stdout, platform as sys_platform
|
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
|
2021-12-11 17:50:30 +00:00
|
|
|
from legendary.models.game import SaveGameStatus, VerifyResult, Game
|
2021-12-29 11:56:00 +00:00
|
|
|
from legendary.utils.cli import get_boolean_choice, get_int_choice, sdl_prompt, strtobool
|
|
|
|
from legendary.utils.crossover import mac_find_crossover_apps, mac_get_crossover_bottles, mac_is_valid_bottle
|
2020-05-04 12:21:25 +00:00
|
|
|
from legendary.utils.custom_parser import AliasedSubParsersAction
|
2021-12-02 15:51:48 +00:00
|
|
|
from legendary.utils.env import is_windows_mac_or_pyi
|
2021-12-28 16:47:08 +00:00
|
|
|
from legendary.utils.eos import add_registry_entries, query_registry_entries, remove_registry_entries
|
2020-05-19 16:19:15 +00:00
|
|
|
from legendary.utils.lfs import validate_files
|
2020-12-16 11:35:31 +00:00
|
|
|
from legendary.utils.selective_dl import get_sdl_appname
|
2021-09-03 17:00:56 +00:00
|
|
|
from legendary.utils.wine_helpers import read_registry, get_shell_folders
|
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:
|
2021-09-28 01:07:15 +00:00
|
|
|
def __init__(self, override_config=None):
|
|
|
|
self.core = LegendaryCore(override_config)
|
2020-04-25 10:20:14 +00:00
|
|
|
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
|
|
|
|
2021-10-02 19:10:25 +00:00
|
|
|
def _resolve_aliases(self, name):
|
|
|
|
# make sure aliases exist if not yet created
|
|
|
|
self.core.update_aliases(force=False)
|
|
|
|
name = name.strip()
|
2021-10-02 05:41:11 +00:00
|
|
|
# resolve alias (if any) to real app name
|
2021-10-02 19:10:25 +00:00
|
|
|
return self.core.lgd.config.get(
|
|
|
|
section='Legendary.aliases', option=name,
|
|
|
|
fallback=self.core.lgd.aliases.get(name.lower(), name)
|
|
|
|
)
|
2021-10-02 05:41:11 +00:00
|
|
|
|
2021-10-05 06:47:28 +00:00
|
|
|
@staticmethod
|
|
|
|
def _print_json(data, pretty=False):
|
|
|
|
if pretty:
|
|
|
|
print(json.dumps(data, indent=2, sort_keys=True))
|
|
|
|
else:
|
|
|
|
print(json.dumps(data))
|
|
|
|
|
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()
|
2021-10-05 05:34:52 +00:00
|
|
|
logger.info('User data deleted.')
|
2020-05-12 18:01:25 +00:00
|
|
|
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-05-31 00:01:39 +00:00
|
|
|
return
|
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
|
|
|
|
2021-10-05 05:34:52 +00:00
|
|
|
# Force an update check and notice in case there are API changes
|
|
|
|
self.core.check_for_updates(force=True)
|
|
|
|
self.core.force_show_update = True
|
|
|
|
|
2020-05-31 01:16:03 +00:00
|
|
|
if args.import_egs_auth:
|
|
|
|
# get appdata path on Linux
|
|
|
|
if not self.core.egl.appdata_path:
|
2021-09-03 17:00:56 +00:00
|
|
|
egl_wine_pfx = None
|
|
|
|
lutris_wine_pfx = os.path.expanduser('~/Games/epic-games-store')
|
|
|
|
if os.path.exists(lutris_wine_pfx):
|
|
|
|
logger.info(f'Found Lutris EGL WINE prefix at "{lutris_wine_pfx}"')
|
2020-05-31 01:16:03 +00:00
|
|
|
if args.yes or get_boolean_choice('Do you want to use the Lutris install?'):
|
2021-09-03 17:00:56 +00:00
|
|
|
egl_wine_pfx = lutris_wine_pfx
|
2020-05-31 01:16:03 +00:00
|
|
|
|
2021-09-03 17:00:56 +00:00
|
|
|
if not egl_wine_pfx:
|
2020-05-31 01:16:03 +00:00
|
|
|
logger.info('Please enter the path to the Wine prefix that has EGL installed')
|
|
|
|
wine_pfx = input('Path [empty input to quit]: ').strip()
|
|
|
|
if not wine_pfx:
|
|
|
|
print('Empty input, quitting...')
|
|
|
|
exit(0)
|
2021-09-03 17:00:56 +00:00
|
|
|
if not os.path.exists(wine_pfx) and os.path.isdir(wine_pfx):
|
2020-05-31 01:16:03 +00:00
|
|
|
print('Path is invalid (does not exist)!')
|
|
|
|
exit(1)
|
|
|
|
|
2021-09-03 17:20:48 +00:00
|
|
|
try:
|
|
|
|
wine_folders = get_shell_folders(read_registry(egl_wine_pfx), egl_wine_pfx)
|
|
|
|
egl_appdata = os.path.realpath(os.path.join(wine_folders['Local AppData'],
|
|
|
|
'EpicGamesLauncher', 'Saved',
|
|
|
|
'Config', 'Windows'))
|
|
|
|
except Exception as e:
|
|
|
|
logger.error(f'Got exception when trying to read WINE registry: {e!r}')
|
|
|
|
logger.error('Make sure you are specifying a valid wine prefix.')
|
|
|
|
exit(1)
|
|
|
|
|
2021-09-03 17:00:56 +00:00
|
|
|
if not os.path.exists(egl_appdata):
|
|
|
|
logger.error(f'Wine prefix does not have EGL appdata path at "{egl_appdata}"')
|
2020-05-31 01:16:03 +00:00
|
|
|
exit(0)
|
|
|
|
else:
|
2021-09-03 17:00:56 +00:00
|
|
|
logger.info(f'Using EGL appdata path at "{egl_appdata}"')
|
|
|
|
self.core.egl.appdata_path = egl_appdata
|
2020-05-31 01:16:03 +00:00
|
|
|
|
2020-04-14 12:47:46 +00:00
|
|
|
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-05-31 01:16:03 +00:00
|
|
|
return
|
2020-04-14 12:47:46 +00:00
|
|
|
else:
|
|
|
|
logger.warning('Login session from EGS seems to no longer be valid.')
|
|
|
|
exit(1)
|
2021-09-03 18:08:20 +00:00
|
|
|
except Exception as e:
|
|
|
|
logger.error(f'No EGS login session found, please login manually. (Exception: {e!r})')
|
2020-04-14 12:47:46 +00:00
|
|
|
exit(1)
|
|
|
|
|
2020-05-31 00:01:39 +00:00
|
|
|
exchange_token = ''
|
|
|
|
if not args.auth_code and not args.session_id:
|
2021-10-06 08:40:26 +00:00
|
|
|
# only import here since pywebview import is slow
|
|
|
|
from legendary.utils.webview_login import webview_available, do_webview_login
|
|
|
|
|
2021-10-07 03:20:08 +00:00
|
|
|
if not webview_available or args.no_webview or self.core.webview_killswitch:
|
2021-10-06 08:40:26 +00:00
|
|
|
# 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%2Fredirect'
|
|
|
|
)
|
2021-12-03 16:54:14 +00:00
|
|
|
print('If the web page did not open automatically, please manually open the following URL: '
|
2021-10-06 08:40:26 +00:00
|
|
|
'https://www.epicgames.com/id/login?redirectUrl=https://www.epicgames.com/id/api/redirect')
|
|
|
|
sid = input('Please enter the "sid" value from the JSON response: ')
|
|
|
|
sid = sid.strip()
|
|
|
|
if sid[0] == '{':
|
|
|
|
tmp = json.loads(sid)
|
|
|
|
sid = tmp['sid']
|
|
|
|
else:
|
|
|
|
sid = sid.strip('"')
|
|
|
|
exchange_token = self.core.auth_sid(sid)
|
2021-10-06 05:24:33 +00:00
|
|
|
else:
|
2021-10-07 03:10:14 +00:00
|
|
|
if do_webview_login(callback_sid=self.core.auth_sid, callback_code=self.core.auth_code):
|
2021-10-06 08:40:26 +00:00
|
|
|
logger.info(f'Successfully logged in as "{self.core.lgd.userdata["displayName"]}" via WebView')
|
|
|
|
else:
|
|
|
|
logger.error('WebView login attempt failed, please see log for details.')
|
|
|
|
return
|
2020-05-31 00:01:39 +00:00
|
|
|
elif args.session_id:
|
|
|
|
exchange_token = self.core.auth_sid(args.session_id)
|
|
|
|
elif args.auth_code:
|
2020-05-12 18:01:25 +00:00
|
|
|
exchange_token = args.auth_code
|
2020-04-14 12:47:46 +00:00
|
|
|
|
2020-05-31 00:01:39 +00:00
|
|
|
if not exchange_token:
|
|
|
|
logger.fatal('No exchange token, cannot login.')
|
|
|
|
return
|
|
|
|
|
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)
|
2021-09-28 03:56:19 +00:00
|
|
|
|
|
|
|
if args.force_refresh:
|
|
|
|
logger.info('Refreshing game list, this may take a while...')
|
|
|
|
else:
|
|
|
|
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(
|
2021-12-01 19:57:43 +00:00
|
|
|
platform=args.platform, skip_ue=not args.include_ue,
|
2021-09-28 03:56:19 +00:00
|
|
|
force_refresh=args.force_refresh
|
2020-04-28 13:32:38 +00:00
|
|
|
)
|
2021-09-01 13:28:25 +00:00
|
|
|
# Get information for games that cannot be installed through legendary (yet), such
|
|
|
|
# as games that have to be activated on and launched through Origin.
|
|
|
|
if args.include_noasset:
|
|
|
|
na_games, na_dlcs = self.core.get_non_asset_library_items(skip_ue=not args.include_ue)
|
|
|
|
games.extend(na_games)
|
|
|
|
else:
|
|
|
|
na_dlcs = []
|
|
|
|
|
2020-04-30 10:03:23 +00:00
|
|
|
# sort games and dlc by name
|
2020-12-23 17:04:53 +00:00
|
|
|
games = sorted(games, key=lambda x: x.app_title.lower())
|
2020-04-30 10:03:23 +00:00
|
|
|
for citem_id in dlc_list.keys():
|
2021-09-01 13:28:25 +00:00
|
|
|
if citem_id in na_dlcs:
|
|
|
|
dlc_list[citem_id].extend(na_dlcs[citem_id])
|
2020-12-23 17:04:53 +00:00
|
|
|
dlc_list[citem_id] = sorted(dlc_list[citem_id], key=lambda d: d.app_title.lower())
|
2020-04-30 10:03:23 +00:00
|
|
|
|
|
|
|
if args.csv or args.tsv:
|
2021-10-21 09:39:11 +00:00
|
|
|
writer = csv.writer(stdout, dialect='excel-tab' if args.tsv else 'excel', lineterminator='\n')
|
2020-04-30 10:03:23 +00:00
|
|
|
writer.writerow(['App name', 'App title', 'Version', 'Is DLC'])
|
|
|
|
for game in games:
|
2021-12-01 19:57:43 +00:00
|
|
|
writer.writerow((game.app_name, game.app_title, game.app_version(args.platform), False))
|
2021-12-02 13:28:21 +00:00
|
|
|
for dlc in dlc_list[game.catalog_item_id]:
|
2021-12-01 19:57:43 +00:00
|
|
|
writer.writerow((dlc.app_name, dlc.app_title, dlc.app_version(args.platform), True))
|
2020-04-30 10:03:23 +00:00
|
|
|
return
|
2020-04-14 12:47:46 +00:00
|
|
|
|
2020-09-08 03:12:14 +00:00
|
|
|
if args.json:
|
|
|
|
_out = []
|
|
|
|
for game in games:
|
|
|
|
_j = vars(game)
|
2021-12-02 13:28:21 +00:00
|
|
|
_j['dlcs'] = [vars(dlc) for dlc in dlc_list[game.catalog_item_id]]
|
2020-09-08 03:12:14 +00:00
|
|
|
_out.append(_j)
|
|
|
|
|
2021-10-05 06:47:28 +00:00
|
|
|
return self._print_json(_out, args.pretty_json)
|
2020-09-08 03:12:14 +00:00
|
|
|
|
2020-04-14 12:47:46 +00:00
|
|
|
print('\nAvailable games:')
|
2020-04-30 10:03:23 +00:00
|
|
|
for game in games:
|
2021-12-06 18:33:55 +00:00
|
|
|
version = game.app_version(args.platform)
|
|
|
|
print(f' * {game.app_title.strip()} (App name: {game.app_name} | Version: {version})')
|
|
|
|
# Games that "require" launching through EGL/Legendary, but have to be installed and managed through
|
|
|
|
# a third-party application (such as Origin).
|
|
|
|
if not version:
|
2021-10-16 17:44:15 +00:00
|
|
|
_store = game.third_party_store
|
2021-09-08 08:43:30 +00:00
|
|
|
if _store == 'Origin':
|
2021-09-03 20:59:47 +00:00
|
|
|
print(f' - This game has to be activated, installed, and launched via Origin, use '
|
|
|
|
f'"legendary launch --origin {game.app_name}" to activate and/or run the game.')
|
2021-10-16 17:44:15 +00:00
|
|
|
elif _store:
|
2021-12-06 18:33:55 +00:00
|
|
|
print(f' ! This game has to be installed through a third-party store ({_store}, not supported)')
|
2021-10-16 17:44:15 +00:00
|
|
|
else:
|
|
|
|
print(f' ! No version information (unknown cause)')
|
2021-12-06 18:33:55 +00:00
|
|
|
# Games that have assets, but only require a one-time activation before they can be independently installed
|
|
|
|
# via a third-party platform (e.g. Uplay)
|
|
|
|
if game.partner_link_type:
|
|
|
|
_type = game.partner_link_type
|
|
|
|
if _type == 'ubisoft':
|
|
|
|
print(' - This game can be activated directly on your Ubisoft account and does not require '
|
|
|
|
'legendary to install/run. Use "legendary activate --uplay" and follow the instructions.')
|
|
|
|
else:
|
|
|
|
print(f' ! This app requires linking to a third-party account (name: "{_type}", not supported)')
|
|
|
|
|
2021-12-02 13:28:21 +00:00
|
|
|
for dlc in dlc_list[game.catalog_item_id]:
|
2021-12-01 19:57:43 +00:00
|
|
|
print(f' + {dlc.app_title} (App name: {dlc.app_name} | Version: {dlc.app_version(args.platform)})')
|
|
|
|
if not dlc.app_version(args.platform):
|
2021-12-02 13:28:21 +00:00
|
|
|
print(f' ! This DLC is either included in the base game, or not available for {args.platform}')
|
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:
|
2021-12-01 20:02:38 +00:00
|
|
|
# Update assets for all platforms currently installed
|
2021-12-02 12:31:55 +00:00
|
|
|
for app_platform in self.core.get_installed_platforms():
|
|
|
|
self.core.get_assets(True, platform=app_platform)
|
2020-04-14 12:47:46 +00:00
|
|
|
|
2021-09-10 18:23:16 +00:00
|
|
|
games = sorted(self.core.get_installed_list(include_dlc=True),
|
2020-12-23 17:04:53 +00:00
|
|
|
key=lambda x: x.title.lower())
|
2020-04-30 10:03:23 +00:00
|
|
|
|
|
|
|
versions = dict()
|
|
|
|
for game in games:
|
2020-09-08 02:25:34 +00:00
|
|
|
try:
|
2021-12-01 19:57:43 +00:00
|
|
|
versions[game.app_name] = self.core.get_asset(game.app_name, platform=game.platform).build_version
|
2020-09-08 02:25:34 +00:00
|
|
|
except ValueError:
|
|
|
|
logger.warning(f'Metadata for "{game.app_name}" is missing, the game may have been removed from '
|
|
|
|
f'your account or not be in legendary\'s database yet, try rerunning the command '
|
|
|
|
f'with "--check-updates".')
|
2020-04-30 10:03:23 +00:00
|
|
|
|
|
|
|
if args.csv or args.tsv:
|
2021-10-21 09:39:11 +00:00
|
|
|
writer = csv.writer(stdout, dialect='excel-tab' if args.tsv else 'excel', lineterminator='\n')
|
2020-09-05 03:25:13 +00:00
|
|
|
writer.writerow(['App name', 'App title', 'Installed version', 'Available version',
|
2021-12-02 12:35:56 +00:00
|
|
|
'Update available', 'Install size', 'Install path', 'Platform'])
|
2020-04-30 10:03:23 +00:00
|
|
|
writer.writerows((game.app_name, game.title, game.version, versions[game.app_name],
|
2021-12-02 12:35:56 +00:00
|
|
|
versions[game.app_name] != game.version, game.install_size, game.install_path,
|
|
|
|
game.platform)
|
2020-09-08 02:25:34 +00:00
|
|
|
for game in games if game.app_name in versions)
|
2020-04-30 10:03:23 +00:00
|
|
|
return
|
|
|
|
|
2020-09-08 03:12:14 +00:00
|
|
|
if args.json:
|
2021-10-05 06:47:28 +00:00
|
|
|
return self._print_json([vars(g) for g in games], args.pretty_json)
|
2020-09-08 03:12:14 +00:00
|
|
|
|
2021-09-10 18:23:16 +00:00
|
|
|
installed_dlcs = defaultdict(list)
|
|
|
|
for game in games.copy():
|
|
|
|
if not game.is_dlc:
|
|
|
|
continue
|
|
|
|
games.remove(game)
|
|
|
|
dlc = self.core.get_game(game.app_name)
|
2021-12-01 20:11:53 +00:00
|
|
|
if not dlc or not dlc.metadata:
|
|
|
|
logger.warning(f'DLC "{game.app_name}" is missing metadata for some reason. '
|
|
|
|
f'Running "legendary list-games" may fix this.')
|
|
|
|
continue
|
2021-09-10 18:23:16 +00:00
|
|
|
main_app_name = dlc.metadata['mainGameItem']['releaseInfo'][0]['appId']
|
|
|
|
installed_dlcs[main_app_name].append(game)
|
|
|
|
|
2020-04-14 12:47:46 +00:00
|
|
|
print('\nInstalled games:')
|
2020-04-30 10:03:23 +00:00
|
|
|
for game in games:
|
2020-05-28 21:05:36 +00:00
|
|
|
if game.install_size == 0:
|
|
|
|
logger.debug(f'Updating missing size for {game.app_name}')
|
2020-06-05 13:01:02 +00:00
|
|
|
m = self.core.load_manifest(self.core.get_installed_manifest(game.app_name)[0])
|
2020-05-28 21:05:36 +00:00
|
|
|
game.install_size = sum(fm.file_size for fm in m.file_manifest_list.elements)
|
|
|
|
self.core.install_game(game)
|
|
|
|
|
|
|
|
print(f' * {game.title} (App name: {game.app_name} | Version: {game.version} | '
|
2021-12-28 13:03:26 +00:00
|
|
|
f'Platform: {game.platform} | {game.install_size / (1024 * 1024 * 1024):.02f} GiB)')
|
2020-06-02 05:54:51 +00:00
|
|
|
if args.include_dir:
|
|
|
|
print(f' + Location: {game.install_path}')
|
2020-06-02 10:12:42 +00:00
|
|
|
if not os.path.exists(game.install_path):
|
|
|
|
print(f' ! Game does no longer appear to be installed (directory "{game.install_path}" missing)!')
|
2020-09-08 02:25:34 +00:00
|
|
|
elif game.app_name in versions and versions[game.app_name] != game.version:
|
2020-04-30 10:03:23 +00:00
|
|
|
print(f' -> Update available! Installed: {game.version}, Latest: {versions[game.app_name]}')
|
2021-09-10 18:23:16 +00:00
|
|
|
for dlc in installed_dlcs[game.app_name]:
|
2021-09-10 18:36:51 +00:00
|
|
|
print(f' + {dlc.title} (App name: {dlc.app_name} | Version: {dlc.version}) | '
|
2021-12-28 13:03:26 +00:00
|
|
|
f'{dlc.install_size / (1024 * 1024 * 1024):.02f} GiB)')
|
2021-09-10 18:23:16 +00:00
|
|
|
if dlc.app_name in versions and versions[dlc.app_name] != dlc.version:
|
|
|
|
print(f' -> Update available! Installed: {dlc.version}, Latest: {versions[dlc.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):
|
2021-12-01 19:57:43 +00:00
|
|
|
if args.platform:
|
2020-04-30 09:12:26 +00:00
|
|
|
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
|
2021-10-02 05:41:11 +00:00
|
|
|
elif args.app_name:
|
|
|
|
args.app_name = self._resolve_aliases(args.app_name)
|
2020-04-30 10:31:23 +00:00
|
|
|
|
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-06-05 13:01:02 +00:00
|
|
|
manifest_data, _ = self.core.get_uri_manifest(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-09-09 07:53:05 +00:00
|
|
|
if not game:
|
|
|
|
logger.fatal(f'Could not fetch metadata for "{args.app_name}" (check spelling/account ownership)')
|
|
|
|
exit(1)
|
2021-12-01 19:57:43 +00:00
|
|
|
manifest_data, _ = self.core.get_cdn_manifest(game, platform=args.platform)
|
2020-04-30 09:12:26 +00:00
|
|
|
|
2020-06-05 13:01:02 +00:00
|
|
|
manifest = self.core.load_manifest(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:
|
2021-10-21 09:39:11 +00:00
|
|
|
writer = csv.writer(stdout, dialect='excel-tab' if args.tsv else 'excel', lineterminator='\n')
|
2020-05-01 12:34:34 +00:00
|
|
|
writer.writerow(['path', 'hash', 'size', 'install_tags'])
|
2020-12-16 11:37:12 +00:00
|
|
|
writer.writerows((fm.filename, fm.hash.hex(), fm.file_size, '|'.join(fm.install_tags)) for fm in files)
|
2020-09-08 03:12:14 +00:00
|
|
|
elif args.json:
|
|
|
|
_files = []
|
|
|
|
for fm in files:
|
|
|
|
_files.append(dict(
|
|
|
|
filename=fm.filename,
|
|
|
|
sha_hash=fm.hash.hex(),
|
|
|
|
install_tags=fm.install_tags,
|
|
|
|
file_size=fm.file_size,
|
|
|
|
flags=fm.flags,
|
|
|
|
))
|
2021-10-05 06:47:28 +00:00
|
|
|
return self._print_json(_files, args.pretty_json)
|
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...')
|
2021-10-02 05:41:11 +00:00
|
|
|
saves = self.core.get_save_games(self._resolve_aliases(args.app_name))
|
2020-05-06 13:40:04 +00:00
|
|
|
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()}"')
|
2021-10-02 05:41:11 +00:00
|
|
|
self.core.download_saves(self._resolve_aliases(args.app_name))
|
2020-05-14 12:52:33 +00:00
|
|
|
|
2021-10-21 11:26:36 +00:00
|
|
|
def clean_saves(self, args):
|
|
|
|
if not self.core.login():
|
|
|
|
logger.error('Login failed! Cannot continue with download process.')
|
|
|
|
exit(1)
|
|
|
|
logger.info(f'Cleaning saves...')
|
2021-10-21 12:27:08 +00:00
|
|
|
self.core.clean_saves(self._resolve_aliases(args.app_name), args.delete_incomplete)
|
2021-10-21 11:26:36 +00:00
|
|
|
|
2020-05-14 12:52:33 +00:00
|
|
|
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:
|
2021-10-02 05:41:11 +00:00
|
|
|
args.app_name = self._resolve_aliases(args.app_name)
|
2020-05-14 12:52:33 +00:00
|
|
|
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)
|
2021-12-02 14:24:01 +00:00
|
|
|
if not game or not (game.supports_cloud_saves or game.supports_mac_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:
|
2021-12-02 14:24:01 +00:00
|
|
|
save_path = self.core.get_save_path(igame.app_name, platform=igame.platform)
|
2020-05-14 12:52:33 +00:00
|
|
|
|
|
|
|
# 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.')
|
2020-05-29 21:09:21 +00:00
|
|
|
yn = False
|
2020-05-14 12:52:33 +00:00
|
|
|
else:
|
2020-05-29 21:09:21 +00:00
|
|
|
yn = get_boolean_choice('Is this correct?')
|
2020-05-14 12:52:33 +00:00
|
|
|
|
2020-05-29 21:09:21 +00:00
|
|
|
if not yn:
|
2020-05-14 12:52:33 +00:00
|
|
|
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:
|
2020-05-29 21:09:21 +00:00
|
|
|
if not get_boolean_choice(f'Download cloud save?'):
|
2020-05-14 12:52:33 +00:00
|
|
|
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:
|
2020-05-29 21:09:21 +00:00
|
|
|
if not get_boolean_choice(f'Upload local save?'):
|
2020-05-14 12:52:33 +00:00
|
|
|
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):
|
2021-10-02 05:41:11 +00:00
|
|
|
app_name = self._resolve_aliases(args.app_name)
|
2021-09-03 20:59:47 +00:00
|
|
|
if args.origin:
|
2021-09-28 03:23:39 +00:00
|
|
|
return self._launch_origin(args)
|
2021-09-03 20:59:47 +00:00
|
|
|
|
2020-06-02 10:12:03 +00:00
|
|
|
igame = self.core.get_installed_game(app_name)
|
|
|
|
if not igame:
|
2020-04-14 12:47:46 +00:00
|
|
|
logger.error(f'Game {app_name} is not currently installed!')
|
|
|
|
exit(1)
|
|
|
|
|
2020-06-02 10:12:03 +00:00
|
|
|
if igame.is_dlc:
|
2020-04-18 00:11:58 +00:00
|
|
|
logger.error(f'{app_name} is DLC; please launch the base game instead!')
|
|
|
|
exit(1)
|
|
|
|
|
2020-06-02 10:12:03 +00:00
|
|
|
if not os.path.exists(igame.install_path):
|
|
|
|
logger.fatal(f'Install directory "{igame.install_path}" appears to be deleted, cannot launch {app_name}!')
|
|
|
|
exit(1)
|
|
|
|
|
2020-06-01 06:40:00 +00:00
|
|
|
if args.reset_defaults:
|
|
|
|
logger.info(f'Removing configuration section for "{app_name}"...')
|
|
|
|
self.core.lgd.config.remove_section(app_name)
|
|
|
|
return
|
|
|
|
|
2021-12-29 11:56:00 +00:00
|
|
|
# Interactive CrossOver setup
|
|
|
|
if args.crossover and sys_platform == 'darwin':
|
|
|
|
logger.info('Looking for CrossOver installs...')
|
|
|
|
apps = mac_find_crossover_apps()
|
|
|
|
if len(apps) > 1:
|
|
|
|
print('Found multiple CrossOver installs, please select one:')
|
|
|
|
for i, (ver, path) in enumerate(apps, start=1):
|
|
|
|
print(f'\t{i:2d}. {ver} ({path})')
|
|
|
|
choice = get_int_choice(f'Select a CrossOver install', 1, 1, len(apps))
|
|
|
|
if choice is None:
|
|
|
|
logger.error(f'No valid choice made, aborting.')
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
cx_version, args.crossover_app = apps[choice-1]
|
|
|
|
elif len(apps) == 1:
|
|
|
|
cx_version, args.crossover_app = apps[0]
|
|
|
|
logger.info(f'Found CrossOver {cx_version} at {args.crossover_app}')
|
|
|
|
else:
|
|
|
|
logger.error(f'No CrossOver installs found, see https://legendary.gl/crossover-setup '
|
|
|
|
f'for setup instructions')
|
|
|
|
return
|
|
|
|
|
|
|
|
bottles = mac_get_crossover_bottles()
|
|
|
|
if 'Legendary' not in bottles:
|
|
|
|
logger.info('It is recommended to set up a bottle specifically for Legendary, see '
|
|
|
|
'https://legendary.gl/crossover-setup for setup instructions.')
|
|
|
|
|
|
|
|
if len(bottles) > 1:
|
|
|
|
print('Found multiple CrossOver bottles, please select one:')
|
|
|
|
|
|
|
|
if 'Legendary' in bottles:
|
|
|
|
default_choice = bottles.index('Legendary') + 1
|
|
|
|
elif 'Heroic' in bottles:
|
|
|
|
default_choice = bottles.index('Heroic') + 1
|
|
|
|
elif 'default' in bottles:
|
|
|
|
default_choice = bottles.index('default') + 1
|
|
|
|
else:
|
|
|
|
default_choice = 1
|
|
|
|
|
|
|
|
for i, bottle in enumerate(bottles, start=1):
|
|
|
|
if i == default_choice:
|
|
|
|
print(f'\t{i:2d}. {bottle} (default)')
|
|
|
|
else:
|
|
|
|
print(f'\t{i:2d}. {bottle}')
|
|
|
|
|
|
|
|
choice = get_int_choice(f'Select a bottle', default_choice, 1, len(bottles))
|
|
|
|
if choice is None:
|
|
|
|
logger.error(f'No valid choice made, aborting.')
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
args.crossover_bottle = bottles[choice-1]
|
|
|
|
elif len(bottles) == 1:
|
|
|
|
logger.info(f'Found only one bottle: {bottles[0]}')
|
|
|
|
args.crossover_bottle = bottles[0]
|
|
|
|
else:
|
|
|
|
logger.error('No Bottles found, see https://legendary.gl/crossover-setup for setup instructions.')
|
|
|
|
return
|
|
|
|
|
|
|
|
logger.info(f'Current launch configuration: '
|
|
|
|
f'--crossover-bottle "{args.crossover_bottle}" '
|
|
|
|
f'--crossover-app "{args.crossover_app}" ')
|
|
|
|
y_n = get_boolean_choice('Would you like to save these choices for this application?')
|
|
|
|
if y_n:
|
|
|
|
self.core.lgd.config.set(app_name, 'crossover_app', args.crossover_app)
|
|
|
|
self.core.lgd.config.set(app_name, 'crossover_bottle', args.crossover_bottle)
|
|
|
|
|
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-09-08 02:25:34 +00:00
|
|
|
try:
|
2021-12-01 20:02:38 +00:00
|
|
|
latest = self.core.get_asset(app_name, update=True, platform=igame.platform)
|
2020-09-08 02:25:34 +00:00
|
|
|
except ValueError:
|
|
|
|
logger.fatal(f'Metadata for "{app_name}" does not exist, cannot launch!')
|
|
|
|
exit(1)
|
|
|
|
|
2020-06-02 10:12:03 +00:00
|
|
|
if latest.build_version != igame.version:
|
2020-04-14 12:47:46 +00:00
|
|
|
logger.error('Game is out of date, please update or launch with update check skipping!')
|
|
|
|
exit(1)
|
|
|
|
|
2021-09-28 02:04:15 +00:00
|
|
|
params = self.core.get_launch_parameters(app_name=app_name, offline=args.offline,
|
|
|
|
extra_args=extra, user=args.user_name_override,
|
|
|
|
wine_bin=args.wine_bin, wine_pfx=args.wine_pfx,
|
|
|
|
language=args.language, wrapper=args.wrapper,
|
|
|
|
disable_wine=args.no_wine,
|
2021-12-29 11:56:00 +00:00
|
|
|
executable_override=args.executable_override,
|
|
|
|
crossover_app=args.crossover_app,
|
|
|
|
crossover_bottle=args.crossover_bottle)
|
2020-04-14 12:47:46 +00:00
|
|
|
|
2020-06-01 06:40:00 +00:00
|
|
|
if args.set_defaults:
|
|
|
|
self.core.lgd.config[app_name] = dict()
|
|
|
|
# we have to do this if-cacophony here because an empty value is still
|
|
|
|
# valid and could cause issues when relying on config.get()'s fallback
|
|
|
|
if args.offline:
|
|
|
|
self.core.lgd.config[app_name]['offline'] = 'true'
|
|
|
|
if args.skip_version_check:
|
|
|
|
self.core.lgd.config[app_name]['skip_update_check'] = 'true'
|
|
|
|
if extra:
|
|
|
|
self.core.lgd.config[app_name]['start_params'] = shlex.join(extra)
|
|
|
|
if args.wine_bin:
|
|
|
|
self.core.lgd.config[app_name]['wine_executable'] = args.wine_bin
|
|
|
|
if args.wine_pfx:
|
|
|
|
self.core.lgd.config[app_name]['wine_prefix'] = args.wine_pfx
|
|
|
|
if args.no_wine:
|
|
|
|
self.core.lgd.config[app_name]['no_wine'] = 'true'
|
|
|
|
if args.language:
|
|
|
|
self.core.lgd.config[app_name]['language'] = args.language
|
|
|
|
if args.wrapper:
|
|
|
|
self.core.lgd.config[app_name]['wrapper'] = args.wrapper
|
2021-12-29 11:56:00 +00:00
|
|
|
if sys_platform == 'darwin':
|
|
|
|
if args.crossover_app:
|
|
|
|
self.core.lgd.config[app_name]['crossover_app'] = args.crossover_app
|
|
|
|
if args.crossover_bottle:
|
|
|
|
self.core.lgd.config[app_name]['crossover_bottle'] = args.crossover_bottle
|
2020-06-01 06:40:00 +00:00
|
|
|
|
2021-09-28 02:04:15 +00:00
|
|
|
if args.json:
|
2021-10-05 06:47:28 +00:00
|
|
|
return self._print_json(vars(params), args.pretty_json)
|
2021-09-28 02:04:15 +00:00
|
|
|
|
|
|
|
full_params = list()
|
|
|
|
full_params.extend(params.launch_command)
|
|
|
|
full_params.append(os.path.join(params.game_directory, params.game_executable))
|
|
|
|
full_params.extend(params.game_parameters)
|
|
|
|
full_params.extend(params.egl_parameters)
|
|
|
|
full_params.extend(params.user_parameters)
|
2021-09-28 03:07:06 +00:00
|
|
|
# Copying existing env vars is required on Windows, probably a good idea on Linux
|
|
|
|
full_env = os.environ.copy()
|
|
|
|
full_env.update(params.environment)
|
2021-09-28 02:04:15 +00:00
|
|
|
|
2021-12-29 11:56:00 +00:00
|
|
|
if 'CX_BOTTLE' in full_env:
|
|
|
|
# if using crossover, unset WINEPREFIX
|
|
|
|
full_env.pop('WINEPREFIX', None)
|
|
|
|
# check that bottle is valid, show error otherwise
|
|
|
|
bottle_name = full_env["CX_BOTTLE"].strip()
|
|
|
|
if not mac_is_valid_bottle(bottle_name):
|
|
|
|
if bottle_name == 'Legendary':
|
|
|
|
logger.error('Attempted to use default CrossOver bottle ("Legendary"), but it does not exist, '
|
|
|
|
'see https://legendary.gl/crossover-setup for setup instructions.')
|
|
|
|
else:
|
|
|
|
logger.error(f'Specified CrossOver bottle {bottle_name} does not exist, cannot launch.')
|
|
|
|
exit(1)
|
|
|
|
|
2020-04-14 12:47:46 +00:00
|
|
|
if args.dry_run:
|
2020-06-01 06:40:00 +00:00
|
|
|
logger.info(f'Not Launching {app_name} (dry run)')
|
2021-09-28 02:04:15 +00:00
|
|
|
logger.info(f'Launch parameters: {shlex.join(full_params)}')
|
|
|
|
logger.info(f'Working directory: {params.working_directory}')
|
2021-09-28 03:07:06 +00:00
|
|
|
if params.environment:
|
|
|
|
logger.info('Environment overrides: {}'.format(', '.join(
|
|
|
|
f'{k}={v}' for k, v in params.environment.items())))
|
2020-04-14 12:47:46 +00:00
|
|
|
else:
|
2020-06-01 06:40:00 +00:00
|
|
|
logger.info(f'Launching {app_name}...')
|
2021-09-28 02:04:15 +00:00
|
|
|
logger.debug(f'Launch parameters: {shlex.join(full_params)}')
|
|
|
|
logger.debug(f'Working directory: {params.working_directory}')
|
2021-09-28 03:07:06 +00:00
|
|
|
if params.environment:
|
2021-12-29 10:56:16 +00:00
|
|
|
logger.debug('Environment overrides: {}'.format(', '.join(
|
2021-09-28 03:07:06 +00:00
|
|
|
f'{k}={v}' for k, v in params.environment.items())))
|
|
|
|
subprocess.Popen(full_params, cwd=params.working_directory, env=full_env)
|
2020-04-14 12:47:46 +00:00
|
|
|
|
2021-09-28 03:23:39 +00:00
|
|
|
def _launch_origin(self, args):
|
2021-09-28 03:57:39 +00:00
|
|
|
game = self.core.get_game(app_name=args.app_name)
|
|
|
|
if not game:
|
2021-12-06 18:31:39 +00:00
|
|
|
logger.error(f'Unknown game "{args.app_name}", run "legendary list-games --third-party" '
|
2021-09-28 03:57:39 +00:00
|
|
|
f'to fetch data for Origin titles before using this command.')
|
|
|
|
return
|
|
|
|
|
2021-10-16 17:44:15 +00:00
|
|
|
if not game.third_party_store or game.third_party_store != 'Origin':
|
2021-09-28 03:57:39 +00:00
|
|
|
logger.error(f'The specified game is not an Origin title.')
|
|
|
|
return
|
|
|
|
|
2021-09-03 20:59:47 +00:00
|
|
|
# login is not required to launch the game, but linking does require it.
|
|
|
|
if not args.offline:
|
|
|
|
logger.info('Logging in...')
|
|
|
|
if not self.core.login():
|
|
|
|
logger.error('Login failed, cannot continue!')
|
|
|
|
exit(1)
|
|
|
|
|
|
|
|
origin_uri = self.core.get_origin_uri(args.app_name, args.offline)
|
2021-09-28 03:20:40 +00:00
|
|
|
if args.json:
|
2021-10-05 06:47:28 +00:00
|
|
|
return self._print_json(dict(uri=origin_uri), args.pretty_json)
|
2021-09-28 03:20:40 +00:00
|
|
|
|
2021-09-08 08:43:30 +00:00
|
|
|
if os.name == 'nt':
|
2021-10-10 10:33:42 +00:00
|
|
|
if args.dry_run:
|
|
|
|
logger.info(f'Origin URI: {origin_uri}')
|
|
|
|
else:
|
|
|
|
logger.debug(f'Opening Origin URI: {origin_uri}')
|
|
|
|
webbrowser.open(origin_uri)
|
|
|
|
return
|
2021-09-08 08:43:30 +00:00
|
|
|
|
|
|
|
# on linux, require users to specify at least the wine binary and prefix in config or command line
|
2021-09-28 03:23:39 +00:00
|
|
|
command = self.core.get_app_launch_command(args.app_name, wrapper=args.wrapper,
|
|
|
|
wine_binary=args.wine_bin,
|
|
|
|
disable_wine=args.no_wine)
|
|
|
|
env = self.core.get_app_environment(args.app_name, wine_pfx=args.wine_pfx)
|
|
|
|
full_env = os.environ.copy()
|
|
|
|
full_env.update(env)
|
|
|
|
|
|
|
|
if not command:
|
|
|
|
logger.error(f'In order to launch Origin correctly you must specify a prefix and wine binary or '
|
|
|
|
f'wrapper in the configuration file or command line. See the README for details.')
|
2021-09-08 08:43:30 +00:00
|
|
|
return
|
2021-09-28 03:23:39 +00:00
|
|
|
|
|
|
|
command.append(origin_uri)
|
2021-10-10 10:33:42 +00:00
|
|
|
if args.dry_run:
|
|
|
|
logger.info(f'Origin launch command: {shlex.join(command)}')
|
|
|
|
else:
|
|
|
|
logger.debug(f'Opening Origin URI with command: {shlex.join(command)}')
|
|
|
|
subprocess.Popen(command, env=full_env)
|
2021-09-03 20:59:47 +00:00
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
def install_game(self, args):
|
2021-10-02 05:41:11 +00:00
|
|
|
args.app_name = self._resolve_aliases(args.app_name)
|
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)
|
2021-12-01 19:57:43 +00:00
|
|
|
args.platform = igame.platform
|
2020-05-20 12:06:55 +00:00
|
|
|
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
|
2020-12-17 13:55:32 +00:00
|
|
|
args.no_install = args.repair_and_update is False
|
2020-05-20 10:41:49 +00:00
|
|
|
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)
|
|
|
|
|
2021-06-17 13:21:46 +00:00
|
|
|
if args.file_prefix or args.file_exclude_prefix:
|
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)
|
|
|
|
|
2021-12-02 15:16:52 +00:00
|
|
|
game = self.core.get_game(args.app_name, update_meta=True, platform=args.platform)
|
2020-04-14 12:47:46 +00:00
|
|
|
|
|
|
|
if not game:
|
2021-10-02 05:41:11 +00:00
|
|
|
logger.error(f'Could not find "{args.app_name}" in list of available games, '
|
2020-04-25 10:20:14 +00:00
|
|
|
f'did you type the name correctly?')
|
2020-04-14 12:47:46 +00:00
|
|
|
exit(1)
|
|
|
|
|
2021-10-16 17:47:19 +00:00
|
|
|
if store := game.third_party_store:
|
|
|
|
logger.error(f'The selected title has to be installed via a third-party store: {store}')
|
|
|
|
if store == 'Origin':
|
|
|
|
logger.info(f'For Origin games use "legendary launch --origin {args.app_name}" to '
|
|
|
|
f'activate and/or run the game.')
|
|
|
|
exit(0)
|
|
|
|
|
2021-12-28 09:04:37 +00:00
|
|
|
if args.platform not in game.asset_infos:
|
|
|
|
if not args.no_install:
|
|
|
|
logger.error(f'No app asset found for platform "{args.platform}", run '
|
2021-12-29 11:54:38 +00:00
|
|
|
f'"legendary info --platform {args.platform}" and make '
|
2021-12-28 09:04:37 +00:00
|
|
|
f'sure the app is available for the specified platform.')
|
|
|
|
exit(1)
|
|
|
|
else:
|
|
|
|
logger.warning(f'No asset found for platform "{args.platform}", '
|
|
|
|
f'trying anyway since --no-install is set.')
|
|
|
|
|
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:
|
2020-05-29 21:09:21 +00:00
|
|
|
if not get_boolean_choice(f'Verify "{game.app_name}" now ("no" will abort repair)?'):
|
2020-05-20 10:41:49 +00:00
|
|
|
print('Aborting...')
|
|
|
|
exit(0)
|
|
|
|
|
|
|
|
self.verify_game(args, print_command=False)
|
|
|
|
else:
|
|
|
|
logger.info(f'Using existing repair file: {repair_file}')
|
|
|
|
|
2021-09-29 06:05:37 +00:00
|
|
|
# check if SDL should be disabled
|
|
|
|
sdl_enabled = not args.install_tag and not game.is_dlc
|
|
|
|
config_tags = self.core.lgd.config.get(game.app_name, 'install_tags', fallback=None)
|
|
|
|
config_disable_sdl = self.core.lgd.config.getboolean(game.app_name, 'disable_sdl', fallback=False)
|
|
|
|
# remove config flag if SDL is reset
|
|
|
|
if config_disable_sdl and args.reset_sdl and not args.disable_sdl:
|
|
|
|
self.core.lgd.config.remove_option(game.app_name, 'disable_sdl')
|
|
|
|
# if config flag is not yet set, set it and remove previous install tags
|
|
|
|
elif not config_disable_sdl and args.disable_sdl:
|
|
|
|
logger.info('Clearing install tags from config and disabling SDL for title.')
|
|
|
|
if config_tags:
|
|
|
|
self.core.lgd.config.remove_option(game.app_name, 'install_tags')
|
|
|
|
config_tags = None
|
|
|
|
self.core.lgd.config.set(game.app_name, 'disable_sdl', True)
|
|
|
|
sdl_enabled = False
|
|
|
|
# just disable SDL, but keep config tags that have been manually specified
|
|
|
|
elif config_disable_sdl or args.disable_sdl:
|
|
|
|
sdl_enabled = False
|
|
|
|
|
|
|
|
if sdl_enabled and ((sdl_name := get_sdl_appname(game.app_name)) is not None):
|
2020-12-17 13:56:09 +00:00
|
|
|
if not self.core.is_installed(game.app_name) or config_tags is None or args.reset_sdl:
|
2021-12-17 00:25:24 +00:00
|
|
|
sdl_data = self.core.get_sdl_data(sdl_name, platform=args.platform)
|
2021-09-05 07:41:54 +00:00
|
|
|
if sdl_data:
|
2021-09-29 06:05:37 +00:00
|
|
|
if args.skip_sdl:
|
|
|
|
args.install_tag = ['']
|
|
|
|
if '__required' in sdl_data:
|
|
|
|
args.install_tag.extend(sdl_data['__required']['tags'])
|
|
|
|
else:
|
|
|
|
args.install_tag = sdl_prompt(sdl_data, game.app_title)
|
2021-09-05 07:41:54 +00:00
|
|
|
self.core.lgd.config.set(game.app_name, 'install_tags', ','.join(args.install_tag))
|
|
|
|
else:
|
|
|
|
logger.error(f'Unable to get SDL data for {sdl_name}')
|
2020-12-08 05:43:43 +00:00
|
|
|
else:
|
2020-12-16 11:35:31 +00:00
|
|
|
args.install_tag = config_tags.split(',')
|
2021-06-17 13:21:46 +00:00
|
|
|
elif args.install_tag and not game.is_dlc and not args.no_install:
|
|
|
|
config_tags = ','.join(args.install_tag)
|
|
|
|
logger.info(f'Saving install tags for "{game.app_name}" to config: {config_tags}')
|
|
|
|
self.core.lgd.config.set(game.app_name, 'install_tags', config_tags)
|
|
|
|
elif not game.is_dlc:
|
|
|
|
if config_tags and args.reset_sdl:
|
|
|
|
logger.info('Clearing install tags from config.')
|
|
|
|
self.core.lgd.config.remove_option(game.app_name, 'install_tags')
|
|
|
|
elif config_tags:
|
|
|
|
logger.info(f'Using install tags from config: {config_tags}')
|
|
|
|
args.install_tag = config_tags.split(',')
|
2020-12-08 05:43:43 +00:00
|
|
|
|
2021-10-02 21:09:59 +00:00
|
|
|
logger.info(f'Preparing download for "{game.app_title}" ({game.app_name})...')
|
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,
|
2021-12-01 19:57:43 +00:00
|
|
|
platform=args.platform,
|
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,
|
2020-09-05 03:20:27 +00:00
|
|
|
repair=args.repair_mode,
|
|
|
|
repair_use_latest=args.repair_and_update,
|
2020-09-09 08:29:57 +00:00
|
|
|
disable_delta=args.disable_delta,
|
2021-08-09 09:17:15 +00:00
|
|
|
override_delta_manifest=args.override_delta_manifest,
|
2021-08-09 09:31:03 +00:00
|
|
|
preferred_cdn=args.preferred_cdn,
|
|
|
|
disable_https=args.disable_https)
|
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:
|
2020-12-17 14:22:26 +00:00
|
|
|
old_igame = self.core.get_installed_game(game.app_name)
|
2020-04-14 12:47:46 +00:00
|
|
|
logger.info('Download size is 0, the game is either already up to date or has not changed. Exiting...')
|
2020-12-17 15:31:38 +00:00
|
|
|
if old_igame and args.repair_mode and os.path.exists(repair_file):
|
2020-12-17 14:22:26 +00:00
|
|
|
if old_igame.needs_verification:
|
|
|
|
old_igame.needs_verification = False
|
|
|
|
self.core.install_game(old_igame)
|
2020-05-20 12:06:55 +00:00
|
|
|
|
2020-05-20 10:41:49 +00:00
|
|
|
logger.debug('Removing repair file.')
|
|
|
|
os.remove(repair_file)
|
2020-12-17 14:22:26 +00:00
|
|
|
|
|
|
|
# check if install tags have changed, if they did; try deleting files that are no longer required.
|
2020-12-17 15:31:38 +00:00
|
|
|
if old_igame and old_igame.install_tags != igame.install_tags:
|
2020-12-17 14:22:26 +00:00
|
|
|
old_igame.install_tags = igame.install_tags
|
|
|
|
self.logger.info('Deleting now untagged files.')
|
|
|
|
self.core.uninstall_tag(old_igame)
|
|
|
|
self.core.install_game(old_igame)
|
|
|
|
|
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) / '
|
2020-12-16 11:37:12 +00:00
|
|
|
f'{analysis.unchanged / 1024 / 1024:.02f} MiB (unchanged / skipped)')
|
2021-12-03 16:54:39 +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-14 12:47:46 +00:00
|
|
|
|
2020-11-02 18:08:06 +00:00
|
|
|
res = self.core.check_installation_conditions(analysis=analysis, install=igame, game=game,
|
2020-09-05 03:20:27 +00:00
|
|
|
updating=self.core.is_installed(args.app_name),
|
|
|
|
ignore_space_req=args.ignore_space)
|
2020-04-14 12:47:46 +00:00
|
|
|
|
2020-11-02 18:08:06 +00:00
|
|
|
if res.warnings or res.failures:
|
2021-12-03 16:54:39 +00:00
|
|
|
print('\nInstallation requirements check returned the following results:')
|
2020-04-14 12:47:46 +00:00
|
|
|
|
|
|
|
if res.warnings:
|
|
|
|
for warn in sorted(res.warnings):
|
2021-12-03 16:54:39 +00:00
|
|
|
print(' - Warning:', warn)
|
|
|
|
if not res.failures:
|
|
|
|
print()
|
2020-04-14 12:47:46 +00:00
|
|
|
|
2020-11-02 18:08:06 +00:00
|
|
|
if res.failures:
|
|
|
|
for msg in sorted(res.failures):
|
2021-12-03 16:54:39 +00:00
|
|
|
print(' ! Failure:', msg)
|
|
|
|
print()
|
|
|
|
logger.fatal('Installation cannot proceed, exiting.')
|
2020-11-02 18:08:06 +00:00
|
|
|
exit(1)
|
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
if not args.yes:
|
2020-05-29 21:09:21 +00:00
|
|
|
if not get_boolean_choice(f'Do you wish to install "{igame.title}"?'):
|
2020-04-25 10:20:14 +00:00
|
|
|
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.')
|
2021-01-02 05:53:21 +00:00
|
|
|
logger.warning(f'The following exception occurred while waiting for the downloader to finish: {e!r}. '
|
2020-04-14 12:47:46 +00:00
|
|
|
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
|
2021-12-02 14:24:01 +00:00
|
|
|
if (game.supports_cloud_saves or game.supports_mac_cloud_saves) and args.save_path:
|
2020-05-14 14:40:27 +00:00
|
|
|
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)
|
2021-10-08 08:20:39 +00:00
|
|
|
if dlcs and not args.skip_dlcs:
|
2020-04-18 00:11:58 +00:00
|
|
|
print('The following DLCs are available for this game:')
|
|
|
|
for dlc in dlcs:
|
2021-12-01 19:57:43 +00:00
|
|
|
print(f' - {dlc.app_title} (App name: {dlc.app_name}, version: '
|
|
|
|
f'{dlc.app_version(args.platform)})')
|
2020-05-14 14:04:03 +00:00
|
|
|
print('Manually installing DLCs works the same; just use the DLC app name instead.')
|
|
|
|
|
2021-10-08 08:20:39 +00:00
|
|
|
install_dlcs = not args.skip_dlcs
|
|
|
|
if not args.yes and not args.with_dlcs and not args.skip_dlcs:
|
2020-05-29 21:09:21 +00:00
|
|
|
if not get_boolean_choice(f'Do you wish to automatically install DLCs?'):
|
2020-05-14 14:04:03 +00:00
|
|
|
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
|
|
|
|
|
2021-12-02 14:24:01 +00:00
|
|
|
if (game.supports_cloud_saves or game.supports_mac_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-12-17 14:22:26 +00:00
|
|
|
old_igame = self.core.get_installed_game(game.app_name)
|
2020-12-17 15:31:38 +00:00
|
|
|
if old_igame and args.repair_mode and os.path.exists(repair_file):
|
2020-12-17 14:22:26 +00:00
|
|
|
if old_igame.needs_verification:
|
|
|
|
old_igame.needs_verification = False
|
|
|
|
self.core.install_game(old_igame)
|
2020-05-20 12:06:55 +00:00
|
|
|
|
2020-05-20 10:41:49 +00:00
|
|
|
logger.debug('Removing repair file.')
|
|
|
|
os.remove(repair_file)
|
|
|
|
|
2020-12-17 14:22:26 +00:00
|
|
|
# check if install tags have changed, if they did; try deleting files that are no longer required.
|
2020-12-17 15:31:38 +00:00
|
|
|
if old_igame and old_igame.install_tags != igame.install_tags:
|
2020-12-17 14:22:26 +00:00
|
|
|
old_igame.install_tags = igame.install_tags
|
|
|
|
self.logger.info('Deleting now untagged files.')
|
|
|
|
self.core.uninstall_tag(old_igame)
|
|
|
|
self.core.install_game(old_igame)
|
|
|
|
|
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):
|
2021-10-02 05:41:11 +00:00
|
|
|
args.app_name = self._resolve_aliases(args.app_name)
|
2020-04-25 10:20:14 +00:00
|
|
|
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-14 12:47:46 +00:00
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
if not args.yes:
|
2020-05-29 21:09:21 +00:00
|
|
|
if not get_boolean_choice(f'Do you wish to uninstall "{igame.title}"?', default=False):
|
2020-04-25 10:20:14 +00:00
|
|
|
print('Aborting...')
|
|
|
|
exit(0)
|
2020-04-18 00:17:01 +00:00
|
|
|
|
2020-04-14 12:47:46 +00:00
|
|
|
try:
|
2021-10-10 15:08:05 +00:00
|
|
|
if not igame.is_dlc:
|
|
|
|
# Remove DLC first so directory is empty when game uninstall runs
|
|
|
|
dlcs = self.core.get_dlc_for_game(igame.app_name)
|
|
|
|
for dlc in dlcs:
|
|
|
|
if (idlc := self.core.get_installed_game(dlc.app_name)) is not None:
|
|
|
|
logger.info(f'Uninstalling DLC "{dlc.app_name}"...')
|
|
|
|
self.core.uninstall_game(idlc, delete_files=not args.keep_files)
|
2020-04-18 00:11:58 +00:00
|
|
|
|
2020-06-10 16:21:47 +00:00
|
|
|
logger.info(f'Removing "{igame.title}" from "{igame.install_path}"...')
|
2021-10-10 15:08:05 +00:00
|
|
|
self.core.uninstall_game(igame, delete_files=not args.keep_files,
|
|
|
|
delete_root_directory=not igame.is_dlc)
|
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):
|
2021-10-02 05:41:11 +00:00
|
|
|
args.app_name = self._resolve_aliases(args.app_name)
|
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)
|
2021-10-10 15:17:42 +00:00
|
|
|
if not os.path.exists(igame.install_path):
|
|
|
|
logger.error(f'Install path "{igame.install_path}" does not exist, make sure all necessary mounts '
|
|
|
|
f'are available. If you previously deleted the game folder without uninstalling, run '
|
|
|
|
f'"legendary uninstall -y {igame.app_name}" and reinstall from scratch.')
|
|
|
|
return
|
|
|
|
|
2020-05-19 16:19:15 +00:00
|
|
|
manifest_data, _ = self.core.get_installed_manifest(args.app_name)
|
2020-06-05 13:01:02 +00:00
|
|
|
manifest = self.core.load_manifest(manifest_data)
|
2020-05-19 16:19:15 +00:00
|
|
|
|
|
|
|
files = sorted(manifest.file_manifest_list.elements,
|
|
|
|
key=lambda a: a.filename.lower())
|
|
|
|
|
|
|
|
# build list of hashes
|
2021-06-17 13:08:31 +00:00
|
|
|
if config_tags := self.core.lgd.config.get(args.app_name, 'install_tags', fallback=None):
|
|
|
|
install_tags = set(i.strip() for i in config_tags.split(','))
|
|
|
|
file_list = [
|
|
|
|
(f.filename, f.sha_hash.hex())
|
|
|
|
for f in files
|
|
|
|
if any(it in install_tags for it in f.install_tags) or not f.install_tags
|
|
|
|
]
|
|
|
|
else:
|
|
|
|
file_list = [(f.filename, f.sha_hash.hex()) for f in files]
|
|
|
|
|
2020-05-19 16:19:15 +00:00
|
|
|
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')
|
2021-09-28 00:42:17 +00:00
|
|
|
with open(repair_filename, 'w', encoding='utf-8') as f:
|
2020-05-20 10:41:49 +00:00
|
|
|
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):
|
2020-09-05 03:21:36 +00:00
|
|
|
# make sure path is absolute
|
|
|
|
args.app_path = os.path.abspath(args.app_path)
|
2021-10-02 05:41:11 +00:00
|
|
|
args.app_name = self._resolve_aliases(args.app_name)
|
2020-09-05 03:25:13 +00:00
|
|
|
|
2020-05-20 12:06:55 +00:00
|
|
|
if not os.path.exists(args.app_path):
|
|
|
|
logger.error(f'Specified path "{args.app_path}" does not exist!')
|
2021-10-08 08:20:23 +00:00
|
|
|
return
|
2020-05-20 12:06:55 +00:00
|
|
|
|
|
|
|
if self.core.is_installed(args.app_name):
|
|
|
|
logger.error('Game is already installed!')
|
2021-10-08 08:20:23 +00:00
|
|
|
return
|
2020-05-20 12:06:55 +00:00
|
|
|
|
|
|
|
if not self.core.login():
|
|
|
|
logger.error('Log in failed!')
|
2021-10-08 08:20:23 +00:00
|
|
|
return
|
2020-05-20 12:06:55 +00:00
|
|
|
|
|
|
|
# do some basic checks
|
2021-12-01 20:30:15 +00:00
|
|
|
game = self.core.get_game(args.app_name, update_meta=True, platform=args.platform)
|
2020-05-20 12:06:55 +00:00
|
|
|
if not game:
|
|
|
|
logger.fatal(f'Did not find game "{args.app_name}" on account.')
|
2021-10-08 08:20:23 +00:00
|
|
|
return
|
2020-05-20 12:06:55 +00:00
|
|
|
|
2021-10-08 07:39:55 +00:00
|
|
|
if game.is_dlc:
|
|
|
|
release_info = game.metadata.get('mainGameItem', {}).get('releaseInfo')
|
|
|
|
if release_info:
|
|
|
|
main_game_appname = release_info[0]['appId']
|
|
|
|
main_game_title = game.metadata['mainGameItem']['title']
|
|
|
|
if not self.core.is_installed(main_game_appname):
|
|
|
|
logger.error(f'Import candidate is DLC but base game "{main_game_title}" '
|
|
|
|
f'(App name: "{main_game_appname}") is not installed!')
|
2021-10-08 08:20:23 +00:00
|
|
|
return
|
2021-10-08 07:39:55 +00:00
|
|
|
else:
|
|
|
|
logger.fatal(f'Unable to get base game information for DLC, cannot continue.')
|
2021-10-08 08:20:23 +00:00
|
|
|
return
|
2021-10-08 07:39:55 +00:00
|
|
|
|
2020-05-20 12:06:55 +00:00
|
|
|
# get everything needed for import from core, then run additional checks.
|
2021-12-01 20:30:15 +00:00
|
|
|
manifest, igame = self.core.import_game(game, args.app_path, args.platform)
|
2020-05-28 00:40:12 +00:00
|
|
|
exe_path = os.path.join(args.app_path, manifest.meta.launch_exe.lstrip('/'))
|
2020-05-20 12:06:55 +00:00
|
|
|
# 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)
|
2020-05-28 00:40:12 +00:00
|
|
|
ratio = found / total
|
|
|
|
|
2021-12-11 15:34:07 +00:00
|
|
|
if not found:
|
|
|
|
logger.error(f'No files belonging to {"DLC" if game.is_dlc else "Game"} "{game.app_title}" '
|
|
|
|
f'({game.app_name}) found in the specified location, please verify that the path is correct.')
|
|
|
|
if not game.is_dlc:
|
|
|
|
# check if game folder is in path, suggest alternative
|
|
|
|
folder = game.metadata.get('customAttributes', {}).get('FolderName', {}).get('value', game.app_name)
|
|
|
|
if folder and folder not in args.app_path:
|
|
|
|
new_path = os.path.join(args.app_path, folder)
|
|
|
|
logger.info(f'Did you mean "{new_path}"?')
|
2021-10-08 08:20:23 +00:00
|
|
|
return
|
|
|
|
|
2021-12-11 15:23:12 +00:00
|
|
|
if not game.is_dlc and not os.path.exists(exe_path) and not args.disable_check:
|
2020-05-28 00:40:12 +00:00
|
|
|
logger.error(f'Game executable could not be found at "{exe_path}", '
|
|
|
|
f'please verify that the specified path is correct.')
|
2021-10-08 08:20:23 +00:00
|
|
|
return
|
2020-05-28 00:40:12 +00:00
|
|
|
|
|
|
|
if ratio < 0.95:
|
|
|
|
logger.warning('Some files are missing from the game installation, install may not '
|
|
|
|
'match latest Epic Games Store version or might be corrupted.')
|
2020-05-20 12:06:55 +00:00
|
|
|
else:
|
2021-10-08 08:20:23 +00:00
|
|
|
logger.info(f'{"DLC" if game.is_dlc else "Game"} install appears to be complete.')
|
2020-05-20 12:06:55 +00:00
|
|
|
|
|
|
|
self.core.install_game(igame)
|
2020-05-28 22:19:57 +00:00
|
|
|
if igame.needs_verification:
|
2021-10-08 08:20:23 +00:00
|
|
|
logger.info(f'NOTE: The {"DLC" if game.is_dlc else "Game"} installation will have to be '
|
|
|
|
f'verified before it can be updated with legendary.')
|
|
|
|
logger.info(f'Run "legendary repair {args.app_name}" to do so.')
|
2020-05-28 22:19:57 +00:00
|
|
|
else:
|
|
|
|
logger.info(f'Installation had Epic Games Launcher metadata for version "{igame.version}", '
|
2021-01-02 05:53:21 +00:00
|
|
|
f'verification will not be required.')
|
2021-10-08 08:20:23 +00:00
|
|
|
|
|
|
|
# check for importable DLC
|
|
|
|
if not args.skip_dlcs:
|
|
|
|
dlcs = self.core.get_dlc_for_game(game.app_name)
|
|
|
|
if dlcs:
|
|
|
|
logger.info(f'Found {len(dlcs)} items of DLC that could be imported.')
|
|
|
|
import_dlc = True
|
|
|
|
if not args.yes and not args.with_dlcs:
|
|
|
|
if not get_boolean_choice(f'Do you wish to automatically attempt to import all DLCs?'):
|
|
|
|
import_dlc = False
|
|
|
|
|
|
|
|
if import_dlc:
|
|
|
|
for dlc in dlcs:
|
|
|
|
args.app_name = dlc.app_name
|
|
|
|
self.import_game(args)
|
|
|
|
|
|
|
|
logger.info(f'{"DLC" if game.is_dlc else "Game"} "{game.app_title}" has been imported.')
|
2020-05-20 12:06:55 +00:00
|
|
|
|
2020-05-29 21:09:02 +00:00
|
|
|
def egs_sync(self, args):
|
2020-05-29 22:11:21 +00:00
|
|
|
if args.unlink:
|
|
|
|
logger.info('Unlinking and resetting EGS and LGD sync...')
|
|
|
|
self.core.lgd.config.remove_option('Legendary', 'egl_programdata')
|
|
|
|
self.core.lgd.config.remove_option('Legendary', 'egl_sync')
|
|
|
|
# remove EGL GUIDs from all games, DO NOT remove .egstore folders because that would fuck things up.
|
|
|
|
for igame in self.core.get_installed_list():
|
|
|
|
igame.egl_guid = ''
|
|
|
|
self.core.install_game(igame)
|
|
|
|
# todo track which games were imported, remove those from LGD and exported ones from EGL
|
|
|
|
logger.info('NOTE: Games have not been removed from the Epic Games Launcher or Legendary.')
|
|
|
|
logger.info('Games will not be removed from EGL or Legendary if it was removed from the other launcher.')
|
|
|
|
return
|
2020-06-01 10:58:47 +00:00
|
|
|
elif args.disable_sync:
|
|
|
|
logger.info('Disabling EGS/LGD sync...')
|
|
|
|
self.core.lgd.config.remove_option('Legendary', 'egl_sync')
|
|
|
|
return
|
2020-05-29 22:11:21 +00:00
|
|
|
|
2021-01-02 05:31:47 +00:00
|
|
|
if not self.core.lgd.assets:
|
|
|
|
logger.error('Legendary is missing game metadata, please login (if not already) and use the '
|
|
|
|
'"status" command to fetch necessary information to set-up syncing.')
|
|
|
|
return
|
|
|
|
|
2020-05-29 21:09:02 +00:00
|
|
|
if not self.core.egl.programdata_path:
|
2020-05-29 23:07:45 +00:00
|
|
|
if not args.egl_manifest_path and not args.egl_wine_prefix:
|
2020-05-29 21:09:02 +00:00
|
|
|
# search default Lutris install path
|
2020-05-29 22:16:25 +00:00
|
|
|
lutris_data_path = os.path.expanduser('~/Games/epic-games-store/drive_c/ProgramData'
|
|
|
|
'/Epic/EpicGamesLauncher/Data')
|
|
|
|
egl_path = None
|
|
|
|
if os.path.exists(lutris_data_path):
|
|
|
|
logger.info(f'Found Lutris EGL install at "{lutris_data_path}"')
|
|
|
|
|
2020-05-29 23:10:11 +00:00
|
|
|
if args.yes or get_boolean_choice('Do you want to use the Lutris install?'):
|
2020-05-29 22:16:25 +00:00
|
|
|
egl_path = os.path.join(lutris_data_path, 'Manifests')
|
|
|
|
if not os.path.exists(egl_path):
|
|
|
|
print('EGL Data path exists but Manifests directory is missing, creating...')
|
|
|
|
os.makedirs(egl_path)
|
|
|
|
|
|
|
|
if not egl_path:
|
|
|
|
print('EGL path not found, please manually provide the path to the WINE prefix it is installed in')
|
2020-05-29 21:09:02 +00:00
|
|
|
egl_path = input('Path [empty input to quit]: ').strip()
|
|
|
|
if not egl_path:
|
|
|
|
print('Empty input, quitting...')
|
|
|
|
exit(0)
|
|
|
|
if not os.path.exists(egl_path):
|
|
|
|
print('Path is invalid (does not exist)!')
|
|
|
|
exit(1)
|
2020-05-29 21:43:04 +00:00
|
|
|
egl_data_path = os.path.join(egl_path, 'drive_c/ProgramData/Epic/EpicGamesLauncher/Data')
|
|
|
|
egl_path = os.path.join(egl_data_path, 'Manifests')
|
2020-05-29 21:09:02 +00:00
|
|
|
if not os.path.exists(egl_path):
|
2020-05-29 21:43:04 +00:00
|
|
|
if not os.path.exists(egl_data_path):
|
|
|
|
print('Invalid path (wrong directory, WINE prefix, or EGL not installed/launched)')
|
|
|
|
exit(1)
|
|
|
|
print('EGL Data path exists but Manifests directory is missing, creating...')
|
|
|
|
os.makedirs(egl_path)
|
2020-05-29 21:09:02 +00:00
|
|
|
|
|
|
|
if not os.listdir(egl_path):
|
|
|
|
logger.warning('Folder is empty, this may be fine if nothing has been installed yet.')
|
|
|
|
self.core.egl.programdata_path = egl_path
|
|
|
|
self.core.lgd.config.set('Legendary', 'egl_programdata', egl_path)
|
2020-05-29 23:07:45 +00:00
|
|
|
elif args.egl_wine_prefix:
|
|
|
|
egl_data_path = os.path.join(args.egl_wine_prefix,
|
|
|
|
'drive_c/ProgramData/Epic/EpicGamesLauncher/Data')
|
|
|
|
egl_path = os.path.join(egl_data_path, 'Manifests')
|
|
|
|
if not os.path.exists(egl_path):
|
|
|
|
if not os.path.exists(egl_data_path):
|
|
|
|
print('Invalid path (wrong directory, WINE prefix, or EGL not installed/launched)')
|
|
|
|
exit(1)
|
|
|
|
print('EGL Data path exists but Manifests directory is missing, creating...')
|
|
|
|
os.makedirs(egl_path)
|
2020-06-01 06:13:47 +00:00
|
|
|
|
|
|
|
if not os.listdir(egl_path):
|
|
|
|
logger.warning('Folder is empty, this may be fine if nothing has been installed yet.')
|
|
|
|
self.core.egl.programdata_path = egl_path
|
|
|
|
self.core.lgd.config.set('Legendary', 'egl_programdata', egl_path)
|
2020-05-29 21:09:02 +00:00
|
|
|
else:
|
2020-06-01 06:16:36 +00:00
|
|
|
if not os.path.exists(args.egl_manifest_path):
|
|
|
|
logger.fatal('Path specified via --egl-manifest-path does not exist')
|
|
|
|
exit(1)
|
2020-05-29 21:09:02 +00:00
|
|
|
self.core.egl.programdata_path = args.egl_manifest_path
|
2020-06-01 06:16:36 +00:00
|
|
|
self.core.lgd.config.set('Legendary', 'egl_programdata', args.egl_manifest_path)
|
2020-05-29 21:09:02 +00:00
|
|
|
|
|
|
|
logger.debug(f'Using EGL ProgramData path "{self.core.egl.programdata_path}"...')
|
|
|
|
logger.info('Reading EGL game manifests...')
|
|
|
|
|
|
|
|
if not args.export_only:
|
|
|
|
print('\nChecking for importable games...')
|
|
|
|
importable = self.core.egl_get_importable()
|
|
|
|
if importable:
|
|
|
|
print('The following games are importable (EGL -> Legendary):')
|
|
|
|
for egl_game in importable:
|
|
|
|
print(' *', egl_game.app_name, '-', egl_game.display_name)
|
|
|
|
|
2020-09-08 02:38:29 +00:00
|
|
|
print('\nNote: Only games that are also in Legendary\'s database are listed, '
|
|
|
|
'if anything is missing run "list-games" first to update it.')
|
|
|
|
|
2020-05-29 23:10:11 +00:00
|
|
|
if args.yes or get_boolean_choice('Do you want to import the games from EGL?'):
|
2020-05-29 21:09:02 +00:00
|
|
|
for egl_game in importable:
|
|
|
|
logger.info(f'Importing "{egl_game.display_name}"...')
|
|
|
|
self.core.egl_import(egl_game.app_name)
|
|
|
|
else:
|
|
|
|
print('Nothing to import.')
|
|
|
|
|
|
|
|
if not args.import_only:
|
|
|
|
print('\nChecking for exportable games...')
|
|
|
|
exportable = self.core.egl_get_exportable()
|
|
|
|
if exportable:
|
|
|
|
print('The following games are exportable (Legendary -> EGL)')
|
|
|
|
for lgd_game in exportable:
|
|
|
|
print(' *', lgd_game.app_name, '-', lgd_game.title)
|
|
|
|
|
2020-05-29 23:10:11 +00:00
|
|
|
if args.yes or get_boolean_choice('Do you want to export the games to EGL?'):
|
2020-05-29 21:09:02 +00:00
|
|
|
for lgd_game in exportable:
|
|
|
|
logger.info(f'Exporting "{lgd_game.title}"...')
|
|
|
|
self.core.egl_export(lgd_game.app_name)
|
|
|
|
else:
|
|
|
|
print('Nothing to export.')
|
|
|
|
|
|
|
|
print('\nChecking automatic sync...')
|
|
|
|
if not self.core.egl_sync_enabled and not args.one_shot:
|
|
|
|
if not args.enable_sync:
|
2020-06-01 06:18:13 +00:00
|
|
|
args.enable_sync = args.yes or get_boolean_choice('Enable automatic synchronization?')
|
|
|
|
if not args.enable_sync: # if user chooses no, still run the sync once
|
2020-05-30 00:56:05 +00:00
|
|
|
self.core.egl_sync()
|
2020-05-29 21:09:02 +00:00
|
|
|
self.core.lgd.config.set('Legendary', 'egl_sync', str(args.enable_sync))
|
|
|
|
else:
|
|
|
|
self.core.egl_sync()
|
|
|
|
|
2020-09-08 02:50:14 +00:00
|
|
|
def status(self, args):
|
|
|
|
if not args.offline:
|
2020-09-08 15:50:36 +00:00
|
|
|
try:
|
|
|
|
if not self.core.login():
|
|
|
|
logger.error('Log in failed!')
|
|
|
|
exit(1)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
2021-09-02 17:29:50 +00:00
|
|
|
# if automatic checks are off force an update here
|
|
|
|
self.core.check_for_updates(force=True)
|
2020-09-08 15:50:36 +00:00
|
|
|
|
|
|
|
if not self.core.lgd.userdata:
|
|
|
|
user_name = '<not logged in>'
|
|
|
|
args.offline = True
|
|
|
|
else:
|
|
|
|
user_name = self.core.lgd.userdata['displayName']
|
2020-09-08 02:50:14 +00:00
|
|
|
|
2020-09-08 15:50:36 +00:00
|
|
|
games_available = len(self.core.get_game_list(update_assets=not args.offline))
|
|
|
|
games_installed = len(self.core.get_installed_list())
|
2020-09-08 03:12:14 +00:00
|
|
|
if args.json:
|
2021-10-05 06:47:28 +00:00
|
|
|
return self._print_json(dict(
|
2020-09-08 15:50:36 +00:00
|
|
|
account=user_name,
|
|
|
|
games_available=games_available,
|
|
|
|
games_installed=games_installed,
|
2020-09-08 03:12:14 +00:00
|
|
|
egl_sync_enabled=self.core.egl_sync_enabled,
|
|
|
|
config_directory=self.core.lgd.path
|
2021-10-05 06:47:28 +00:00
|
|
|
), args.pretty_json)
|
2020-09-08 03:12:14 +00:00
|
|
|
|
2020-09-08 15:50:36 +00:00
|
|
|
print(f'Epic account: {user_name}')
|
|
|
|
print(f'Games available: {games_available}')
|
|
|
|
print(f'Games installed: {games_installed}')
|
2020-09-08 02:50:14 +00:00
|
|
|
print(f'EGL Sync enabled: {self.core.egl_sync_enabled}')
|
|
|
|
print(f'Config directory: {self.core.lgd.path}')
|
2021-12-01 21:04:30 +00:00
|
|
|
print(f'Platform (System): {platform()} ({os.name})')
|
2021-09-02 17:29:50 +00:00
|
|
|
print(f'\nLegendary version: {__version__} - "{__codename__}"')
|
|
|
|
print(f'Update available: {"yes" if self.core.update_available else "no"}')
|
|
|
|
if self.core.update_available:
|
|
|
|
if update_info := self.core.get_update_info():
|
|
|
|
print(f'- New version: {update_info["version"]} - "{update_info["name"]}"')
|
|
|
|
print(f'- Release summary:\n{update_info["summary"]}\n- Release URL: {update_info["gh_url"]}')
|
|
|
|
if update_info['critical']:
|
|
|
|
print('! This update is recommended as it fixes major issues.')
|
|
|
|
# prevent update message on close
|
|
|
|
self.core.update_available = False
|
2020-09-08 02:50:14 +00:00
|
|
|
|
2021-09-28 05:58:50 +00:00
|
|
|
def info(self, args):
|
|
|
|
name_or_path = args.app_name_or_manifest
|
|
|
|
app_name = manifest_uri = None
|
|
|
|
if os.path.exists(name_or_path) or name_or_path.startswith('http'):
|
|
|
|
manifest_uri = name_or_path
|
|
|
|
else:
|
2021-10-02 05:41:11 +00:00
|
|
|
app_name = self._resolve_aliases(name_or_path)
|
2021-09-28 05:58:50 +00:00
|
|
|
|
|
|
|
if not args.offline and not manifest_uri:
|
|
|
|
try:
|
|
|
|
if not self.core.login():
|
|
|
|
logger.error('Log in failed!')
|
|
|
|
exit(1)
|
|
|
|
except ValueError:
|
|
|
|
pass
|
|
|
|
|
2021-10-05 06:41:57 +00:00
|
|
|
# lists that will be printed or turned into JSON data
|
|
|
|
info_items = dict(game=list(), manifest=list(), install=list())
|
|
|
|
InfoItem = namedtuple('InfoItem', ['name', 'json_name', 'value', 'json_value'])
|
|
|
|
|
2021-12-01 19:57:43 +00:00
|
|
|
if self.core.is_installed(app_name):
|
2021-12-28 09:09:08 +00:00
|
|
|
installed_platform = self.core.get_installed_game(app_name).platform
|
|
|
|
if installed_platform != args.platform:
|
|
|
|
logger.warning(f'Game is installed for platform "{installed_platform}", '
|
|
|
|
f'but requested metadata is for "{args.platform}", this may '
|
|
|
|
f'lead to unexpected results.')
|
2021-12-01 19:57:43 +00:00
|
|
|
|
|
|
|
game = self.core.get_game(app_name, update_meta=not args.offline, platform=args.platform)
|
|
|
|
if game and not self.core.asset_available(game, platform=args.platform):
|
2021-12-28 09:09:08 +00:00
|
|
|
logger.warning(f'Asset information for "{game.app_name}" is missing, this may be due to the game '
|
|
|
|
f'not being available on the selected platform or currently logged-in account.')
|
2021-10-16 16:59:54 +00:00
|
|
|
args.offline = True
|
|
|
|
|
2021-09-28 05:58:50 +00:00
|
|
|
manifest_data = None
|
|
|
|
entitlements = None
|
|
|
|
# load installed manifest or URI
|
|
|
|
if args.offline or manifest_uri:
|
|
|
|
if app_name and self.core.is_installed(app_name):
|
|
|
|
manifest_data, _ = self.core.get_installed_manifest(app_name)
|
|
|
|
elif manifest_uri and manifest_uri.startswith('http'):
|
|
|
|
r = self.core.egs.unauth_session.get(manifest_uri)
|
|
|
|
r.raise_for_status()
|
|
|
|
manifest_data = r.content
|
|
|
|
elif manifest_uri and os.path.exists(manifest_uri):
|
|
|
|
with open(manifest_uri, 'rb') as f:
|
|
|
|
manifest_data = f.read()
|
|
|
|
else:
|
|
|
|
logger.info('Game not installed and offline mode enabled, cannot load manifest.')
|
|
|
|
elif game:
|
|
|
|
entitlements = self.core.egs.get_user_entitlements()
|
2021-12-02 13:28:21 +00:00
|
|
|
egl_meta = self.core.egs.get_game_info(game.namespace, game.catalog_item_id)
|
|
|
|
game.metadata = egl_meta
|
|
|
|
# Get manifest if asset exists for current platform
|
|
|
|
if args.platform in game.asset_infos:
|
2021-12-01 19:57:43 +00:00
|
|
|
manifest_data, _ = self.core.get_cdn_manifest(game, args.platform)
|
2021-09-28 05:58:50 +00:00
|
|
|
|
|
|
|
if game:
|
2021-10-05 06:41:57 +00:00
|
|
|
game_infos = info_items['game']
|
|
|
|
game_infos.append(InfoItem('App name', 'app_name', game.app_name, game.app_name))
|
|
|
|
game_infos.append(InfoItem('Title', 'title', game.app_title, game.app_title))
|
2021-12-01 19:57:43 +00:00
|
|
|
game_infos.append(InfoItem('Latest version', 'version', game.app_version(args.platform),
|
|
|
|
game.app_version(args.platform)))
|
2021-12-28 13:03:26 +00:00
|
|
|
all_versions = {k: v.build_version for k, v in game.asset_infos.items()}
|
2021-12-01 19:57:43 +00:00
|
|
|
game_infos.append(InfoItem('All versions', 'platform_versions', all_versions, all_versions))
|
2021-12-02 14:24:01 +00:00
|
|
|
# Cloud save support for Mac and Windows
|
2021-10-05 06:41:57 +00:00
|
|
|
game_infos.append(InfoItem('Cloud saves supported', 'cloud_saves_supported',
|
2021-12-02 14:24:01 +00:00
|
|
|
game.supports_cloud_saves or game.supports_mac_cloud_saves,
|
|
|
|
game.supports_cloud_saves or game.supports_mac_cloud_saves))
|
|
|
|
cs_dir = None
|
2021-09-28 05:58:50 +00:00
|
|
|
if game.supports_cloud_saves:
|
2021-10-05 06:41:57 +00:00
|
|
|
cs_dir = game.metadata['customAttributes']['CloudSaveFolder']['value']
|
2021-12-02 14:24:01 +00:00
|
|
|
game_infos.append(InfoItem('Cloud save folder (Windows)', 'cloud_save_folder', cs_dir, cs_dir))
|
|
|
|
|
|
|
|
cs_dir = None
|
|
|
|
if game.supports_mac_cloud_saves:
|
|
|
|
cs_dir = game.metadata['customAttributes']['CloudSaveFolder_MAC']['value']
|
|
|
|
game_infos.append(InfoItem('Cloud save folder (Mac)', 'cloud_save_folder_mac', cs_dir, cs_dir))
|
|
|
|
|
2021-10-05 06:41:57 +00:00
|
|
|
game_infos.append(InfoItem('Is DLC', 'is_dlc', game.is_dlc, game.is_dlc))
|
2021-12-21 22:59:00 +00:00
|
|
|
|
|
|
|
external_activation = game.third_party_store or game.partner_link_type
|
|
|
|
game_infos.append(InfoItem('Activates on external platform', 'external_activation',
|
|
|
|
external_activation or 'No', external_activation))
|
|
|
|
|
2021-09-28 05:58:50 +00:00
|
|
|
# Find custom launch options, if available
|
|
|
|
launch_options = []
|
|
|
|
i = 1
|
|
|
|
while f'extraLaunchOption_{i:03d}_Name' in game.metadata['customAttributes']:
|
|
|
|
launch_options.append((
|
|
|
|
game.metadata['customAttributes'][f'extraLaunchOption_{i:03d}_Name']['value'],
|
|
|
|
game.metadata['customAttributes'][f'extraLaunchOption_{i:03d}_Args']['value']
|
|
|
|
))
|
|
|
|
i += 1
|
|
|
|
|
|
|
|
if launch_options:
|
2021-10-05 06:41:57 +00:00
|
|
|
human_list = []
|
|
|
|
json_list = []
|
2021-09-28 05:58:50 +00:00
|
|
|
for opt_name, opt_cmd in sorted(launch_options):
|
2021-10-05 06:41:57 +00:00
|
|
|
human_list.append(f'Name: "{opt_name}", Parameters: {opt_cmd}')
|
|
|
|
json_list.append(dict(name=opt_name, parameters=opt_cmd))
|
|
|
|
game_infos.append(InfoItem('Extra launch options', 'launch_options',
|
|
|
|
human_list, json_list))
|
|
|
|
else:
|
|
|
|
game_infos.append(InfoItem('Extra launch options', 'launch_options', None, []))
|
2021-09-28 05:58:50 +00:00
|
|
|
|
|
|
|
# list all owned DLC based on entitlements
|
|
|
|
if entitlements and not game.is_dlc:
|
|
|
|
owned_entitlements = {i['entitlementName'] for i in entitlements}
|
2021-12-02 13:34:29 +00:00
|
|
|
owned_app_names = {g.app_name for g in self.core.get_assets(args.platform)}
|
2021-09-28 05:58:50 +00:00
|
|
|
owned_dlc = []
|
2021-09-28 07:39:49 +00:00
|
|
|
for dlc in game.metadata.get('dlcItemList', []):
|
2021-09-28 05:58:50 +00:00
|
|
|
installable = dlc.get('releaseInfo', None)
|
|
|
|
if dlc['entitlementName'] in owned_entitlements:
|
2021-10-05 06:41:57 +00:00
|
|
|
owned_dlc.append((installable, None, dlc['title'], dlc['id']))
|
2021-09-28 05:58:50 +00:00
|
|
|
elif installable:
|
|
|
|
app_name = dlc['releaseInfo'][0]['appId']
|
|
|
|
if app_name in owned_app_names:
|
2021-10-05 06:41:57 +00:00
|
|
|
owned_dlc.append((installable, app_name, dlc['title'], dlc['id']))
|
2021-09-28 05:58:50 +00:00
|
|
|
|
|
|
|
if owned_dlc:
|
2021-10-05 06:41:57 +00:00
|
|
|
human_list = []
|
|
|
|
json_list = []
|
|
|
|
for installable, app_name, title, dlc_id in owned_dlc:
|
|
|
|
json_list.append(dict(app_name=app_name, title=title,
|
|
|
|
installable=installable, id=dlc_id))
|
2021-09-28 05:58:50 +00:00
|
|
|
if installable:
|
2021-10-05 06:41:57 +00:00
|
|
|
human_list.append(f'App name: {app_name}, Title: "{title}"')
|
2021-09-28 05:58:50 +00:00
|
|
|
else:
|
2021-10-05 06:41:57 +00:00
|
|
|
human_list.append(f'Title: "{title}" (no installation required)')
|
|
|
|
game_infos.append(InfoItem('Owned DLC', 'owned_dlc', human_list, json_list))
|
|
|
|
else:
|
|
|
|
game_infos.append(InfoItem('Owned DLC', 'owned_dlc', None, []))
|
|
|
|
else:
|
|
|
|
game_infos.append(InfoItem('Owned DLC', 'owned_dlc', None, []))
|
2021-09-28 05:58:50 +00:00
|
|
|
|
|
|
|
igame = self.core.get_installed_game(app_name)
|
|
|
|
if igame:
|
2021-10-05 06:41:57 +00:00
|
|
|
installation_info = info_items['install']
|
2021-12-01 19:57:43 +00:00
|
|
|
installation_info.append(InfoItem('Platform', 'platform', igame.platform, igame.platform))
|
2021-10-05 06:41:57 +00:00
|
|
|
installation_info.append(InfoItem('Version', 'version', igame.version, igame.version))
|
|
|
|
disk_size_human = f'{igame.install_size / 1024 / 1024 / 1024:.02f} GiB'
|
|
|
|
installation_info.append(InfoItem('Install size', 'disk_size', disk_size_human,
|
|
|
|
igame.install_size))
|
|
|
|
installation_info.append(InfoItem('Install path', 'install_path', igame.install_path,
|
|
|
|
igame.install_path))
|
|
|
|
installation_info.append(InfoItem('Save data path', 'save_path', igame.save_path,
|
|
|
|
igame.save_path))
|
|
|
|
installation_info.append(InfoItem('EGL sync GUID', 'synced_egl_guid', igame.egl_guid,
|
|
|
|
igame.egl_guid))
|
2021-09-28 05:58:50 +00:00
|
|
|
if igame.install_tags:
|
2021-10-05 06:41:57 +00:00
|
|
|
tags = ', '.join(igame.install_tags)
|
2021-09-28 05:58:50 +00:00
|
|
|
else:
|
2021-10-05 06:41:57 +00:00
|
|
|
tags = '(None, all game data selected for install)'
|
|
|
|
installation_info.append(InfoItem('Install tags', 'install_tags', tags, igame.install_tags))
|
|
|
|
installation_info.append(InfoItem('Requires ownership verification token (DRM)', 'requires_ovt',
|
|
|
|
igame.requires_ot, igame.requires_ot))
|
2021-09-28 05:58:50 +00:00
|
|
|
|
2021-10-05 06:41:57 +00:00
|
|
|
installed_dlc_human = []
|
|
|
|
installed_dlc_json = []
|
2021-09-28 07:39:49 +00:00
|
|
|
for dlc in game.metadata.get('dlcItemList', []):
|
2021-09-28 05:58:50 +00:00
|
|
|
if not dlc.get('releaseInfo', None):
|
|
|
|
continue
|
|
|
|
app_name = dlc['releaseInfo'][0]['appId']
|
|
|
|
if igame := self.core.get_installed_game(app_name):
|
2021-10-05 06:41:57 +00:00
|
|
|
installed_dlc_json.append(dict(app_name=igame.app_name, title=igame.title,
|
|
|
|
install_size=igame.install_size))
|
|
|
|
installed_dlc_human.append('App name: {}, Title: "{}", Size: {:.02f} GiB'.format(
|
2021-09-28 05:58:50 +00:00
|
|
|
igame.app_name, igame.title, igame.install_size / 1024 / 1024 / 1024
|
|
|
|
))
|
2021-10-09 15:33:56 +00:00
|
|
|
installation_info.append(InfoItem('Installed DLC', 'installed_dlc',
|
|
|
|
installed_dlc_human or None,
|
2021-10-05 06:41:57 +00:00
|
|
|
installed_dlc_json))
|
2021-09-28 05:58:50 +00:00
|
|
|
|
|
|
|
if manifest_data:
|
2021-10-05 06:41:57 +00:00
|
|
|
manifest_info = info_items['manifest']
|
2021-09-28 05:58:50 +00:00
|
|
|
manifest = self.core.load_manifest(manifest_data)
|
2021-10-05 06:41:57 +00:00
|
|
|
manifest_size = len(manifest_data)
|
|
|
|
manifest_size_human = f'{manifest_size / 1024:.01f} KiB'
|
|
|
|
manifest_info.append(InfoItem('Manifest size', 'size', manifest_size_human, manifest_size))
|
|
|
|
manifest_type = 'JSON' if hasattr(manifest, 'json_data') else 'Binary'
|
|
|
|
manifest_info.append(InfoItem('Manifest type', 'type', manifest_type, manifest_type.lower()))
|
|
|
|
manifest_info.append(InfoItem('Manifest version', 'version', manifest.version, manifest.version))
|
|
|
|
manifest_info.append(InfoItem('Manifest feature level', 'feature_level',
|
|
|
|
manifest.meta.feature_level, manifest.meta.feature_level))
|
|
|
|
manifest_info.append(InfoItem('Manifest app name', 'app_name', manifest.meta.app_name,
|
|
|
|
manifest.meta.app_name))
|
2021-10-09 15:33:56 +00:00
|
|
|
manifest_info.append(InfoItem('Launch EXE', 'launch_exe',
|
|
|
|
manifest.meta.launch_exe or 'N/A',
|
2021-10-05 06:41:57 +00:00
|
|
|
manifest.meta.launch_exe))
|
|
|
|
manifest_info.append(InfoItem('Launch Command', 'launch_command',
|
|
|
|
manifest.meta.launch_command or '(None)',
|
|
|
|
manifest.meta.launch_command))
|
|
|
|
manifest_info.append(InfoItem('Build version', 'build_version', manifest.meta.build_version,
|
|
|
|
manifest.meta.build_version))
|
|
|
|
manifest_info.append(InfoItem('Build ID', 'build_id', manifest.meta.build_id,
|
|
|
|
manifest.meta.build_id))
|
2021-09-28 05:58:50 +00:00
|
|
|
if manifest.meta.prereq_ids:
|
2021-10-05 06:41:57 +00:00
|
|
|
human_list = [
|
|
|
|
f'Prerequisite IDs: {", ".join(manifest.meta.prereq_ids)}',
|
|
|
|
f'Prerequisite name: {manifest.meta.prereq_name}',
|
|
|
|
f'Prerequisite path: {manifest.meta.prereq_path}',
|
|
|
|
f'Prerequisite args: {manifest.meta.prereq_args or "(None)"}',
|
|
|
|
]
|
|
|
|
manifest_info.append(InfoItem('Prerequisites', 'prerequisites', human_list,
|
|
|
|
dict(ids=manifest.meta.prereq_ids,
|
|
|
|
name=manifest.meta.prereq_name,
|
|
|
|
path=manifest.meta.prereq_path,
|
|
|
|
args=manifest.meta.prereq_args)))
|
2021-09-28 05:58:50 +00:00
|
|
|
else:
|
2021-10-05 06:41:57 +00:00
|
|
|
manifest_info.append(InfoItem('Prerequisites', 'prerequisites', None, None))
|
|
|
|
|
2021-10-05 07:47:59 +00:00
|
|
|
install_tags = {''}
|
|
|
|
for fm in manifest.file_manifest_list.elements:
|
|
|
|
for tag in fm.install_tags:
|
|
|
|
install_tags.add(tag)
|
|
|
|
|
|
|
|
install_tags = sorted(install_tags)
|
|
|
|
install_tags_human = ', '.join(i if i else '(empty)' for i in install_tags)
|
|
|
|
manifest_info.append(InfoItem('Install tags', 'install_tags', install_tags_human, install_tags))
|
2021-10-09 15:33:56 +00:00
|
|
|
# file and chunk count
|
2021-10-05 06:41:57 +00:00
|
|
|
manifest_info.append(InfoItem('Files', 'num_files', manifest.file_manifest_list.count,
|
|
|
|
manifest.file_manifest_list.count))
|
2021-10-09 15:33:56 +00:00
|
|
|
manifest_info.append(InfoItem('Chunks', 'num_chunks', manifest.chunk_data_list.count,
|
|
|
|
manifest.chunk_data_list.count))
|
|
|
|
# total file size
|
2021-09-28 05:58:50 +00:00
|
|
|
total_size = sum(fm.file_size for fm in manifest.file_manifest_list.elements)
|
2021-10-05 06:41:57 +00:00
|
|
|
file_size = '{:.02f} GiB'.format(total_size / 1024 / 1024 / 1024)
|
|
|
|
manifest_info.append(InfoItem('Disk size (uncompressed)', 'disk_size', file_size, total_size))
|
2021-10-09 15:33:56 +00:00
|
|
|
# total chunk size
|
2021-09-28 05:58:50 +00:00
|
|
|
total_size = sum(c.file_size for c in manifest.chunk_data_list.elements)
|
2021-10-05 06:41:57 +00:00
|
|
|
chunk_size = '{:.02f} GiB'.format(total_size / 1024 / 1024 / 1024)
|
|
|
|
manifest_info.append(InfoItem('Download size (compressed)', 'download_size',
|
|
|
|
chunk_size, total_size))
|
|
|
|
|
2021-10-09 15:33:56 +00:00
|
|
|
# if there are install tags break down size by tag
|
|
|
|
tag_disk_size = []
|
|
|
|
tag_disk_size_human = []
|
|
|
|
tag_download_size = []
|
|
|
|
tag_download_size_human = []
|
|
|
|
if len(install_tags) > 1:
|
|
|
|
longest_tag = max(max(len(t) for t in install_tags), len('(empty)'))
|
|
|
|
for tag in install_tags:
|
|
|
|
# sum up all file sizes for the tag
|
|
|
|
human_tag = tag or '(empty)'
|
|
|
|
tag_files = [fm for fm in manifest.file_manifest_list.elements if
|
|
|
|
(tag in fm.install_tags) or (not tag and not fm.install_tags)]
|
|
|
|
tag_file_size = sum(fm.file_size for fm in tag_files)
|
|
|
|
tag_disk_size.append(dict(tag=tag, size=tag_file_size, count=len(tag_files)))
|
|
|
|
tag_file_size_human = '{:.02f} GiB'.format(tag_file_size / 1024 / 1024 / 1024)
|
|
|
|
tag_disk_size_human.append(f'{human_tag.ljust(longest_tag)} - {tag_file_size_human} '
|
|
|
|
f'(Files: {len(tag_files)})')
|
|
|
|
# tag_disk_size_human.append(f'Size: {tag_file_size_human}, Files: {len(tag_files)}, Tag: "{tag}"')
|
|
|
|
# accumulate chunk guids used for this tag and count their size too
|
|
|
|
tag_chunk_guids = set()
|
|
|
|
for fm in tag_files:
|
|
|
|
for cp in fm.chunk_parts:
|
|
|
|
tag_chunk_guids.add(cp.guid_num)
|
|
|
|
|
|
|
|
tag_chunk_size = sum(c.file_size for c in manifest.chunk_data_list.elements
|
|
|
|
if c.guid_num in tag_chunk_guids)
|
|
|
|
tag_download_size.append(dict(tag=tag, size=tag_chunk_size, count=len(tag_chunk_guids)))
|
|
|
|
tag_chunk_size_human = '{:.02f} GiB'.format(tag_chunk_size / 1024 / 1024 / 1024)
|
|
|
|
tag_download_size_human.append(f'{human_tag.ljust(longest_tag)} - {tag_chunk_size_human} '
|
2021-12-28 13:03:26 +00:00
|
|
|
f'(Chunks: {len(tag_chunk_guids)})')
|
2021-10-09 15:33:56 +00:00
|
|
|
|
|
|
|
manifest_info.append(InfoItem('Disk size by install tag', 'tag_disk_size',
|
|
|
|
tag_disk_size_human or 'N/A', tag_disk_size))
|
|
|
|
manifest_info.append(InfoItem('Download size by install tag', 'tag_download_size',
|
|
|
|
tag_download_size_human or 'N/A', tag_download_size))
|
|
|
|
|
2021-10-05 06:41:57 +00:00
|
|
|
if not args.json:
|
|
|
|
def print_info_item(item: InfoItem):
|
|
|
|
if item.value is None:
|
|
|
|
print(f'- {item.name}: (None)')
|
|
|
|
elif isinstance(item.value, list):
|
|
|
|
print(f'- {item.name}:')
|
|
|
|
for list_item in item.value:
|
|
|
|
print(' + ', list_item)
|
2021-12-01 19:57:43 +00:00
|
|
|
elif isinstance(item.value, dict):
|
|
|
|
print(f'- {item.name}:')
|
|
|
|
for k, v in item.value.items():
|
|
|
|
print(' + ', k, ':', v)
|
2021-10-05 06:41:57 +00:00
|
|
|
else:
|
|
|
|
print(f'- {item.name}: {item.value}')
|
|
|
|
|
2021-10-10 10:36:16 +00:00
|
|
|
if info_items['game']:
|
|
|
|
print('\nGame Information:')
|
|
|
|
for info_item in info_items['game']:
|
|
|
|
print_info_item(info_item)
|
|
|
|
if info_items['install']:
|
|
|
|
print('\nInstallation information:')
|
|
|
|
for info_item in info_items['install']:
|
|
|
|
print_info_item(info_item)
|
|
|
|
if info_items['manifest']:
|
|
|
|
print('\nManifest information:')
|
|
|
|
for info_item in info_items['manifest']:
|
|
|
|
print_info_item(info_item)
|
2021-10-16 17:33:59 +00:00
|
|
|
|
|
|
|
if not any(info_items.values()):
|
|
|
|
print('No game information available.')
|
2021-10-05 06:41:57 +00:00
|
|
|
else:
|
|
|
|
json_out = dict(game=dict(), install=dict(), manifest=dict())
|
|
|
|
for info_item in info_items['game']:
|
|
|
|
json_out['game'][info_item.json_name] = info_item.json_value
|
|
|
|
for info_item in info_items['install']:
|
|
|
|
json_out['install'][info_item.json_name] = info_item.json_value
|
|
|
|
for info_item in info_items['manifest']:
|
|
|
|
json_out['manifest'][info_item.json_name] = info_item.json_value
|
2021-10-16 16:58:20 +00:00
|
|
|
# set empty items to null
|
|
|
|
for key, value in json_out.items():
|
|
|
|
if not value:
|
|
|
|
json_out[key] = None
|
2021-10-05 06:47:28 +00:00
|
|
|
return self._print_json(json_out, args.pretty_json)
|
2021-09-28 05:58:50 +00:00
|
|
|
|
2021-10-02 20:54:56 +00:00
|
|
|
def alias(self, args):
|
|
|
|
if args.action == 'add':
|
|
|
|
alias = args.alias
|
2021-10-07 15:06:39 +00:00
|
|
|
app_name = self._resolve_aliases(args.app_or_alias)
|
2021-10-02 20:54:56 +00:00
|
|
|
game = self.core.get_game(app_name)
|
|
|
|
if not game:
|
|
|
|
logger.error(f'Invalid app name: "{app_name}"')
|
|
|
|
return
|
|
|
|
self.core.lgd.config.set('Legendary.aliases', alias, app_name)
|
|
|
|
logger.info(f'Added alias "{alias}" to "{app_name}" (Title: "{game.app_title}")')
|
|
|
|
elif args.action == 'rename':
|
|
|
|
old_alias = args.app_or_alias
|
|
|
|
new_alias = args.alias
|
|
|
|
app_name = self.core.lgd.config.get('Legendary.aliases', old_alias, fallback=None)
|
|
|
|
if not app_name:
|
|
|
|
logger.error(f'Invalid old alias: "{app_name}"')
|
|
|
|
return
|
|
|
|
self.core.lgd.config.set('Legendary.aliases', new_alias, app_name)
|
|
|
|
self.core.lgd.config.remove_option('Legendary.aliases', old_alias)
|
|
|
|
logger.info(f'Renamed alias "{old_alias}" to "{new_alias}"')
|
|
|
|
elif args.action == 'remove':
|
|
|
|
alias = args.app_or_alias
|
|
|
|
if not self.core.lgd.config.has_option('Legendary.aliases', alias):
|
|
|
|
logger.error(f'Alias does not exist: "{args.alias}"')
|
|
|
|
return
|
|
|
|
self.core.lgd.config.remove_option('Legendary.aliases', alias)
|
|
|
|
logger.info(f'Removed alias "{alias}"')
|
|
|
|
elif args.action == 'list':
|
|
|
|
if args.app_or_alias:
|
|
|
|
self.core.update_aliases(force=True)
|
|
|
|
app_name = self._resolve_aliases(args.app_or_alias)
|
|
|
|
game = self.core.get_game(app_name)
|
|
|
|
if not game:
|
|
|
|
logger.error(f'Invalid app name: "{app_name}"')
|
|
|
|
return
|
|
|
|
print(f'\nAliases for "{game.app_title}" ({app_name}):')
|
|
|
|
# Use-defined
|
|
|
|
if self.core.lgd.config.has_section('Legendary.aliases'):
|
|
|
|
aliases = [alias for (alias, app_name) in self.core.lgd.config['Legendary.aliases'].items()
|
|
|
|
if app_name == game.app_name]
|
|
|
|
if aliases:
|
|
|
|
print('- User-defined aliases:')
|
|
|
|
for alias in sorted(aliases):
|
|
|
|
print(f' + {alias}')
|
|
|
|
else:
|
|
|
|
print('- User-defined aliases: (None)')
|
|
|
|
# Automatically generated
|
|
|
|
aliases = [alias for (alias, app_name) in self.core.lgd.aliases.items()
|
|
|
|
if app_name == game.app_name]
|
|
|
|
if aliases:
|
|
|
|
print('- Automatic aliases:')
|
|
|
|
for alias in sorted(aliases):
|
|
|
|
print(f' + {alias}')
|
|
|
|
else:
|
|
|
|
print('- Automatic aliases: (None)')
|
|
|
|
else:
|
|
|
|
if not self.core.lgd.config.has_section('Legendary.aliases'):
|
|
|
|
logger.error('No aliases in config!')
|
|
|
|
return
|
|
|
|
|
|
|
|
print('User-defined aliases:')
|
|
|
|
for alias, app_name in self.core.lgd.config['Legendary.aliases'].items():
|
|
|
|
print(f' - {alias} => {app_name}')
|
|
|
|
|
2020-11-02 14:53:11 +00:00
|
|
|
def cleanup(self, args):
|
|
|
|
before = self.core.lgd.get_dir_size()
|
|
|
|
# delete metadata
|
|
|
|
logger.debug('Removing app metadata...')
|
2021-12-14 13:30:33 +00:00
|
|
|
app_names = set()
|
2021-12-02 13:34:29 +00:00
|
|
|
for _platform in self.core.get_installed_platforms():
|
|
|
|
app_names |= set(g.app_name for g in self.core.get_assets(update_assets=False, platform=_platform))
|
2020-11-02 14:53:11 +00:00
|
|
|
self.core.lgd.clean_metadata(app_names)
|
|
|
|
|
|
|
|
if not args.keep_manifests:
|
|
|
|
logger.debug('Removing manifests...')
|
|
|
|
installed = [(ig.app_name, ig.version) for ig in self.core.get_installed_list()]
|
|
|
|
installed.extend((ig.app_name, ig.version) for ig in self.core.get_installed_dlc_list())
|
|
|
|
self.core.lgd.clean_manifests(installed)
|
|
|
|
|
|
|
|
logger.debug('Removing tmp data')
|
|
|
|
self.core.lgd.clean_tmp_data()
|
|
|
|
|
|
|
|
after = self.core.lgd.get_dir_size()
|
2021-12-28 13:03:26 +00:00
|
|
|
logger.info(f'Cleanup complete! Removed {(before - after) / 1024 / 1024:.02f} MiB.')
|
2020-11-02 14:53:11 +00:00
|
|
|
|
2021-12-03 13:07:57 +00:00
|
|
|
def activate(self, args):
|
|
|
|
if not self.core.login():
|
|
|
|
logger.error('Login failed!')
|
|
|
|
return
|
|
|
|
|
2021-12-06 18:33:36 +00:00
|
|
|
if args.uplay:
|
|
|
|
ubi_account_id = ''
|
|
|
|
ext_auths = self.core.egs.get_external_auths()
|
|
|
|
for ext_auth in ext_auths:
|
|
|
|
if ext_auth['type'] != 'ubisoft':
|
|
|
|
continue
|
|
|
|
ubi_account_id = ext_auth['externalAuthId']
|
|
|
|
break
|
|
|
|
else:
|
|
|
|
logger.error('No linked ubisoft account found! Link your accounts via your browser and try again.')
|
|
|
|
webbrowser.open('https://www.epicgames.com/id/link/ubisoft')
|
|
|
|
print('If the web page did not open automatically, please manually open the following URL: '
|
|
|
|
'https://www.epicgames.com/id/link/ubisoft')
|
|
|
|
return
|
2021-12-03 13:07:57 +00:00
|
|
|
|
2021-12-06 18:33:36 +00:00
|
|
|
uplay_keys = self.core.egs.store_get_uplay_codes()
|
|
|
|
key_list = uplay_keys['data']['PartnerIntegration']['accountUplayCodes']
|
|
|
|
redeemed = {k['gameId'] for k in key_list if k['redeemedOnUplay']}
|
2021-12-03 13:07:57 +00:00
|
|
|
|
2021-12-06 18:33:36 +00:00
|
|
|
games = self.core.get_game_list()
|
2021-12-11 17:50:30 +00:00
|
|
|
entitlements = self.core.egs.get_user_entitlements()
|
|
|
|
owned_entitlements = {i['entitlementName'] for i in entitlements}
|
|
|
|
|
2021-12-06 18:33:36 +00:00
|
|
|
uplay_games = []
|
|
|
|
activated = 0
|
|
|
|
for game in games:
|
2021-12-11 17:50:30 +00:00
|
|
|
for dlc_data in game.metadata.get('dlcItemList', []):
|
|
|
|
if dlc_data['entitlementName'] not in owned_entitlements:
|
|
|
|
continue
|
|
|
|
|
|
|
|
try:
|
|
|
|
app_name = dlc_data['releaseInfo'][0]['appId']
|
|
|
|
except (IndexError, KeyError):
|
|
|
|
app_name = 'unknown'
|
|
|
|
|
|
|
|
dlc_game = Game(app_name=app_name, app_title=dlc_data['title'], metadata=dlc_data)
|
|
|
|
if dlc_game.partner_link_type != 'ubisoft':
|
|
|
|
continue
|
|
|
|
if dlc_game.partner_link_id in redeemed:
|
|
|
|
continue
|
|
|
|
uplay_games.append(dlc_game)
|
|
|
|
|
2021-12-06 18:33:36 +00:00
|
|
|
if game.partner_link_type != 'ubisoft':
|
|
|
|
continue
|
|
|
|
if game.partner_link_id in redeemed:
|
|
|
|
activated += 1
|
|
|
|
continue
|
|
|
|
uplay_games.append(game)
|
2021-12-03 13:07:57 +00:00
|
|
|
|
2021-12-06 18:33:36 +00:00
|
|
|
if not uplay_games:
|
|
|
|
logger.info(f'All of your {activated} titles have already been activated on your Ubisoft account.')
|
|
|
|
return
|
2021-12-03 13:07:57 +00:00
|
|
|
|
2021-12-06 18:33:36 +00:00
|
|
|
logger.info(f'Found {len(uplay_games)} game(s) to redeem:')
|
|
|
|
for game in sorted(uplay_games, key=lambda g: g.app_title.lower()):
|
|
|
|
logger.info(f' - {game.app_title}')
|
|
|
|
|
|
|
|
if not args.yes:
|
|
|
|
y_n = get_boolean_choice('Do you want to redeem these games?')
|
|
|
|
if not y_n:
|
|
|
|
logger.info('Aborting.')
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
for game in uplay_games:
|
|
|
|
self.core.egs.store_claim_uplay_code(ubi_account_id, game.partner_link_id)
|
|
|
|
self.core.egs.store_redeem_uplay_codes(ubi_account_id)
|
|
|
|
except Exception as e:
|
|
|
|
logger.error(f'Failed to redeem Uplay codes: {e!r}')
|
|
|
|
else:
|
|
|
|
logger.info('Redeemed all outstanding Uplay codes.')
|
|
|
|
elif args.origin:
|
|
|
|
na_games, _ = self.core.get_non_asset_library_items(skip_ue=True)
|
|
|
|
origin_games = [game for game in na_games if game.third_party_store == 'Origin']
|
|
|
|
|
|
|
|
logger.info(f'Found {len(origin_games)} game(s) to redeem:')
|
|
|
|
for game in origin_games:
|
|
|
|
logger.info(f' - {game.app_title}')
|
|
|
|
|
|
|
|
logger.info('Note: Legendary does not know which of these have already been activated. '
|
|
|
|
'Proceeding will result in it attempting to activate all of them.')
|
|
|
|
logger.info('If Origin asks you to install the title rather than to activate, '
|
|
|
|
'it has already been activated, and the dialog can be dismissed.')
|
2021-12-21 22:28:24 +00:00
|
|
|
|
|
|
|
if os.name != 'nt':
|
|
|
|
logger.info('On non-Windows systems the automatic portion of this process does not work yet, '
|
|
|
|
'please use the launch commands listed below together with --wine/--wine-prefix to '
|
|
|
|
'specify the wine binary to use and the prefix where Origin is installed.')
|
|
|
|
for idx, game in enumerate(origin_games, start=1):
|
|
|
|
logger.info(f'{idx}. legendary launch --origin {game.app_name}')
|
|
|
|
return
|
|
|
|
|
2021-12-06 18:33:36 +00:00
|
|
|
logger.info('After one title has been processed, hit enter to proceed with the next one.')
|
2021-12-03 13:07:57 +00:00
|
|
|
|
|
|
|
y_n = get_boolean_choice('Do you want to redeem these games?')
|
|
|
|
if not y_n:
|
2021-12-06 18:33:36 +00:00
|
|
|
logger.info('Aborting...')
|
2021-12-03 13:07:57 +00:00
|
|
|
return
|
|
|
|
|
2021-12-06 18:33:36 +00:00
|
|
|
last_game = origin_games[-1]
|
|
|
|
for game in origin_games:
|
|
|
|
origin_uri = self.core.get_origin_uri(game.app_name)
|
|
|
|
logger.info(f'Opening Origin to activate "{game.app_title}"')
|
2021-12-21 22:28:24 +00:00
|
|
|
logger.debug(f'Opening Origin URI: {origin_uri}')
|
|
|
|
webbrowser.open(origin_uri)
|
2021-12-06 18:33:36 +00:00
|
|
|
|
|
|
|
if game == last_game:
|
|
|
|
break
|
|
|
|
|
|
|
|
y_n = get_boolean_choice('Do you want to proceed with the next title?')
|
|
|
|
if not y_n:
|
|
|
|
logger.info('User requested abort.')
|
|
|
|
return
|
|
|
|
|
|
|
|
logger.info('Origin activation process completed.')
|
2021-12-03 13:07:57 +00:00
|
|
|
|
2021-12-21 22:51:48 +00:00
|
|
|
def get_token(self, args):
|
2021-12-28 09:21:34 +00:00
|
|
|
if not self.core.login(force_refresh=args.bearer):
|
2021-12-21 22:51:48 +00:00
|
|
|
logger.error('Login failed!')
|
|
|
|
return
|
|
|
|
|
2021-12-28 09:21:34 +00:00
|
|
|
if args.bearer:
|
|
|
|
args.json = True
|
|
|
|
token = dict(token_type='bearer',
|
|
|
|
access_token=self.core.egs.user['access_token'],
|
|
|
|
expires_in=self.core.egs.user['expires_in'],
|
|
|
|
expires_at=self.core.egs.user['expires_at'],
|
|
|
|
account_id=self.core.egs.user['account_id'])
|
|
|
|
else:
|
|
|
|
token = self.core.egs.get_game_token()
|
|
|
|
|
2021-12-21 22:51:48 +00:00
|
|
|
if args.json:
|
|
|
|
if args.pretty_json:
|
|
|
|
print(json.dumps(token, indent=2, sort_keys=True))
|
|
|
|
else:
|
|
|
|
print(json.dumps(token))
|
|
|
|
return
|
|
|
|
logger.info(f'Exchange code: {token["code"]}')
|
|
|
|
|
2021-12-28 16:47:08 +00:00
|
|
|
def manage_eos_overlay(self, args):
|
|
|
|
if os.name != 'nt':
|
|
|
|
logger.fatal('This command is only supported on Windows.')
|
|
|
|
return
|
|
|
|
|
|
|
|
if args.action == 'info':
|
|
|
|
reg_paths = query_registry_entries()
|
|
|
|
available_installs = self.core.search_overlay_installs()
|
|
|
|
igame = self.core.lgd.get_overlay_install_info()
|
|
|
|
if not igame:
|
|
|
|
logger.info('No Legendary-managed installation found.')
|
|
|
|
else:
|
|
|
|
logger.info(f'Installed version: {igame.version}')
|
|
|
|
logger.info(f'Installed path: {igame.install_path}')
|
|
|
|
|
|
|
|
logger.info('Found available Overlay installations in:')
|
|
|
|
for install in available_installs:
|
|
|
|
logger.info(f' - {install}')
|
|
|
|
|
|
|
|
# check if overlay path is in registry, and if it is valid
|
|
|
|
overlay_enabled = False
|
|
|
|
if reg_paths['overlay_path'] and self.core.is_overlay_install(reg_paths['overlay_path']):
|
|
|
|
overlay_enabled = True
|
|
|
|
|
|
|
|
logger.info(f'Overlay enabled: {"Yes" if overlay_enabled else "No"}')
|
|
|
|
logger.info(f'Enabled Overlay path: {reg_paths["overlay_path"]}')
|
|
|
|
|
|
|
|
# Also log Vulkan overlays
|
|
|
|
vulkan_overlays = set(reg_paths['vulkan_hkcu']) | set(reg_paths['vulkan_hklm'])
|
|
|
|
if vulkan_overlays:
|
|
|
|
logger.info('Enabled Vulkan layers:')
|
|
|
|
for vk_overlay in sorted(vulkan_overlays):
|
|
|
|
logger.info(f' - {vk_overlay}')
|
|
|
|
else:
|
|
|
|
logger.info('No enabled Vulkan layers.')
|
|
|
|
|
|
|
|
elif args.action == 'enable':
|
|
|
|
if not args.path:
|
|
|
|
igame = self.core.lgd.get_overlay_install_info()
|
|
|
|
if igame:
|
|
|
|
args.path = igame.install_path
|
|
|
|
else:
|
|
|
|
available_installs = self.core.search_overlay_installs()
|
|
|
|
args.path = available_installs[0]
|
|
|
|
|
|
|
|
if not self.core.is_overlay_install(args.path):
|
|
|
|
logger.error(f'Not a valid Overlay installation: {args.path}')
|
|
|
|
return
|
|
|
|
|
|
|
|
args.path = os.path.normpath(args.path)
|
|
|
|
# Check for existing entries
|
|
|
|
reg_paths = query_registry_entries()
|
|
|
|
if old_path := reg_paths["overlay_path"]:
|
|
|
|
if os.path.normpath(old_path) == args.path:
|
|
|
|
logger.info(f'Overlay already enabled, nothing to do.')
|
|
|
|
return
|
|
|
|
else:
|
|
|
|
logger.info(f'Updating overlay registry entries from "{old_path}" to "{args.path}"')
|
|
|
|
remove_registry_entries()
|
|
|
|
add_registry_entries(args.path)
|
|
|
|
logger.info(f'Enabled overlay at: {args.path}')
|
|
|
|
|
|
|
|
elif args.action == 'disable':
|
|
|
|
logger.info('Disabling overlay (removing registry keys)..')
|
|
|
|
reg_paths = query_registry_entries()
|
|
|
|
old_path = reg_paths["overlay_path"]
|
|
|
|
remove_registry_entries()
|
|
|
|
# if the install is not managed by legendary, specify the command including the path
|
|
|
|
if self.core.is_overlay_installed():
|
|
|
|
logger.info(f'To re-enable the overlay, run: legendary eos-overlay enable')
|
|
|
|
else:
|
|
|
|
logger.info(f'To re-enable the overlay, run: legendary eos-overlay enable --path "{old_path}"')
|
|
|
|
|
|
|
|
elif args.action == 'remove':
|
|
|
|
if not self.core.is_overlay_installed():
|
|
|
|
logger.error('No legendary-managed overlay installation found.')
|
|
|
|
return
|
|
|
|
|
|
|
|
if not args.yes:
|
|
|
|
if not get_boolean_choice('Do you want to uninstall the overlay?', default=False):
|
|
|
|
print('Aborting...')
|
|
|
|
return
|
|
|
|
|
|
|
|
logger.info('Removing registry entries...')
|
|
|
|
remove_registry_entries()
|
|
|
|
logger.info('Deleting overlay installation...')
|
|
|
|
self.core.remove_overlay_install()
|
|
|
|
logger.info('Done.')
|
|
|
|
|
|
|
|
elif args.action in {'install', 'update'}:
|
|
|
|
if args.action == 'update' and not self.core.is_overlay_installed():
|
|
|
|
logger.error(f'Overlay not installed, nothing to update.')
|
|
|
|
return
|
|
|
|
logger.info('Preparing to start overlay install...')
|
|
|
|
dlm, ares, igame = self.core.prepare_overlay_install(args.path)
|
|
|
|
|
|
|
|
if old_install := self.core.lgd.get_overlay_install_info():
|
|
|
|
if old_install.version == igame.version:
|
|
|
|
logger.info('Installed version is up to date, nothing to do.')
|
|
|
|
return
|
|
|
|
|
|
|
|
logger.info(f'Install directory: {igame.install_path}')
|
|
|
|
logger.info(f'Install size: {ares.install_size / 1024 / 1024:.2f} MiB')
|
|
|
|
logger.info(f'Download size: {ares.dl_size / 1024 / 1024:.2f} MiB')
|
|
|
|
|
|
|
|
if not args.yes:
|
|
|
|
if not get_boolean_choice('Do you want to install the overlay?'):
|
|
|
|
print('Aborting...')
|
|
|
|
return
|
|
|
|
|
|
|
|
try:
|
|
|
|
# set up logging stuff (should be moved somewhere else later)
|
|
|
|
dlm.logging_queue = self.logging_queue
|
|
|
|
dlm.start()
|
|
|
|
dlm.join()
|
|
|
|
except Exception as e:
|
|
|
|
logger.warning(f'The following exception occurred while waiting for the downloader 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:
|
|
|
|
logger.info('Finished downloading, setting up overlay...')
|
|
|
|
self.core.finish_overlay_install(igame)
|
|
|
|
|
|
|
|
# Check for existing registry entries, and remove them if necessary
|
|
|
|
install_path = os.path.normpath(igame.install_path)
|
|
|
|
reg_paths = query_registry_entries()
|
|
|
|
if old_path := reg_paths["overlay_path"]:
|
2021-12-28 16:51:35 +00:00
|
|
|
if os.path.normpath(old_path) != install_path:
|
|
|
|
logger.info(f'Updating overlay registry entries from "{old_path}" to "{install_path}"')
|
2021-12-28 16:47:08 +00:00
|
|
|
remove_registry_entries()
|
|
|
|
add_registry_entries(install_path)
|
|
|
|
logger.info('Done.')
|
|
|
|
|
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
|
2020-09-08 16:10:05 +00:00
|
|
|
parser.add_argument('-v', '--debug', dest='debug', action='store_true', help='Set loglevel to debug')
|
2020-05-29 23:09:53 +00:00
|
|
|
parser.add_argument('-y', '--yes', dest='yes', action='store_true', help='Default to yes for all prompts')
|
2020-09-08 16:10:05 +00:00
|
|
|
parser.add_argument('-V', '--version', dest='version', action='store_true', help='Print version and exit')
|
2021-09-28 01:07:15 +00:00
|
|
|
parser.add_argument('-c', '--config-file', dest='config_file', action='store', metavar='<path/name>',
|
2021-12-22 07:28:23 +00:00
|
|
|
help=argparse.SUPPRESS)
|
2021-10-05 06:47:28 +00:00
|
|
|
parser.add_argument('-J', '--pretty-json', dest='pretty_json', action='store_true',
|
|
|
|
help='Pretty-print JSON')
|
2021-12-22 07:20:36 +00:00
|
|
|
parser.add_argument('-H', '--full-help', dest='full_help', action='store_true',
|
|
|
|
help='Show full help (including individual command help)')
|
2020-04-25 10:20:14 +00:00
|
|
|
|
|
|
|
# all the commands
|
2021-12-22 07:20:36 +00:00
|
|
|
subparsers = parser.add_subparsers(title='Commands', dest='subparser_name', metavar='<command>')
|
|
|
|
auth_parser = subparsers.add_parser('auth', help='Authenticate with the Epic Games Store')
|
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')
|
2021-10-21 11:26:36 +00:00
|
|
|
clean_saves_parser = subparsers.add_parser('clean-saves', help='Clean 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-05-29 21:09:02 +00:00
|
|
|
egl_sync_parser = subparsers.add_parser('egl-sync', help='Setup or run Epic Games Launcher sync')
|
2020-09-08 02:50:14 +00:00
|
|
|
status_parser = subparsers.add_parser('status', help='Show legendary status information')
|
2021-09-28 05:58:50 +00:00
|
|
|
info_parser = subparsers.add_parser('info', help='Prints info about specified app name or manifest')
|
2021-10-02 20:54:56 +00:00
|
|
|
alias_parser = subparsers.add_parser('alias', help='Manage aliases')
|
|
|
|
clean_parser = subparsers.add_parser('cleanup', help='Remove old temporary, metadata, and manifest files')
|
2021-12-03 13:07:57 +00:00
|
|
|
activate_parser = subparsers.add_parser('activate', help='Activate games on third party launchers')
|
2021-12-21 22:51:48 +00:00
|
|
|
get_token_parser = subparsers.add_parser('get-token')
|
2021-12-28 16:47:08 +00:00
|
|
|
eos_overlay_parser = subparsers.add_parser('eos-overlay', help='Manage EOS Overlay install')
|
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)')
|
2021-10-21 11:26:36 +00:00
|
|
|
clean_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
|
|
|
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>')
|
2021-09-28 05:58:50 +00:00
|
|
|
info_parser.add_argument('app_name_or_manifest', help='App name or manifest path/URI',
|
|
|
|
metavar='<App Name/Manifest URI>')
|
2020-04-25 10:20:14 +00:00
|
|
|
|
2021-10-02 20:54:56 +00:00
|
|
|
alias_parser.add_argument('action', help='Action: Add, rename, remove, or list alias(es)',
|
2021-12-28 13:20:44 +00:00
|
|
|
choices=['add', 'rename', 'remove', 'list'],
|
2021-12-28 13:03:26 +00:00
|
|
|
metavar='<add|rename|remove|list>')
|
2021-10-02 20:54:56 +00:00
|
|
|
alias_parser.add_argument('app_or_alias', help='App name when using "add" or "list" action, '
|
|
|
|
'existing alias when using "rename" or "remove" action',
|
2021-12-28 13:03:26 +00:00
|
|
|
metavar='App name/Old alias', nargs='?')
|
2021-10-02 20:54:56 +00:00
|
|
|
alias_parser.add_argument('alias', help='New alias when using "add" action',
|
2021-12-28 13:03:26 +00:00
|
|
|
metavar='New alias', nargs='?')
|
2021-10-02 20:54:56 +00:00
|
|
|
|
2020-05-31 01:16:03 +00:00
|
|
|
auth_parser.add_argument('--import', dest='import_egs_auth', action='store_true',
|
|
|
|
help='Import Epic Games Launcher authentication data (logs out of EGL)')
|
2020-05-12 18:01:25 +00:00
|
|
|
auth_parser.add_argument('--code', dest='auth_code', action='store', metavar='<exchange code>',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Use specified exchange code instead of interactive authentication')
|
2020-05-31 00:01:39 +00:00
|
|
|
auth_parser.add_argument('--sid', dest='session_id', action='store', metavar='<session id>',
|
|
|
|
help='Use specified session id instead of interactive authentication')
|
2020-05-12 18:01:25 +00:00
|
|
|
auth_parser.add_argument('--delete', dest='auth_delete', action='store_true',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Remove existing authentication (log out)')
|
2021-10-06 08:40:26 +00:00
|
|
|
auth_parser.add_argument('--disable-webview', dest='no_webview', action='store_true',
|
|
|
|
help='Do not use embedded browser for login')
|
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>',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Folder for game installation (defaults to folder specified in metadata)')
|
2020-04-25 10:20:14 +00:00
|
|
|
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>',
|
2020-05-30 20:56:20 +00:00
|
|
|
type=int, help='Maximum amount of download workers, default: min(2 * CPUs, 16)')
|
2020-04-25 10:20:14 +00:00
|
|
|
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)')
|
2020-09-09 08:29:57 +00:00
|
|
|
install_parser.add_argument('--delta-manifest', dest='override_delta_manifest', action='store', metavar='<uri>',
|
|
|
|
help='Manifest URL or path to use as the delta one (e.g. for testing)')
|
2020-04-25 10:20:14 +00:00
|
|
|
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',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Download all files / ignore existing (overwrite)')
|
2020-04-25 10:20:14 +00:00
|
|
|
install_parser.add_argument('--disable-patching', dest='disable_patching', action='store_true',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Do not attempt to patch existing installation (download entire changed files)')
|
2020-05-05 14:01:53 +00:00
|
|
|
install_parser.add_argument('--download-only', '--no-install', dest='no_install', action='store_true',
|
2021-01-02 05:53:21 +00:00
|
|
|
help='Do not install app and do not run prerequisite installers after download')
|
2020-04-26 11:20:11 +00:00
|
|
|
install_parser.add_argument('--update-only', dest='update_only', action='store_true',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Only update, do not do anything if specified app is not installed')
|
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')
|
2021-12-03 20:01:30 +00:00
|
|
|
install_parser.add_argument('--platform', dest='platform', action='store', metavar='<Platform>', type=str,
|
2021-12-02 14:23:16 +00:00
|
|
|
help='Platform for install (default: installed or Windows)')
|
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-30 20:56:20 +00:00
|
|
|
type=str, help='Only download files with the specified install tag')
|
2020-05-04 11:59:04 +00:00
|
|
|
install_parser.add_argument('--enable-reordering', dest='order_opt', action='store_true',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Enable reordering optimization to reduce RAM requirements '
|
|
|
|
'during download (may have adverse results for some titles)')
|
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>',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Set save game path to be used for sync-saves')
|
2020-05-20 10:41:49 +00:00
|
|
|
install_parser.add_argument('--repair', dest='repair_mode', action='store_true',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Repair installed game by checking and redownloading corrupted/missing files')
|
2020-09-05 03:20:27 +00:00
|
|
|
install_parser.add_argument('--repair-and-update', dest='repair_and_update', action='store_true',
|
|
|
|
help='Update game to the latest version when repairing')
|
|
|
|
install_parser.add_argument('--ignore-free-space', dest='ignore_space', action='store_true',
|
|
|
|
help='Do not abort if not enough free space is available')
|
|
|
|
install_parser.add_argument('--disable-delta-manifests', dest='disable_delta', action='store_true',
|
2020-12-16 19:21:20 +00:00
|
|
|
help='Do not use delta manifests when updating (may increase download size)')
|
2020-12-17 13:56:09 +00:00
|
|
|
install_parser.add_argument('--reset-sdl', dest='reset_sdl', action='store_true',
|
|
|
|
help='Reset selective downloading choices (requires repair to download new components)')
|
2021-09-29 06:05:37 +00:00
|
|
|
install_parser.add_argument('--skip-sdl', dest='skip_sdl', action='store_true',
|
|
|
|
help='Skip SDL prompt and continue with defaults (only required game data)')
|
|
|
|
install_parser.add_argument('--disable-sdl', dest='disable_sdl', action='store_true',
|
|
|
|
help='Disable selective downloading for title, reset existing configuration (if any)')
|
2021-08-09 09:17:15 +00:00
|
|
|
install_parser.add_argument('--preferred-cdn', dest='preferred_cdn', action='store', metavar='<hostname>',
|
2021-08-09 09:31:03 +00:00
|
|
|
help='Set the hostname of the preferred CDN to use when available')
|
|
|
|
install_parser.add_argument('--no-https', dest='disable_https', action='store_true',
|
|
|
|
help='Download games via plaintext HTTP (like EGS), e.g. for use with a lan cache')
|
2021-09-28 06:07:28 +00:00
|
|
|
install_parser.add_argument('--with-dlcs', dest='with_dlcs', action='store_true',
|
|
|
|
help='Automatically install all DLCs with the base game')
|
2021-10-08 08:20:39 +00:00
|
|
|
install_parser.add_argument('--skip-dlcs', dest='skip_dlcs', action='store_true',
|
|
|
|
help='Do not ask about installing DLCs.')
|
2020-04-25 10:20:14 +00:00
|
|
|
|
2020-11-02 14:55:36 +00:00
|
|
|
uninstall_parser.add_argument('--keep-files', dest='keep_files', action='store_true',
|
|
|
|
help='Keep files but remove game from Legendary database')
|
|
|
|
|
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>',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Override language for game launch (defaults to system locale)')
|
2020-05-20 10:49:51 +00:00
|
|
|
launch_parser.add_argument('--wrapper', dest='wrapper', action='store', metavar='<wrapper command>',
|
2020-05-23 16:33:11 +00:00
|
|
|
default=os.environ.get('LGDRY_WRAPPER', None),
|
2020-05-20 10:49:51 +00:00
|
|
|
help='Wrapper command to launch game with')
|
2020-06-01 06:40:00 +00:00
|
|
|
launch_parser.add_argument('--set-defaults', dest='set_defaults', action='store_true',
|
|
|
|
help='Save parameters used to launch to config (does not include env vars)')
|
|
|
|
launch_parser.add_argument('--reset-defaults', dest='reset_defaults', action='store_true',
|
|
|
|
help='Reset config settings for app and exit')
|
2021-01-10 13:24:06 +00:00
|
|
|
launch_parser.add_argument('--override-exe', dest='executable_override', action='store', metavar='<exe path>',
|
|
|
|
help='Override executable to launch (relative path)')
|
2021-09-08 08:43:30 +00:00
|
|
|
launch_parser.add_argument('--origin', dest='origin', action='store_true',
|
|
|
|
help='Launch Origin to activate or run the game.')
|
2021-09-28 02:04:15 +00:00
|
|
|
launch_parser.add_argument('--json', dest='json', action='store_true',
|
|
|
|
help='Print launch information as JSON and exit')
|
2020-05-20 10:49:51 +00:00
|
|
|
|
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),
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Set WINE binary to use to launch the app')
|
2020-05-12 00:31:01 +00:00
|
|
|
launch_parser.add_argument('--wine-prefix', dest='wine_pfx', action='store', metavar='<wine pfx path>',
|
|
|
|
default=os.environ.get('LGDRY_WINE_PREFIX', None),
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Set WINE prefix to use')
|
2020-05-27 19:18:02 +00:00
|
|
|
launch_parser.add_argument('--no-wine', dest='no_wine', action='store_true',
|
2020-05-23 17:01:30 +00:00
|
|
|
default=strtobool(os.environ.get('LGDRY_NO_WINE', 'False')),
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Do not run game with WINE (e.g. if a wrapper is 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
|
|
|
|
2021-12-29 11:56:00 +00:00
|
|
|
if sys_platform == 'darwin':
|
|
|
|
launch_parser.add_argument('--crossover', dest='crossover', action='store_true',
|
|
|
|
help='Interactively configure CrossOver for this application.')
|
2021-12-29 12:13:00 +00:00
|
|
|
launch_parser.add_argument('--crossover-app', dest='crossover_app', action='store', metavar='<path to .app>',
|
2021-12-29 11:56:00 +00:00
|
|
|
help='Specify which App to use for CrossOver (e.g. "/Applications/CrossOver.app")')
|
|
|
|
launch_parser.add_argument('--crossover-bottle', dest='crossover_bottle', action='store',
|
2021-12-29 12:13:00 +00:00
|
|
|
help='Specify which bottle to use for CrossOver', metavar='<bottle name>')
|
2021-12-29 11:56:00 +00:00
|
|
|
else:
|
|
|
|
launch_parser.add_argument('--crossover', dest='crossover', action='store_true',
|
|
|
|
help=argparse.SUPPRESS)
|
|
|
|
launch_parser.add_argument('--crossover-app', dest='crossover_app', action='store',
|
|
|
|
help=argparse.SUPPRESS)
|
|
|
|
launch_parser.add_argument('--crossover-bottle', dest='crossover_bottle', action='store',
|
|
|
|
help=argparse.SUPPRESS)
|
|
|
|
|
2021-12-03 20:01:30 +00:00
|
|
|
list_parser.add_argument('--platform', dest='platform', action='store', metavar='<Platform>', type=str,
|
2021-12-02 14:23:16 +00:00
|
|
|
help='Platform to fetch game list for (default: Mac on macOS, otherwise Windows)')
|
2020-04-28 13:32:38 +00:00
|
|
|
list_parser.add_argument('--include-ue', dest='include_ue', action='store_true',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Also include Unreal Engine content (Engine/Marketplace) in list')
|
2021-12-06 18:31:39 +00:00
|
|
|
list_parser.add_argument('-T', '--third-party', '--include-non-installable',
|
|
|
|
dest='include_noasset', action='store_true', default=False,
|
2021-09-01 13:28:25 +00:00
|
|
|
help='Include apps that are not installable (e.g. that have to be activated on Origin)')
|
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-09-08 03:12:14 +00:00
|
|
|
list_parser.add_argument('--json', dest='json', action='store_true', help='List games in JSON format')
|
2021-09-28 03:56:19 +00:00
|
|
|
list_parser.add_argument('--force-refresh', dest='force_refresh', action='store_true',
|
|
|
|
help='Force a refresh of all game metadata')
|
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',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Check for updates for 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-09-08 03:12:14 +00:00
|
|
|
list_installed_parser.add_argument('--json', dest='json', action='store_true',
|
|
|
|
help='List games in JSON format')
|
2020-06-02 05:54:51 +00:00
|
|
|
list_installed_parser.add_argument('--show-dirs', dest='include_dir', action='store_true',
|
|
|
|
help='Print installation directory in output')
|
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')
|
2021-12-01 19:57:43 +00:00
|
|
|
list_files_parser.add_argument('--platform', dest='platform', action='store', metavar='<Platform>',
|
2021-12-03 20:01:30 +00:00
|
|
|
type=str, help='Platform (default: Mac on macOS, otherwise Windows)')
|
2020-04-30 09:12:26 +00:00
|
|
|
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-09-08 03:12:14 +00:00
|
|
|
list_files_parser.add_argument('--json', dest='json', action='store_true', help='Output in JSON format')
|
2020-04-30 09:12:26 +00:00
|
|
|
list_files_parser.add_argument('--hashlist', dest='hashlist', action='store_true',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Output file hash list in hashcheck/sha1sum -c 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-30 20:56:20 +00:00
|
|
|
help='Override savegame path (requires single app name to be specified)')
|
2020-05-16 10:19:44 +00:00
|
|
|
sync_saves_parser.add_argument('--disable-filters', dest='disable_filters', action='store_true',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Disable save game file filtering')
|
2020-05-14 12:52:33 +00:00
|
|
|
|
2021-10-21 12:27:08 +00:00
|
|
|
clean_saves_parser.add_argument('--delete-incomplete', dest='delete_incomplete', action='store_true',
|
|
|
|
help='Delete incomplete save files')
|
|
|
|
|
2020-05-28 00:40:12 +00:00
|
|
|
import_parser.add_argument('--disable-check', dest='disable_check', action='store_true',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Disables completeness check of the to-be-imported game installation '
|
|
|
|
'(useful if the imported game is a much older version or missing files)')
|
2021-10-08 08:20:23 +00:00
|
|
|
import_parser.add_argument('--with-dlcs', dest='with_dlcs', action='store_true',
|
|
|
|
help='Automatically attempt to import all DLCs with the base game')
|
|
|
|
import_parser.add_argument('--skip-dlcs', dest='skip_dlcs', action='store_true',
|
|
|
|
help='Do not ask about importing DLCs.')
|
2021-12-03 20:01:30 +00:00
|
|
|
import_parser.add_argument('--platform', dest='platform', action='store', metavar='<Platform>', type=str,
|
|
|
|
help='Platform for import (default: Mac on macOS, otherwise Windows)')
|
2020-05-28 00:40:12 +00:00
|
|
|
|
2020-05-29 21:09:02 +00:00
|
|
|
egl_sync_parser.add_argument('--egl-manifest-path', dest='egl_manifest_path', action='store',
|
2020-05-29 23:07:45 +00:00
|
|
|
help='Path to the Epic Games Launcher\'s Manifests folder, should '
|
2020-05-29 21:09:02 +00:00
|
|
|
'point to /ProgramData/Epic/EpicGamesLauncher/Data/Manifests')
|
2020-05-29 23:07:45 +00:00
|
|
|
egl_sync_parser.add_argument('--egl-wine-prefix', dest='egl_wine_prefix', action='store',
|
|
|
|
help='Path to the WINE prefix the Epic Games Launcher is installed in')
|
2020-05-29 21:09:02 +00:00
|
|
|
egl_sync_parser.add_argument('--enable-sync', dest='enable_sync', action='store_true',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Enable automatic EGL <-> Legendary sync')
|
2020-06-01 10:58:47 +00:00
|
|
|
egl_sync_parser.add_argument('--disable-sync', dest='disable_sync', action='store_true',
|
|
|
|
help='Disable automatic sync and exit')
|
2020-05-29 21:09:02 +00:00
|
|
|
egl_sync_parser.add_argument('--one-shot', dest='one_shot', action='store_true',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Sync once, do not ask to setup automatic sync')
|
2020-05-29 21:09:02 +00:00
|
|
|
egl_sync_parser.add_argument('--import-only', dest='import_only', action='store_true',
|
|
|
|
help='Only import games from EGL (no export)')
|
|
|
|
egl_sync_parser.add_argument('--export-only', dest='export_only', action='store_true',
|
|
|
|
help='Only export games to EGL (no import)')
|
2020-05-29 22:11:21 +00:00
|
|
|
egl_sync_parser.add_argument('--unlink', dest='unlink', action='store_true',
|
2020-05-30 20:56:20 +00:00
|
|
|
help='Disable sync and remove EGL metadata from installed games')
|
2020-05-29 21:09:02 +00:00
|
|
|
|
2020-09-08 02:50:14 +00:00
|
|
|
status_parser.add_argument('--offline', dest='offline', action='store_true',
|
|
|
|
help='Only print offline status information, do not login')
|
2020-09-08 03:12:14 +00:00
|
|
|
status_parser.add_argument('--json', dest='json', action='store_true',
|
|
|
|
help='Show status in JSON format')
|
2020-09-08 02:50:14 +00:00
|
|
|
|
2020-11-02 14:53:11 +00:00
|
|
|
clean_parser.add_argument('--keep-manifests', dest='keep_manifests', action='store_true',
|
|
|
|
help='Do not delete old manifests')
|
|
|
|
|
2021-09-28 05:58:50 +00:00
|
|
|
info_parser.add_argument('--offline', dest='offline', action='store_true',
|
|
|
|
help='Only print info available offline')
|
2021-10-05 06:41:57 +00:00
|
|
|
info_parser.add_argument('--json', dest='json', action='store_true',
|
|
|
|
help='Output information in JSON format')
|
2021-12-03 20:01:30 +00:00
|
|
|
info_parser.add_argument('--platform', dest='platform', action='store', metavar='<Platform>', type=str,
|
2021-12-02 14:23:16 +00:00
|
|
|
help='Platform to fetch info for (default: installed or Mac on macOS, Windows otherwise)')
|
2021-09-28 05:58:50 +00:00
|
|
|
|
2021-12-06 18:33:36 +00:00
|
|
|
store_group = activate_parser.add_mutually_exclusive_group(required=True)
|
|
|
|
store_group.add_argument('-U', '--uplay', dest='uplay', action='store_true',
|
|
|
|
help='Activate Uplay/Ubisoft Connect titles on your Ubisoft account '
|
|
|
|
'(Uplay install not required)')
|
|
|
|
store_group.add_argument('-O', '--origin', dest='origin', action='store_true',
|
|
|
|
help='Activate Origin/EA App managed titles on your EA account '
|
|
|
|
'(requires Origin to be installed)')
|
2021-12-03 13:07:57 +00:00
|
|
|
|
2021-12-21 22:51:48 +00:00
|
|
|
get_token_parser.add_argument('--json', dest='json', action='store_true',
|
|
|
|
help='Output information in JSON format')
|
2021-12-28 09:21:34 +00:00
|
|
|
get_token_parser.add_argument('--bearer', dest='bearer', action='store_true',
|
|
|
|
help='Return fresh bearer token rather than an exchange code')
|
2021-12-21 22:51:48 +00:00
|
|
|
|
2021-12-28 16:47:08 +00:00
|
|
|
eos_overlay_parser.add_argument('action', help='Action: install, remove, enable, disable, '
|
|
|
|
'or print info about the overlay',
|
|
|
|
choices=['install', 'update', 'remove', 'enable', 'disable', 'info'],
|
|
|
|
metavar='<install|update|remove|enable|disable|info>')
|
|
|
|
eos_overlay_parser.add_argument('--path', dest='path', action='store',
|
|
|
|
help='Path to the EOS overlay folder to be enabled/installed to.')
|
|
|
|
# eos_overlay_parser.add_argument('--prefix', dest='prefix', action='store',
|
|
|
|
# help='WINE prefix to install the overlay in')
|
|
|
|
# eos_overlay_parser.add_argument('--app', dest='app', action='store',
|
|
|
|
# help='Use this app\'s wine prefix (if configured in config)')
|
|
|
|
|
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)
|
|
|
|
|
2021-12-22 07:20:36 +00:00
|
|
|
if not args.subparser_name or args.full_help:
|
2020-04-25 10:20:14 +00:00
|
|
|
print(parser.format_help())
|
|
|
|
|
2021-12-22 07:20:36 +00:00
|
|
|
if args.full_help:
|
|
|
|
# Commands that should not be shown in full help/list of commands (e.g. aliases)
|
|
|
|
_hidden_commands = {'download', 'update', 'repair', 'get-token'}
|
|
|
|
# Print the help for all of the subparsers. 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():
|
|
|
|
if choice in _hidden_commands:
|
|
|
|
continue
|
|
|
|
print(f'\nCommand: {choice}')
|
|
|
|
print(subparser.format_help())
|
2020-04-25 10:20:14 +00:00
|
|
|
return
|
|
|
|
|
2021-09-28 01:07:15 +00:00
|
|
|
cli = LegendaryCLI(override_config=args.config_file)
|
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)
|
|
|
|
|
2021-12-03 20:01:30 +00:00
|
|
|
if hasattr(args, 'platform'):
|
|
|
|
if not args.platform:
|
|
|
|
os_default = 'Mac' if sys_platform == 'darwin' else 'Windows'
|
|
|
|
args.platform = cli.core.lgd.config.get('Legendary', 'default_platform', fallback=os_default)
|
|
|
|
elif args.platform not in ('Win32', 'Windows', 'Mac'):
|
|
|
|
logger.warning(f'Platform "{args.platform}" may be invalid. Valid ones are: Windows, Win32, Mac.')
|
|
|
|
|
2020-11-21 13:30:30 +00:00
|
|
|
# if --yes is used as part of the subparsers arguments manually set the flag in the main parser.
|
2020-06-01 06:12:24 +00:00
|
|
|
if '-y' in extra or '--yes' in extra:
|
2020-11-21 13:30:30 +00:00
|
|
|
args.yes = True
|
|
|
|
extra = [i for i in extra if i not in ('--yes', '-y')]
|
2020-06-01 06:12:24 +00:00
|
|
|
|
2020-04-25 10:20:14 +00:00
|
|
|
# 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)
|
2021-10-21 11:26:36 +00:00
|
|
|
elif args.subparser_name == 'clean-saves':
|
|
|
|
cli.clean_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-05-29 21:09:02 +00:00
|
|
|
elif args.subparser_name == 'egl-sync':
|
|
|
|
cli.egs_sync(args)
|
2020-09-08 02:50:14 +00:00
|
|
|
elif args.subparser_name == 'status':
|
|
|
|
cli.status(args)
|
2021-09-28 05:58:50 +00:00
|
|
|
elif args.subparser_name == 'info':
|
|
|
|
cli.info(args)
|
2021-10-02 20:54:56 +00:00
|
|
|
elif args.subparser_name == 'alias':
|
|
|
|
cli.alias(args)
|
2020-11-02 14:53:11 +00:00
|
|
|
elif args.subparser_name == 'cleanup':
|
|
|
|
cli.cleanup(args)
|
2021-12-03 13:07:57 +00:00
|
|
|
elif args.subparser_name == 'activate':
|
|
|
|
cli.activate(args)
|
2021-12-21 22:51:48 +00:00
|
|
|
elif args.subparser_name == 'get-token':
|
|
|
|
cli.get_token(args)
|
2021-12-28 16:47:08 +00:00
|
|
|
elif args.subparser_name == 'eos-overlay':
|
|
|
|
cli.manage_eos_overlay(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
|
|
|
|
2021-09-03 19:11:09 +00:00
|
|
|
# Disable the update message if JSON/TSV/CSV outputs are used
|
|
|
|
disable_update_message = False
|
|
|
|
if hasattr(args, 'json'):
|
|
|
|
disable_update_message = args.json
|
|
|
|
if not disable_update_message and hasattr(args, 'tsv'):
|
|
|
|
disable_update_message = args.tsv
|
|
|
|
if not disable_update_message and hasattr(args, 'csv'):
|
|
|
|
disable_update_message = args.csv
|
|
|
|
|
2021-09-02 17:29:50 +00:00
|
|
|
# show note if update is available
|
2021-09-03 19:11:09 +00:00
|
|
|
if not disable_update_message and cli.core.update_available and cli.core.update_notice_enabled():
|
2021-09-02 17:29:50 +00:00
|
|
|
if update_info := cli.core.get_update_info():
|
|
|
|
print(f'\nLegendary update available!')
|
|
|
|
print(f'- New version: {update_info["version"]} - "{update_info["name"]}"')
|
|
|
|
print(f'- Release summary:\n{update_info["summary"]}\n- Release URL: {update_info["gh_url"]}')
|
|
|
|
if update_info['critical']:
|
|
|
|
print('! This update is recommended as it fixes major issues.')
|
2021-12-02 15:51:48 +00:00
|
|
|
if not is_windows_mac_or_pyi():
|
2021-09-03 18:14:00 +00:00
|
|
|
print('If you installed legendary via a package manager it may '
|
|
|
|
'take some time for the update to become available.')
|
2021-12-03 11:47:07 +00:00
|
|
|
elif 'downloads' in update_info:
|
|
|
|
dl_platform = 'windows'
|
|
|
|
if sys_platform == 'darwin':
|
|
|
|
dl_platform = 'macos'
|
|
|
|
elif sys_platform == 'linux':
|
|
|
|
dl_platform = 'linux'
|
|
|
|
|
|
|
|
print(f'\n- Download URL: {update_info["downloads"][dl_platform]}')
|
2021-09-02 17:29:50 +00:00
|
|
|
|
2021-12-28 16:48:24 +00:00
|
|
|
if not disable_update_message and cli.core.overlay_update_available:
|
2021-12-28 17:17:13 +00:00
|
|
|
old_version = cli.core.lgd.get_overlay_install_info().version
|
|
|
|
new_version = cli.core.lgd.get_cached_overlay_version()["data"]["buildVersion"]
|
|
|
|
print(f'\nEOS Overlay update available: {new_version} (Current: {old_version}).')
|
2021-12-28 16:48:24 +00:00
|
|
|
print('Run "legendary eos-overlay update" to update to the latest version.')
|
|
|
|
|
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()
|