Improved game executable launcher, and added argument validation
Now uses proper shell escaping and parsing for all executable arguments, for more robust game launching. All existing game JSON files with the old string values will automatically be converted to the new format on app launch. The executable parsing uses the "shlex" library, which guarantees accurate parsing. We now also use direct process launching (without any intermediary shell) by default, but the old "shell"-based launch method still exists in the code via an alternative flag in `run_command.py` (if we ever need to restore it for some reason). Furthermore, if the user attempts to manually write an improperly escaped argument into the game's details (such as missing closing quotation marks), the GUI will now alert the user that their executable argument is invalid, along with telling them the exact reason why it's invalid.
This commit is contained in:
@@ -19,6 +19,7 @@
|
||||
|
||||
import json
|
||||
import os
|
||||
import shlex
|
||||
import time
|
||||
|
||||
from gi.repository import Adw, GdkPixbuf, Gio, GLib, GObject, Gtk
|
||||
@@ -52,7 +53,7 @@ def create_details_window(parent_widget, game_id=None):
|
||||
)
|
||||
name = Gtk.Entry.new_with_buffer(Gtk.EntryBuffer.new(games[game_id].name, -1))
|
||||
executable = Gtk.Entry.new_with_buffer(
|
||||
Gtk.EntryBuffer.new((games[game_id].executable), -1)
|
||||
Gtk.EntryBuffer.new(shlex.join(games[game_id].executable), -1)
|
||||
)
|
||||
apply_button = Gtk.Button.new_with_label(_("Apply"))
|
||||
|
||||
@@ -201,6 +202,21 @@ def create_details_window(parent_widget, game_id=None):
|
||||
final_developer = developer.get_buffer().get_text()
|
||||
final_executable = executable.get_buffer().get_text()
|
||||
|
||||
try:
|
||||
# Attempt to parse using shell parsing rules (doesn't verify executable existence).
|
||||
final_executable_split = shlex.split(
|
||||
final_executable, comments=False, posix=True
|
||||
)
|
||||
except Exception as e:
|
||||
create_dialog(
|
||||
window,
|
||||
_("Couldn't Add Game")
|
||||
if game_id is None
|
||||
else _("Couldn't Apply Preferences"),
|
||||
f'{_("Executable")}: {e}.', # e = Shell parsing error message. Not translatable.
|
||||
)
|
||||
return
|
||||
|
||||
if game_id is None:
|
||||
if final_name == "":
|
||||
create_dialog(
|
||||
@@ -252,7 +268,7 @@ def create_details_window(parent_widget, game_id=None):
|
||||
|
||||
values["name"] = final_name
|
||||
values["developer"] = final_developer or None
|
||||
values["executable"] = final_executable
|
||||
values["executable"] = final_executable_split
|
||||
|
||||
path = os.path.join(
|
||||
os.path.join(
|
||||
|
||||
Reference in New Issue
Block a user