mirror of
https://github.com/derrod/legendary.git
synced 2024-12-22 17:55:27 +00:00
[cli] Add Origin activation process to "activate" command
This commit is contained in:
parent
eb8bc3713b
commit
db5cd43047
|
@ -1730,13 +1730,11 @@ class LegendaryCLI:
|
||||||
logger.info(f'Cleanup complete! Removed {(before - after)/1024/1024:.02f} MiB.')
|
logger.info(f'Cleanup complete! Removed {(before - after)/1024/1024:.02f} MiB.')
|
||||||
|
|
||||||
def activate(self, args):
|
def activate(self, args):
|
||||||
if not args.uplay:
|
|
||||||
logger.error('Only Uplay is supported.')
|
|
||||||
return
|
|
||||||
if not self.core.login():
|
if not self.core.login():
|
||||||
logger.error('Login failed!')
|
logger.error('Login failed!')
|
||||||
return
|
return
|
||||||
|
|
||||||
|
if args.uplay:
|
||||||
ubi_account_id = ''
|
ubi_account_id = ''
|
||||||
ext_auths = self.core.egs.get_external_auths()
|
ext_auths = self.core.egs.get_external_auths()
|
||||||
for ext_auth in ext_auths:
|
for ext_auth in ext_auths:
|
||||||
|
@ -1745,7 +1743,7 @@ class LegendaryCLI:
|
||||||
ubi_account_id = ext_auth['externalAuthId']
|
ubi_account_id = ext_auth['externalAuthId']
|
||||||
break
|
break
|
||||||
else:
|
else:
|
||||||
logger.error('No linked ubisoft account found! Please link your accounts via your browser and try again.')
|
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')
|
webbrowser.open('https://www.epicgames.com/id/link/ubisoft')
|
||||||
print('If the web page did not open automatically, please manually open the following URL: '
|
print('If the web page did not open automatically, please manually open the following URL: '
|
||||||
'https://www.epicgames.com/id/link/ubisoft')
|
'https://www.epicgames.com/id/link/ubisoft')
|
||||||
|
@ -1767,7 +1765,7 @@ class LegendaryCLI:
|
||||||
uplay_games.append(game)
|
uplay_games.append(game)
|
||||||
|
|
||||||
if not uplay_games:
|
if not uplay_games:
|
||||||
logger.info(f'All of your {activated} Uplay titles have already been activated on your Ubisoft account.')
|
logger.info(f'All of your {activated} titles have already been activated on your Ubisoft account.')
|
||||||
return
|
return
|
||||||
|
|
||||||
logger.info(f'Found {len(uplay_games)} game(s) to redeem:')
|
logger.info(f'Found {len(uplay_games)} game(s) to redeem:')
|
||||||
|
@ -1788,6 +1786,60 @@ class LegendaryCLI:
|
||||||
logger.error(f'Failed to redeem Uplay codes: {e!r}')
|
logger.error(f'Failed to redeem Uplay codes: {e!r}')
|
||||||
else:
|
else:
|
||||||
logger.info('Redeemed all outstanding Uplay codes.')
|
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.')
|
||||||
|
logger.info('After one title has been processed, hit enter to proceed with the next one.')
|
||||||
|
|
||||||
|
y_n = get_boolean_choice('Do you want to redeem these games?')
|
||||||
|
if not y_n:
|
||||||
|
logger.info('Aborting...')
|
||||||
|
return
|
||||||
|
|
||||||
|
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}"')
|
||||||
|
|
||||||
|
if os.name == 'nt':
|
||||||
|
logger.debug(f'Opening Origin URI: {origin_uri}')
|
||||||
|
webbrowser.open(origin_uri)
|
||||||
|
else:
|
||||||
|
# on linux, require users to specify at least the wine binary and prefix in config or command line
|
||||||
|
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.')
|
||||||
|
return
|
||||||
|
|
||||||
|
command.append(origin_uri)
|
||||||
|
logger.debug(f'Opening Origin URI with command: {shlex.join(command)}')
|
||||||
|
subprocess.Popen(command, env=full_env)
|
||||||
|
|
||||||
|
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.')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
@ -2073,8 +2125,13 @@ def main():
|
||||||
info_parser.add_argument('--platform', dest='platform', action='store', metavar='<Platform>', type=str,
|
info_parser.add_argument('--platform', dest='platform', action='store', metavar='<Platform>', type=str,
|
||||||
help='Platform to fetch info for (default: installed or Mac on macOS, Windows otherwise)')
|
help='Platform to fetch info for (default: installed or Mac on macOS, Windows otherwise)')
|
||||||
|
|
||||||
activate_parser.add_argument('-U', '--uplay', '--ubisoft', dest='uplay', action='store_true',
|
store_group = activate_parser.add_mutually_exclusive_group(required=True)
|
||||||
help='Activate Uplay titles')
|
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)')
|
||||||
|
|
||||||
args, extra = parser.parse_known_args()
|
args, extra = parser.parse_known_args()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue