83 lines
3.1 KiB
Batchfile
83 lines
3.1 KiB
Batchfile
@echo off
|
|
chcp 936 >nul
|
|
cd /d "%~dp0"
|
|
rem This file is intentionally ASCII-only. The previous GBK version was corrupted
|
|
rem when edited by a UTF-8 tool, so cmd tried to execute mojibake as a command.
|
|
rem Python discovery order: project .venv (exe or cmd shim), then py -3, then python.
|
|
rem The Windows Store python placeholder exits silently (exit 49), so probe each candidate.
|
|
rem [!] Every %PY% invocation must use call: PY may be a .cmd shim (batch file).
|
|
rem Without call, control transfers and never returns; the bat ends silently.
|
|
set "PY="
|
|
if exist ".venv\Scripts\python.exe" set "PY=.venv\Scripts\python.exe"
|
|
if not defined PY if exist ".venv\Scripts\python.cmd" set "PY=.venv\Scripts\python.cmd"
|
|
if defined PY goto HAVEPY
|
|
py -3 -c "import sys" >nul 2>&1
|
|
if not errorlevel 1 set "PY=py -3"
|
|
if not defined PY (
|
|
python -c "import sys" >nul 2>&1
|
|
if not errorlevel 1 set "PY=python"
|
|
)
|
|
if not defined PY goto NOPY
|
|
:HAVEPY
|
|
if not exist "launch.py" goto NOFILE
|
|
|
|
rem ---- dependency precheck (missing cryptography blocks startup on a new machine) ----
|
|
rem Probe all five dependencies; if any is missing, offer a one-key install.
|
|
call %PY% -c "import cryptography, httpx, openpyxl, xlrd, webview" >nul 2>&1
|
|
if not errorlevel 1 goto DEPOK
|
|
echo.
|
|
echo Missing Python dependencies. First deployment needs a one-time online install.
|
|
set "GO="
|
|
set /p GO=Install now? Press Enter to install, type N to exit:
|
|
if /i "%GO%"=="N" goto NODIST
|
|
echo Installing dependencies: %PY% -m pip install -r requirements.txt ...
|
|
call %PY% -m pip install -r requirements.txt
|
|
if errorlevel 1 goto PIPFAIL
|
|
echo Dependencies installed.
|
|
:DEPOK
|
|
echo Starting Pricing Review, please wait...
|
|
|
|
rem ---- Clear a stale instance holding port 8365 before launching ----
|
|
rem WARNING: this kills whatever is LISTENING on 8365, including an open app window.
|
|
set "FOUND8365="
|
|
for /f "tokens=5" %%a in ('netstat -ano ^| findstr "LISTENING" ^| findstr ":8365 "') do (
|
|
if not defined FOUND8365 (
|
|
echo [cleanup] port 8365 held by PID %%a, terminating it before restart...
|
|
taskkill /PID %%a /F >nul 2>&1
|
|
set "FOUND8365=1"
|
|
)
|
|
)
|
|
if defined FOUND8365 %SystemRoot%\System32\ping.exe -n 2 127.0.0.1 >nul
|
|
call %PY% launch.py
|
|
if errorlevel 1 goto FAIL
|
|
goto END
|
|
:NODIST
|
|
echo Cancelled. You can install later with: %PY% -m pip install -r requirements.txt
|
|
pause
|
|
goto END
|
|
:PIPFAIL
|
|
echo.
|
|
echo Dependency installation failed. Common causes: no network, or Python too old.
|
|
echo Run manually to see details: %PY% -m pip install -r requirements.txt
|
|
pause
|
|
goto END
|
|
:FAIL
|
|
echo.
|
|
echo Startup failed. Common causes:
|
|
echo 1. ModuleNotFoundError (missing dependency) - run: %PY% -m pip install -r requirements.txt
|
|
rem 2026-10-20: the license/activation hint was temporarily removed at owner request (decision 125).
|
|
echo Please send a screenshot of the error above.
|
|
pause
|
|
goto END
|
|
:NOPY
|
|
echo No usable Python found. This app requires Python 3.11 or newer.
|
|
echo Install from https://www.python.org/downloads/ and check "Add python.exe to PATH",
|
|
echo then double-click this file again.
|
|
pause
|
|
goto END
|
|
:NOFILE
|
|
echo launch.py not found.
|
|
echo Make sure you are running this file from the correct folder.
|
|
pause
|
|
:END
|