' QQ 助手 —— 双击入口（不弹黑框）
' 找到 node.exe -> 以隐藏窗口方式运行 desktop\launcher.js
' 注意：本文件是源码模板（UTF-8），真正给 Windows 用的是 desktop\launch.vbs（UTF-16LE+BOM）。
' 改完跑一次：node desktop\encode-assets.js
Option Explicit

Dim fso, sh, root, nodeExe, cand, p, f, args, rc

Set fso = CreateObject("Scripting.FileSystemObject")
Set sh  = CreateObject("WScript.Shell")

root = fso.GetParentFolderName(fso.GetParentFolderName(WScript.ScriptFullName))
nodeExe = ""

' 1) 便携版：项目根目录放 runtime\node.exe
cand = fso.BuildPath(root, "runtime\node.exe")
If fso.FileExists(cand) Then nodeExe = cand

' 2) PATH 里的 node
If nodeExe = "" Then
  p = sh.ExpandEnvironmentStrings("%PATH%")
  For Each f In Split(p, ";")
    If Len(f) > 0 Then
      cand = fso.BuildPath(f, "node.exe")
      If fso.FileExists(cand) Then
        nodeExe = cand
        Exit For
      End If
    End If
  Next
End If

' 3) DeepSeek Harness 自带的 node runtime
If nodeExe = "" Then
  cand = sh.ExpandEnvironmentStrings("%LOCALAPPDATA%\Programs\DeepSeek Harness\resources\runtime\primary-runtime\dependencies\node\bin\node.exe")
  If fso.FileExists(cand) Then nodeExe = cand
End If

If nodeExe = "" Then
  MsgBox "没找到 node.exe。" & vbCrLf & vbCrLf & "装一个 Node.js 18+ 就能跑（或把 node.exe 放到本目录的 runtime\ 下）。", 16, "QQ 助手"
  WScript.Quit 1
End If

sh.CurrentDirectory = root
args = """" & nodeExe & """ """ & fso.BuildPath(root, "desktop\launcher.js") & """"
' 0 = 隐藏窗口，False = 不等待（launcher 自己会等窗口关闭再收服务）
rc = sh.Run(args, 0, False)
If rc <> 0 Then
  MsgBox "启动失败（错误码 " & rc & "）。" & vbCrLf & "可在命令行执行 node desktop\launcher.js 查看详情。", 16, "QQ 助手"
End If
