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 |     import ModuleUpdate | ||||||
|     ModuleUpdate.update() |     ModuleUpdate.update() | ||||||
| 
 | 
 | ||||||
| from worlds.Files import AutoPatchRegister, APDeltaPatch | from worlds.Files import AutoPatchRegister, APPatch | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class RomMeta(TypedDict): | class RomMeta(TypedDict): | ||||||
|  | @ -20,7 +20,7 @@ class RomMeta(TypedDict): | ||||||
| def create_rom_file(patch_file: str) -> Tuple[RomMeta, str]: | def create_rom_file(patch_file: str) -> Tuple[RomMeta, str]: | ||||||
|     auto_handler = AutoPatchRegister.get_handler(patch_file) |     auto_handler = AutoPatchRegister.get_handler(patch_file) | ||||||
|     if auto_handler: |     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 |         target = os.path.splitext(patch_file)[0]+handler.result_file_ending | ||||||
|         handler.patch(target) |         handler.patch(target) | ||||||
|         return {"server": handler.server, |         return {"server": handler.server, | ||||||
|  |  | ||||||
|  | @ -1,5 +1,6 @@ | ||||||
| from __future__ import annotations | from __future__ import annotations | ||||||
| 
 | 
 | ||||||
|  | import abc | ||||||
| import json | import json | ||||||
| import zipfile | import zipfile | ||||||
| import os | import os | ||||||
|  | @ -15,7 +16,7 @@ del threading | ||||||
| del os | del os | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class AutoPatchRegister(type): | class AutoPatchRegister(abc.ABCMeta): | ||||||
|     patch_types: ClassVar[Dict[str, AutoPatchRegister]] = {} |     patch_types: ClassVar[Dict[str, AutoPatchRegister]] = {} | ||||||
|     file_endings: ClassVar[Dict[str, AutoPatchRegister]] = {} |     file_endings: ClassVar[Dict[str, AutoPatchRegister]] = {} | ||||||
| 
 | 
 | ||||||
|  | @ -112,14 +113,25 @@ class APContainer: | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| class APDeltaPatch(APContainer, metaclass=AutoPatchRegister): | class APPatch(APContainer, abc.ABC, metaclass=AutoPatchRegister): | ||||||
|     """An APContainer that additionally has delta.bsdiff4 |     """ | ||||||
|  |     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.""" |     containing a delta patch to get the desired file, often a rom.""" | ||||||
| 
 | 
 | ||||||
|     hash: Optional[str]  # base checksum of source file |     hash: Optional[str]  # base checksum of source file | ||||||
|     patch_file_ending: str = "" |     patch_file_ending: str = "" | ||||||
|     delta: Optional[bytes] = None |     delta: Optional[bytes] = None | ||||||
|     result_file_ending: str = ".sfc" |  | ||||||
|     source_data: bytes |     source_data: bytes | ||||||
| 
 | 
 | ||||||
|     def __init__(self, *args: Any, patched_path: str = "", **kwargs: Any) -> None: |     def __init__(self, *args: Any, patched_path: str = "", **kwargs: Any) -> None: | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue