Files
barcode_reader_pc/server/run.bat
T

115 lines
3.2 KiB
Batchfile

@echo off
setlocal EnableExtensions
REM Script di avvio per Windows
chcp 65001 >nul 2>&1
set "PYTHONUTF8=1"
set "PYTHONIOENCODING=utf-8"
pushd "%~dp0" >nul 2>&1
if errorlevel 1 (
echo [!] Impossibile accedere alla directory dello script: %~dp0
pause
exit /b 1
)
set "PY_CMD="
call :try_python py -3
if not defined PY_CMD call :try_python python
if not defined PY_CMD call :try_python python3
if not defined PY_CMD (
echo.
echo [!] Python 3.9 o superiore ^(con modulo venv^) non trovato.
echo Assicurati di aver installato Python da https://www.python.org/downloads/windows/
echo oppure dal Microsoft Store, e verifica con: py -3 --version
echo.
popd
pause
exit /b 1
)
set "VENV_DIR=venv"
if exist "venv\bin" (
if not exist "venv\Scripts\python.exe" (
echo [!] Rilevato ambiente virtuale Unix/Linux in "venv". Uso "venv_win" per Windows.
set "VENV_DIR=venv_win"
)
)
set "VENV_PY=%VENV_DIR%\Scripts\python.exe"
set "VENV_PYW=%VENV_DIR%\Scripts\pythonw.exe"
if not exist "%VENV_PY%" (
echo [+] Creazione ambiente virtuale Python in "%VENV_DIR%"...
%PY_CMD% -m venv "%VENV_DIR%"
if errorlevel 1 (
echo [!] Errore durante la creazione dell'ambiente virtuale Python.
popd
pause
exit /b 1
)
)
"%VENV_PY%" -c "import aiohttp, pynput, pyperclip, qrcode, pystray, PIL" >nul 2>&1
if errorlevel 1 (
echo [+] Installazione dipendenze da requirements.txt...
"%VENV_PY%" -m pip install --disable-pip-version-check -q -r requirements.txt
if errorlevel 1 (
echo [!] Errore durante l'installazione delle dipendenze da requirements.txt.
popd
pause
exit /b 1
)
)
set "FORCE_CONSOLE=0"
for %%A in (%*) do (
if /i "%%~A"=="--cli" set "FORCE_CONSOLE=1"
if /i "%%~A"=="--headless" set "FORCE_CONSOLE=1"
if /i "%%~A"=="--no-gui" set "FORCE_CONSOLE=1"
if /i "%%~A"=="-h" set "FORCE_CONSOLE=1"
if /i "%%~A"=="--help" set "FORCE_CONSOLE=1"
)
if "%FORCE_CONSOLE%"=="0" (
"%VENV_PY%" -c "import tkinter" >nul 2>&1
if errorlevel 1 (
echo ------------------------------------------------------------------
echo [!] ATTENZIONE: Tkinter non risulta installato in questo Python.
echo L'applicazione fara' fallback sulla modalita' terminale ^(CLI^).
echo Per avere la GUI e la Tray Icon, reinstalla Python includendo
echo l'opzione "tcl/tk and IDLE".
echo ------------------------------------------------------------------
set "FORCE_CONSOLE=1"
)
)
if "%FORCE_CONSOLE%"=="0" (
if exist "%VENV_PYW%" (
start "" "%VENV_PYW%" main.py %*
popd
exit /b 0
)
echo [!] pythonw.exe non trovato in "%VENV_DIR%\Scripts": avvio con console aperta.
)
"%VENV_PY%" main.py %*
set "APP_EXIT=%ERRORLEVEL%"
popd
if not "%APP_EXIT%"=="0" (
echo.
echo [!] Il server e' terminato con codice %APP_EXIT%.
)
pause
exit /b %APP_EXIT%
:try_python
set "CANDIDATE=%~1"
if not "%~2"=="" set "CANDIDATE=%~1 %~2"
where %~1 >nul 2>&1
if errorlevel 1 goto :eof
%CANDIDATE% -c "import sys, venv; raise SystemExit(0 if sys.version_info >= (3, 9) else 1)" >nul 2>&1
if not errorlevel 1 set "PY_CMD=%CANDIDATE%"
goto :eof