feat: test mission integrity

This commit is contained in:
aclist committed 2026-06-11 12:01:17 +09:00
1 parent 820deb2955
commit 9983e91526
1 file changed
+9 -3
+9 -3
View File
@@ -48,11 +48,16 @@ def get_local_mods(workshop_path: Path) -> list[Path]:
mods = [file for file in workshop_path.iterdir() if file.is_dir()] mods = [file for file in workshop_path.iterdir() if file.is_dir()]
return mods return mods
def is_mission(path: Path) -> None:
# TODO: parse integrity of other files
file = path / "init.c"
return file.exists()
def parse_meta(file: Path) -> ModMeta | None: def parse_meta(file: Path) -> ModMeta | None:
mod = file / "meta.cpp" mod = file / "meta.cpp"
if mod.exists() is False: if mod.exists() is False:
return None return None
try:
with open(file / "meta.cpp", "r") as f: with open(file / "meta.cpp", "r") as f:
st = f.read() st = f.read()
lex = shlex.shlex(st) lex = shlex.shlex(st)
@@ -75,8 +80,10 @@ def parse_meta(file: Path) -> ModMeta | None:
ntok = ntok.split('"')[1] ntok = ntok.split('"')[1]
if ntok is not None: if ntok is not None:
v.append(ntok) v.append(ntok)
meta = ModMeta(*v) return ModMeta(*v)
return meta except Exception as e:
logger.critical(e)
return None
def get_mod_size(path: Path) -> float: def get_mod_size(path: Path) -> float:
@@ -98,7 +105,6 @@ def parse_mods(mods: list[Path]) -> list[Any]:
for mod in mods: for mod in mods:
mod_dir = mod.name mod_dir = mod.name
symlink = _hash(mod_dir) symlink = _hash(mod_dir)
# FIXME: malformed .cpp files could break this
meta = parse_meta(mod) meta = parse_meta(mod)
if meta is None: if meta is None:
continue continue