Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove requirement for setting WINEPREFIX #32

Merged
merged 3 commits into from
Feb 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 26 additions & 10 deletions ulwgl_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ def parse_args() -> Union[Namespace, Tuple[str, List[str]]]: # noqa: D103
exe: str = Path(__file__).name
usage: str = f"""
example usage:
GAMEID= {exe} /home/foo/example.exe
WINEPREFIX= GAMEID= {exe} /home/foo/example.exe
WINEPREFIX= GAMEID= PROTONPATH= {exe} /home/foo/example.exe
WINEPREFIX= GAMEID= PROTONPATH= {exe} /home/foo/example.exe -opengl
WINEPREFIX= GAMEID= PROTONPATH= {exe} ""
Expand Down Expand Up @@ -103,24 +105,38 @@ def check_env(

return toml

if "WINEPREFIX" not in os.environ:
err: str = "Environment variable not set or not a directory: WINEPREFIX"
raise ValueError(err)

if not Path(os.environ["WINEPREFIX"]).expanduser().is_dir():
Path(os.environ["WINEPREFIX"]).mkdir(parents=True)
env["WINEPREFIX"] = os.environ["WINEPREFIX"]

if "GAMEID" not in os.environ:
err: str = "Environment variable not set: GAMEID"
raise ValueError(err)
env["GAMEID"] = os.environ["GAMEID"]

if (
"WINEPREFIX" not in os.environ
or not Path(os.environ["WINEPREFIX"]).expanduser().is_dir()
):
# Automatically create a prefix for the user if WINEPREFIX is not set
# The GAMEID will be the name of the dir
pfx: Path = Path.home().joinpath("Games/ULWGL/" + env["GAMEID"])

pfx.mkdir(parents=True, exist_ok=True)
os.environ["WINEPREFIX"] = pfx.as_posix()
env["WINEPREFIX"] = os.environ["WINEPREFIX"]
else:
env["WINEPREFIX"] = os.environ["WINEPREFIX"]

if "PROTONPATH" not in os.environ:
os.environ["PROTONPATH"] = ""
get_ulwgl_proton(env)
elif Path("~/.local/share/Steam/compatibilitytools.d/" + os.environ["PROTONPATH"]).expanduser().is_dir():
env["PROTONPATH"] = Path("~/.local/share/Steam/compatibilitytools.d/").expanduser().joinpath(os.environ["PROTONPATH"])
elif (
Path("~/.local/share/Steam/compatibilitytools.d/" + os.environ["PROTONPATH"])
.expanduser()
.is_dir()
):
env["PROTONPATH"] = (
Path("~/.local/share/Steam/compatibilitytools.d/")
.expanduser()
.joinpath(os.environ["PROTONPATH"])
)
elif not Path(os.environ["PROTONPATH"]).expanduser().is_dir():
os.environ["PROTONPATH"] = ""
get_ulwgl_proton(env)
Expand Down
7 changes: 5 additions & 2 deletions ulwgl_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1553,8 +1553,11 @@ def test_env_vars_wine(self):
ulwgl_run.check_env(self.env)

def test_env_vars_none(self):
"""Tests check_env when setting no env vars."""
with self.assertRaisesRegex(ValueError, "WINEPREFIX"):
"""Tests check_env when setting no env vars.

GAMEID should be the only strictly required env var
"""
with self.assertRaisesRegex(ValueError, "GAMEID"):
ulwgl_run.check_env(self.env)


Expand Down