feat(clew): extract rpa archives into game tree
This commit is contained in:
@@ -8,6 +8,8 @@ import sys
|
|||||||
from collections import deque
|
from collections import deque
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
from rpycdec.rpa import extract_rpa
|
||||||
|
|
||||||
LOG = logging.getLogger(__name__)
|
LOG = logging.getLogger(__name__)
|
||||||
|
|
||||||
def parse_args(argv: list[str]) -> argparse.Namespace:
|
def parse_args(argv: list[str]) -> argparse.Namespace:
|
||||||
@@ -32,11 +34,6 @@ def parse_args(argv: list[str]) -> argparse.Namespace:
|
|||||||
action="store_true",
|
action="store_true",
|
||||||
help="Replace Clew-managed output directories.",
|
help="Replace Clew-managed output directories.",
|
||||||
)
|
)
|
||||||
parser.add_argument(
|
|
||||||
"--suffix",
|
|
||||||
action="append",
|
|
||||||
help="Extract only archive paths with this suffix. Repeatable.",
|
|
||||||
)
|
|
||||||
return parser.parse_args(argv)
|
return parser.parse_args(argv)
|
||||||
|
|
||||||
|
|
||||||
@@ -57,6 +54,12 @@ def get_output_directory(output_root: Path, folder: str) -> Path:
|
|||||||
return directory
|
return directory
|
||||||
|
|
||||||
|
|
||||||
|
def extract_archive(archive: Path, destination: Path) -> None:
|
||||||
|
destination.mkdir(parents=True, exist_ok=True)
|
||||||
|
with archive.open("rb") as handle:
|
||||||
|
extract_rpa(handle, output_dir=str(destination))
|
||||||
|
|
||||||
|
|
||||||
def extract_game_files(game_root: Path, output_path: Path) -> None:
|
def extract_game_files(game_root: Path, output_path: Path) -> None:
|
||||||
queue = deque(game_root.iterdir())
|
queue = deque(game_root.iterdir())
|
||||||
|
|
||||||
@@ -67,6 +70,8 @@ def extract_game_files(game_root: Path, output_path: Path) -> None:
|
|||||||
if item.is_dir():
|
if item.is_dir():
|
||||||
destination.mkdir(parents=True, exist_ok=True)
|
destination.mkdir(parents=True, exist_ok=True)
|
||||||
queue.extend(item.iterdir())
|
queue.extend(item.iterdir())
|
||||||
|
elif item.is_file() and item.suffix.lower() == ".rpa":
|
||||||
|
extract_archive(item, destination.with_suffix(""))
|
||||||
elif item.is_file():
|
elif item.is_file():
|
||||||
destination.parent.mkdir(parents=True, exist_ok=True)
|
destination.parent.mkdir(parents=True, exist_ok=True)
|
||||||
shutil.copy2(item, destination)
|
shutil.copy2(item, destination)
|
||||||
|
|||||||
Reference in New Issue
Block a user