11from pathlib import Path
22from ..utils .common import resolve
3-
3+ import os
44
55def update_game (self , context ):
6- self ['game' ] = resolve (self .game )
6+ g = resolve (self .game )
7+ # Don't bother re-resolving paths if we haven't changed our game path
8+ if g == self ['game' ]:
9+ return
10+
11+ self ['game' ] = g
712 game = Path (self .game )
813
914 if game .joinpath ('gameinfo.txt' ).is_file ():
1015 bin = game .parent .joinpath ('bin' )
1116
12- if not bin .joinpath ('studiomdl.exe' ).is_file ():
13- for path in bin .iterdir ():
14- if path .is_dir () and path .joinpath ('studiomdl.exe' ).is_file ():
15- bin = path
16- break
17+ # If we're not on the old-style pattern bin/<something> layout, check for platform subdirs
18+ actualbin = None
19+ if not bin .joinpath ('studiomdl.exe' ).is_file () and not bin .joinpath ('studiomdl' ).is_file ():
20+ def check_subdir (subdirs , smdl ):
21+ for s in subdirs :
22+ p = bin .joinpath (s )
23+ if p .is_dir () and p .joinpath (smdl ).is_file ():
24+ return p
25+ return None
26+
27+ # For linux, prefer the native binaries (if possible)
28+ if os .name == 'posix' :
29+ actualbin = check_subdir (['linux32' , 'linux64' ], 'studiomdl' )
30+ # Resolve windows paths
31+ if actualbin is None :
32+ actualbin = check_subdir (['win32' , 'win64' ], 'studiomdl.exe' )
33+
34+ if actualbin is not None :
35+ bin = actualbin
1736
1837 self ['bin' ] = str (bin )
1938 self ['modelsrc' ] = str (game .joinpath ('modelsrc' ))
@@ -39,5 +58,12 @@ def update_mapsrc(self, context):
3958
4059def verify (game ):
4160 gameinfo = Path (game .game ).joinpath ('gameinfo.txt' )
42- studiomdl = Path (game .bin ).joinpath ('studiomdl.exe' )
43- return gameinfo .is_file () and studiomdl .is_file ()
61+ return gameinfo .is_file () and get_studiomdl_path (game ).is_file ()
62+
63+ def get_studiomdl_path (game ):
64+ if os .name == 'posix' and (game .bin .endswith ('linux32' ) or game .bin .endswith ('linux64' )):
65+ p = Path (game .bin ).joinpath ('studiomdl' )
66+ if p .is_file ():
67+ return p
68+ return Path (game .bin ).joinpath ('studiomdl.exe' )
69+
0 commit comments