Files
ykxmz/_build/fix_code_oneshot.py
T
xmz7891 b86eeb349b 1.7.0:常规发布
- 版本号 1.7.0 -> 1.7.0
- 重建三端并打包
- 关键测试全过
2026-10-06 22:49:14 +08:00

110 lines
3.9 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
r"""修:--code / --name 处理完不退出,害得安装程序卡死。
现象:
装完之后配对码没写进去,而且安装程序在 CurStepChanged 里
用 ewWaitUntilTerminated 等 ykxmz.exe --code ... --silent,
**永远等不到** —— 因为 --silent 是常驻守护进程,不会返回。
根因:
main() 里 --code 那段处理完之后没有 return,
继续往下走到 run_silent(),于是变成"启动一个常驻服务"。
改法:
--code / --name 做成**一次性命令**:写完配置、打印、立刻退出。
想同时启动服务就显式加 --silent(那时才走守护进程)。
这样安装程序的分工就干净了:
CurStepChanged ykxmz.exe --code 123456 <- 秒退,只写配置
[Run] postinstall ykxmz.exe --silent <- 启动,nowait 不等
"""
from __future__ import annotations
import ast
import sys
from pathlib import Path
RUN = (Path(r"C:\Users\shu\Desktop\deepseekagent\LanRemote\windows"
r"\run_agent.py"))
OLD = ''' if args.code is not None or args.name:
store = Store(data_dir())
if args.code is not None:
digits = "".join(ch for ch in str(args.code) if ch.isdigit())
if len(digits) != 6:
print(f"配对码要 6 位数字,收到的是 {args.code!r}")
return 2
try:
store.set_pairing_code(digits)
except ValueError as exc:
print(f"设置配对码失败:{exc}")
return 2
# 装完就算"设置好了",不要再弹设置窗口
store.set("setup_done", True)
store.set("allow_new_pairing", True)
print(f"配对码已设为 {digits}")
if args.name:
store.set("name", str(args.name).strip()[:32])
print(f"电脑名已设为 {store.get('name')}")
if args.autostart:'''
NEW = ''' if args.code is not None or args.name:
store = Store(data_dir())
wrote = False
if args.code is not None:
digits = "".join(ch for ch in str(args.code) if ch.isdigit())
if len(digits) != 6:
print(f"配对码要 6 位数字,收到的是 {args.code!r}")
return 2
try:
store.set_pairing_code(digits)
except ValueError as exc:
print(f"设置配对码失败:{exc}")
return 2
# 装完就算"设置好了",不要再弹设置窗口
store.set("setup_done", True)
store.set("allow_new_pairing", True)
print(f"配对码已设为 {digits}")
wrote = True
if args.name:
store.set("name", str(args.name).strip()[:32])
print(f"电脑名已设为 {store.get('name')}")
wrote = True
# 只写了配置就结束 —— 这是一次性命令。
# 不加这个 return 的话会继续走到 run_silent(),
# 变成常驻进程永不返回,调用方(安装程序)会一直等下去。
# 想顺便启动服务,显式加 --silent。
if wrote and not (args.silent or args.add_device is not None
or args.setup):
return 0
if args.autostart:'''
def main() -> int:
text = RUN.read_text(encoding="utf-8")
if "只写了配置就结束" in text:
print(" 已经改过")
return 0
if OLD not in text:
print(" [失败] 锚点没找到")
return 1
text = text.replace(OLD, NEW, 1)
RUN.write_text(text, encoding="utf-8", newline="\n")
print(" --code / --name 改成一次性命令(写完就退出)")
try:
ast.parse(text)
print(" run_agent.py 语法 OK")
except SyntaxError as exc:
print(f" 语法错误: 行 {exc.lineno}: {exc.msg}")
return 1
return 0
if __name__ == "__main__":
sys.exit(main())