-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_coexist.py
More file actions
64 lines (49 loc) · 1.97 KB
/
Copy pathauto_coexist.py
File metadata and controls
64 lines (49 loc) · 1.97 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
import shutil
import subprocess
import sys
from pathlib import Path
from _utils import GREEN, RED, RESET, title, wxbasepath, iter_version_dirs, get_valid_dll_versions
def cleanup_invalid_versions(base: Path):
removed = []
kept = []
for version_dir in sorted(iter_version_dirs(base), key=lambda p: tuple(int(part) for part in p.name.split(".")), reverse=True):
dll_path = version_dir / "Weixin.dll"
if dll_path.is_file():
kept.append(version_dir)
continue
print(f"- Removing invalid version folder: {version_dir}")
shutil.rmtree(version_dir)
removed.append(version_dir)
return kept, removed
def run_coexist(number: str):
cmd = [sys.executable, "coexist.py", "-n", number, "--no-pause"]
print(f"\n> Running: {' '.join(cmd)}")
subprocess.run(cmd, check=True)
def main():
title("Auto Coexist")
print("\n - Clean stale Weixin version folders and rebuild coexist executables.")
base = wxbasepath()
print(f"\n> Weixin base path: {base}")
kept, removed = cleanup_invalid_versions(base)
valid_versions = get_valid_dll_versions(base)
if not valid_versions:
print(f"{RED}[ERR] No valid Weixin.dll was found after cleanup{RESET}")
return 1
print("\n> Valid version folders:")
for version_dir in valid_versions:
print(f" {GREEN}[keep]{RESET} {version_dir}")
if not removed:
print("\n> No stale version folders needed removal")
run_coexist("0")
run_coexist("1")
print(f"\n{GREEN}[√] Done. Rebuilt coexist files with the latest valid Weixin.dll{RESET}")
return 0
if __name__ == "__main__":
try:
raise SystemExit(main())
except subprocess.CalledProcessError as exc:
print(f"\n{RED}[ERR] coexist.py failed with exit code {exc.returncode}{RESET}")
raise SystemExit(exc.returncode)
except PermissionError as exc:
print(f"\n{RED}[ERR] Permission denied: {exc}{RESET}")
raise SystemExit(1)