-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull_users_xml.py
More file actions
executable file
·81 lines (60 loc) · 2.26 KB
/
Copy pathpull_users_xml.py
File metadata and controls
executable file
·81 lines (60 loc) · 2.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env python3
"""Pull Shadow Fight 2 save files from a connected Android device."""
from __future__ import annotations
import argparse
import shutil
import subprocess
import sys
from pathlib import Path
from dotenv import load_dotenv
DEFAULT_PACKAGE = "com.nekki.shadowfight"
def run(command: list[str], *, check: bool = True) -> subprocess.CompletedProcess[str]:
print("+", " ".join(command))
return subprocess.run(command, check=check, text=True)
def adb_path(package: str, filename: str) -> str:
return f"/sdcard/Android/data/{package}/files/userdata/{filename}"
def check_adb_available() -> None:
if shutil.which("adb") is None:
print(
"adb not found in PATH. Install Android platform-tools and ensure adb is on $PATH.",
file=sys.stderr,
)
sys.exit(1)
def main() -> int:
load_dotenv()
parser = argparse.ArgumentParser(description="Pull Shadow Fight 2 users.xml save files for manual editing.")
parser.add_argument("--package", default=DEFAULT_PACKAGE)
parser.add_argument("--out-dir", type=Path, default=Path(".local/saves"))
args = parser.parse_args()
check_adb_available()
out_dir = args.out_dir.resolve()
out_dir.mkdir(parents=True, exist_ok=True)
files = [
"users.xml",
"users.xml.hash",
"users_backup.xml",
"users_backup.xml.hash",
]
existing = [name for name in files if (out_dir / name).exists()]
if existing:
print(f"Warning: these local files will be overwritten: {', '.join(existing)}")
# A save the game has only just created has no backup pair yet, so a missing
# file is normal rather than a failure. users.xml is the one that must exist.
pulled = []
for filename in files:
result = run(["adb", "pull", adb_path(args.package, filename), str(out_dir / filename)], check=False)
if result.returncode == 0:
pulled.append(filename)
else:
print(f"Skipped {filename}: not present on the device.")
if "users.xml" not in pulled:
print(
f"Could not pull users.xml. Launch the game once so it writes a save, then retry.",
file=sys.stderr,
)
return 1
print(f"Pulled save files into {out_dir}: {', '.join(pulled)}")
print("Edit users.xml, then run: uv run push_users_xml.py")
return 0
if __name__ == "__main__":
raise SystemExit(main())