# -*- coding: utf-8 -*- r"""把 TlsCompat.java 加进各处的 Java 编译清单。 背景: RelayTransport 改成用 TlsCompat.open() 之后, 那些"只编译一部分 java"的地方就编译不过了 —— 它们没有把 TlsCompat.java 列进去。 需要补的三处: _tests/test_package_remote.py _tests/test_watch_lan_switch.py _tests/verify_all.ps1 """ from __future__ import annotations import re import sys from pathlib import Path ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote") TARGETS = [ ROOT / "_tests" / "test_package_remote.py", ROOT / "_tests" / "test_watch_lan_switch.py", ROOT / "_tests" / "verify_all.ps1", ] def patch(path: Path) -> bool: raw = path.read_bytes() had_bom = raw.startswith(b"\xef\xbb\xbf") text = raw.decode("utf-8-sig") if "TlsCompat.java" in text: print(f" {path.name}: 已经有了") return True # 在 RelayTransport.java 那一行后面插一行同格式的 TlsCompat.java pattern = re.compile( r"([ \t]*(?:\(Join-Path \$root )?[\"']?[^\n\"']*RelayTransport\.java[\"']?\)?\,?[ \t]*\r?\n)") match = pattern.search(text) if not match: print(f" [失败] {path.name}: 找不到 RelayTransport.java 那一行") return False line = match.group(1) indent = re.match(r"[ \t]*", line).group(0) # 保留原来的包裹形式 if "Join-Path" in line: new_line = f'{indent}(Join-Path $root "android\\src\\com\\lanremote\\watch\\TlsCompat.java")`\n' elif '"' in line: new_line = f'{indent}"TlsCompat.java",\n' if line.rstrip().endswith(",") \ else f'{indent}"TlsCompat.java"\n' else: new_line = f'{indent}TlsCompat.java\n' text = text[:match.end(1)] + new_line + text[match.end(1):] body = text.replace("\r\n", "\n").encode("utf-8") path.write_bytes((b"\xef\xbb\xbf" if had_bom else b"") + body) print(f" {path.name}: 补上了 TlsCompat.java") return True def main() -> int: ok = True for path in TARGETS: if not path.is_file(): print(f" [跳过] {path.name} 不存在") continue if not patch(path): ok = False return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())