Add AOI upload search and resilient downloads
This commit is contained in:
+33
-1
@@ -21,6 +21,29 @@ function Get-RunningProcess {
|
||||
}
|
||||
}
|
||||
|
||||
function Get-ListeningProcessId {
|
||||
param([int]$Port)
|
||||
|
||||
try {
|
||||
$connection = Get-NetTCPConnection -LocalPort $Port -State Listen -ErrorAction Stop |
|
||||
Select-Object -First 1
|
||||
if ($connection) {
|
||||
return [int]$connection.OwningProcess
|
||||
}
|
||||
} catch {
|
||||
}
|
||||
|
||||
$lines = netstat -ano -p tcp | Select-String "LISTENING"
|
||||
foreach ($line in $lines) {
|
||||
$parts = ($line.Line.Trim() -split "\s+")
|
||||
if ($parts.Count -ge 5 -and $parts[1].EndsWith(":$Port")) {
|
||||
return [int]$parts[4]
|
||||
}
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
$projectRoot = Split-Path -Parent $PSCommandPath
|
||||
$statePath = Join-Path $projectRoot ".s1dl\web-ui-state.json"
|
||||
|
||||
@@ -36,7 +59,16 @@ if ($process) {
|
||||
Write-Info "Stopping UI process $($process.Id)"
|
||||
Stop-Process -Id $process.Id -Force
|
||||
} else {
|
||||
Write-Info "Tracked process is not running."
|
||||
$listenerProcessId = 0
|
||||
if ($state.port) {
|
||||
$listenerProcessId = Get-ListeningProcessId -Port ([int]$state.port)
|
||||
}
|
||||
if ($listenerProcessId -gt 0) {
|
||||
Write-Info "Stopping listener process $listenerProcessId"
|
||||
Stop-Process -Id $listenerProcessId -Force
|
||||
} else {
|
||||
Write-Info "Tracked process is not running."
|
||||
}
|
||||
}
|
||||
|
||||
Remove-Item -LiteralPath $statePath -Force
|
||||
|
||||
Reference in New Issue
Block a user