diff --git a/caver/patcher.py b/caver/patcher.py index b2af7d4..368f11f 100644 --- a/caver/patcher.py +++ b/caver/patcher.py @@ -9,6 +9,9 @@ pre_edited_cs = __import__("pre-edited-cs") CSVERSION = 3 +class CaverException(Exception): + pass + def patch_files(patch_data: dict, output_dir: Path, progress_update: Callable[[str, float], None]): progress_update("Copying base files...", 0.0) ensure_base_files_exist(output_dir) @@ -39,13 +42,16 @@ def ensure_base_files_exist(output_dir: Path): keep_existing_files = version.exists() and int(version.read_text()) >= CSVERSION def should_ignore(path: str, names: list[str]): - base = ["__init__.py", "__pycache__"] + base = ["__init__.py", "__pycache__", "ScriptSource"] if keep_existing_files: p = Path(path) base.extend([p.joinpath(name) for name in names if p.joinpath(name).exists() and p.joinpath(name).is_file()]) return base - - shutil.copytree(internal_copy, output_dir, ignore=should_ignore, dirs_exist_ok=True) + + try: + shutil.copytree(internal_copy, 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) def patch_map(mapname: str, mapdata: dict[str, dict], TscFile, output_dir: Path): @@ -63,7 +69,7 @@ def patch_map(mapname: str, mapdata: dict[str, dict], TscFile, output_dir: Path) TscFile.placeScriptAtEvent(tsc_file, script, event, mapname, needle) for event, hint in mapdata["hints"].items(): - script = create_hint_script(hint["text"], hint.get("facepic", "0000"), hint.get("ending", " str: +def create_hint_script(text: str, facepic: bool, ending: str) -> str: """ A desperate attempt to generate valid str: match = next(re.finditer(pattern, line1), None) if match is not None and len(text) > msgbox_limit: - line1 = line1[:match.start] - split += match.start + line1 = line1[:match.start(0)] + split += match.start(0)+1 if split % hard_limit != 0: line2 = "\r\n" line2 += text[split:split+msgbox_limit] match = next(re.finditer(pattern, line2), None) if match is not None and len(text) > msgbox_limit*2: - line2 = line2[:match.start] + line2 = line2[:match.start(0)] if split % hard_limit != 0: split -= 2 - split += match.start + split += match.start(0)+1 if split % hard_limit != 0: line3 = "\r\n" line3 += text[split:split+msgbox_limit] - return f"