Skip to content

Commit

Permalink
use shlex to split vars and command to support spaces when quoted
Browse files Browse the repository at this point in the history
  • Loading branch information
GB609 committed Nov 29, 2024
1 parent fa7abf4 commit f60d21b
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
5 changes: 3 additions & 2 deletions minigalaxy/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import re
import json
import glob
import shlex
import threading

from minigalaxy.config import Config
Expand Down Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion minigalaxy/ui/preferences.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
"""
Expand Down
12 changes: 9 additions & 3 deletions minigalaxy/wine_utils.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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

Expand Down

0 comments on commit f60d21b

Please sign in to comment.