11
11
from umu_plugins import enable_zenity
12
12
from socket import gaierror
13
13
from umu_log import log
14
- from umu_consts import STEAM_COMPAT , umu_CACHE
14
+ from umu_consts import STEAM_COMPAT , UMU_CACHE
15
15
16
16
try :
17
17
from tarfile import tar_filter
@@ -30,30 +30,30 @@ def get_umu_proton(env: Dict[str, str]) -> Union[Dict[str, str]]:
30
30
"""
31
31
files : List [Tuple [str , str ]] = []
32
32
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 )
39
34
STEAM_COMPAT .mkdir (exist_ok = True , parents = True )
40
35
41
36
# 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 ):
43
38
return env
44
39
40
+ try :
41
+ files = _fetch_releases ()
42
+ except gaierror :
43
+ pass # User is offline
44
+
45
45
# 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 ):
47
47
return env
48
48
49
49
# Download the latest if Proton is not in Steam compat
50
50
# 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 ):
52
52
return env
53
53
54
54
# Refer to an old version previously downloaded
55
55
# 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 ):
57
57
return env
58
58
59
59
# No internet and cache/compat tool is empty, just return and raise an
@@ -121,7 +121,7 @@ def _fetch_releases() -> List[Tuple[str, str]]:
121
121
def _fetch_proton (
122
122
env : Dict [str , str ], steam_compat : Path , cache : Path , files : List [Tuple [str , str ]]
123
123
) -> 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."""
125
125
hash , hash_url = files [0 ]
126
126
proton , proton_url = files [1 ]
127
127
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
228
228
229
229
230
230
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
232
232
) -> Union [Dict [str , str ], None ]:
233
233
"""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
+ ):
240
242
log .console (f"{ proton .name } found in: { steam_compat } " )
241
243
log .console (f"Using { proton .name } " )
242
-
243
244
environ ["PROTONPATH" ] = proton .as_posix ()
244
245
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
-
254
246
return env
255
247
256
248
return None
@@ -269,40 +261,40 @@ def _get_from_cache(
269
261
Older Proton versions are only referred to when: digests mismatch, user
270
262
interrupt, or download failure/no internet
271
263
"""
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
+ ]:
276
272
# Online
277
273
if files and tarball == cache .joinpath (files [1 ][0 ]) and use_latest :
278
- path = tarball
279
- name = tarball .name
274
+ resource = (tarball , tarball .name )
280
275
break
281
276
# Offline, download interrupt, digest mismatch
282
277
if not files or not use_latest :
283
- path = tarball
284
- name = tarball .name
278
+ resource = (tarball , tarball .name )
285
279
break
286
280
287
- if path :
288
- proton_dir : str = name [: name . find ( ".tar.gz" )] # Proton dir
281
+ if not resource :
282
+ return None
289
283
284
+ path , name = resource
285
+ proton : str = name [: name .find (".tar.gz" )] # Proton dir
286
+ try :
290
287
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
306
298
307
299
308
300
def _get_latest (
@@ -312,37 +304,35 @@ def _get_latest(
312
304
313
305
When the digests mismatched or when interrupted, refer to cache for an old version
314
306
"""
315
- if files :
316
- log . console ( "Fetching latest release ..." )
307
+ if not files :
308
+ return None
317
309
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
347
337
348
338
return env
0 commit comments