@@ -32,11 +32,45 @@ def cli(args=None):
32
32
main (args )
33
33
34
34
35
+
35
36
@cli_error_handler
36
37
def main (args = None , steam_path = None , steam_root = None ):
37
38
"""
38
39
'protontricks' script entrypoint
39
40
"""
41
+ def _find_proton_app_or_exit (steam_path , steam_apps , appid ):
42
+ """
43
+ Attempt to find a Proton app. Fail with an appropriate CLI error
44
+ message if one cannot be found.
45
+ """
46
+ proton_app = find_proton_app (
47
+ steam_path = steam_path , steam_apps = steam_apps , appid = appid
48
+ )
49
+
50
+ if not proton_app :
51
+ if os .environ .get ("PROTON_VERSION" ):
52
+ # Print an error listing accepted values if PROTON_VERSION was
53
+ # set, as the user is trying to use a certain Proton version
54
+ proton_names = sorted (set ([
55
+ app .name for app in steam_apps if app .is_proton
56
+ ]))
57
+ exit_ (
58
+ "Protontricks installation could not be found with given "
59
+ "$PROTON_VERSION!\n \n "
60
+ f"Valid values include: { ", " .join (proton_names )} "
61
+ )
62
+ else :
63
+ exit_ ("Proton installation could not be found!" )
64
+
65
+ if not proton_app .is_proton_ready :
66
+ exit_ (
67
+ "Proton installation is incomplete. Have you launched a Steam "
68
+ "app using this Proton version at least once to finish the "
69
+ "installation?"
70
+ )
71
+
72
+ return proton_app
73
+
40
74
if args is None :
41
75
args = sys .argv [1 :]
42
76
@@ -297,19 +331,9 @@ def exit_(error):
297
331
cwd = str (steam_app .install_path ) if args .cwd_app else None
298
332
299
333
# 6. Find Proton version of selected app
300
- proton_app = find_proton_app (
334
+ proton_app = _find_proton_app_or_exit (
301
335
steam_path = steam_path , steam_apps = steam_apps , appid = steam_app .appid
302
336
)
303
- if not proton_app :
304
- exit_ ("Proton installation could not be found!" )
305
-
306
- if not proton_app .is_proton_ready :
307
- exit_ (
308
- "Proton installation is incomplete. Have you launched a Steam "
309
- "app using this Proton version at least once to finish the "
310
- "installation?"
311
- )
312
-
313
337
314
338
run_command (
315
339
winetricks_path = winetricks_path ,
@@ -361,19 +385,9 @@ def exit_(error):
361
385
return
362
386
363
387
# 6. Find globally active Proton version now
364
- proton_app = find_proton_app (
388
+ proton_app = _find_proton_app_or_exit (
365
389
steam_path = steam_path , steam_apps = steam_apps , appid = args .appid )
366
390
367
- if not proton_app :
368
- exit_ ("Proton installation could not be found!" )
369
-
370
- if not proton_app .is_proton_ready :
371
- exit_ (
372
- "Proton installation is incomplete. Have you launched a Steam app "
373
- "using this Proton version at least once to finish the "
374
- "installation?"
375
- )
376
-
377
391
# If neither search or GUI are set, do a normal Winetricks command
378
392
# Find game by appid
379
393
steam_appid = int (args .appid )
0 commit comments