Skip to content

Commit 2cde078

Browse files
authored
Merge pull request #67 from R1kaB3rN/fixes
Fixes after name change
2 parents 0237fb4 + 8b36fae commit 2cde078

File tree

5 files changed

+108
-115
lines changed

5 files changed

+108
-115
lines changed

umu/umu_consts.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ class Color(Enum):
1919

2020
CONFIG = "umu_version.json"
2121

22-
umu_LOCAL: Path = Path.home().joinpath(".local", "share", "umu")
22+
UMU_LOCAL: Path = Path.home().joinpath(".local", "share", "umu")
2323

24-
umu_CACHE: Path = Path.home().joinpath(".cache", "umu")
24+
UMU_CACHE: Path = Path.home().joinpath(".cache", "umu")
2525

2626
STEAM_COMPAT: Path = Path.home().joinpath(
2727
".local", "share", "Steam", "compatibilitytools.d"

umu/umu_dl_util.py

+75-85
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from umu_plugins import enable_zenity
1212
from socket import gaierror
1313
from umu_log import log
14-
from umu_consts import STEAM_COMPAT, umu_CACHE
14+
from umu_consts import STEAM_COMPAT, UMU_CACHE
1515

1616
try:
1717
from tarfile import tar_filter
@@ -30,30 +30,30 @@ def get_umu_proton(env: Dict[str, str]) -> Union[Dict[str, str]]:
3030
"""
3131
files: List[Tuple[str, str]] = []
3232

33-
try:
34-
files = _fetch_releases()
35-
except gaierror:
36-
pass # User is offline
37-
38-
umu_CACHE.mkdir(exist_ok=True, parents=True)
33+
UMU_CACHE.mkdir(exist_ok=True, parents=True)
3934
STEAM_COMPAT.mkdir(exist_ok=True, parents=True)
4035

4136
# Prioritize the Steam compat
42-
if _get_from_steamcompat(env, STEAM_COMPAT, umu_CACHE, files):
37+
if _get_from_steamcompat(env, STEAM_COMPAT, UMU_CACHE):
4338
return env
4439

40+
try:
41+
files = _fetch_releases()
42+
except gaierror:
43+
pass # User is offline
44+
4545
# Use the latest Proton in the cache if it exists
46-
if _get_from_cache(env, STEAM_COMPAT, umu_CACHE, files, True):
46+
if _get_from_cache(env, STEAM_COMPAT, UMU_CACHE, files, True):
4747
return env
4848

4949
# Download the latest if Proton is not in Steam compat
5050
# If the digests mismatched, refer to the cache in the next block
51-
if _get_latest(env, STEAM_COMPAT, umu_CACHE, files):
51+
if _get_latest(env, STEAM_COMPAT, UMU_CACHE, files):
5252
return env
5353

5454
# Refer to an old version previously downloaded
5555
# Reached on digest mismatch, user interrupt or download failure/no internet
56-
if _get_from_cache(env, STEAM_COMPAT, umu_CACHE, files, False):
56+
if _get_from_cache(env, STEAM_COMPAT, UMU_CACHE, files, False):
5757
return env
5858

5959
# No internet and cache/compat tool is empty, just return and raise an
@@ -121,7 +121,7 @@ def _fetch_releases() -> List[Tuple[str, str]]:
121121
def _fetch_proton(
122122
env: Dict[str, str], steam_compat: Path, cache: Path, files: List[Tuple[str, str]]
123123
) -> Dict[str, str]:
124-
"""Download the latest umu-Proton and set it as PROTONPATH."""
124+
"""Download the latest umu-proton and set it as PROTONPATH."""
125125
hash, hash_url = files[0]
126126
proton, proton_url = files[1]
127127
proton_dir: str = proton[: proton.find(".tar.gz")] # Proton dir
@@ -228,29 +228,21 @@ def _cleanup(tarball: str, proton: str, cache: Path, steam_compat: Path) -> None
228228

229229

230230
def _get_from_steamcompat(
231-
env: Dict[str, str], steam_compat: Path, cache: Path, files: List[Tuple[str, str]]
231+
env: Dict[str, str], steam_compat: Path, cache: Path
232232
) -> Union[Dict[str, str], None]:
233233
"""Refer to Steam compat folder for any existing Proton directories."""
234-
proton_dir: str = "" # Latest Proton
235-
236-
if len(files) == 2:
237-
proton_dir: str = files[1][0][: files[1][0].find(".tar.gz")]
238-
239-
for proton in steam_compat.glob("umu-Proton*"):
234+
for proton in sorted(
235+
[
236+
proton
237+
for proton in steam_compat.glob("*")
238+
if proton.name.startswith("umu-proton")
239+
or proton.name.startswith("ULWGL-Proton")
240+
]
241+
):
240242
log.console(f"{proton.name} found in: {steam_compat}")
241243
log.console(f"Using {proton.name}")
242-
243244
environ["PROTONPATH"] = proton.as_posix()
244245
env["PROTONPATH"] = environ["PROTONPATH"]
245-
246-
# Notify the user that they're not using the latest
247-
if proton_dir and proton.name != proton_dir:
248-
link: str = files[1][1]
249-
log.console(
250-
"umu-Proton is outdated.\n"
251-
f"For latest release, please download {link}"
252-
)
253-
254246
return env
255247

256248
return None
@@ -269,40 +261,40 @@ def _get_from_cache(
269261
Older Proton versions are only referred to when: digests mismatch, user
270262
interrupt, or download failure/no internet
271263
"""
272-
path: Path = None
273-
name: str = ""
274-
275-
for tarball in cache.glob("umu-Proton*.tar.gz"):
264+
resource: Tuple[Path, str] = None # Path to the archive and its file name
265+
266+
for tarball in [
267+
tarball
268+
for tarball in cache.glob("*.tar.gz")
269+
if tarball.name.startswith("umu-proton")
270+
or tarball.name.startswith("ULWGL-Proton")
271+
]:
276272
# Online
277273
if files and tarball == cache.joinpath(files[1][0]) and use_latest:
278-
path = tarball
279-
name = tarball.name
274+
resource = (tarball, tarball.name)
280275
break
281276
# Offline, download interrupt, digest mismatch
282277
if not files or not use_latest:
283-
path = tarball
284-
name = tarball.name
278+
resource = (tarball, tarball.name)
285279
break
286280

287-
if path:
288-
proton_dir: str = name[: name.find(".tar.gz")] # Proton dir
281+
if not resource:
282+
return None
289283

284+
path, name = resource
285+
proton: str = name[: name.find(".tar.gz")] # Proton dir
286+
try:
290287
log.console(f"{name} found in: {path}")
291-
try:
292-
_extract_dir(path, steam_compat)
293-
294-
log.console(f"Using {proton_dir}")
295-
environ["PROTONPATH"] = steam_compat.joinpath(proton_dir).as_posix()
296-
env["PROTONPATH"] = environ["PROTONPATH"]
297-
298-
return env
299-
except KeyboardInterrupt:
300-
if steam_compat.joinpath(proton_dir).is_dir():
301-
log.console(f"Purging {proton_dir} in {steam_compat} ...")
302-
rmtree(steam_compat.joinpath(proton_dir).as_posix())
303-
raise
304-
305-
return None
288+
_extract_dir(path, steam_compat)
289+
log.console(f"Using {proton}")
290+
environ["PROTONPATH"] = steam_compat.joinpath(proton).as_posix()
291+
env["PROTONPATH"] = environ["PROTONPATH"]
292+
return env
293+
except KeyboardInterrupt:
294+
if steam_compat.joinpath(proton).is_dir():
295+
log.console(f"Purging {proton} in {steam_compat} ...")
296+
rmtree(steam_compat.joinpath(proton).as_posix())
297+
raise
306298

307299

308300
def _get_latest(
@@ -312,37 +304,35 @@ def _get_latest(
312304
313305
When the digests mismatched or when interrupted, refer to cache for an old version
314306
"""
315-
if files:
316-
log.console("Fetching latest release ...")
307+
if not files:
308+
return None
317309

318-
try:
319-
tarball: str = files[1][0]
320-
proton_dir: str = tarball[: tarball.find(".tar.gz")] # Proton dir
321-
322-
_fetch_proton(env, steam_compat, cache, files)
323-
324-
log.console(f"Using {proton_dir}")
325-
env["PROTONPATH"] = environ["PROTONPATH"]
326-
except ValueError:
327-
log.exception("Exception")
328-
tarball: str = files[1][0]
329-
330-
# Digest mismatched
331-
# Refer to the cache for old version next
332-
# Since we do not want the user to use a suspect file, delete it
333-
cache.joinpath(tarball).unlink(missing_ok=True)
334-
return None
335-
except KeyboardInterrupt:
336-
tarball: str = files[1][0]
337-
proton_dir: str = tarball[: tarball.find(".tar.gz")] # Proton dir
338-
339-
# Exit cleanly
340-
# Clean up extracted data and cache to prevent corruption/errors
341-
# Refer to the cache for old version next
342-
_cleanup(tarball, proton_dir, cache, steam_compat)
343-
return None
344-
except HTTPException:
345-
# Download failed
346-
return None
310+
try:
311+
log.console("Fetching latest release ...")
312+
tarball: str = files[1][0]
313+
proton: str = tarball[: tarball.find(".tar.gz")]
314+
_fetch_proton(env, steam_compat, cache, files)
315+
log.console(f"Using {proton}")
316+
env["PROTONPATH"] = environ["PROTONPATH"]
317+
except ValueError:
318+
log.exception("Exception")
319+
tarball: str = files[1][0]
320+
321+
# Digest mismatched
322+
# Refer to the cache for old version next
323+
# Since we do not want the user to use a suspect file, delete it
324+
cache.joinpath(tarball).unlink(missing_ok=True)
325+
return None
326+
except KeyboardInterrupt:
327+
tarball: str = files[1][0]
328+
proton_dir: str = tarball[: tarball.find(".tar.gz")] # Proton dir
329+
330+
# Exit cleanly
331+
# Clean up extracted data and cache to prevent corruption/errors
332+
# Refer to the cache for old version next
333+
_cleanup(tarball, proton_dir, cache, steam_compat)
334+
return None
335+
except HTTPException: # Download failed
336+
return None
347337

348338
return env

umu/umu_run.py

+20-15
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from re import match
1010
from subprocess import run
1111
from umu_dl_util import get_umu_proton
12-
from umu_consts import PROTON_VERBS, DEBUG_FORMAT, STEAM_COMPAT, umu_LOCAL
12+
from umu_consts import PROTON_VERBS, DEBUG_FORMAT, STEAM_COMPAT, UMU_LOCAL
1313
from umu_util import setup_umu
1414
from umu_log import log, console_handler, CustomFormatter
1515
from umu_util import UnixUser
@@ -27,7 +27,10 @@ def parse_args() -> Union[Namespace, Tuple[str, List[str]]]: # noqa: D103
2727
parser.add_argument("--config", help="path to TOML file (requires Python 3.11+)")
2828

2929
if not sys.argv[1:]:
30-
err: str = "Please see project README.md for more info and examples.\nhttps://github.com/Open-Wine-Components/umu-launcher"
30+
err: str = (
31+
"Please see project README.md for more info and examples.\n"
32+
"https://github.com/Open-Wine-Components/umu-launcher"
33+
)
3134
parser.print_help(sys.stderr)
3235
raise SystemExit(err)
3336

@@ -46,21 +49,21 @@ def set_log() -> None:
4649
"""Adjust the log level for the logger."""
4750
levels: Set[str] = {"1", "warn", "debug"}
4851

49-
if os.environ["umu_LOG"] not in levels:
52+
if os.environ["UMU_LOG"] not in levels:
5053
return
5154

52-
if os.environ["umu_LOG"] == "1":
55+
if os.environ["UMU_LOG"] == "1":
5356
# Show the envvars and command at this level
5457
log.setLevel(level=INFO)
55-
elif os.environ["umu_LOG"] == "warn":
58+
elif os.environ["UMU_LOG"] == "warn":
5659
log.setLevel(level=WARNING)
57-
elif os.environ["umu_LOG"] == "debug":
60+
elif os.environ["UMU_LOG"] == "debug":
5861
# Show all logs
5962
console_handler.setFormatter(CustomFormatter(DEBUG_FORMAT))
6063
log.addHandler(console_handler)
6164
log.setLevel(level=DEBUG)
6265

63-
os.environ.pop("umu_LOG")
66+
os.environ.pop("UMU_LOG")
6467

6568

6669
def setup_pfx(path: str) -> None:
@@ -192,6 +195,7 @@ def set_env(
192195

193196
# UMU_ID
194197
env["UMU_ID"] = env["GAMEID"]
198+
env["ULWGL_ID"] = env["UMU_ID"] # Set ULWGL_ID for compatibility
195199
env["STEAM_COMPAT_APP_ID"] = "0"
196200

197201
if match(r"^umu-[\d\w]+$", env["UMU_ID"]):
@@ -204,7 +208,7 @@ def set_env(
204208
env["PROTONPATH"] = Path(env["PROTONPATH"]).expanduser().as_posix()
205209
env["STEAM_COMPAT_DATA_PATH"] = env["WINEPREFIX"]
206210
env["STEAM_COMPAT_SHADER_PATH"] = env["STEAM_COMPAT_DATA_PATH"] + "/shadercache"
207-
env["STEAM_COMPAT_TOOL_PATHS"] = env["PROTONPATH"] + ":" + umu_LOCAL.as_posix()
211+
env["STEAM_COMPAT_TOOL_PATHS"] = env["PROTONPATH"] + ":" + UMU_LOCAL.as_posix()
208212
env["STEAM_COMPAT_MOUNTS"] = env["STEAM_COMPAT_TOOL_PATHS"]
209213

210214
return env
@@ -270,6 +274,7 @@ def main() -> int: # noqa: D103
270274
"STORE": "",
271275
"PROTON_VERB": "",
272276
"UMU_ID": "",
277+
"ULWGL_ID": "",
273278
}
274279
command: List[str] = []
275280
opts: List[str] = None
@@ -284,17 +289,17 @@ def main() -> int: # noqa: D103
284289
err: str = "This script is not designed to run on musl-based systems"
285290
raise SystemExit(err)
286291

287-
if "umu_LOG" in os.environ:
292+
if "UMU_LOG" in os.environ:
288293
set_log()
289294

290295
log.debug("Arguments: %s", args)
291296

292297
# Setup the launcher and runtime files
293298
# An internet connection is required for new setups
294299
try:
295-
setup_umu(root, umu_LOCAL)
300+
setup_umu(root, UMU_LOCAL)
296301
except TimeoutError: # Request to a server timed out
297-
if not umu_LOCAL.exists() or not any(umu_LOCAL.iterdir()):
302+
if not UMU_LOCAL.exists() or not any(UMU_LOCAL.iterdir()):
298303
err: str = (
299304
"umu has not been setup for the user\n"
300305
"An internet connection is required to setup umu"
@@ -304,8 +309,8 @@ def main() -> int: # noqa: D103
304309
except OSError as e: # No internet
305310
if (
306311
e.errno == ENETUNREACH
307-
and not umu_LOCAL.exists()
308-
or not any(umu_LOCAL.iterdir())
312+
and not UMU_LOCAL.exists()
313+
or not any(UMU_LOCAL.iterdir())
309314
):
310315
err: str = (
311316
"umu has not been setup for the user\n"
@@ -339,7 +344,7 @@ def main() -> int: # noqa: D103
339344
os.environ[key] = val
340345

341346
# Run
342-
build_command(env, umu_LOCAL, command, opts)
347+
build_command(env, UMU_LOCAL, command, opts)
343348
log.debug(command)
344349

345350
return run(command).returncode
@@ -358,6 +363,6 @@ def main() -> int: # noqa: D103
358363
log.exception("Exception")
359364
sys.exit(1)
360365
finally:
361-
umu_LOCAL.joinpath(".ref").unlink(
366+
UMU_LOCAL.joinpath(".ref").unlink(
362367
missing_ok=True
363368
) # Cleanup .ref file on every exit

0 commit comments

Comments
 (0)