proton: Move session methods into Session class

This commit is contained in:
Andrew Eikum 2019-07-29 13:41:01 -05:00
parent adcdea1315
commit 7425001e8e

168
proton
View File

@ -44,9 +44,6 @@ def file_is_wine_fake_dll(path):
except IOError:
return False
def run_wine(args):
subprocess.call(args, env=g_session.env, stderr=g_session.log_file, stdout=g_session.log_file)
def makedirs(path):
try:
os.makedirs(path)
@ -131,8 +128,8 @@ class Proton:
if not os.path.isdir(self.default_pfx_dir):
#make default prefix
local_env["WINEPREFIX"] = self.default_pfx_dir
run_wine([self.wine, "wineboot"])
run_wine([self.wineserver, "-w"])
g_session.run_wine([self.wine, "wineboot"])
g_session.run_wine([self.wineserver, "-w"])
class CompatData:
def __init__(self, compatdata):
@ -418,58 +415,54 @@ class Session:
else:
self.compat_config = set()
if not "STEAM_COMPAT_DATA_PATH" in os.environ:
log("No compat data path?")
sys.exit(1)
g_proton = Proton(os.path.dirname(sys.argv[0]))
g_proton.extract_tarball()
g_compatdata = CompatData(os.environ["STEAM_COMPAT_DATA_PATH"])
g_session = Session()
if "HOST_LC_ALL" in g_session.env and len(g_session.env["HOST_LC_ALL"]) > 0:
def init_wine(self):
if "HOST_LC_ALL" in g_session.env and len(g_session.env["HOST_LC_ALL"]) > 0:
#steam sets LC_ALL=C to help some games, but Wine requires the real value
#in order to do path conversion between win32 and host. steam sets
#HOST_LC_ALL to allow us to use the real value.
g_session.env["LC_ALL"] = g_session.env["HOST_LC_ALL"]
else:
else:
g_session.env.pop("LC_ALL", "")
#for performance, logging is disabled by default; override with user_settings.py
g_session.env["DXVK_LOG_LEVEL"] = "none"
g_session.env["WINEDEBUG"] = "-all"
g_session.env.pop("WINEARCH", "")
#for performance, logging is disabled by default; override with user_settings.py
g_session.env["DXVK_LOG_LEVEL"] = "none"
g_session.env["WINEDEBUG"] = "-all"
g_session.env.pop("WINEARCH", "")
if ld_path_var in os.environ:
if ld_path_var in os.environ:
g_session.env[ld_path_var] = g_proton.lib64_dir + ":" + g_proton.lib_dir + ":" + os.environ[ld_path_var]
else:
else:
g_session.env[ld_path_var] = g_proton.lib64_dir + ":" + g_proton.lib_dir
g_session.env["WINEDLLPATH"] = g_proton.lib64_dir + "/wine:" + g_proton.lib_dir + "/wine"
g_session.env["WINEDLLPATH"] = g_proton.lib64_dir + "/wine:" + g_proton.lib_dir + "/wine"
if "PATH" in os.environ:
if "PATH" in os.environ:
g_session.env["PATH"] = g_proton.bin_dir + ":" + os.environ["PATH"]
else:
else:
g_session.env["PATH"] = g_proton.bin_dir
g_proton.make_default_prefix(g_session.env)
def check_environment(self, env_name, config_name):
if not env_name in g_session.env:
return False
if nonzero(g_session.env[env_name]):
g_session.compat_config.add(config_name)
else:
g_session.compat_config.discard(config_name)
return True
g_session.env["WINEPREFIX"] = g_compatdata.prefix_dir
def init_session(self):
g_session.env["WINEPREFIX"] = g_compatdata.prefix_dir
if "PROTON_LOG" in g_session.env and nonzero(g_session.env["PROTON_LOG"]):
if "PROTON_LOG" in g_session.env and nonzero(g_session.env["PROTON_LOG"]):
g_session.env["WINEDEBUG"] = "+timestamp,+pid,+tid,+seh,+debugstr,+loaddll,+mscoree"
g_session.env["DXVK_LOG_LEVEL"] = "info"
g_session.env["WINE_MONO_TRACE"] = "E:System.NotImplementedException"
#default wine-mono override for FNA games
g_session.env["WINE_MONO_OVERRIDES"] = "Microsoft.Xna.Framework.*,Gac=n"
#default wine-mono override for FNA games
g_session.env["WINE_MONO_OVERRIDES"] = "Microsoft.Xna.Framework.*,Gac=n"
#load environment overrides
if os.path.exists(g_proton.user_settings_file):
#load environment overrides
if os.path.exists(g_proton.user_settings_file):
try:
import user_settings
g_session.env.update(user_settings.user_settings)
@ -479,47 +472,38 @@ if os.path.exists(g_proton.user_settings_file):
log("%s" % sys.exc_info()[1])
log("************************************************")
def check_environment(env_name, config_name):
if not env_name in g_session.env:
return False
if nonzero(g_session.env[env_name]):
g_session.compat_config.add(config_name)
else:
g_session.compat_config.discard(config_name)
return True
if "wined3d11" in g_session.compat_config:
if "wined3d11" in g_session.compat_config:
g_session.compat_config.add("wined3d")
if not check_environment("PROTON_USE_WINED3D", "wined3d"):
check_environment("PROTON_USE_WINED3D11", "wined3d")
check_environment("PROTON_USE_D9VK", "d9vk")
check_environment("PROTON_NO_D3D11", "nod3d11")
check_environment("PROTON_NO_D3D10", "nod3d10")
check_environment("PROTON_NO_ESYNC", "noesync")
check_environment("PROTON_NO_FSYNC", "nofsync")
check_environment("PROTON_FORCE_LARGE_ADDRESS_AWARE", "forcelgadd")
check_environment("PROTON_OLD_GL_STRING", "oldglstr")
if not self.check_environment("PROTON_USE_WINED3D", "wined3d"):
self.check_environment("PROTON_USE_WINED3D11", "wined3d")
self.check_environment("PROTON_USE_D9VK", "d9vk")
self.check_environment("PROTON_NO_D3D11", "nod3d11")
self.check_environment("PROTON_NO_D3D10", "nod3d10")
self.check_environment("PROTON_NO_ESYNC", "noesync")
self.check_environment("PROTON_NO_FSYNC", "nofsync")
self.check_environment("PROTON_FORCE_LARGE_ADDRESS_AWARE", "forcelgadd")
self.check_environment("PROTON_OLD_GL_STRING", "oldglstr")
if not "noesync" in g_session.compat_config:
if not "noesync" in g_session.compat_config:
g_session.env["WINEESYNC"] = "1"
if not "nofsync" in g_session.compat_config:
if not "nofsync" in g_session.compat_config:
g_session.env["WINEFSYNC"] = "1"
if "oldglstr" in g_session.compat_config:
if "oldglstr" in g_session.compat_config:
#mesa override
g_session.env["MESA_EXTENSION_MAX_YEAR"] = "2003"
#nvidia override
g_session.env["__GL_ExtensionStringVersion"] = "17700"
if "forcelgadd" in g_session.compat_config:
if "forcelgadd" in g_session.compat_config:
#forcelgadd should be used just for testing whether a game is helped by
#setting LARGE_ADDRESS_AWARE. If it does, then add an AppDefault in the
#registry, so that it doesn't impact every executable in the prefix.
g_session.env["WINE_LARGE_ADDRESS_AWARE"] = "1"
if "SteamGameId" in g_session.env:
if "SteamGameId" in g_session.env:
if g_session.env["WINEDEBUG"] != "-all":
lfile_path = os.environ["HOME"] + "/steam-" + os.environ["SteamGameId"] + ".log"
if os.path.exists(lfile_path):
@ -533,34 +517,34 @@ if "SteamGameId" in g_session.env:
g_session.log_file.write("Options: " + str(g_session.compat_config) + "\n")
g_session.log_file.write("======================\n")
g_session.log_file.flush()
else:
else:
g_session.env["WINEDEBUG"] = "-all"
g_compatdata.setup_prefix()
g_compatdata.setup_prefix()
if "nod3d11" in g_session.compat_config:
if "nod3d11" in g_session.compat_config:
g_session.dlloverrides["d3d11"] = ""
if "dxgi" in g_session.dlloverrides:
del g_session.dlloverrides["dxgi"]
if "nod3d10" in g_session.compat_config:
if "nod3d10" in g_session.compat_config:
g_session.dlloverrides["d3d10_1"] = ""
g_session.dlloverrides["d3d10"] = ""
g_session.dlloverrides["dxgi"] = ""
s = ""
for dll in g_session.dlloverrides:
s = ""
for dll in g_session.dlloverrides:
setting = g_session.dlloverrides[dll]
if len(s) > 0:
s = s + ";" + dll + "=" + setting
else:
s = dll + "=" + setting
if "WINEDLLOVERRIDES" in os.environ:
if "WINEDLLOVERRIDES" in os.environ:
g_session.env["WINEDLLOVERRIDES"] = os.environ["WINEDLLOVERRIDES"] + ";" + s
else:
else:
g_session.env["WINEDLLOVERRIDES"] = s
def dump_dbg_env(f):
def dump_dbg_env(self, f):
f.write("PATH=\"" + g_session.env["PATH"] + "\" \\\n")
f.write("\tTERM=\"xterm\" \\\n") #XXX
f.write("\tWINEDEBUG=\"-all\" \\\n")
@ -582,7 +566,7 @@ def dump_dbg_env(f):
if "WINE_LARGE_ADDRESS_AWARE" in g_session.env:
f.write("\tWINE_LARGE_ADDRESS_AWARE=\"" + g_session.env["WINE_LARGE_ADDRESS_AWARE"] + "\" \\\n")
def dump_dbg_scripts():
def dump_dbg_scripts(self):
exe_name = os.path.basename(sys.argv[2])
tmpdir = g_session.env.get("PROTON_DEBUG_DIR", "/tmp") + "/proton_" + os.environ["USER"] + "/"
@ -592,7 +576,7 @@ def dump_dbg_scripts():
f.write("#!/bin/bash\n")
f.write("#Run winedbg with args\n\n")
f.write("cd \"" + os.getcwd() + "\"\n")
dump_dbg_env(f)
self.dump_dbg_env(f)
f.write("\t\"" + g_proton.wine_bin + "\" winedbg \"$@\"\n")
os.chmod(tmpdir + "winedbg", 0o755)
@ -609,7 +593,7 @@ def dump_dbg_scripts():
else:
f.write(" \"" + arg + "\"")
f.write(")\n")
dump_dbg_env(f)
self.dump_dbg_env(f)
f.write("\t\"" + g_proton.wine_bin + "\" winedbg \"${@:-${DEF_CMD[@]}}\"\n")
os.chmod(tmpdir + "winedbg_run", 0o755)
@ -624,7 +608,7 @@ def dump_dbg_scripts():
f.write(" exit 1\n")
f.write("fi\n")
f.write("WPID_DEC=$(printf %d 0x$WPID_HEX)\n")
dump_dbg_env(f)
self.dump_dbg_env(f)
f.write("\t\"" + g_proton.wine_bin + "\" winedbg --gdb $WPID_DEC\n")
os.chmod(tmpdir + "gdb_attach", 0o755)
@ -641,7 +625,7 @@ def dump_dbg_scripts():
else:
f.write(" \"" + arg + "\"")
f.write(")\n")
dump_dbg_env(f)
self.dump_dbg_env(f)
f.write("\t\"" + g_proton.wine_bin + "\" winedbg --gdb \"${@:-${DEF_CMD[@]}}\"\n")
os.chmod(tmpdir + "gdb_run", 0o755)
@ -658,17 +642,39 @@ def dump_dbg_scripts():
else:
f.write(" \"" + arg + "\"")
f.write(")\n")
dump_dbg_env(f)
self.dump_dbg_env(f)
f.write("\t\"" + g_proton.wine_bin + "\" steam.exe \"${@:-${DEF_CMD[@]}}\"\n")
os.chmod(tmpdir + "run", 0o755)
def run():
def run_wine(self, args):
subprocess.call(args, env=g_session.env, stderr=g_session.log_file, stdout=g_session.log_file)
def run(self):
if "PROTON_DUMP_DEBUG_COMMANDS" in g_session.env and nonzero(g_session.env["PROTON_DUMP_DEBUG_COMMANDS"]):
try:
dump_dbg_scripts()
self.dump_dbg_scripts()
except OSError:
log("Unable to write debug scripts! " + str(sys.exc_info()[1]))
run_wine([g_proton.wine_bin, "steam"] + sys.argv[2:])
self.run_wine([g_proton.wine_bin, "steam"] + sys.argv[2:])
if not "STEAM_COMPAT_DATA_PATH" in os.environ:
log("No compat data path?")
sys.exit(1)
g_proton = Proton(os.path.dirname(sys.argv[0]))
g_proton.extract_tarball()
g_compatdata = CompatData(os.environ["STEAM_COMPAT_DATA_PATH"])
g_session = Session()
g_session.init_wine()
g_proton.make_default_prefix(g_session.env)
g_session.init_session()
if sys.version_info[0] == 2:
binary_stdout = sys.stdout
@ -680,12 +686,12 @@ else:
#determine mode
if sys.argv[1] == "run":
#start target app
run()
g_session.run()
elif sys.argv[1] == "waitforexitandrun":
#wait for wineserver to shut down
run_wine([g_proton.wineserver_bin, "-w"])
g_session.run_wine([g_proton.wineserver_bin, "-w"])
#then run
run()
g_session.run()
elif sys.argv[1] == "getcompatpath":
#linux -> windows path
path = subprocess.check_output([g_proton.wine_bin, "winepath", "-w", sys.argv[2]], env=g_session.env, stderr=g_session.log_file)