Core: APPatch interface (#2808)
define interface that has only the bare minimum required for `Patch.create_rom_file`
This commit is contained in:
parent
f178d438b8
commit
475e803500
4
Patch.py
4
Patch.py
|
@ -8,7 +8,7 @@ if __name__ == "__main__":
|
|||
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,
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
from __future__ import annotations
|
||||
|
||||
import abc
|
||||
import json
|
||||
import zipfile
|
||||
import os
|
||||
|
@ -15,7 +16,7 @@ del threading
|
|||
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 @@ class APContainer:
|
|||
}
|
||||
|
||||
|
||||
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:
|
||||
|
|
Loading…
Reference in New Issue