# -*- coding: utf-8 -*- r"""精准升级版本号 1.4.0 -> 1.5.0。 **不能全局替换** —— 项目里有 40 多个文件含 "1.4.0",其中大部分是: * 测试用的数据(配对码、设备版本号字段) * HTTP User-Agent "LanRemote/1.4.0" (Cloudflare 的 Browser Integrity Check 认这个, 而且 20 多个测试都在断言它 —— 动它要同步改一大片) * _build/ 下的一次性脚本(历史记录,不用改) 所以只改**用户能看到版本号的地方**: 1. android/build_apk.ps1 APK 文件名 + manifest 版本 2. docs/*.txt 三份文档 3. windows/lanremote/__init__.py __version__ 4. 会断言版本号的测试 UA 保持 "LanRemote/1.4.0" 不动(它是协议标识,不是产品版本)。 """ from __future__ import annotations import re import sys from pathlib import Path ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote") OLD, NEW = "1.4.0", "1.5.0" # 逐文件、逐模式改,写清楚每一处为什么改 PLAN = [ # (文件, 旧片段, 新片段, 说明) ("android/build_apk.ps1", '$apkName = "ykxmz-watch-1.4.0.apk"', '$apkName = "ykxmz-watch-1.5.0.apk"', "APK 文件名"), ("android/build_apk.ps1", '--version-code 3 `', '--version-code 5 `', "versionCode"), ("android/build_apk.ps1", '--version-name "1.4.0" `', '--version-name "1.5.0" `', "versionName"), ("windows/lanremote/__init__.py", '"1.4.0"', '"1.5.0"', "__version__"), ] # 文档:把"版本 1.4.0"之类改掉 DOC_PATTERNS = [ (r"1\.4\.0", "1.5.0"), ] # 测试里断言成品文件名的 TEST_PATTERNS = [ ("ykxmz-1.4.0", "ykxmz-1.5.0"), ("ykxmz-watch-1.4.0", "ykxmz-watch-1.5.0"), ] def main() -> int: changed = [] # ---- 1. 精准替换 ---- for rel, old, new, why in PLAN: path = ROOT / rel if not path.is_file(): print(f" [跳过] {rel} 不存在") continue text = path.read_text(encoding="utf-8") if old not in text: print(f" [跳过] {rel}: 找不到 {old[:40]!r}(可能已改)") continue path.write_text(text.replace(old, new, 1), encoding="utf-8", newline="\n") changed.append(f"{rel}({why})") # ---- 2. 文档 ---- for path in sorted((ROOT / "docs").glob("*.txt")): raw = path.read_bytes() had_bom = raw.startswith(b"\xef\xbb\xbf") text = raw.decode("utf-8-sig") new_text = re.sub(r"1\.4\.0", "1.5.0", text) if new_text != text: path.write_bytes((b"\xef\xbb\xbf" if had_bom else b"") + new_text.replace("\r\n", "\n").encode("utf-8")) changed.append(f"docs/{path.name}") # ---- 3. 断言成品文件名的测试 ---- for name in ("test_package_remote.py", "test_apk_contents.py", "acceptance.py"): path = ROOT / "_tests" / name if not path.is_file(): continue text = path.read_text(encoding="utf-8") original = text for old, new in TEST_PATTERNS: text = text.replace(old, new) if text != original: path.write_text(text, encoding="utf-8", newline="\n") changed.append(f"_tests/{name}") print(f" 共改了 {len(changed)} 处:") for item in changed: print(f" {item}") print() print(" 注意:HTTP User-Agent 仍是 \"LanRemote/1.4.0\"(协议标识,不是产品版本)。") # ---- 复核 ---- print() print(" 复核关键位置:") for rel, needle in (("android/build_apk.ps1", "ykxmz-watch-1.5.0.apk"), ("android/AndroidManifest.xml", '1.5.0'), ("_build/package_remote.py", '"1.5.0"')): path = ROOT / rel if path.is_file(): ok = needle in path.read_text(encoding="utf-8") print(f" {rel}: {'✓' if ok else '✗'} 含 {needle}") return 0 if __name__ == "__main__": sys.exit(main())