236 lines
8.1 KiB
Batchfile
236 lines
8.1 KiB
Batchfile
@echo off
|
|
setlocal EnableExtensions
|
|
cd /d "%~dp0"
|
|
|
|
set "NODE_EXE=%~dp0Zcbot.WindowsNode.exe"
|
|
set "NODE_DATA_ROOT=%ZCBOT_WINDOWS_NODE_DATA_DIR%"
|
|
if not defined NODE_DATA_ROOT (
|
|
for /f "tokens=2,*" %%A in ('reg.exe query "HKCU\Software\Zcbot\WindowsNode" /v DataRoot 2^>nul ^| findstr.exe /I /C:"DataRoot"') do set "NODE_DATA_ROOT=%%B"
|
|
)
|
|
if not defined NODE_DATA_ROOT set "NODE_DATA_ROOT=%ProgramData%\Zcbot\WindowsNode"
|
|
set "ORIGIN_REQUIREMENTS=%~dp0adapters\origin.plot@v2\requirements.txt"
|
|
set "ORIGIN_RUNTIME_DIR=%NODE_DATA_ROOT%\runtimes\origin"
|
|
set "ORIGIN_RUNTIME_PYTHON=%ORIGIN_RUNTIME_DIR%\Scripts\python.exe"
|
|
set "ANSYS_REQUIREMENTS=%~dp0adapters\ansys.mechanical.static_structural@v2\requirements.txt"
|
|
set "ANSYS_RUNTIME_DIR=%NODE_DATA_ROOT%\runtimes\ansys"
|
|
set "ANSYS_RUNTIME_PYTHON=%ANSYS_RUNTIME_DIR%\Scripts\python.exe"
|
|
set "BLENDER_REQUIREMENTS=%~dp0adapters\blender.scene.author@v1\requirements.txt"
|
|
set "BLENDER_RUNTIME_DIR=%NODE_DATA_ROOT%\runtimes\blender"
|
|
set "BLENDER_RUNTIME_PYTHON=%BLENDER_RUNTIME_DIR%\Scripts\python.exe"
|
|
if not defined ZCBOT_PIP_INDEX_URL set "ZCBOT_PIP_INDEX_URL=https://pypi.tuna.tsinghua.edu.cn/simple/"
|
|
|
|
echo [INFO] Installing zcbot Windows Node...
|
|
echo [INFO] Data root: "%NODE_DATA_ROOT%"
|
|
|
|
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_ansys
|
|
)
|
|
|
|
echo [INFO] Origin/OriginPro detected.
|
|
if not exist "%ORIGIN_REQUIREMENTS%" (
|
|
echo [ERR] Origin worker requirements are missing: %ORIGIN_REQUIREMENTS%
|
|
goto :failed
|
|
)
|
|
|
|
if not exist "%ORIGIN_RUNTIME_PYTHON%" (
|
|
echo [INFO] Creating Origin Python runtime...
|
|
call :create_python_runtime "%ORIGIN_RUNTIME_DIR%" "%~1"
|
|
if errorlevel 1 (
|
|
echo [ERR] Failed to create the Origin Python runtime.
|
|
goto :failed
|
|
)
|
|
)
|
|
if not exist "%ORIGIN_RUNTIME_PYTHON%" (
|
|
echo [ERR] Python venv did not create its interpreter: %ORIGIN_RUNTIME_PYTHON%
|
|
goto :failed
|
|
)
|
|
|
|
"%ORIGIN_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: %ORIGIN_RUNTIME_PYTHON%
|
|
goto :failed
|
|
)
|
|
|
|
echo [INFO] Installing Origin worker dependencies...
|
|
"%ORIGIN_RUNTIME_PYTHON%" -m pip install --index-url "%ZCBOT_PIP_INDEX_URL%" --requirement "%ORIGIN_REQUIREMENTS%"
|
|
if errorlevel 1 (
|
|
echo [ERR] Failed to install the Origin worker dependencies.
|
|
goto :failed
|
|
)
|
|
"%ORIGIN_RUNTIME_PYTHON%" -c "import originpro, openpyxl, numpy, pymupdf; 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: %ORIGIN_RUNTIME_PYTHON%
|
|
|
|
:install_ansys
|
|
call :detect_ansys_242
|
|
if errorlevel 1 (
|
|
echo [WARN] ANSYS Mechanical 2024 R2 was not detected; skipped the ANSYS runtime.
|
|
goto :install_blender
|
|
)
|
|
|
|
echo [INFO] ANSYS Mechanical 2024 R2 detected.
|
|
if not exist "%ANSYS_REQUIREMENTS%" (
|
|
echo [ERR] ANSYS worker requirements are missing: %ANSYS_REQUIREMENTS%
|
|
goto :failed
|
|
)
|
|
if not exist "%ANSYS_RUNTIME_PYTHON%" (
|
|
echo [INFO] Creating ANSYS Python runtime...
|
|
call :create_python_runtime "%ANSYS_RUNTIME_DIR%" "%~1"
|
|
if errorlevel 1 (
|
|
echo [ERR] Failed to create the ANSYS Python runtime.
|
|
goto :failed
|
|
)
|
|
)
|
|
if not exist "%ANSYS_RUNTIME_PYTHON%" (
|
|
echo [ERR] Python venv did not create its interpreter: %ANSYS_RUNTIME_PYTHON%
|
|
goto :failed
|
|
)
|
|
"%ANSYS_RUNTIME_PYTHON%" -c "import sys; raise SystemExit(0 if sys.version_info[:2] == (3, 12) else 1)"
|
|
if errorlevel 1 (
|
|
echo [ERR] Existing ANSYS runtime is not Python 3.12: %ANSYS_RUNTIME_PYTHON%
|
|
goto :failed
|
|
)
|
|
echo [INFO] Installing ANSYS worker dependencies...
|
|
"%ANSYS_RUNTIME_PYTHON%" -m pip install --index-url "%ZCBOT_PIP_INDEX_URL%" --requirement "%ANSYS_REQUIREMENTS%"
|
|
if errorlevel 1 (
|
|
echo [ERR] Failed to install the ANSYS worker dependencies.
|
|
goto :failed
|
|
)
|
|
"%ANSYS_RUNTIME_PYTHON%" -c "from ansys.mechanical.core import App; print('[OK] ANSYS worker Python packages are available.')"
|
|
if errorlevel 1 (
|
|
echo [ERR] ANSYS runtime import verification failed.
|
|
goto :failed
|
|
)
|
|
echo [OK] ANSYS runtime installed: %ANSYS_RUNTIME_PYTHON%
|
|
|
|
:install_blender
|
|
call :detect_blender
|
|
if errorlevel 1 (
|
|
echo [WARN] Blender was not detected; skipped the Blender launcher runtime.
|
|
goto :install_startup
|
|
)
|
|
|
|
echo [INFO] Blender detected.
|
|
if not exist "%BLENDER_REQUIREMENTS%" (
|
|
echo [ERR] Blender adapter requirements marker is missing: %BLENDER_REQUIREMENTS%
|
|
goto :failed
|
|
)
|
|
if not exist "%BLENDER_RUNTIME_PYTHON%" (
|
|
echo [INFO] Creating Blender launcher runtime...
|
|
call :create_python_runtime "%BLENDER_RUNTIME_DIR%" "%~1"
|
|
if errorlevel 1 (
|
|
echo [ERR] Failed to create the Blender launcher runtime.
|
|
goto :failed
|
|
)
|
|
)
|
|
if not exist "%BLENDER_RUNTIME_PYTHON%" (
|
|
echo [ERR] Python venv did not create its interpreter: %BLENDER_RUNTIME_PYTHON%
|
|
goto :failed
|
|
)
|
|
"%BLENDER_RUNTIME_PYTHON%" -c "import sys; raise SystemExit(0 if sys.version_info[:2] == (3, 12) else 1)"
|
|
if errorlevel 1 (
|
|
echo [ERR] Existing Blender launcher runtime is not Python 3.12: %BLENDER_RUNTIME_PYTHON%
|
|
goto :failed
|
|
)
|
|
echo [OK] Blender launcher runtime installed: %BLENDER_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
|
|
|
|
:detect_ansys_242
|
|
if defined AWP_ROOT242 if exist "%AWP_ROOT242%\aisol\bin\winx64\AnsysWBU.exe" exit /b 0
|
|
if exist "C:\Program Files\ANSYS Inc\v242\aisol\bin\winx64\AnsysWBU.exe" exit /b 0
|
|
exit /b 1
|
|
|
|
:detect_blender
|
|
if defined ZCBOT_BLENDER_EXE if exist "%ZCBOT_BLENDER_EXE%" exit /b 0
|
|
where.exe blender.exe >nul 2>&1
|
|
if not errorlevel 1 exit /b 0
|
|
for /d %%D in ("%ProgramFiles%\Blender Foundation\Blender *") do (
|
|
if exist "%%~fD\blender.exe" exit /b 0
|
|
)
|
|
exit /b 1
|
|
|
|
:create_python_runtime
|
|
if not "%~2"=="" (
|
|
if not exist "%~2" (
|
|
echo [ERR] Python executable was not found: %~2
|
|
exit /b 1
|
|
)
|
|
"%~2" -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: %~2
|
|
exit /b 1
|
|
)
|
|
echo [INFO] Using Python 3.12: %~2
|
|
"%~2" -m venv "%~1"
|
|
exit /b %ERRORLEVEL%
|
|
)
|
|
|
|
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 (
|
|
echo [INFO] Using Python 3.12 through py.exe.
|
|
py.exe -3.12 -m venv "%~1"
|
|
exit /b %ERRORLEVEL%
|
|
)
|
|
)
|
|
|
|
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 (
|
|
echo [INFO] Using Python 3.12 from PATH.
|
|
python.exe -m venv "%~1"
|
|
exit /b %ERRORLEVEL%
|
|
)
|
|
)
|
|
|
|
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
|
|
|
|
: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
|