diff --git a/extract_assets.py b/extract_assets.py index 5c9658d228..47e65ca23e 100755 --- a/extract_assets.py +++ b/extract_assets.py @@ -6,6 +6,7 @@ import os import signal import time import multiprocessing +from pathlib import Path EXTRACTED_ASSETS_NAMEFILE = ".extracted-assets.json" @@ -21,7 +22,13 @@ def ExtractFile(xmlPath, outputPath, outputSourcePath): # Don't extract if another file wasn't extracted properly. return - execStr = f"tools/ZAPD/ZAPD.out e -eh -i {xmlPath} -b baserom/ -o {outputPath} -osf {outputSourcePath} -gsf 1 -rconf tools/ZAPDConfigs/MqDbg/Config.xml {ZAPDArgs}" + zapdPath = Path("tools") / "ZAPD" / "ZAPD.out" + configPath = Path("tools") / "ZAPDConfigs" / "MqDbg" / "Config.xml" + + Path(outputPath).mkdir(parents=True, exist_ok=True) + Path(outputSourcePath).mkdir(parents=True, exist_ok=True) + + execStr = f"{zapdPath} e -eh -i {xmlPath} -b baserom -o {outputPath} -osf {outputSourcePath} -gsf 1 -rconf {configPath} {ZAPDArgs}" if "overlays" in xmlPath: execStr += " --static" @@ -143,14 +150,21 @@ def main(): if file.endswith(".xml"): xmlFiles.append(fullPath) + class CannotMultiprocessError(Exception): + pass + try: numCores = int(args.jobs or 0) if numCores <= 0: numCores = 1 print("Extracting assets with " + str(numCores) + " CPU core" + ("s" if numCores > 1 else "") + ".") - with multiprocessing.get_context("fork").Pool(numCores, initializer=initializeWorker, initargs=(mainAbort, args.unaccounted, extractedAssetsTracker, manager)) as p: + try: + mp_context = multiprocessing.get_context("fork") + except ValueError as e: + raise CannotMultiprocessError() from e + with mp_context.Pool(numCores, initializer=initializeWorker, initargs=(mainAbort, args.unaccounted, extractedAssetsTracker, manager)) as p: p.map(ExtractFunc, xmlFiles) - except (multiprocessing.ProcessError, TypeError): + except (multiprocessing.ProcessError, TypeError, CannotMultiprocessError): print("Warning: Multiprocessing exception ocurred.", file=os.sys.stderr) print("Disabling mutliprocessing.", file=os.sys.stderr) diff --git a/tools/msgdis.py b/tools/msgdis.py index 3d569802b3..9329ea7a89 100644 --- a/tools/msgdis.py +++ b/tools/msgdis.py @@ -391,7 +391,7 @@ def extract_all_text(text_out, staff_text_out): out += "\n#endif" out += "\n\n" - with open(text_out, "w") as outfile: + with open(text_out, "w", encoding="utf8") as outfile: outfile.write(out.strip() + "\n") if staff_text_out is not None: @@ -402,5 +402,5 @@ def extract_all_text(text_out, staff_text_out): out += f"DEFINE_MESSAGE(0x{message[0]:04X}, {textbox_type[message[1]]}, {textbox_ypos[message[2]]},\n{message[3]}\n)\n\n" - with open(staff_text_out, "w") as outfile: + with open(staff_text_out, "w", encoding="utf8") as outfile: outfile.write(out.strip() + "\n")