@echo off setlocal EnableDelayedExpansion :: Ensure we always pause on exit so user can see errors if "%~1"=="" ( cmd /k "%~f0" run exit /b ) echo. echo ======================================== echo CQ TDM Installer for Windows echo ======================================== echo. :: Check if Python is installed set "PYTHON=" :: First check if python is in PATH python --version >nul 2>&1 if not errorlevel 1 ( set "PYTHON=python" goto :python_found ) :: Check common install locations (newest first) call :find_python if defined PYTHON goto :python_found :: Python not found, attempt to install echo Python not found. Attempting to install Python 3.14... echo. :: Try winget first (Windows 10/11) set "INSTALL_SUCCESS=0" winget --version >nul 2>&1 if errorlevel 1 goto :try_direct_download echo Installing Python via winget... winget install Python.Python.3.14 --silent --accept-package-agreements --accept-source-agreements if errorlevel 1 ( echo [WARNING] winget install failed, trying direct download... goto :try_direct_download ) set "INSTALL_SUCCESS=1" goto :check_installed :try_direct_download :: Fallback: download installer directly echo Downloading Python installer... set "PYTHON_INSTALLER=%TEMP%\python-installer.exe" powershell -Command "Invoke-WebRequest -Uri 'https://www.python.org/ftp/python/3.14.0/python-3.14.0-amd64.exe' -OutFile '%PYTHON_INSTALLER%'" if not exist "%PYTHON_INSTALLER%" ( echo [ERROR] Failed to download Python installer. echo Please install Python 3.10+ manually from https://python.org pause exit /b 1 ) echo Installing Python (this may take a minute)... "%PYTHON_INSTALLER%" /quiet InstallAllUsers=0 PrependPath=0 Include_launcher=1 if errorlevel 1 ( echo [ERROR] Python installation failed. echo Please install Python 3.10+ manually from https://python.org del "%PYTHON_INSTALLER%" >nul 2>&1 pause exit /b 1 ) del "%PYTHON_INSTALLER%" >nul 2>&1 set "INSTALL_SUCCESS=1" :check_installed :: Re-check for Python after installation call :find_python if defined PYTHON ( echo [OK] Python installed successfully goto :python_found ) echo [ERROR] Python installation completed but executable not found. echo Please install Python 3.10+ manually from https://python.org pause exit /b 1 :python_found :: Get Python version for /f "tokens=2" %%i in ('"%PYTHON%" --version 2^>^&1') do set PYVER=%%i echo [OK] Python %PYVER% found :: Install cq-tdm with pip echo. echo Installing CQ TDM... "%PYTHON%" -m pip install --upgrade cq-tdm if errorlevel 1 ( echo [ERROR] Failed to install CQ TDM pause exit /b 1 ) echo [OK] CQ TDM installed :: Find the installed script location set "SCRIPT_PATH=" :: Use Python to find the Scripts directory (most reliable) for /f "delims=" %%i in ('"%PYTHON%" -c "import sysconfig; print(sysconfig.get_path('scripts'))"') do set "SCRIPTS_DIR=%%i" echo Looking for executable in: %SCRIPTS_DIR% if exist "%SCRIPTS_DIR%\cq-tdm-gui.exe" ( set "SCRIPT_PATH=%SCRIPTS_DIR%\cq-tdm-gui.exe" ) if not defined SCRIPT_PATH ( :: Try 'where' in case it's in PATH for /f "delims=" %%i in ('where cq-tdm-gui.exe 2^>nul') do ( if not defined SCRIPT_PATH set "SCRIPT_PATH=%%i" ) ) if not defined SCRIPT_PATH ( echo [WARNING] Could not find cq-tdm-gui.exe automatically. echo Shortcuts will not be created. echo You can still run 'cq-tdm-gui' from the command line. goto :skip_shortcuts ) echo [OK] Executable: %SCRIPT_PATH% :: Download icon from GitHub echo. echo Downloading icon... set ICON_DIR=%LOCALAPPDATA%\CQ TDM set ICON_PATH=%ICON_DIR%\icon.ico if not exist "%ICON_DIR%" mkdir "%ICON_DIR%" powershell -Command "Invoke-WebRequest -Uri 'https://raw.githubusercontent.com/lammour/cq-tdm/main/src/cq_tdm/assets/icon.ico' -OutFile '%ICON_PATH%'" >nul 2>&1 if exist "%ICON_PATH%" ( echo [OK] Icon downloaded ) else ( echo [NOTE] Could not download icon, using default set ICON_PATH=%SCRIPT_PATH% ) :: Create Start Menu shortcut echo. echo Creating Start Menu shortcut... set STARTMENU=%APPDATA%\Microsoft\Windows\Start Menu\Programs set SHORTCUT=%STARTMENU%\CQ TDM.lnk :: Create shortcut using PowerShell powershell -Command "$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut('%SHORTCUT%'); $s.TargetPath = '%SCRIPT_PATH%'; $s.WorkingDirectory = '%USERPROFILE%'; $s.IconLocation = '%ICON_PATH%'; $s.Description = 'CT Scanner Internal Quality Control Software'; $s.Save()" if exist "%SHORTCUT%" ( echo [OK] Start Menu shortcut created ) else ( echo [WARNING] Could not create shortcut ) :: Handle Desktop shortcut set DESKTOP_SHORTCUT=%USERPROFILE%\Desktop\CQ TDM.lnk if exist "%DESKTOP_SHORTCUT%" ( :: Update existing shortcut (handles upgrades from older versions) echo Updating existing Desktop shortcut... powershell -Command "$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut('%DESKTOP_SHORTCUT%'); $s.TargetPath = '%SCRIPT_PATH%'; $s.WorkingDirectory = '%USERPROFILE%'; $s.IconLocation = '%ICON_PATH%'; $s.Description = 'CT Scanner Internal Quality Control Software'; $s.Save()" echo [OK] Desktop shortcut updated ) else ( :: Offer to create new shortcut echo. set /p DESKTOP_CHOICE="Create Desktop shortcut? (Y/N): " if /i "!DESKTOP_CHOICE!"=="Y" ( powershell -Command "$ws = New-Object -ComObject WScript.Shell; $s = $ws.CreateShortcut('%DESKTOP_SHORTCUT%'); $s.TargetPath = '%SCRIPT_PATH%'; $s.WorkingDirectory = '%USERPROFILE%'; $s.IconLocation = '%ICON_PATH%'; $s.Description = 'CT Scanner Internal Quality Control Software'; $s.Save()" echo [OK] Desktop shortcut created ) ) :skip_shortcuts echo. echo ======================================== echo Installation complete! echo ======================================== echo. echo You can now: echo - Find "CQ TDM" in your Start Menu echo - Run "cq-tdm-gui" from the command line (or "cq-tdm" for console mode) echo. echo To uninstall later: pip uninstall cq-tdm echo. pause goto :eof :: Subroutine to find Python in common locations :find_python set "PYTHON=" if exist "%LOCALAPPDATA%\Programs\Python\Python314\python.exe" ( set "PYTHON=%LOCALAPPDATA%\Programs\Python\Python314\python.exe" goto :eof ) if exist "%LOCALAPPDATA%\Programs\Python\Python313\python.exe" ( set "PYTHON=%LOCALAPPDATA%\Programs\Python\Python313\python.exe" goto :eof ) if exist "%LOCALAPPDATA%\Programs\Python\Python312\python.exe" ( set "PYTHON=%LOCALAPPDATA%\Programs\Python\Python312\python.exe" goto :eof ) if exist "%LOCALAPPDATA%\Programs\Python\Python311\python.exe" ( set "PYTHON=%LOCALAPPDATA%\Programs\Python\Python311\python.exe" goto :eof ) if exist "%LOCALAPPDATA%\Programs\Python\Python310\python.exe" ( set "PYTHON=%LOCALAPPDATA%\Programs\Python\Python310\python.exe" goto :eof ) if exist "C:\Program Files\Python314\python.exe" ( set "PYTHON=C:\Program Files\Python314\python.exe" goto :eof ) if exist "C:\Program Files\Python313\python.exe" ( set "PYTHON=C:\Program Files\Python313\python.exe" goto :eof ) if exist "C:\Program Files\Python312\python.exe" ( set "PYTHON=C:\Program Files\Python312\python.exe" goto :eof ) if exist "C:\Program Files\Python311\python.exe" ( set "PYTHON=C:\Program Files\Python311\python.exe" goto :eof ) if exist "C:\Program Files\Python310\python.exe" ( set "PYTHON=C:\Program Files\Python310\python.exe" goto :eof ) goto :eof