mirror of
https://github.com/ArchipelagoMW/Archipelago.git
synced 2026-03-07 07:03:44 -08:00
Core: Add a bunch of validation to AutoPatchRegister (#5431)
* Add a bunch of validation to AutoPatchRegister * slightly change it * lmao
This commit is contained in:
@@ -21,6 +21,10 @@ if TYPE_CHECKING:
|
||||
from Utils import Version
|
||||
|
||||
|
||||
class ImproperlyConfiguredAutoPatchError(Exception):
|
||||
pass
|
||||
|
||||
|
||||
class AutoPatchRegister(abc.ABCMeta):
|
||||
patch_types: ClassVar[Dict[str, AutoPatchRegister]] = {}
|
||||
file_endings: ClassVar[Dict[str, AutoPatchRegister]] = {}
|
||||
@@ -30,8 +34,28 @@ class AutoPatchRegister(abc.ABCMeta):
|
||||
new_class = super().__new__(mcs, name, bases, dct)
|
||||
if "game" in dct:
|
||||
AutoPatchRegister.patch_types[dct["game"]] = new_class
|
||||
if not dct["patch_file_ending"]:
|
||||
raise Exception(f"Need an expected file ending for {name}")
|
||||
|
||||
if not callable(getattr(new_class, "patch", None)):
|
||||
raise ImproperlyConfiguredAutoPatchError(
|
||||
f"Container {new_class} uses metaclass AutoPatchRegister, but does not have a patch method defined."
|
||||
)
|
||||
|
||||
patch_file_ending = dct.get("patch_file_ending")
|
||||
if patch_file_ending == ".zip":
|
||||
raise ImproperlyConfiguredAutoPatchError(
|
||||
f'Auto patch container {new_class} uses file ending ".zip", which is not allowed.'
|
||||
)
|
||||
if patch_file_ending is None:
|
||||
raise ImproperlyConfiguredAutoPatchError(
|
||||
f"Need an expected file ending for auto patch container {new_class}"
|
||||
)
|
||||
|
||||
existing_handler = AutoPatchRegister.file_endings.get(patch_file_ending)
|
||||
if existing_handler:
|
||||
raise ImproperlyConfiguredAutoPatchError(
|
||||
f"Two auto patch containers are using the same file extension: {new_class}, {existing_handler}"
|
||||
)
|
||||
|
||||
AutoPatchRegister.file_endings[dct["patch_file_ending"]] = new_class
|
||||
return new_class
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ import bsdiff4
|
||||
|
||||
import Utils
|
||||
from settings import get_settings
|
||||
from worlds.Files import APPatch, AutoPatchRegister
|
||||
from worlds.Files import APPatch
|
||||
from .Locations import LocationData
|
||||
|
||||
ADVENTUREHASH: str = "157bddb7192754a45372be196797f284"
|
||||
@@ -78,7 +78,7 @@ class BatNoTouchLocation:
|
||||
return ret_dict
|
||||
|
||||
|
||||
class AdventureDeltaPatch(APPatch, metaclass=AutoPatchRegister):
|
||||
class AdventureDeltaPatch(APPatch):
|
||||
hash = ADVENTUREHASH
|
||||
game = "Adventure"
|
||||
patch_file_ending = ".apadvn"
|
||||
|
||||
Reference in New Issue
Block a user