Skip to content

Commit c8b9085

Browse files
protonfixes: move more protonfixes related functions out of the proton script
1 parent c8a6f6c commit c8b9085

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

__init__.py

+43-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
"""Starts the protonfix module and runs fixes after pre-flight-checks"""
22

33
import os
4+
import subprocess
45
import sys
56
import traceback
67
from typing import Callable
@@ -18,6 +19,10 @@
1819
x86_64_lib_dir: str = f'{os.path.dirname(os.path.realpath(__file__))}/files/lib/x86_64-linux-gnu'
1920

2021

22+
# This is needed for protonfixes
23+
os.environ['PROTON_DLL_COPY'] = '*'
24+
25+
2126
def check_conditions() -> bool:
2227
"""Determine, if the actual game was executed and protonfixes isn't deactivated.
2328
@@ -49,6 +54,43 @@ def setup(env: dict, bin_path_var: str, lib_path_var: str, func: Callable[[dict,
4954
func(env, lib_path_var, f'{x86_64_lib_dir}:{i386_lib_dir}', ':')
5055

5156

57+
def winetricks(env: dict, wine_bin, wineserver_bin) -> None:
58+
if (env.get("UMU_ID")
59+
and env.get("EXE", "").endswith("winetricks")
60+
and env.get("PROTON_VERB") == "waitforexitandrun"
61+
):
62+
wt_verbs = " ".join(sys.argv[2:][2:])
63+
env["WINE"] = wine_bin
64+
env["WINELOADER"] = wine_bin
65+
env["WINESERVER"] = wineserver_bin
66+
env["WINETRICKS_LATEST_VERSION_CHECK"] = "disabled"
67+
env["LD_PRELOAD"] = ""
68+
69+
log(f"Running winetricks verbs in prefix: {wt_verbs}")
70+
rc = subprocess.run(sys.argv[2:], check=False, env=env).returncode
71+
72+
sys.exit(rc)
73+
74+
75+
def _is_directory_empty(dir_path):
76+
# Check if the directory is empty
77+
return not any(os.scandir(dir_path))
78+
79+
80+
def setup_mount_drives(func: Callable[[str, str, str], None]):
81+
if os.environ.get('UMU_ID', ''):
82+
drive_map = {
83+
'/media': 'u:',
84+
'/run/media': 'v:',
85+
'/mnt': 'w:',
86+
os.path.expanduser('~'): 'x:', # Current user's home directory
87+
}
88+
89+
for directory in drive_map.keys():
90+
if os.path.exists(directory) and not _is_directory_empty(directory):
91+
func('gamedrive', drive_map[directory], directory)
92+
93+
5294
def execute() -> None:
5395
"""Execute protonfixes"""
5496
if check_iscriptevaluator():
@@ -65,4 +107,4 @@ def execute() -> None:
65107
sys.stderr.flush()
66108

67109

68-
__all__ = ["setup", "execute"]
110+
__all__ = ["setup", "execute", "winetricks", "setup_mount_drives"]

0 commit comments

Comments
 (0)