# -*- coding: utf-8 -*- """补齐被误删的字段 + import + 删掉局域网自检的调用点。 前面那个补丁的正则太贪,挖掉了这些字段声明: busy boolean (if (busy) / busy = true/false) mirrorStreaming boolean (mirrorStreaming = false / ok) incoming ByteArrayOutputStream incomingName String (.isEmpty()) 还差一个 import:DialogInterface(promptPairingCode 里用了)。 以及 requestPcSelfCheck() 被删了,但 942 行还在调它。 """ from __future__ import annotations import sys from pathlib import Path MAIN = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\android\src" r"\com\lanremote\watch\MainActivity.java") # 1. import IMPORT_OLD = "import android.content.Intent;" IMPORT_NEW = ("import android.content.DialogInterface;\n" "import android.content.Intent;") # 2. 字段(挂在 deviceBox 那一组后面) FIELD_ANCHOR = ''' // 待排版的按钮队列,flushGrid() 里按列数切成行 private final java.util.List cellQueue = new java.util.ArrayList();''' FIELD_NEW = FIELD_ANCHOR + ''' // 正在连接中(避免重复点) private volatile boolean busy; // 屏幕镜像是否在推流 private volatile boolean mirrorStreaming; // 正在接收的文件缓冲 + 文件名 private ByteArrayOutputStream incoming; private String incomingName = "";''' # 3. 自检调用点 CALL_OLD = " public void run() { requestPcSelfCheck(); }" def main() -> int: text = MAIN.read_text(encoding="utf-8") ok = True if "import android.content.DialogInterface;" in text: print(" import DialogInterface 已在") elif IMPORT_OLD in text: text = text.replace(IMPORT_OLD, IMPORT_NEW, 1) print(" 加了 import DialogInterface") else: print(" [失败] 找不到 import 锚点") ok = False if "private volatile boolean busy;" in text or "private boolean busy;" in text: print(" busy 字段已在") elif FIELD_ANCHOR in text: text = text.replace(FIELD_ANCHOR, FIELD_NEW, 1) print(" 补回 busy / mirrorStreaming / incoming / incomingName") else: print(" [失败] 找不到字段锚点") ok = False # 删掉自检调用 if CALL_OLD in text: text = text.replace(CALL_OLD, " public void run() {\n" " // 局域网自检已随局域网功能一起移除\n" " statusView.setText(\"该功能已移除\");\n" " }", 1) print(" 修掉 requestPcSelfCheck() 的调用点(改成提示已移除)") else: count = text.count("requestPcSelfCheck") print(f" requestPcSelfCheck 剩余引用 {count} 处") MAIN.write_text(text, encoding="utf-8", newline="\n") return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())