[cli/egl] Make EGL auth import work on Linux

This commit is contained in:
derrod 2020-05-31 03:16:03 +02:00
parent 211f65c4c6
commit 5eecabfb4a
2 changed files with 43 additions and 11 deletions

View file

@ -11,6 +11,7 @@ import time
import webbrowser import webbrowser
from distutils.util import strtobool from distutils.util import strtobool
from getpass import getuser
from logging.handlers import QueueListener from logging.handlers import QueueListener
from multiprocessing import freeze_support, Queue as MPQueue from multiprocessing import freeze_support, Queue as MPQueue
from sys import exit, stdout from sys import exit, stdout
@ -63,18 +64,49 @@ class LegendaryCLI:
logger.error('Stored credentials were found but were no longer valid. Continuing with login...') logger.error('Stored credentials were found but were no longer valid. Continuing with login...')
self.core.lgd.invalidate_userdata() self.core.lgd.invalidate_userdata()
if os.name == 'nt' and args.import_egs_auth: if args.import_egs_auth:
# get appdata path on Linux
if not self.core.egl.appdata_path:
wine_pfx_users = None
lutris_wine_users = os.path.expanduser('~/Games/epic-games-store/drive_c/users')
if os.path.exists(lutris_wine_users):
logger.info(f'Found Lutris EGL WINE prefix at "{lutris_wine_users}"')
if args.yes or get_boolean_choice('Do you want to use the Lutris install?'):
wine_pfx_users = lutris_wine_users
if not wine_pfx_users:
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)
if not os.path.exists(wine_pfx):
print('Path is invalid (does not exist)!')
exit(1)
wine_pfx_users = os.path.join(wine_pfx, 'drive_c/users')
# todo instead of getuser() this should read from the user.reg in the WINE prefix
appdata_dir = os.path.join(wine_pfx_users, getuser(),
'Local Settings/Application Data/EpicGamesLauncher',
'Saved/Config/Windows')
if not os.path.exists(appdata_dir):
logger.error(f'Wine prefix does not have EGL appdata path at "{appdata_dir}"')
exit(0)
else:
logger.info(f'Using EGL appdata path at "{appdata_dir}"')
self.core.egl.appdata_path = appdata_dir
logger.info('Importing login session from the Epic Launcher...') logger.info('Importing login session from the Epic Launcher...')
try: try:
if self.core.auth_import(): if self.core.auth_import():
logger.info('Successfully imported login session from EGS!') logger.info('Successfully imported login session from EGS!')
logger.info(f'Now logged in as user "{self.core.lgd.userdata["displayName"]}"') logger.info(f'Now logged in as user "{self.core.lgd.userdata["displayName"]}"')
exit(0) return
else: else:
logger.warning('Login session from EGS seems to no longer be valid.') logger.warning('Login session from EGS seems to no longer be valid.')
exit(1) exit(1)
except ValueError: except ValueError:
logger.error('No EGS login session found, please login normally.') logger.error('No EGS login session found, please login manually.')
exit(1) exit(1)
exchange_token = '' exchange_token = ''
@ -905,8 +937,6 @@ def main():
import_parser.add_argument('app_path', help='Path where the game is installed', import_parser.add_argument('app_path', help='Path where the game is installed',
metavar='<Installation directory>') metavar='<Installation directory>')
# importing only works on Windows right now
if os.name == 'nt':
auth_parser.add_argument('--import', dest='import_egs_auth', action='store_true', auth_parser.add_argument('--import', dest='import_egs_auth', action='store_true',
help='Import Epic Games Launcher authentication data (logs out of EGL)') help='Import Epic Games Launcher authentication data (logs out of EGL)')
auth_parser.add_argument('--code', dest='auth_code', action='store', metavar='<exchange code>', auth_parser.add_argument('--code', dest='auth_code', action='store', metavar='<exchange code>',

View file

@ -27,13 +27,15 @@ class EPCLFS:
self.manifests = dict() self.manifests = dict()
def read_config(self): def read_config(self):
if os.name != 'nt': if not self.appdata_path:
raise NotImplementedError('Reading EGS config is not implemented on Linux') raise ValueError('EGS AppData path is not set')
self.config.read(os.path.join(self.appdata_path, 'GameUserSettings.ini')) self.config.read(os.path.join(self.appdata_path, 'GameUserSettings.ini'))
def save_config(self): def save_config(self):
if os.name != 'nt': if not self.appdata_path:
raise NotImplementedError('Writing EGS config is not implemented on Linux') raise ValueError('EGS AppData path is not set')
with open(os.path.join(self.appdata_path, 'GameUserSettings.ini'), 'w') as f: with open(os.path.join(self.appdata_path, 'GameUserSettings.ini'), 'w') as f:
self.config.write(f, space_around_delimiters=False) self.config.write(f, space_around_delimiters=False)