43 lines
1.5 KiB
Python
43 lines
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""Extract numeric missing FileData IDs from selected #136 game error TXT headers."""
|
|
import argparse
|
|
from pathlib import Path
|
|
import re
|
|
|
|
ERROR = re.compile(rb"^\s*ERROR\s+#(\d+)\b", re.I)
|
|
FILE_DATA = re.compile(rb"\bFileData\s+ID\s+(\d{1,10})\b", re.I)
|
|
|
|
|
|
def missing_id(report):
|
|
if not re.fullmatch(r"[0-9_.-]+_Error_[0-9]+\.txt", report.name, re.I):
|
|
raise ValueError("Expected a native Error TXT report")
|
|
code = fdid = None
|
|
with report.open("rb") as stream:
|
|
remaining = 64 * 1024
|
|
while remaining and (line := stream.readline(min(4096, remaining))):
|
|
remaining -= len(line)
|
|
if match := ERROR.match(line):
|
|
code = int(match[1])
|
|
if code != 136:
|
|
return None
|
|
if line.lstrip().lower().startswith((b"description:", b"<errordescription>")):
|
|
if match := FILE_DATA.search(line):
|
|
fdid = int(match[1])
|
|
if code == 136 and fdid is not None:
|
|
return fdid if 0 < fdid <= 0xffffffff else None
|
|
return None
|
|
|
|
|
|
def main():
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
parser.add_argument("reports", type=Path, nargs="+")
|
|
reports = parser.parse_args().reports
|
|
if len(reports) > 128:
|
|
parser.error("Select at most 128 reports for one capture")
|
|
for fdid in sorted({value for report in reports if (value := missing_id(report)) is not None}):
|
|
print(fdid)
|
|
|
|
|
|
if __name__ == "__main__":
|
|
main()
|