mirror of
https://github.com/Flowseal/zapret-discord-youtube.git
synced 2026-10-21 02:58:44 +00:00
Исправление завершения тестирования (#17329)
This commit is contained in:
1 parent
ffec6c8c22
commit
a1552cb1a9
1 file changed
+38
-13
+38
-13
@@ -49,12 +49,28 @@ function Set-IpsetMode {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Pause that tolerates stray keystrokes and non-interactive hosts.
|
||||||
|
# Tests run for minutes, so any key pressed meanwhile stays in the console
|
||||||
|
# input buffer and would be swallowed instantly by a bare ReadKey.
|
||||||
|
function Wait-AnyKey {
|
||||||
|
param([string]$message = "Press any key to close...")
|
||||||
|
Write-Host $message -ForegroundColor Yellow
|
||||||
|
try {
|
||||||
|
while ([System.Console]::KeyAvailable) { [void][System.Console]::ReadKey($true) }
|
||||||
|
[void][System.Console]::ReadKey($true)
|
||||||
|
} catch {
|
||||||
|
# No interactive console (stdin redirected): ReadKey throws here
|
||||||
|
[void](Read-Host)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
trap {
|
trap {
|
||||||
Write-Host "[ERROR] Script interrupted. Restoring ipset..." -ForegroundColor Red
|
Write-Host "[ERROR] Script interrupted. Restoring ipset..." -ForegroundColor Red
|
||||||
if ($originalIpsetStatus -and $originalIpsetStatus -ne "any") {
|
if ($originalIpsetStatus -and $originalIpsetStatus -ne "any") {
|
||||||
Set-IpsetMode -mode "restore"
|
Set-IpsetMode -mode "restore"
|
||||||
}
|
}
|
||||||
Remove-Item -Path $ipsetFlagFile -ErrorAction SilentlyContinue
|
Remove-Item -Path $ipsetFlagFile -ErrorAction SilentlyContinue
|
||||||
|
Wait-AnyKey
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -382,8 +398,7 @@ if (Test-ZapretServiceConflict) {
|
|||||||
if ($hasErrors) {
|
if ($hasErrors) {
|
||||||
Write-Host ""
|
Write-Host ""
|
||||||
Write-Host "Fix the errors above and rerun." -ForegroundColor Yellow
|
Write-Host "Fix the errors above and rerun." -ForegroundColor Yellow
|
||||||
Write-Host "Press any key to exit..." -ForegroundColor Yellow
|
Wait-AnyKey -message "Press any key to exit..."
|
||||||
[void][System.Console]::ReadKey($true)
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -566,8 +581,7 @@ if ($testType -eq 'standard') {
|
|||||||
# Ensure we have configs to run
|
# Ensure we have configs to run
|
||||||
if (-not $batFiles -or $batFiles.Count -eq 0) {
|
if (-not $batFiles -or $batFiles.Count -eq 0) {
|
||||||
Write-Host "[ERROR] No general*.bat files found" -ForegroundColor Red
|
Write-Host "[ERROR] No general*.bat files found" -ForegroundColor Red
|
||||||
Write-Host "Press any key to exit..." -ForegroundColor Yellow
|
Wait-AnyKey -message "Press any key to exit..."
|
||||||
[void][System.Console]::ReadKey($true)
|
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -602,17 +616,29 @@ function Restore-WinwsSnapshot {
|
|||||||
if ($current -and $current -contains $p.CommandLine) { continue }
|
if ($current -and $current -contains $p.CommandLine) { continue }
|
||||||
|
|
||||||
$exe = $p.ExecutablePath
|
$exe = $p.ExecutablePath
|
||||||
$processArgs = ""
|
|
||||||
if ($p.CommandLine) {
|
# Split the program token off the command line to recover the arguments.
|
||||||
$quotedExe = '"' + $exe + '"'
|
# A quoted token is unambiguous; an unquoted one may contain spaces, so
|
||||||
if ($p.CommandLine.StartsWith($quotedExe)) {
|
# fall back to the known executable path before guessing at whitespace.
|
||||||
$processArgs = $p.CommandLine.Substring($quotedExe.Length).Trim()
|
$processArgs = $null
|
||||||
} elseif ($p.CommandLine.StartsWith($exe)) {
|
if ($p.CommandLine -match '^\s*"[^"]*"\s*(.*)$') {
|
||||||
|
$processArgs = $matches[1].Trim()
|
||||||
|
} elseif ($p.CommandLine -and $p.CommandLine.StartsWith($exe, [StringComparison]::OrdinalIgnoreCase)) {
|
||||||
$processArgs = $p.CommandLine.Substring($exe.Length).Trim()
|
$processArgs = $p.CommandLine.Substring($exe.Length).Trim()
|
||||||
}
|
} elseif ($p.CommandLine -match '^\s*\S+\s*(.*)$') {
|
||||||
|
$processArgs = $matches[1].Trim()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (-not $processArgs) {
|
||||||
|
Write-Host "[WARN] Could not read arguments of previous winws instance ($exe); skipping restore." -ForegroundColor Yellow
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
Start-Process -FilePath $exe -ArgumentList $processArgs -WorkingDirectory (Split-Path $exe -Parent) -WindowStyle Minimized | Out-Null
|
Start-Process -FilePath $exe -ArgumentList $processArgs -WorkingDirectory (Split-Path $exe -Parent) -WindowStyle Minimized | Out-Null
|
||||||
|
} catch {
|
||||||
|
Write-Host "[WARN] Failed to restore previous winws instance ($exe): $_" -ForegroundColor Yellow
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -989,7 +1015,6 @@ try {
|
|||||||
Remove-Item -Path $ipsetFlagFile -ErrorAction SilentlyContinue
|
Remove-Item -Path $ipsetFlagFile -ErrorAction SilentlyContinue
|
||||||
}
|
}
|
||||||
|
|
||||||
Write-Host "Press any key to close..." -ForegroundColor Yellow
|
Wait-AnyKey
|
||||||
[void][System.Console]::ReadKey($true)
|
|
||||||
exit
|
exit
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user