"""Decompile .rpyc files without sources via unrpyc (best effort).""" import subprocess import sys from pathlib import Path from app.config import get_settings def decompile_missing(game_dir: Path, warn) -> int: """Decompile every .rpyc that has no matching .rpy. Returns how many were produced.""" pending = [p for p in game_dir.rglob("*.rpyc") if not p.with_suffix(".rpy").exists()] if not pending: return 0 script = get_settings().unrpyc_path if not script.exists(): warn("unrpyc не установлен — скомпилированные скрипты (.rpyc) пропущены") return 0 produced = 0 # several files per call keeps process start-up overhead low for i in range(0, len(pending), 50): batch = pending[i:i + 50] proc = subprocess.run([sys.executable, str(script), "--try-harder", *map(str, batch)], capture_output=True, text=True, timeout=1800) for p in batch: if p.with_suffix(".rpy").exists(): produced += 1 else: warn(f"Не удалось декомпилировать {p.name}") if proc.returncode != 0 and not any(p.with_suffix(".rpy").exists() for p in batch): warn(f"unrpyc: {proc.stderr.strip()[-300:]}") return produced