连接器修改

This commit is contained in:
tianmo committed 2026-09-05 22:21:52 +08:00
1 parent 26371ac7b4
commit 76d272b378
4 files changed
+110 -20

No files matched your search

+19 -8
View File
@@ -4,6 +4,7 @@ setlocal
set "PROJECT_DIR=%~dp0"
set "PID_FILE=%PROJECT_DIR%.run\spine-connector-windows.pid"
set "CONNECTOR_ENTRY=%PROJECT_DIR%connector\spine-connector.mjs"
set "CONNECTOR_PID="
if exist "%PID_FILE%" set /p CONNECTOR_PID=<"%PID_FILE%"
@@ -11,17 +12,27 @@ powershell -NoProfile -Command ^
"$pidValue=0; [void][int]::TryParse($env:CONNECTOR_PID,[ref]$pidValue);" ^
"$process=if($pidValue -gt 0){Get-CimInstance Win32_Process -Filter ('ProcessId = ' + $pidValue) -ErrorAction SilentlyContinue};" ^
"if($null -eq $process){$listener=Get-NetTCPConnection -LocalPort 27843 -State Listen -ErrorAction SilentlyContinue | Select-Object -First 1; if($listener){$process=Get-CimInstance Win32_Process -Filter ('ProcessId = ' + $listener.OwningProcess) -ErrorAction SilentlyContinue}};" ^
"if ($null -eq $process) { exit 2 };" ^
"$expected=(Join-Path $env:PROJECT_DIR 'connector\spine-connector.mjs');" ^
"if (($process.CommandLine -notlike ('*' + $expected + '*')) -and ($process.CommandLine -notlike '*connector/spine-connector.mjs*') -and ($process.CommandLine -notlike '*connector\spine-connector.mjs*')) { exit 3 };" ^
"Stop-Process -Id $process.ProcessId -Force"
"if($null -eq $process){exit 2};" ^
"$expected=$env:CONNECTOR_ENTRY;" ^
"if((-not $process.CommandLine) -or $process.CommandLine.IndexOf($expected,[StringComparison]::OrdinalIgnoreCase) -lt 0){exit 3};" ^
"Stop-Process -Id $process.ProcessId -Force -ErrorAction Stop"
set "STOP_RESULT=%ERRORLEVEL%"
del /q "%PID_FILE%" >nul 2>&1
if "%STOP_RESULT%"=="0" (
del /q "%PID_FILE%" >nul 2>&1
echo Spine粒子连接器已停止。
exit /b 0
)
if "%STOP_RESULT%"=="2" (
del /q "%PID_FILE%" >nul 2>&1
echo Spine粒子连接器已经停止。
exit /b 0
)
if "%STOP_RESULT%"=="3" (
echo 27843 端口对应的进程不是 Spine粒子连接器,为避免误关,本次未执行停止。
echo 27843 端口对应的进程不属于当前项目,为避免误关,本次未执行停止。
pause
exit /b 1
)
echo Spine粒子连接器已停止。
exit /b 0
echo 停止 Spine粒子连接器失败,请检查 PowerShell 权限或手动结束对应进程。
pause
exit /b 1