@echo off
REM ============================================================
REM   FrankNex Windows 一键安装助手
REM   - 自动下载最新安装包
REM   - 自动解除 Mark-of-the-Web (Zone.Identifier)，绕过 SmartScreen
REM   - 自动启动安装程序
REM
REM   用法：双击运行此 .bat 文件即可。
REM ============================================================
setlocal EnableExtensions EnableDelayedExpansion
chcp 65001 >nul 2>&1

set "VERSION=2026.5.15"
set "EXE_NAME=FrankNex-%VERSION%-x64.exe"
set "URL=https://www.franknex.com/downloads/%EXE_NAME%"
set "DST=%TEMP%\%EXE_NAME%"

echo.
echo ============================================================
echo   FrankNex %VERSION% 安装助手
echo ============================================================
echo.

echo [1/4] 正在下载安装包...
echo       %URL%
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  "$ProgressPreference='SilentlyContinue';" ^
  "try { Invoke-WebRequest -Uri '%URL%' -OutFile '%DST%' -UseBasicParsing } catch { Write-Host '下载失败：' $_.Exception.Message -ForegroundColor Red; exit 1 }"

if not exist "%DST%" (
  echo.
  echo [错误] 下载失败，请检查网络或访问 https://franknex.com 手动下载。
  pause
  exit /b 1
)
echo       完成。

echo.
echo [2/4] 正在解除 Windows 文件下载标记（防 SmartScreen 阻拦）...
powershell -NoProfile -ExecutionPolicy Bypass -Command ^
  "try { Unblock-File -Path '%DST%' -ErrorAction Stop; Remove-Item -Path '%DST%:Zone.Identifier' -ErrorAction SilentlyContinue } catch {}"
echo       完成。

echo.
echo [3/4] 校验文件...
for %%A in ("%DST%") do set "SIZE=%%~zA"
if !SIZE! LSS 1000000 (
  echo [错误] 文件大小异常 ^(!SIZE! 字节^)，下载可能不完整。
  del "%DST%" >nul 2>&1
  pause
  exit /b 1
)
echo       OK ^(!SIZE! 字节^)。

echo.
echo [4/4] 启动安装程序...
echo       如出现 SmartScreen 蓝屏，点击 "更多信息" -^> "仍要运行" 即可。
echo.
start "" "%DST%"

echo ============================================================
echo   安装程序已启动，请按窗口指引完成。
echo ============================================================
echo.
timeout /t 5 /nobreak >nul
endlocal
exit /b 0
