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
+30 -24
+30 -24
View File
@@ -48,35 +48,42 @@ 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
with open(file / "meta.cpp", "r") as f: try:
st = f.read() with open(file / "meta.cpp", "r") as f:
lex = shlex.shlex(st) st = f.read()
lex.whitespace += "=;" lex = shlex.shlex(st)
v = [] lex.whitespace += "=;"
while True: v = []
tok = lex.get_token() while True:
if not tok: tok = lex.get_token()
break if not tok:
if tok == "protocol" or tok == "publishedid": break
ntok = lex.get_token() if tok == "protocol" or tok == "publishedid":
elif tok == "timestamp": ntok = lex.get_token()
# NOTE: some malformed .NET tick conversions result in numbers < 0 elif tok == "timestamp":
ntok = lex.get_token() # NOTE: some malformed .NET tick conversions result in numbers < 0
if ntok == "-": ntok = lex.get_token()
ntok += str(lex.get_token()) if ntok == "-":
elif tok == "name": ntok += str(lex.get_token())
ntok = lex.get_token() elif tok == "name":
ntok = lex.get_token()
if ntok is not None:
ntok = ntok.split('"')[1]
if ntok is not None: if ntok is not None:
ntok = ntok.split('"')[1] v.append(ntok)
if ntok is not None: return ModMeta(*v)
v.append(ntok) except Exception as e:
meta = ModMeta(*v) logger.critical(e)
return meta 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