Skip to content

Commit 6e3e872

Browse files
committed
Add --game-launch flag
Add `--game-launch` flag to launch the game executable with the same arguments as the Steam client. Refs #399
1 parent 1b77f09 commit 6e3e872

File tree

1 file changed

+36
-19
lines changed

1 file changed

+36
-19
lines changed

src/protontricks/cli/main.py

Lines changed: 36 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@
1818
from ..gui import (prompt_filesystem_access, select_steam_app_with_gui,
1919
select_steam_installation)
2020
from ..steam import (find_legacy_steam_runtime_path, find_proton_app,
21-
find_steam_installations, get_steam_apps,
22-
get_steam_lib_paths)
21+
find_steam_installations, get_app_launch_parameters,
22+
get_steam_apps, get_steam_lib_paths)
2323
from ..util import run_command
2424
from ..winetricks import get_winetricks_path
2525
from .util import (CustomArgumentParser, cli_error_handler, enable_logging,
@@ -144,7 +144,12 @@ def _find_proton_app_or_exit(steam_path, steam_apps, appid):
144144
"The command is passed to the shell as-is without being escaped.")
145145
parser.add_argument(
146146
"--gui", action="store_true",
147-
help="Launch the Protontricks GUI.")
147+
help="Launch the Protontricks GUI."
148+
)
149+
parser.add_argument(
150+
"--game-launch", action="store_true",
151+
help="Launch the game"
152+
)
148153
parser.add_argument(
149154
"--no-runtime", action="store_true", default=False,
150155
help="Disable Steam Runtime")
@@ -207,6 +212,7 @@ def exit_(error):
207212
do_command = bool(args.command)
208213
do_list_apps = bool(args.search) or bool(args.list)
209214
do_gui = bool(args.gui)
215+
do_game_launch = bool(args.game_launch)
210216
do_winetricks = bool(args.appid and args.winetricks_command)
211217

212218
# Set 'use_bwrap' to opposite of args.no_bwrap if it was provided.
@@ -222,12 +228,16 @@ def exit_(error):
222228
else use_bwrap
223229
)
224230

225-
if not do_command and not do_list_apps and not do_gui and not do_winetricks:
231+
action_count = sum([
232+
do_command, do_list_apps, do_gui, do_game_launch, do_winetricks
233+
])
234+
235+
if action_count == 0:
226236
parser.print_help()
227237
return
228238

229239
# Don't allow more than one action
230-
if sum([do_list_apps, do_gui, do_winetricks, do_command]) != 1:
240+
if action_count != 1:
231241
print("Only one action can be performed at a time.")
232242
parser.print_help()
233243
return
@@ -406,33 +416,40 @@ def exit_(error):
406416

407417
cwd = str(steam_app.install_path) if args.cwd_app else None
408418

419+
command_kwargs = {
420+
"winetricks_path": winetricks_path,
421+
"proton_app": proton_app,
422+
"steam_app": steam_app,
423+
"use_steam_runtime": use_steam_runtime,
424+
"legacy_steam_runtime_path": legacy_steam_runtime_path,
425+
"use_bwrap": use_bwrap,
426+
"start_wineserver": start_background_wineserver,
427+
}
428+
409429
if args.winetricks_command:
410430
returncode = run_command(
411-
winetricks_path=winetricks_path,
412-
proton_app=proton_app,
413-
steam_app=steam_app,
414-
use_steam_runtime=use_steam_runtime,
415-
legacy_steam_runtime_path=legacy_steam_runtime_path,
416-
use_bwrap=use_bwrap,
417-
start_wineserver=start_background_wineserver,
431+
**command_kwargs,
418432
command=[str(winetricks_path)] + args.winetricks_command,
419433
cwd=cwd
420434
)
421435
elif args.command:
422436
returncode = run_command(
423-
winetricks_path=winetricks_path,
424-
proton_app=proton_app,
425-
steam_app=steam_app,
437+
**command_kwargs,
426438
command=args.command,
427-
use_steam_runtime=use_steam_runtime,
428-
legacy_steam_runtime_path=legacy_steam_runtime_path,
429-
use_bwrap=use_bwrap,
430-
start_wineserver=start_background_wineserver,
431439
# Pass the command directly into the shell *without*
432440
# escaping it
433441
shell=True,
434442
cwd=cwd,
435443
)
444+
elif args.game_launch:
445+
game_kwargs = get_app_launch_parameters(
446+
steam_app=steam_app,
447+
steam_path=steam_path
448+
)
449+
returncode = run_command(
450+
**command_kwargs,
451+
**game_kwargs
452+
)
436453

437454
logger.info("Command returned %d", returncode)
438455

0 commit comments

Comments
 (0)