删除多余文件
This commit is contained in:
@@ -1,10 +1,9 @@
|
||||
import asyncio
|
||||
import ctypes
|
||||
# ===== Main.py 顶部放置(所有 import 之前)=====
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import tidevice
|
||||
from hypercorn.asyncio import serve
|
||||
from hypercorn.config import Config
|
||||
|
||||
@@ -14,14 +13,6 @@ from Utils.AiUtils import AiUtils
|
||||
from Utils.DevDiskImageDeployer import DevDiskImageDeployer
|
||||
from Utils.LogManager import LogManager
|
||||
|
||||
if "IOSAI_PYTHON" not in os.environ:
|
||||
base_path = Path(sys.argv[0]).resolve()
|
||||
base_dir = base_path.parent if base_path.is_file() else base_path
|
||||
sidecar = base_dir / "python-rt" / ("python.exe" if os.name == "nt" else "python")
|
||||
if sidecar.exists():
|
||||
os.environ["IOSAI_PYTHON"] = str(sidecar)
|
||||
# ==============================================
|
||||
|
||||
# 确定 exe 或 py 文件所在目录
|
||||
BASE = Path(getattr(sys, 'frozen', False) and sys.executable or __file__).resolve().parent
|
||||
LOG_DIR = BASE / "log"
|
||||
@@ -54,7 +45,7 @@ def _run_flask_role():
|
||||
config.bind = [f"0.0.0.0:{flaskPort}"]
|
||||
config.certfile = os.path.join(resource_dir, "server.crt")
|
||||
config.keyfile = os.path.join(resource_dir, "server.key")
|
||||
config.alpn_protocols = ["h2"] # 👈 这一行
|
||||
config.alpn_protocols = ["h2", "http/1.1"]
|
||||
config.workers = 6 # 你机器 4GB → 推荐 3~4 个 worker
|
||||
|
||||
# 直接跑 Quart(ASGI 原生,不再用 WsgiToAsgi)
|
||||
@@ -64,23 +55,93 @@ if "--role=flask" in sys.argv:
|
||||
_run_flask_role()
|
||||
sys.exit(0)
|
||||
|
||||
def _ensure_wintun_installed():
|
||||
"""
|
||||
确保 wintun.dll 已经在系统目录里:
|
||||
- 优先从当前目录的 resources 中找 wintun.dll
|
||||
- 如果 System32 中没有,就复制过去(需要管理员权限)
|
||||
"""
|
||||
try:
|
||||
# ==== 关键:统一获取 resources 目录 ====
|
||||
if "__compiled__" in globals():
|
||||
# Nuitka 编译后的 exe
|
||||
base_dir = os.path.dirname(sys.executable) # exe 所在目录
|
||||
else:
|
||||
# 开发环境运行 .py
|
||||
cur_file = os.path.abspath(__file__) # Module/Main.py 所在目录
|
||||
base_dir = os.path.dirname(os.path.dirname(cur_file)) # 回到 iOSAi 根目录
|
||||
|
||||
resource_dir = os.path.join(base_dir, "resources")
|
||||
src = os.path.join(resource_dir, "wintun.dll")
|
||||
|
||||
# 1. 检查源文件是否存在
|
||||
if not os.path.exists(src):
|
||||
print(f"[wintun] 未找到资源文件: {src}")
|
||||
return
|
||||
|
||||
# 2. 系统 System32 目录
|
||||
windir = os.environ.get("WINDIR", r"C:\Windows")
|
||||
system32 = Path(windir) / "System32"
|
||||
dst = system32 / "wintun.dll"
|
||||
|
||||
# 3. System32 中已经存在则无需复制
|
||||
if dst.exists():
|
||||
print(f"[wintun] System32 中已存在: {dst}")
|
||||
return
|
||||
|
||||
# 4. 执行复制
|
||||
import shutil
|
||||
print(f"[wintun] 复制 {src} -> {dst}")
|
||||
shutil.copy2(src, dst)
|
||||
print("[wintun] 复制完成")
|
||||
|
||||
except PermissionError as e:
|
||||
print(f"[wintun] 权限不足,无法写入 System32:{e}")
|
||||
except Exception as e:
|
||||
print(f"[wintun] 安装 wintun.dll 时异常: {e}")
|
||||
|
||||
# 启动锁
|
||||
def main(arg):
|
||||
if len(arg) != 2 or arg[1] != "iosai":
|
||||
sys.exit(0)
|
||||
|
||||
# 判断是否为管理员身份原型
|
||||
def isAdministrator():
|
||||
"""
|
||||
检测当前进程是否具有管理员权限。
|
||||
- Windows 下调用 Shell32.IsUserAnAdmin()
|
||||
- 如果不是管理员,直接退出程序
|
||||
"""
|
||||
try:
|
||||
is_admin = ctypes.windll.shell32.IsUserAnAdmin()
|
||||
except Exception:
|
||||
# 非 Windows 或无法判断的情况,一律按“非管理员”处理
|
||||
is_admin = False
|
||||
|
||||
if not is_admin:
|
||||
print("[ERROR] 需要以管理员身份运行本程序!")
|
||||
sys.exit(0)
|
||||
|
||||
return True
|
||||
|
||||
# 项目入口
|
||||
if __name__ == "__main__":
|
||||
# 检测是否有管理员身份权限
|
||||
isAdministrator()
|
||||
|
||||
# 检测程序合法性
|
||||
main(sys.argv)
|
||||
|
||||
# 清空日志
|
||||
LogManager.clearLogs()
|
||||
|
||||
main(sys.argv)
|
||||
|
||||
# 添加iOS开发包到电脑上
|
||||
deployer = DevDiskImageDeployer(verbose=True)
|
||||
deployer.deploy_all()
|
||||
|
||||
# 复制wintun.dll到system32目录下
|
||||
_ensure_wintun_installed()
|
||||
|
||||
# 启动 Flask 子进程
|
||||
manager = FlaskSubprocessManager.get_instance()
|
||||
manager.start()
|
||||
|
||||
Reference in New Issue
Block a user