From b5d422466472677b7628938d0e5563b11d13a628 Mon Sep 17 00:00:00 2001 From: derrod Date: Tue, 28 Sep 2021 05:07:06 +0200 Subject: [PATCH] [cli/core] Only return legendary-defined environment variables --- legendary/cli.py | 22 ++++++++++------------ legendary/core.py | 4 ++-- 2 files changed, 12 insertions(+), 14 deletions(-) diff --git a/legendary/cli.py b/legendary/cli.py index df8deee..1ce59d5 100644 --- a/legendary/cli.py +++ b/legendary/cli.py @@ -556,27 +556,25 @@ class LegendaryCLI: full_params.extend(params.game_parameters) full_params.extend(params.egl_parameters) full_params.extend(params.user_parameters) - - env_overrides = [] - if 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)) + # Copying existing env vars is required on Windows, probably a good idea on Linux + full_env = os.environ.copy() + full_env.update(params.environment) if args.dry_run: logger.info(f'Not Launching {app_name} (dry run)') logger.info(f'Launch parameters: {shlex.join(full_params)}') logger.info(f'Working directory: {params.working_directory}') - if env_overrides: - logger.info('Environment overrides: {}'.format(', '.join(f'{k}={v}' for k, v in env_overrides))) + if params.environment: + logger.info('Environment overrides: {}'.format(', '.join( + f'{k}={v}' for k, v in params.environment.items()))) else: logger.info(f'Launching {app_name}...') logger.debug(f'Launch parameters: {shlex.join(full_params)}') logger.debug(f'Working directory: {params.working_directory}') - if env_overrides: - logger.debug('Environment overrides: {}'.format(', '.join(f'{k}={v}' for k, v in env_overrides))) - subprocess.Popen(full_params, cwd=params.working_directory, env=params.environment) + if params.environment: + logger.info('Environment overrides: {}'.format(', '.join( + 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): # login is not required to launch the game, but linking does require it. diff --git a/legendary/core.py b/legendary/core.py index 3a68b94..db9d9c8 100644 --- a/legendary/core.py +++ b/legendary/core.py @@ -417,7 +417,7 @@ class LegendaryCore: def get_app_environment(self, app_name, wine_pfx=None) -> dict: # get environment overrides from config - env = os.environ.copy() + env = dict() 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(';')}) if f'{app_name}.env' in self.lgd.config: @@ -426,7 +426,7 @@ class LegendaryCore: # override wine prefix if necessary if 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 if wine_pfx := self.lgd.config.get(app_name, 'wine_prefix', fallback=None): env['WINEPREFIX'] = wine_pfx