# -*- coding: utf-8 -*- r'''把全仓版本号从 1.7.1 升到 1.8.0。 为什么写脚本而不是手动改: 版本号散落在 8 个文件里(Python / Java manifest / PowerShell / Inno Setup / 测试 / 打包脚本),手动改必漏。 而且 .ps1 必须保留 UTF-8 BOM —— 用 edit 工具改会把 BOM 吃掉, 导致 PowerShell 按 GBK 解析、中文变乱码、脚本报语法错(这坑踩过)。 所以统一用 Python 读写字节,按后缀决定要不要 BOM。 ''' from __future__ import annotations import sys from pathlib import Path ROOT = Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote") OLD = "1.7.1" NEW = "1.8.0" BOM = b"\xef\xbb\xbf" TARGETS = [ "android/AndroidManifest.xml", "android/build_apk.ps1", "installer/ykxmz.iss", "relay/relay.py", "windows/lanremote/__init__.py", "_tests/test_apk_contents.py", "_tests/test_package_remote.py", "_build/package_remote.py", ] NEEDS_BOM = {".ps1"} def main() -> int: print(" %s -> %s" % (OLD, NEW)) print() total = 0 for rel in TARGETS: path = ROOT / rel if not path.is_file(): print(" [跳过] %s 不存在" % rel) continue raw = path.read_bytes() had_bom = raw.startswith(BOM) text = raw.decode("utf-8-sig") if OLD not in text: print(" [跳过] %-38s 里面没有 %s" % (rel, OLD)) continue count = text.count(OLD) text = text.replace(OLD, NEW) want_bom = path.suffix in NEEDS_BOM or had_bom data = text.encode("utf-8") if want_bom: data = BOM + data path.write_bytes(data) note = "" if want_bom and not had_bom: note = "(补上 BOM)" elif had_bom and not want_bom: note = "(去掉 BOM)" print(" %-38s 改了 %d 处%s" % (rel, count, note)) total += count print() print(" 共改 %d 处" % total) print() print(" 复核 —— 代码里还有哪里留着 %s:" % OLD) found = False for path in sorted(ROOT.rglob("*")): if not path.is_file(): continue rel = str(path.relative_to(ROOT)) if any(part in rel for part in (".git\\", "dist\\", "dist_exe", "_build\\_", "toolchain", "node_modules", "__pycache__", "_shots")): continue if path.suffix not in (".py", ".java", ".iss", ".ps1", ".md", ".json", ".sh", ".bat", ".xml"): continue try: text = path.read_text(encoding="utf-8", errors="ignore") except OSError: continue if OLD in text: tag = "(文档,可保留)" if path.suffix == ".md" else "**要改**" print(" %-52s %s" % (rel, tag)) if path.suffix != ".md": found = True if not found: print(" (代码里已经没有了)") print() print(" BOM 复核(.ps1 必须有):") for rel in TARGETS: path = ROOT / rel if not path.is_file(): continue has = path.read_bytes().startswith(BOM) want = path.suffix in NEEDS_BOM mark = "OK" if has == want else "**不对**" print(" %-38s BOM=%-5s 应=%-5s %s" % (rel, has, want, mark)) return 0 if __name__ == "__main__": sys.exit(main())