@echo off setlocal EnableExtensions cd /d "%~dp0" set "NODE_EXE=%~dp0Zcbot.WindowsNode.exe" set "REQUIREMENTS=%~dp0origin-worker\requirements.txt" set "RUNTIME_DIR=%ProgramData%\Zcbot\WindowsNode\runtimes\origin" set "RUNTIME_PYTHON=%RUNTIME_DIR%\Scripts\python.exe" set "PYTHON_EXE=" set "PYTHON_ARGS=" echo [INFO] Installing zcbot Windows Node... if not exist "%NODE_EXE%" ( echo [ERR] Zcbot.WindowsNode.exe was not found beside this installer. goto :failed ) call :detect_origin if errorlevel 1 ( echo [WARN] Origin/OriginPro was not detected; skipped the Origin runtime. goto :install_startup ) echo [INFO] Origin/OriginPro detected. if not exist "%REQUIREMENTS%" ( echo [ERR] Origin worker requirements are missing: %REQUIREMENTS% goto :failed ) call :find_python "%~1" if errorlevel 1 goto :failed if not exist "%RUNTIME_PYTHON%" ( echo [INFO] Creating Origin Python runtime... call :run_python -m venv "%RUNTIME_DIR%" if errorlevel 1 ( echo [ERR] Failed to create the Origin Python runtime. goto :failed ) ) if not exist "%RUNTIME_PYTHON%" ( echo [ERR] Python venv did not create its interpreter: %RUNTIME_PYTHON% goto :failed ) "%RUNTIME_PYTHON%" -c "import sys; raise SystemExit(0 if sys.version_info[:2] == (3, 12) else 1)" if errorlevel 1 ( echo [ERR] Existing Origin runtime is not Python 3.12: %RUNTIME_PYTHON% goto :failed ) echo [INFO] Installing Origin worker dependencies... "%RUNTIME_PYTHON%" -m pip install --requirement "%REQUIREMENTS%" if errorlevel 1 ( echo [ERR] Failed to install the Origin worker dependencies. goto :failed ) "%RUNTIME_PYTHON%" -c "import originpro, openpyxl, numpy; print('[OK] Origin worker Python packages are available.')" if errorlevel 1 ( echo [ERR] Origin runtime import verification failed. goto :failed ) echo [OK] Origin runtime installed: %RUNTIME_PYTHON% :install_startup echo [INFO] Registering startup task for %USERDOMAIN%\%USERNAME%... schtasks.exe /Create /TN "Zcbot Windows Node" /SC ONLOGON /RU "%USERDOMAIN%\%USERNAME%" /RL LIMITED /IT /TR "\"%NODE_EXE%\"" /F if errorlevel 1 ( echo [ERR] Failed to register the Windows Node startup task. goto :failed ) echo [OK] Windows Node installation completed. echo [INFO] Start Zcbot.WindowsNode.exe to register or connect the node. goto :finish_ok :detect_origin reg.exe query "HKCR\Origin.ApplicationSI\CLSID" >nul 2>&1 if not errorlevel 1 exit /b 0 reg.exe query "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "OriginLab" /d >nul 2>&1 if not errorlevel 1 exit /b 0 reg.exe query "HKLM\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "OriginLab" /d >nul 2>&1 if not errorlevel 1 exit /b 0 reg.exe query "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall" /s /f "OriginLab" /d >nul 2>&1 if not errorlevel 1 exit /b 0 exit /b 1 :find_python if not "%~1"=="" ( if not exist "%~1" ( echo [ERR] Python executable was not found: %~1 exit /b 1 ) "%~1" -c "import sys; raise SystemExit(0 if sys.version_info[:2] == (3, 12) else 1)" if errorlevel 1 ( echo [ERR] The specified Python must be Python 3.12: %~1 exit /b 1 ) set "PYTHON_EXE=%~1" set "PYTHON_ARGS=" echo [INFO] Using Python 3.12: %~1 exit /b 0 ) where.exe py.exe >nul 2>&1 if not errorlevel 1 ( py.exe -3.12 -c "import sys; raise SystemExit(0 if sys.version_info[:2] == (3, 12) else 1)" >nul 2>&1 if not errorlevel 1 ( set "PYTHON_EXE=py.exe" set "PYTHON_ARGS=-3.12" echo [INFO] Using Python 3.12 through py.exe. exit /b 0 ) ) where.exe python.exe >nul 2>&1 if not errorlevel 1 ( python.exe -c "import sys; raise SystemExit(0 if sys.version_info[:2] == (3, 12) else 1)" >nul 2>&1 if not errorlevel 1 ( set "PYTHON_EXE=python.exe" set "PYTHON_ARGS=" echo [INFO] Using Python 3.12 from PATH. exit /b 0 ) ) echo [ERR] Python 3.12 was not found. echo [INFO] Add Python 3.12 to PATH or run: install-windows-node.bat "C:\path\python.exe" exit /b 1 :run_python if defined PYTHON_ARGS ( "%PYTHON_EXE%" %PYTHON_ARGS% %* ) else ( "%PYTHON_EXE%" %* ) exit /b %ERRORLEVEL% :failed echo. echo [ERR] Installation failed. echo [INFO] Press any key to close this window. pause >nul exit /b 1 :finish_ok echo. echo [INFO] Press any key to close this window. pause >nul exit /b 0