@echo off
if not "%1"=="hide" (
    start "" "%~f0" hide
    exit /b
)
chcp 65001 >nul
title QTTools Image Converter - Offline Setup

echo ====================================================
echo   QTTools Image Converter (Free) v1.6
echo   Offline Setup
echo ====================================================
echo.

echo [1/4] Checking Python environment...
python --version >nul 2>&1
if errorlevel 1 (
    echo Python not found, installing Python 3.12.4...
    echo Please wait, installation takes about 2-3 minutes...
    echo.
    
    dependencies\python-3.12.4-amd64.exe /quiet InstallAllUsers=1 PrependPath=1 Include_test=0
    
    if errorlevel 1 (
        echo Python installation failed, please install manually
        echo Download: https://www.python.org/downloads/
        pause
        exit /b 1
    )
    echo Python installed successfully
) else (
    for /f "tokens=2" %%i in ('python --version 2^>^&1') do set PYTHON_VER=%%i
    echo Python %PYTHON_VER% found
)

echo.
echo [2/4] Upgrading pip...
python -m pip install --upgrade pip -q
echo.

echo [3/4] Installing dependencies (offline mode)...
pip install --no-index --find-links=dependencies PyQt6 Pillow numpy

if errorlevel 1 (
    echo Dependency installation failed
    pause
    exit /b 1
) else (
    echo Dependencies installed successfully
)

echo.
echo [4/4] Creating desktop shortcut...

set "CURRENT_DIR=%~dp0"
set "CURRENT_DIR=%CURRENT_DIR:~0,-1%"

(
echo Set WshShell = CreateObject("WScript.Shell"^)
echo Set lnk = WshShell.CreateShortcut(WshShell.SpecialFolders("Desktop"^) + "\QTTools Image Converter.lnk"^)
echo lnk.TargetPath = "python.exe"
echo lnk.Arguments = """%CURRENT_DIR%\启动.pyc"""
echo lnk.WorkingDirectory = "%CURRENT_DIR%"
echo lnk.Description = "QTTools Image Converter (Free)"
echo lnk.Save
) > "%TEMP%\create_shortcut.vbs"

cscript //nologo "%TEMP%\create_shortcut.vbs"
del "%TEMP%\create_shortcut.vbs" >nul 2>&1

echo Desktop shortcut created
echo.

echo ====================================================
echo   Setup complete!
echo ====================================================
echo.
echo Please double-click the desktop shortcut to run
echo.
timeout /t 3 >nul
exit