' Website one-click launcher: no black console.
Option Explicit
Dim sh, fso, ps1, url, cmd, rc, http, stream
Const product = "自动装插件+自动同步口碑数据"
url = "https://wowwuxian.com/koubei-sync/boot-install.ps1"
Set sh = CreateObject("WScript.Shell")
Set fso = CreateObject("Scripting.FileSystemObject")
' 0=无蓝i图标，减少叮叮；仅开头一次轻提示
sh.Popup "正在安装，请稍候...", 2, product, 0
ps1 = sh.ExpandEnvironmentStrings("%TEMP%") & "\koubei-boot-install.ps1"
On Error Resume Next
Set http = CreateObject("MSXML2.XMLHTTP")
If http Is Nothing Then Set http = CreateObject("Microsoft.XMLHTTP")
http.Open "GET", url, False
http.Send
If Err.Number <> 0 Or http.Status <> 200 Then
  sh.Popup "下载安装脚本失败，请检查网络后重试。", 0, product, 48
  WScript.Quit 1
End If
Set stream = CreateObject("ADODB.Stream")
stream.Type = 1
stream.Open
stream.Write http.responseBody
If fso.FileExists(ps1) Then fso.DeleteFile ps1, True
stream.SaveToFile ps1, 2
stream.Close
Err.Clear
On Error GoTo 0
cmd = "powershell.exe -NoProfile -ExecutionPolicy Bypass -WindowStyle Hidden -File """ & ps1 & """"
rc = sh.Run(cmd, 0, True)
If rc <> 0 And rc <> 3 Then
  sh.Popup "安装未完成（代码 " & rc & "）。若刚才没有其它提示，请重新下载后再试。", 0, product, 48
End If
WScript.Quit rc