1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2024-12-26 14:46:16 +00:00

Fixup assets extraction (#1513)

This commit is contained in:
Dragorn421 2023-05-06 23:31:30 +02:00 committed by GitHub
parent 8e04ae917f
commit 5086939880
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 5 deletions

View file

@ -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)

View file

@ -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")