# -*- coding: utf-8 -*- """两处收尾: 1. 彻底删掉「自动搜索电脑」那一段 (上次我图省事写了个 if(false) 包起来,结果 search 是 null 还在用, 会编译失败,而且很难看。) 2. Json 加 stringList 方法 RelayTransport 里我用它读 lanIps,但 Json 里没这个方法。 """ from __future__ import annotations import sys from pathlib import Path ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote") WATCH = ROOT / "android" / "src" / "com" / "lanremote" / "watch" MAIN = WATCH / "MainActivity.java" JSON = WATCH / "Json.java" # ---------- 1. 删掉搜索按钮那一段 ---------- DEAD_START = " // 老版本的「自动搜索电脑」按钮去掉了:" DEAD_END = " box.addView(search);\n" # ---------- 2. Json.stringList ---------- JSON_ANCHOR = ''' public static List list(Map map, String key) {''' JSON_NEW = ''' /** * 取一个字符串数组。元素不是字符串的会被跳过。 * * 中转会把被控端上报的局域网 IP 列表放在这里(lanIps), * 手表用它判断能不能走局域网直连。 */ public static List stringList(Map map, String key) { List out = new java.util.ArrayList(); List raw = list(map, key); if (raw == null) { return out; } for (Object item : raw) { if (item instanceof String) { String text = ((String) item).trim(); if (!text.isEmpty()) { out.add(text); } } } return out; } public static List list(Map map, String key) {''' def main() -> int: ok = True # ---- 删掉那一段 ---- lines = MAIN.read_text(encoding="utf-8").splitlines(keepends=True) start = end = None for index, line in enumerate(lines): if DEAD_START in line and start is None: start = index if start is not None and line.strip() == "box.addView(search);": end = index break if start is None or end is None: print(" [失败] 找不到要删的那一段") ok = False else: print(f" 删掉第 {start + 1} 到 {end + 1} 行({end - start + 1} 行)") del lines[start:end + 1] MAIN.write_text("".join(lines), encoding="utf-8", newline="\n") # ---- Json.stringList ---- text = JSON.read_text(encoding="utf-8") if "stringList" in text: print(" Json 已经有 stringList") elif JSON_ANCHOR in text: text = text.replace(JSON_ANCHOR, JSON_NEW, 1) JSON.write_text(text, encoding="utf-8", newline="\n") print(" Json 加了 stringList") else: print(" [失败] Json 锚点没找到") ok = False # 确认 startDiscovery 还有没有被引用 main_text = MAIN.read_text(encoding="utf-8") uses = [i + 1 for i, line in enumerate(main_text.splitlines()) if "startDiscovery" in line] print(f" startDiscovery 剩余引用行: {uses if uses else '无'}") if uses: print(" (还引用着的话,得看是不是只剩定义本身)") return 0 if ok else 1 if __name__ == "__main__": sys.exit(main())