diff --git a/caver/patcher.py b/caver/patcher.py index c24c580..40b05a5 100644 --- a/caver/patcher.py +++ b/caver/patcher.py @@ -1,3 +1,4 @@ +from enum import Enum from pathlib import Path from typing import Callable, Optional from lupa import LuaRuntime # type: ignore @@ -14,6 +15,10 @@ CSVERSION = 5 class CaverException(Exception): pass +class CSPlatform(Enum): + FREEWARE = "freeware" + TWEAKED = "tweaked" + def get_path() -> Path: if getattr(sys, "frozen", False): file_dir = Path(getattr(sys, "_MEIPASS")) @@ -21,7 +26,7 @@ def get_path() -> Path: file_dir = Path(__file__).parent.parent return file_dir.joinpath("caver") -def patch_files(patch_data: dict, output_dir: Path, platform: str, progress_update: Callable[[str, float], None]): +def patch_files(patch_data: dict, output_dir: Path, platform: CSPlatform, progress_update: Callable[[str, float], None]): progress_update("Copying base files...", -1) ensure_base_files_exist(platform, output_dir) @@ -41,7 +46,7 @@ def patch_files(patch_data: dict, output_dir: Path, platform: str, progress_upda i += 1 progress_update("Copying MyChar...", i/total) - patch_mychar(patch_data["mychar"], output_dir, patch_data["platform"] == "tweaked") + patch_mychar(patch_data["mychar"], output_dir, platform is CSPlatform.TWEAKED) i += 1 progress_update("Copying hash...", i/total) @@ -51,10 +56,10 @@ def patch_files(patch_data: dict, output_dir: Path, platform: str, progress_upda progress_update("Copying UUID...", i/total) patch_uuid(patch_data["uuid"], output_dir) -def ensure_base_files_exist(platform: str, output_dir: Path): +def ensure_base_files_exist(platform: CSPlatform, output_dir: Path): internal_copy = pre_edited_cs.get_path() - version = output_dir.joinpath(platform, "data", "Stage", "_version.txt") + version = output_dir.joinpath(platform.value, "data", "Stage", "_version.txt") keep_existing_files = version.exists() and int(version.read_text()) >= CSVERSION def should_ignore(path: str, names: list[str]): @@ -65,7 +70,7 @@ def ensure_base_files_exist(platform: str, output_dir: Path): return base try: - shutil.copytree(internal_copy.joinpath(platform), output_dir, ignore=should_ignore, dirs_exist_ok=True) + shutil.copytree(internal_copy.joinpath(platform.value), output_dir, ignore=should_ignore, dirs_exist_ok=True) except shutil.Error: raise CaverException("Error copying base files. Ensure the directory is not read-only, and that Doukutsu.exe is closed") output_dir.joinpath("data", "Plaintext").mkdir(exist_ok=True) diff --git a/pre_edited_cs/tweaked/data/patcher_data.json b/pre_edited_cs/tweaked/data/patcher_data.json deleted file mode 100755 index f7e6f32..0000000 --- a/pre_edited_cs/tweaked/data/patcher_data.json +++ /dev/null @@ -1,2446 +0,0 @@ -{ - "hash": [ - 33, - 21, - 3, - 6, - 21 - ], - "maps": { - "0": { - "entrances": {}, - "hints": {}, - "music": { - "0100": { - "original_id": "0033", - "song_id": "0014" - }, - "0200": { - "original_id": "0001", - "song_id": "0027" - } - }, - "pickups": {} - }, - "Almond": { - "entrances": {}, - "hints": {}, - "music": { - "0090": { - "original_id": "0023", - "song_id": "0031" - }, - "0091": { - "original_id": "0023", - "song_id": "0031" - }, - "0092": { - "original_id": "0023", - "song_id": "0031" - }, - "0093": { - "original_id": "0023", - "song_id": "0031" - }, - "0094": { - "original_id": "0023", - "song_id": "0031" - }, - "0361": { - "original_id": "0023", - "song_id": "0031" - }, - "0452": { - "original_id": "0022", - "song_id": "0011" - }, - "0500": { - "original_id": "0022", - "song_id": "0011" - } - }, - "pickups": { - "0243": "