From 0bf7110653dc22779fd69269535a8bca609a6612 Mon Sep 17 00:00:00 2001 From: derrod Date: Wed, 8 Sep 2021 10:37:40 +0200 Subject: [PATCH] [core] Move getting env vars to separate method --- legendary/core.py | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/legendary/core.py b/legendary/core.py index 4bdd46f..493b69a 100644 --- a/legendary/core.py +++ b/legendary/core.py @@ -411,6 +411,24 @@ class LegendaryCore: def _get_installed_game(self, app_name) -> InstalledGame: return self.lgd.get_installed_game(app_name) + def get_app_environment(self, app_name, wine_pfx=None) -> dict: + # get environment overrides from config + env = os.environ.copy() + 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: + env.update({k: v for k, v in self.lgd.config[f'{app_name}.env'].items() if v and not k.startswith(';')}) + + # override wine prefix if necessary + if wine_pfx: + env['WINEPREFIX'] = wine_pfx + elif 'WINEPREFIX' not in env: + # 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 + + return env + def get_launch_parameters(self, app_name: str, offline: bool = False, user: str = None, extra_args: list = None, wine_bin: str = None, wine_pfx: str = None, @@ -500,20 +518,7 @@ class LegendaryCore: if config_args := self.lgd.config.get(app_name, 'start_params', fallback=None): params.extend(shlex.split(config_args.strip())) - # get environment overrides from config - env = os.environ.copy() - 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: - env.update({k: v for k, v in self.lgd.config[f'{app_name}.env'].items() if v and not k.startswith(';')}) - - if wine_pfx: - env['WINEPREFIX'] = wine_pfx - elif 'WINEPREFIX' not in env: - # 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 - + env = self.get_app_environment(app_name, wine_pfx=wine_pfx) return params, working_dir, env def get_origin_uri(self, app_name: str, offline: bool = False) -> str: