From f60d21beb46fd4f36badfa1d9503cc0ff996e88d Mon Sep 17 00:00:00 2001 From: GB609 <39741460+GB609@users.noreply.github.com> Date: Fri, 29 Nov 2024 11:12:34 +0000 Subject: [PATCH] use shlex to split vars and command to support spaces when quoted --- minigalaxy/launcher.py | 5 +++-- minigalaxy/ui/preferences.py | 2 +- minigalaxy/wine_utils.py | 12 +++++++++--- 3 files changed, 13 insertions(+), 6 deletions(-) diff --git a/minigalaxy/launcher.py b/minigalaxy/launcher.py index 7b31c58f..e276d80e 100644 --- a/minigalaxy/launcher.py +++ b/minigalaxy/launcher.py @@ -4,6 +4,7 @@ import re import json import glob +import shlex import threading from minigalaxy.config import Config @@ -87,13 +88,13 @@ def determine_launcher_type(files): def get_exe_cmd_with_var_command(game, exe_cmd, is_wine_cmd): - command_list = game.get_info("command").split() + command_list = shlex.split(game.get_info("command")) if is_wine_cmd: # wine handles all envs on its own return exe_cmd + command_list - var_list = game.get_info("variable").split() + var_list = shlex.split(game.get_info("variable")) if var_list: if var_list[0] not in ["env"]: var_list.insert(0, "env") diff --git a/minigalaxy/ui/preferences.py b/minigalaxy/ui/preferences.py index 4fe8533c..4e84dcb7 100644 --- a/minigalaxy/ui/preferences.py +++ b/minigalaxy/ui/preferences.py @@ -54,7 +54,7 @@ def __init__(self, parent, config: Config, download_manager: DownloadManager): _("Keep installers after downloading a game.\nInstallers are stored in: {}").format(installer_dir) ) - def __init_combobox(self, combobox, data_feed: [], active_option) -> None: + def __init_combobox(self, combobox, data_feed, active_option) -> None: """expects 2-dimensional array with 2 columns for data first entry per row is the config key, second one the string to display in the UI """ diff --git a/minigalaxy/wine_utils.py b/minigalaxy/wine_utils.py index 03d701fd..30d1390d 100644 --- a/minigalaxy/wine_utils.py +++ b/minigalaxy/wine_utils.py @@ -1,5 +1,6 @@ """Some helpers to handle selection, configuration and start of wine commands""" import json +import shlex import shutil from urllib import request, parse @@ -31,7 +32,7 @@ def get_wine_path(game: Game, config: Config = Config()) -> str: return newDefault -def get_wine_env(game: Game, config: Config = Config(), quoted=False) -> []: +def get_wine_env(game: Game, config: Config = Config(), quoted=False): if quoted: envPattern = '{key}="{value}"' else: @@ -45,9 +46,14 @@ def get_wine_env(game: Game, config: Config = Config(), quoted=False) -> []: if shutil.which('zenity'): environment.append('UMU_ZENITY=1') - for var in game.get_info("variable").split(): + variables = game.get_info('variable') + if not variables: + return environment + + for var in shlex.split(variables): kvp = var.split('=', 1) - environment.append(envPattern.format(key=kvp[0], value=kvp[1])) + if len(kvp) == 2: + environment.append(envPattern.format(key=kvp[0], value=kvp[1])) return environment