Add --store option to gamelauncher

- Enable users to optionally specify the game's distribution platform (store). This allows them to properly apply a fix from a specific store rather than Steam's to their game's WINE prefix. As a side effect, this allows users to apply a protonfix from other stores (e.g. gog).
This commit is contained in:
R1kaB3rN 2024-02-09 19:42:22 -08:00
parent b5a3ac2b0f
commit 4622516693
No known key found for this signature in database
2 changed files with 43 additions and 3 deletions

View File

@ -15,15 +15,26 @@ import subprocess
def parse_args() -> Namespace: # noqa: D103
stores: List[str] = [
"amazon",
"battlenet",
"ea",
"egs",
"gog",
"humble",
"itchio",
"ubisoft",
]
exe: str = Path(__file__).name
usage: str = """
example usage:
example usage:
{} --config example.toml
{} --config /home/foo/example.toml --options '-opengl'
WINEPREFIX= GAMEID= PROTONPATH= {} --exe /home/foo/example.exe --options '-opengl'
WINEPREFIX= GAMEID= PROTONPATH= {} --exe /home/foo/example.exe --store gog
WINEPREFIX= GAMEID= PROTONPATH= {} --exe ""
WINEPREFIX= GAMEID= PROTONPATH= {} --exe /home/foo/example.exe --verb waitforexitandrun
""".format(exe, exe, exe, exe, exe)
""".format(exe, exe, exe, exe, exe, exe)
parser: ArgumentParser = argparse.ArgumentParser(
description="Unified Linux Wine Game Launcher",
@ -45,6 +56,10 @@ def parse_args() -> Namespace: # noqa: D103
"--options",
help="launch options for game executable\nNOTE: options must be wrapped in quotes",
)
parser.add_argument(
"--store",
help=f"the store of the game executable\nNOTE: will override the store specified in config\nexamples: {stores}",
)
return parser.parse_args(sys.argv[1:])
@ -54,6 +69,7 @@ def _setup_pfx(path: str) -> None:
if not (Path(path + "/pfx")).expanduser().is_symlink():
# When creating the symlink, we want it to be in expanded form when passed unexpanded paths
# Example: pfx -> /home/.wine
# NOTE: When parsing a config file, an error can be raised if the prefix doesn't already exist
Path(path + "/pfx").expanduser().symlink_to(Path(path).expanduser())
Path(path + "/tracked_files").expanduser().touch()
@ -145,7 +161,7 @@ def set_env_toml(env: Dict[str, str], args: Namespace) -> Dict[str, str]:
for key, val in toml["ulwgl"].items():
# Handle cases for empty values
if not val and isinstance(val, str):
err: str = "Value is empty for key in TOML: " + key
err: str = f'Value is empty for key in TOML: {key}\nPlease specify a value or remove the following entry:\n{key} = "{val}"'
raise ValueError(err)
if key == "prefix":
env["WINEPREFIX"] = val
@ -155,6 +171,8 @@ def set_env_toml(env: Dict[str, str], args: Namespace) -> Dict[str, str]:
elif key == "proton":
env["PROTONPATH"] = val
env["STEAM_COMPAT_INSTALL_PATH"] = val
elif key == "store":
env["STORE"] = val
elif key == "exe":
# Raise an error for executables that do not exist
# One case this can happen is when game options are appended at the end of the exe
@ -217,6 +235,7 @@ def main() -> None: # noqa: D103
"SteamAppId": "",
"SteamGameId": "",
"STEAM_RUNTIME_LIBRARY_PATH": "",
"STORE": "",
}
command: List[str] = []
verb: str = "waitforexitandrun"
@ -240,6 +259,9 @@ def main() -> None: # noqa: D103
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"

View File

@ -1213,6 +1213,24 @@ class TestGameLauncher(unittest.TestCase):
"Expected the same value when setting --verb",
)
def test_parse_args_store(self):
"""Test parse_args --store."""
test_store = "gog"
with patch.object(
gamelauncher,
"parse_args",
return_value=argparse.Namespace(exe=self.test_exe, store=test_store),
):
result = gamelauncher.parse_args()
self.assertIsInstance(
result, Namespace, "Expected a Namespace from parse_arg"
)
self.assertEqual(
result.store,
test_store,
"Expected the same value when setting --store",
)
def test_parse_args_options(self):
"""Test parse_args --options."""
with patch.object(