Skip to content

Commit

Permalink
Merge pull request #405 from loathingKernel/develop
Browse files Browse the repository at this point in the history
Support paths with spaces in pre launch command field
  • Loading branch information
loathingKernel authored May 18, 2024
2 parents 42341d5 + 0ac4cf5 commit 50ff2ae
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
3 changes: 2 additions & 1 deletion rare/commands/launcher/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import platform
import shlex
import subprocess
import time
import traceback
Expand Down Expand Up @@ -76,7 +77,7 @@ def prepare_launch(self, args: InitArgs) -> Optional[LaunchArgs]:
proc = get_configured_process()
proc.setProcessEnvironment(launch_args.environment)
self.signals.started_pre_launch_command.emit()
pre_launch_command = launch_args.pre_launch_command.split()
pre_launch_command = shlex.split(launch_args.pre_launch_command)
# self.logger.debug("Executing prelaunch command %s, %s", pre_launch_command[0], pre_launch_command[1:])
proc.start(pre_launch_command[0], pre_launch_command[1:])
if launch_args.pre_launch_wait:
Expand Down
7 changes: 6 additions & 1 deletion rare/components/tabs/settings/widgets/launch.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import shlex
import shutil
from typing import Tuple, Type, TypeVar

Expand Down Expand Up @@ -73,7 +74,11 @@ def tool_enabled(self):
def __prelaunch_edit_callback(text: str) -> Tuple[bool, str, int]:
if not text.strip():
return True, text, IndicatorReasonsCommon.VALID
if not os.path.isfile(text.split()[0]) and not shutil.which(text.split()[0]):
try:
command = shlex.split(text)[0]
except ValueError:
return False, text, IndicatorReasonsCommon.WRONG_FORMAT
if not os.path.isfile(command) and not shutil.which(command):
return False, text, IndicatorReasonsCommon.FILE_NOT_EXISTS
else:
return True, text, IndicatorReasonsCommon.VALID
Expand Down
2 changes: 1 addition & 1 deletion rare/models/game.py
Original file line number Diff line number Diff line change
Expand Up @@ -571,8 +571,8 @@ def launch(
if wine_pfx:
args.extend(["--wine-prefix", wine_pfx])

logger.info(f"Starting game process: ({executable} {' '.join(args)})")
QProcess.startDetached(executable, args)
logger.info(f"Start new Process: ({executable} {' '.join(args)})")
self.game_process.connect_to_server(on_startup=False)
return True

Expand Down
9 changes: 6 additions & 3 deletions rare/widgets/indicator_edit.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
from enum import IntEnum
from logging import getLogger
import shlex
from typing import Callable, Tuple, Optional, Dict, List

from PyQt5.QtCore import (
Expand Down Expand Up @@ -336,6 +337,8 @@ def __set_path(self):
if self.__name_filter:
dlg.setNameFilter(" ".join(self.__name_filter))
if dlg.exec_():
names = dlg.selectedFiles()
self.line_edit.setText(names[0])
self.__completer_model.setRootPath(names[0])
name = dlg.selectedFiles()[0]
if " " in name:
name = shlex.quote(name)
self.line_edit.setText(name)
self.__completer_model.setRootPath(name)

0 comments on commit 50ff2ae

Please sign in to comment.