mirror of
https://gitee.com/xmz7891/ykxmz.git
synced 2026-10-18 23:00:44 +00:00
琚帶绔?- 淇 MTU 闂锛氬す MSS + 璺緞 MTU 鎺㈡祴锛堝叕缃戝彲鐢ㄧ巼 48% -> 100%锛?- 澶嶇敤 HTTP 杩炴帴锛堝厤鎺夋瘡娆℃柊寤?TLS 鐨?30% 鎻℃墜澶辫触锛?- 姣忓垎閽熷洖澶存壘灞€鍩熺綉锛岃嚜鍔ㄥ垏鍥炲揩 400 鍊嶇殑璺緞 - 鐢婚潰蹇冭烦甯э細闈欐鏃剁渷娴侀噺锛屽鎴风浠嶇煡閬撴祦鏄椿鐨?- 閿佸睆鏃剁粰鍑哄彲鎿嶄綔鐨勬彁绀? 鎵嬭〃绔?- 鍐呯疆 GTS Root R4 / GlobalSign Root CA锛屼慨 SSLHandshakeException - 杩炴帴閿欒缈昏瘧鎴愪汉璇濓紙璇佷功/鏃堕棿/瑙f瀽/瓒呮椂鍒嗗埆鎻愮ず锛?- 缁忎腑杞繛涓婂悗鐢ㄦ湇鍔″櫒鎶ョ殑鍦板潃鍒锋柊宸查厤瀵硅褰?- 鏂板灞€鍩熺綉杩炴帴椤甸潰銆佹湇鍔″櫒寤惰繜妫€娴? 鏈嶅姟鍣ㄧ - 鏀寔 chunked 璇锋眰浣擄紙淇瘡 16 绉掍竴娆$殑杩炴帴閿欎贡涓庡ぇ闈㈢Н 502锛?- 缃戠粶璋冧紭鑴氭湰 net-tune.sh锛堝紑鏈鸿嚜鍔ㄥ簲鐢級 - 绠$悊椤碉細鎵归噺鍒犻櫎銆佺綉缁滀綋妫€銆佷笅杞藉尯 - 闅ч亾鏀?HTTP/2 + 鍙岃繛鎺? 鏂囨。 - 璁稿彲鍗忚 / 瀹夎鍓嶅繀璇?/ 瀹夎鍚庨』鐭ワ紙浣滆€咃細灏忛害瀛愶級
109 lines
3.6 KiB
Python
109 lines
3.6 KiB
Python
# -*- coding: utf-8 -*-
|
||
"""开机自启(当前用户级,不需要管理员)。
|
||
|
||
写 HKCU\\...\\Run,不碰 HKLM —— 不需要 UAC,也不会影响别的用户。
|
||
"""
|
||
from __future__ import annotations
|
||
|
||
import os
|
||
import subprocess
|
||
import sys
|
||
from pathlib import Path
|
||
|
||
RUN_KEY = r"HKCU\Software\Microsoft\Windows\CurrentVersion\Run"
|
||
# 任务管理器「启动」标签页里显示的就是这个名字。
|
||
# 用 ykxmz 而不是冒充 "Windows xxx" —— 用的人应该看得出这是什么。
|
||
VALUE_NAME = "ykxmz"
|
||
# 早期版本用过的名字。开着自启的老用户升级后要把它清掉,别留两条。
|
||
LEGACY_VALUE_NAMES = ("LanRemoteAgent",)
|
||
|
||
_NO_WINDOW = getattr(subprocess, "CREATE_NO_WINDOW", 0)
|
||
|
||
|
||
def executable_path() -> str:
|
||
"""要写进注册表的可执行文件路径。"""
|
||
if getattr(sys, "frozen", False):
|
||
return str(Path(sys.executable).resolve())
|
||
# 源码模式:用 pythonw + run_agent.py,这样不会有黑窗
|
||
script = Path(__file__).resolve().parent.parent / "run_agent.py"
|
||
pythonw = Path(sys.executable).with_name("pythonw.exe")
|
||
exe = pythonw if pythonw.is_file() else Path(sys.executable)
|
||
return f'"{exe}" "{script}"'
|
||
|
||
|
||
def _run(args: list[str]) -> tuple[int, str]:
|
||
try:
|
||
proc = subprocess.run(args, capture_output=True, timeout=20,
|
||
creationflags=_NO_WINDOW,
|
||
encoding="mbcs", errors="replace")
|
||
return proc.returncode, ((proc.stdout or "") + (proc.stderr or "")).strip()
|
||
except Exception as exc: # noqa: BLE001
|
||
return -1, str(exc)
|
||
|
||
|
||
def command_line() -> str:
|
||
"""注册表里存的完整命令行。"""
|
||
if getattr(sys, "frozen", False):
|
||
return f'"{Path(sys.executable).resolve()}" --silent'
|
||
script = Path(__file__).resolve().parent.parent / "run_agent.py"
|
||
pythonw = Path(sys.executable).with_name("pythonw.exe")
|
||
exe = pythonw if pythonw.is_file() else Path(sys.executable)
|
||
return f'"{exe}" "{script}" --silent'
|
||
|
||
|
||
def is_enabled() -> bool:
|
||
code, out = _run(["reg", "query", RUN_KEY, "/v", VALUE_NAME])
|
||
return code == 0 and VALUE_NAME in out
|
||
|
||
|
||
def current_value() -> str:
|
||
code, out = _run(["reg", "query", RUN_KEY, "/v", VALUE_NAME])
|
||
if code != 0:
|
||
return ""
|
||
for line in out.splitlines():
|
||
if VALUE_NAME in line and "REG_SZ" in line:
|
||
return line.split("REG_SZ", 1)[-1].strip()
|
||
return ""
|
||
|
||
|
||
def cleanup_legacy() -> list:
|
||
"""清掉早期版本留下的自启项(换名字了,别留两条)。"""
|
||
removed = []
|
||
for name in LEGACY_VALUE_NAMES:
|
||
code, _out = _run(["reg", "delete", RUN_KEY, "/v", name, "/f"])
|
||
if code == 0:
|
||
removed.append(name)
|
||
return removed
|
||
|
||
|
||
def enable() -> str:
|
||
value = command_line()
|
||
code, out = _run(["reg", "add", RUN_KEY, "/v", VALUE_NAME,
|
||
"/t", "REG_SZ", "/d", value, "/f"])
|
||
if code != 0:
|
||
raise ValueError(f"写入开机自启失败: {out[:120]}")
|
||
gone = cleanup_legacy()
|
||
extra = f"(顺手清掉旧自启项 {', '.join(gone)})" if gone else ""
|
||
return f"已开启开机自启(静默模式){extra}\n{value}"
|
||
|
||
|
||
def disable() -> str:
|
||
code, out = _run(["reg", "delete", RUN_KEY, "/v", VALUE_NAME, "/f"])
|
||
if code != 0 and "找不到" not in out and "unable" not in out.lower():
|
||
# 本来就没开,也算成功
|
||
pass
|
||
return "已关闭开机自启"
|
||
|
||
|
||
def toggle(on: bool) -> str:
|
||
return enable() if on else disable()
|
||
|
||
|
||
def status() -> dict:
|
||
enabled = is_enabled()
|
||
return {
|
||
"enabled": enabled,
|
||
"command": current_value() if enabled else "",
|
||
"expected": command_line(),
|
||
}
|