@echo off
setlocal EnableDelayedExpansion
chcp 65001 >nul 2>&1

set "SCRIPT_DIR=%~dp0"
if "%SCRIPT_DIR:~-1%"=="\" set "SCRIPT_DIR=%SCRIPT_DIR:~0,-1%"

:: 1. venv Python
set "PYTHON="
if exist "%SCRIPT_DIR%\venv\Scripts\python.exe" (
    set "PYTHON=%SCRIPT_DIR%\venv\Scripts\python.exe"
    echo [INFO] 浣跨敤铏氭嫙鐜 Python: !PYTHON!
)

:: 2. 绯荤粺 Python锛堣烦杩?WindowsApps 鍗犱綅锛岄獙璇佺増鏈?>= 3.10锛?if not defined PYTHON (
    where python >nul 2>&1
    if !ERRORLEVEL! equ 0 (
        for /f "delims=" %%p in ('where python 2^>nul') do if not defined PYTHON (
            echo "%%p" | findstr /I "WindowsApps" >nul 2>&1
            if !ERRORLEVEL! neq 0 (
                "%%p" -c "import sys; v=sys.version_info; sys.exit(0 if v.major==3 and v.minor>=10 else 1)" 2>nul
                if !ERRORLEVEL! equ 0 (
                    set "PYTHON=%%p"
                    echo [INFO] 浣跨敤绯荤粺 Python: %%p
                ) else (
                    echo [INFO] 绯荤粺 Python %%p 鐗堟湰杩囦綆锛堥渶瑕?3.10+锛夛紝缁х画鎼滅储...
                )
            ) else (
                echo [INFO] 璺宠繃 WindowsApps 涓殑 Python 鍗犱綅: %%p
            )
        )
    )
)

:: 3. 甯歌瀹夎璺緞
if not defined PYTHON (
    for %%d in (
        "%LOCALAPPDATA%\Programs\Python\Python314"
        "%LOCALAPPDATA%\Programs\Python\Python313"
        "%LOCALAPPDATA%\Programs\Python\Python312"
        "%LOCALAPPDATA%\Programs\Python\Python311"
        "%LOCALAPPDATA%\Programs\Python\Python310"
    ) do (
        if not defined PYTHON (
            if exist "%%~d\python.exe" (
                set "PYTHON=%%~d\python.exe"
                echo [INFO] 鎵惧埌 Python: !PYTHON!
            )
        )
    )
)

if not defined PYTHON (
    echo [ERROR] Python 鏈壘鍒帮紝璇峰厛瀹夎 Python 3.10+
    pause
    exit /b 1
)

echo [INFO] 浣跨敤 Python: !PYTHON!
echo:

"%PYTHON%" "%SCRIPT_DIR%\install_mcp.py" --uninstall %*
exit /b %ERRORLEVEL%


