[cli/core] Only return legendary-defined environment variables

This commit is contained in:
derrod 2021-09-28 05:07:06 +02:00
parent 888d62a96d
commit b5d4224664
2 changed files with 12 additions and 14 deletions

View file

@ -556,27 +556,25 @@ class LegendaryCLI:
full_params.extend(params.game_parameters) full_params.extend(params.game_parameters)
full_params.extend(params.egl_parameters) full_params.extend(params.egl_parameters)
full_params.extend(params.user_parameters) full_params.extend(params.user_parameters)
# Copying existing env vars is required on Windows, probably a good idea on Linux
env_overrides = [] full_env = os.environ.copy()
if params.environment: full_env.update(params.environment)
for env_var, env_value in params.environment.items():
if env_var in os.environ:
continue
env_overrides.append((env_var, env_value))
if args.dry_run: if args.dry_run:
logger.info(f'Not Launching {app_name} (dry run)') logger.info(f'Not Launching {app_name} (dry run)')
logger.info(f'Launch parameters: {shlex.join(full_params)}') logger.info(f'Launch parameters: {shlex.join(full_params)}')
logger.info(f'Working directory: {params.working_directory}') logger.info(f'Working directory: {params.working_directory}')
if env_overrides: if params.environment:
logger.info('Environment overrides: {}'.format(', '.join(f'{k}={v}' for k, v in env_overrides))) logger.info('Environment overrides: {}'.format(', '.join(
f'{k}={v}' for k, v in params.environment.items())))
else: else:
logger.info(f'Launching {app_name}...') logger.info(f'Launching {app_name}...')
logger.debug(f'Launch parameters: {shlex.join(full_params)}') logger.debug(f'Launch parameters: {shlex.join(full_params)}')
logger.debug(f'Working directory: {params.working_directory}') logger.debug(f'Working directory: {params.working_directory}')
if env_overrides: if params.environment:
logger.debug('Environment overrides: {}'.format(', '.join(f'{k}={v}' for k, v in env_overrides))) logger.info('Environment overrides: {}'.format(', '.join(
subprocess.Popen(full_params, cwd=params.working_directory, env=params.environment) f'{k}={v}' for k, v in params.environment.items())))
subprocess.Popen(full_params, cwd=params.working_directory, env=full_env)
def launch_origin(self, args): def launch_origin(self, args):
# login is not required to launch the game, but linking does require it. # login is not required to launch the game, but linking does require it.

View file

@ -417,7 +417,7 @@ class LegendaryCore:
def get_app_environment(self, app_name, wine_pfx=None) -> dict: def get_app_environment(self, app_name, wine_pfx=None) -> dict:
# get environment overrides from config # get environment overrides from config
env = os.environ.copy() env = dict()
if 'default.env' in self.lgd.config: if 'default.env' in self.lgd.config:
env.update({k: v for k, v in self.lgd.config[f'default.env'].items() if v and not k.startswith(';')}) env.update({k: v for k, v in self.lgd.config[f'default.env'].items() if v and not k.startswith(';')})
if f'{app_name}.env' in self.lgd.config: if f'{app_name}.env' in self.lgd.config:
@ -426,7 +426,7 @@ class LegendaryCore:
# override wine prefix if necessary # override wine prefix if necessary
if wine_pfx: if wine_pfx:
env['WINEPREFIX'] = wine_pfx env['WINEPREFIX'] = wine_pfx
elif 'WINEPREFIX' not in env: elif 'WINEPREFIX' not in os.environ:
# only use config variable if not already set in environment # only use config variable if not already set in environment
if wine_pfx := self.lgd.config.get(app_name, 'wine_prefix', fallback=None): if wine_pfx := self.lgd.config.get(app_name, 'wine_prefix', fallback=None):
env['WINEPREFIX'] = wine_pfx env['WINEPREFIX'] = wine_pfx