Skip to content

Commit 7251cc5

Browse files
committed
Add support for Linux-native studiomdl
1 parent 577849c commit 7251cc5

File tree

2 files changed

+38
-11
lines changed

2 files changed

+38
-11
lines changed

addon/types/model_export/model.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from pathlib import Path
88
from traceback import print_exc
99
from ... utils import common
10+
from ... utils import game as game_utils
1011
from . smd import SMD
1112
from . fbx import export_fbx
1213

@@ -34,7 +35,7 @@ def __init__(self, game, model):
3435
directory = self.modelsrc.joinpath(self.name)
3536
self.directory = common.verify_folder(directory)
3637

37-
studiomdl = self.bin.joinpath('studiomdl.exe')
38+
studiomdl = game_utils.get_studiomdl_path(game)
3839
quickmdl = self.bin.joinpath('quickmdl.exe')
3940
self.studiomdl = quickmdl if quickmdl.is_file() else studiomdl
4041
self.hlmv = self.bin.joinpath('hlmv.exe')
@@ -362,7 +363,7 @@ def view_model(self):
362363
# Use wine to run HLMV on Linux.
363364
# Wine tends to complain about the paths we feed HLMV.
364365
# So we use relatve paths working from the base directory of the game.
365-
if (os.name == 'posix') and (self.studiomdl.suffix == '.exe'):
366+
if (os.name == 'posix') and (self.hlmv.suffix == '.exe'):
366367
cwd = self.game.parent
367368
args = [str(self.wine), str(self.hlmv.relative_to(cwd)), '-game',
368369
str(self.game.relative_to(cwd)), str(mdl.relative_to(cwd))]

addon/utils/game.py

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,38 @@
11
from pathlib import Path
22
from ..utils.common import resolve
3-
3+
import os
44

55
def 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

4059
def 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

Comments
 (0)