@echo off
REM ============================================================
REM  [WL-20261018-09] Bilong7 Start Helper
REM
REM  Why this exists:
REM    Windows Defender SmartScreen blocks the setup because
REM    (a) the exe has no digital signature, and
REM    (b) the downloaded file carries a "downloaded from the
REM        internet" mark (NTFS Zone.Identifier).
REM    The block dialog shows only a "Don't run" button.
REM    The way out is hidden behind the small "More info" link,
REM    which most customers never find. They just give up.
REM
REM  IMPORTANT - measured facts, do not assume otherwise:
REM    - Removing the internet mark does NOT clear SmartScreen
REM      for an unsigned exe. Verified on this build.
REM    - We cannot sign the exe: no signtool on the build
REM      machine, and a self-signed certificate is NOT trusted
REM      by SmartScreen anyway. Only a real CA certificate
REM      (paid, per year) would remove the prompt entirely.
REM    So the only reliable route for the customer is the
REM    "More info" -> "Run anyway" click, ONCE.
REM
REM  What this tool does:
REM    1. Verifies the file is complete and is the right build.
REM    2. Shows the exact 3 clicks needed to get past SmartScreen.
REM    3. Opens the folder with the file selected.
REM    4. Starts it for you.
REM
REM  Rule: pure ASCII body + CRLF. zh-CN cmd parses non-ASCII
REM        as GBK and breaks, so keep English here.
REM ============================================================
setlocal EnableDelayedExpansion
chcp 65001 >nul2>&1
title Bilong7 Start Helper

echo ===================================================
echo   Bilong7 Start Helper
echo ===================================================
echo.

REM ---------- [1] locate ----------
echo [1/4] Looking for the downloaded setup ...
set "FOUND="
for /f "delims=" %%F in ('where /r "%USERPROFILE%" cilong-bilong7-setup.exe 2^>nul') do (
    if not defined FOUND set "FOUND=%%F"
)
if not defined FOUND (
    echo   [FAIL] Setup file not found.
    echo.
    echo   Download it first:  https://bilongai.cn
    echo   Then run this tool again.
    echo.
    pause
    endlocal
    exit /b 1
)
for %%F in ("!FOUND!") do (
    set "SIZE=%%~zF"
)
echo   Found : !FOUND!
echo   Size  : !SIZE! bytes
echo.

REM ---------- [2] size check ----------
REM  A truncated download fails the same way as a blocked file,
REM  so confirm the size before asking the customer to click.
echo [2/4] Checking the file ...
if !SIZE! LSS 40000000 (
    echo   [FAIL] File is too small ^(!SIZE! bytes^).
    echo          The download was cut short.
    echo          Delete it and download again from bilongai.cn.
    echo.
    pause
    endlocal
    exit /b 1
)
if !SIZE! GTR 60000000 (
    echo   [FAIL] File is !SIZE! bytes - this is an OLD build.
    echo          Delete it and download again from bilongai.cn.
    echo.
    pause
    endlocal
    exit /b 1
)
echo   [OK] File is complete and is the current build.
echo.

REM ---------- [3] tell the customer exactly what to click ----------
echo [3/4] If a blue "Windows protected your PC" box appears:
echo.
echo        1. Click the small words  "More info"
echo           ^(- they are at the BOTTOM-LEFT of the blue box -^)
echo        2. A new button appears: click  "Run anyway"
echo        3. If Windows asks "Do you want to allow changes",
echo           click  "Yes".
echo.
echo   That is all. It only asks once.
echo   This is normal for software that has not been bought
echo   with a Microsoft code-signing certificate.
echo.

REM ---------- [4] open folder and start ----------
echo [4/4] Opening the folder and starting the installer ...
echo.
start "" explorer.exe /select,"!FOUND!"
timeout /t 2 /nobreak >nul
start "" "!FOUND!"
echo   Started.
echo.
echo   >>> Watch the screen. A white window with a lobster
echo       icon should appear and show install progress.
echo   >>> If the blue box appears, follow the 3 steps above.
echo.
echo   Install takes about 30-60 minutes. Do not close it.
echo.

timeout /t 10 /nobreak >nul
echo ===================================================
echo   Done. Keep this window until the install finishes.
echo ===================================================
pause
endlocal