mirror of
https://github.com/tcsenpai/UWINE.git
synced 2025-06-07 03:55:21 +00:00
gamelauncher.py: refactor main
- Move environment variable functionality to set_env and execute it for both usages.
This commit is contained in:
parent
9642748cb0
commit
bba9f0d060
110
gamelauncher.py
110
gamelauncher.py
@ -84,24 +84,62 @@ def check_env(env: Dict[str, str]) -> Dict[str, str]:
|
|||||||
return env
|
return env
|
||||||
|
|
||||||
|
|
||||||
def set_env(env: Dict[str, str], args: Namespace) -> Dict[str, str]:
|
def set_env(env: Dict[str, str], args: Union[Namespace, str]) -> Dict[str, str]:
|
||||||
"""Set various environment variables for the Steam RT.
|
"""Set various environment variables for the Steam RT.
|
||||||
|
|
||||||
Expects to be invoked if not reading a TOML file
|
Filesystem paths will be formatted and expanded as POSIX
|
||||||
"""
|
"""
|
||||||
is_create_prefix: bool = False
|
verbs: Set[str] = {
|
||||||
|
"waitforexitandrun",
|
||||||
|
"run",
|
||||||
|
"runinprefix",
|
||||||
|
"destroyprefix",
|
||||||
|
"getcompatpath",
|
||||||
|
"getnativepath",
|
||||||
|
}
|
||||||
|
|
||||||
if not getattr(args, "exe", None):
|
# PROTON_VERB
|
||||||
is_create_prefix = True
|
# For invalid Proton verbs, just assign the waitforexitandrun
|
||||||
|
if "PROTON_VERB" in os.environ and os.environ["PROTON_VERB"] in verbs:
|
||||||
|
env["PROTON_VERB"] = os.environ["PROTON_VERB"]
|
||||||
|
else:
|
||||||
|
env["PROTON_VERB"] = "waitforexitandrun"
|
||||||
|
|
||||||
# Sets the environment variables: EXE
|
# EXE
|
||||||
for arg, val in vars(args).items():
|
# Empty string for EXE will be used to create a prefix
|
||||||
if arg == "exe" and not is_create_prefix:
|
if isinstance(args, str) and not args:
|
||||||
# NOTE: options can possibly be appended at the end
|
env["EXE"] = ""
|
||||||
env["EXE"] = val
|
env["STEAM_COMPAT_INSTALL_PATH"] = ""
|
||||||
elif arg == "options" and val and not is_create_prefix:
|
env["PROTON_VERB"] = "waitforexitandrun"
|
||||||
# NOTE: assume it's space separated
|
elif isinstance(args, str):
|
||||||
env["EXE"] = env["EXE"] + " " + " ".join(val.split(" "))
|
env["EXE"] = Path(args).expanduser().as_posix()
|
||||||
|
env["STEAM_COMPAT_INSTALL_PATH"] = Path(env["EXE"]).parent.as_posix()
|
||||||
|
else:
|
||||||
|
# Config branch
|
||||||
|
env["EXE"] = Path(env["EXE"]).expanduser().as_posix()
|
||||||
|
env["STEAM_COMPAT_INSTALL_PATH"] = Path(env["EXE"]).parent.as_posix()
|
||||||
|
|
||||||
|
if "STORE" in os.environ:
|
||||||
|
env["STORE"] = os.environ["STORE"]
|
||||||
|
|
||||||
|
# ULWGL_ID
|
||||||
|
env["ULWGL_ID"] = env["GAMEID"]
|
||||||
|
env["STEAM_COMPAT_APP_ID"] = "0"
|
||||||
|
|
||||||
|
if match(r"^ulwgl-[\d\w]+$", env["ULWGL_ID"]):
|
||||||
|
env["STEAM_COMPAT_APP_ID"] = env["ULWGL_ID"][env["ULWGL_ID"].find("-") + 1 :]
|
||||||
|
env["SteamAppId"] = env["STEAM_COMPAT_APP_ID"]
|
||||||
|
env["SteamGameId"] = env["SteamAppId"]
|
||||||
|
|
||||||
|
# PATHS
|
||||||
|
env["WINEPREFIX"] = Path(env["WINEPREFIX"]).expanduser().as_posix()
|
||||||
|
env["PROTONPATH"] = Path(env["PROTONPATH"]).expanduser().as_posix()
|
||||||
|
env["STEAM_COMPAT_DATA_PATH"] = env["WINEPREFIX"]
|
||||||
|
env["STEAM_COMPAT_SHADER_PATH"] = env["STEAM_COMPAT_DATA_PATH"] + "/shadercache"
|
||||||
|
env["STEAM_COMPAT_TOOL_PATHS"] = (
|
||||||
|
env["PROTONPATH"] + ":" + Path(__file__).parent.as_posix()
|
||||||
|
)
|
||||||
|
env["STEAM_COMPAT_MOUNTS"] = env["STEAM_COMPAT_TOOL_PATHS"]
|
||||||
|
|
||||||
return env
|
return env
|
||||||
|
|
||||||
@ -231,57 +269,19 @@ def main() -> None: # noqa: D103
|
|||||||
"SteamGameId": "",
|
"SteamGameId": "",
|
||||||
"STEAM_RUNTIME_LIBRARY_PATH": "",
|
"STEAM_RUNTIME_LIBRARY_PATH": "",
|
||||||
"STORE": "",
|
"STORE": "",
|
||||||
|
"PROTON_VERB": "",
|
||||||
}
|
}
|
||||||
command: List[str] = []
|
command: List[str] = []
|
||||||
verb: str = "waitforexitandrun"
|
|
||||||
# Represents a valid list of current supported Proton verbs
|
# Represents a valid list of current supported Proton verbs
|
||||||
verbs: Set[str] = {
|
args: Union[Namespace, str] = parse_args()
|
||||||
"waitforexitandrun",
|
|
||||||
"run",
|
|
||||||
"runinprefix",
|
|
||||||
"destroyprefix",
|
|
||||||
"getcompatpath",
|
|
||||||
"getnativepath",
|
|
||||||
}
|
|
||||||
args: Namespace = parse_args()
|
|
||||||
|
|
||||||
if getattr(args, "config", None):
|
if isinstance(args, Namespace):
|
||||||
set_env_toml(env, args)
|
set_env_toml(env, args)
|
||||||
else:
|
else:
|
||||||
check_env(env)
|
check_env(env)
|
||||||
set_env(env, args)
|
|
||||||
|
|
||||||
if getattr(args, "verb", None) and getattr(args, "verb", None) in verbs:
|
|
||||||
verb = getattr(args, "verb", None)
|
|
||||||
|
|
||||||
if getattr(args, "store", None):
|
|
||||||
env["STORE"] = getattr(args, "store", None)
|
|
||||||
|
|
||||||
env["ULWGL_ID"] = env["GAMEID"]
|
|
||||||
env["STEAM_COMPAT_APP_ID"] = "0"
|
|
||||||
|
|
||||||
if match(r"^ulwgl-[\d\w]+$", env["ULWGL_ID"]):
|
|
||||||
env["STEAM_COMPAT_APP_ID"] = env["ULWGL_ID"][env["ULWGL_ID"].find("-") + 1 :]
|
|
||||||
|
|
||||||
env["SteamAppId"] = env["STEAM_COMPAT_APP_ID"]
|
|
||||||
env["SteamGameId"] = env["SteamAppId"]
|
|
||||||
env["WINEPREFIX"] = Path(env["WINEPREFIX"]).expanduser().as_posix()
|
|
||||||
env["PROTONPATH"] = Path(env["PROTONPATH"]).expanduser().as_posix()
|
|
||||||
env["STEAM_COMPAT_DATA_PATH"] = env["WINEPREFIX"]
|
|
||||||
env["STEAM_COMPAT_SHADER_PATH"] = env["STEAM_COMPAT_DATA_PATH"] + "/shadercache"
|
|
||||||
env["STEAM_COMPAT_INSTALL_PATH"] = Path(env["EXE"]).parent.expanduser().as_posix()
|
|
||||||
env["EXE"] = Path(env["EXE"]).expanduser().as_posix()
|
|
||||||
env["STEAM_COMPAT_TOOL_PATHS"] = (
|
|
||||||
env["PROTONPATH"] + ":" + Path(__file__).parent.as_posix()
|
|
||||||
)
|
|
||||||
env["STEAM_COMPAT_MOUNTS"] = env["STEAM_COMPAT_TOOL_PATHS"]
|
|
||||||
|
|
||||||
# Create an empty Proton prefix when asked
|
|
||||||
if not getattr(args, "exe", None) and not getattr(args, "config", None):
|
|
||||||
env["EXE"] = ""
|
|
||||||
env["STEAM_COMPAT_INSTALL_PATH"] = ""
|
|
||||||
verb = "waitforexitandrun"
|
|
||||||
setup_pfx(env["WINEPREFIX"])
|
setup_pfx(env["WINEPREFIX"])
|
||||||
|
set_env(env, args)
|
||||||
|
|
||||||
# Game Drive functionality
|
# Game Drive functionality
|
||||||
gamelauncher_plugins.enable_steam_game_drive(env)
|
gamelauncher_plugins.enable_steam_game_drive(env)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user