diff --git a/Patch.py b/Patch.py index 113d0658c6b7..091545700059 100644 --- a/Patch.py +++ b/Patch.py @@ -8,7 +8,7 @@ import ModuleUpdate ModuleUpdate.update() -from worlds.Files import AutoPatchRegister, APDeltaPatch +from worlds.Files import AutoPatchRegister, APPatch class RomMeta(TypedDict): @@ -20,7 +20,7 @@ class RomMeta(TypedDict): def create_rom_file(patch_file: str) -> Tuple[RomMeta, str]: auto_handler = AutoPatchRegister.get_handler(patch_file) if auto_handler: - handler: APDeltaPatch = auto_handler(patch_file) + handler: APPatch = auto_handler(patch_file) target = os.path.splitext(patch_file)[0]+handler.result_file_ending handler.patch(target) return {"server": handler.server, diff --git a/worlds/Files.py b/worlds/Files.py index 52d3c7da1d35..336a3090937b 100644 --- a/worlds/Files.py +++ b/worlds/Files.py @@ -1,5 +1,6 @@ from __future__ import annotations +import abc import json import zipfile import os @@ -15,7 +16,7 @@ del os -class AutoPatchRegister(type): +class AutoPatchRegister(abc.ABCMeta): patch_types: ClassVar[Dict[str, AutoPatchRegister]] = {} file_endings: ClassVar[Dict[str, AutoPatchRegister]] = {} @@ -112,14 +113,25 @@ def get_manifest(self) -> Dict[str, Any]: } -class APDeltaPatch(APContainer, metaclass=AutoPatchRegister): - """An APContainer that additionally has delta.bsdiff4 +class APPatch(APContainer, abc.ABC, metaclass=AutoPatchRegister): + """ + An abstract `APContainer` that defines the requirements for an object + to be used by the `Patch.create_rom_file` function. + """ + result_file_ending: str = ".sfc" + + @abc.abstractmethod + def patch(self, target: str) -> None: + """ create the output file with the file name `target` """ + + +class APDeltaPatch(APPatch): + """An APPatch that additionally has delta.bsdiff4 containing a delta patch to get the desired file, often a rom.""" hash: Optional[str] # base checksum of source file patch_file_ending: str = "" delta: Optional[bytes] = None - result_file_ending: str = ".sfc" source_data: bytes def __init__(self, *args: Any, patched_path: str = "", **kwargs: Any) -> None: