diff --git a/scripts/explorer-media-rename.ps1 b/scripts/explorer-media-rename.ps1 index f2228b6..419f5d5 100644 --- a/scripts/explorer-media-rename.ps1 +++ b/scripts/explorer-media-rename.ps1 @@ -62,7 +62,8 @@ $ActionPlan = @{ 'archive' = @{ Runner = 'scene-marshal.ps1'; Extra = @('archive') } 'variety' = @{ Runner = 'scene-marshal.ps1'; Extra = @('variety') } 'extract-subs' = @{ Runner = 'scene-marshal.ps1'; Extra = @('extract-subs') } - 'check' = @{ Runner = 'scene-marshal.ps1'; Extra = @('check') } + # 兼容性校验是纯只读(只出 preflight_report),不值得为它挡一次确认 + 'check' = @{ Runner = 'scene-marshal.ps1'; Extra = @('check', '--pass') } 'rename' = @{ Runner = 'scene-marshal.ps1'; Extra = @() } } @@ -216,6 +217,15 @@ function Test-WorkerAlive { return $false } +function Get-PendingQueueCount { + if (-not (Test-Path -LiteralPath $QueueFile)) { return 0 } + try { + return @(Get-Content -LiteralPath $QueueFile -Encoding utf8 | + Where-Object { $_.Trim() }).Count + } + catch { return 0 } +} + function Start-Worker { Start-Process -FilePath $PwshPath ` -ArgumentList @('-NoLogo', '-NoProfile', '-ExecutionPolicy', 'Bypass', @@ -310,9 +320,10 @@ function Invoke-Worker { Write-Host '📋 SceneMarshal 队列已启动' -ForegroundColor Cyan Write-Host '' - $done = 0 - $failed = 0 - $cancelled = 0 + $batches = 0 # 实际跑了几批(一次右键多选合批后算 1 批) + $okDirs = 0 # 下面三个按「目录」累加:一批 10 个目录成功就是 10 + $cancelDirs = 0 + $failDirs = 0 $summaryShown = $false $closeDeadline = $null @@ -383,19 +394,20 @@ function Invoke-Worker { Remove-Item -LiteralPath $CurrentFile -Force -ErrorAction SilentlyContinue } $cost = [int]((Get-Date) - $started).TotalSeconds + $batches++ if ($code -eq 0) { - $done++ + $okDirs += $targets.Count Write-Host (" ✅ 完成,用时 {0}s" -f $cost) -ForegroundColor Green Write-WorkerLog ("完成 {0}({1}s)" -f ($targets -join '; '), $cost) } elseif ($code -eq 2) { # 退出码 2 约定为「用户主动取消」,不算失败 - $cancelled++ + $cancelDirs += $targets.Count Write-Host (" ⏭ 已取消(未改动任何文件),用时 {0}s" -f $cost) -ForegroundColor DarkYellow Write-WorkerLog ("已取消 {0}" -f ($targets -join '; ')) } else { - $failed++ + $failDirs += $targets.Count Write-Host (" ⚠️ 失败(退出码 {0}),用时 {1}s" -f $code, $cost) -ForegroundColor Red Write-WorkerLog ("失败 {0}(code={1}, {2}s)" -f ($targets -join '; '), $code, $cost) } @@ -405,10 +417,13 @@ function Invoke-Worker { # 队列已空:只显示一次汇总,然后等 Esc / Enter 关窗 if (-not $summaryShown) { - Write-Host ('📊 本次共处理 {0} 项:成功 {1},取消 {2},失败 {3}' -f ` - ($done + $cancelled + $failed), $done, $cancelled, $failed) -ForegroundColor Cyan + $dirTotal = $okDirs + $cancelDirs + $failDirs + $batchNote = if ($batches -gt 1) { "($batches 批)" } else { '' } + Write-Host ('📊 本次共处理 {0} 个目录{1}:成功 {2},取消 {3},失败 {4}' -f ` + $dirTotal, $batchNote, $okDirs, $cancelDirs, $failDirs) -ForegroundColor Cyan Write-Host ' 按 Esc / Enter 关闭窗口;期间有新任务会接着处理(2 分钟无操作自动关闭)' -ForegroundColor DarkGray - Write-WorkerLog ("队列处理完毕:成功 {0},取消 {1},失败 {2}" -f $done, $cancelled, $failed) + Write-WorkerLog ("队列处理完毕:成功 {0} 个目录,取消 {1},失败 {2}({3} 批)" -f ` + $okDirs, $cancelDirs, $failDirs, $batches) $summaryShown = $true $closeDeadline = (Get-Date).AddSeconds(120) } @@ -469,8 +484,13 @@ if ($Enqueue) { exit 0 } $queued = Add-QueueItem $Action $targets - # 只有真的入队了才需要 worker;全部是重复项时不要白拉一个窗口 - if ($queued -and -not (Test-WorkerAlive)) { + $pendingCount = Get-PendingQueueCount + # 即使本次全是重复项,只要队列里还有积压且没有 worker,也要拉起 worker 清积压。 + # 否则 worker 在关窗/退出瞬间留下的条目会让后续同路径点击永远静默、连窗口都不开。 + if (-not (Test-WorkerAlive) -and ($queued -or $pendingCount -gt 0)) { + if (-not $queued -and $pendingCount -gt 0) { + Write-WorkerLog ("重复入队,但队列有 {0} 条积压;拉起 worker 清积压" -f $pendingCount) + } # 多选时 Explorer 会同时发起 N 个入队调用,这里必须串行化, # 否则每个调用都会在 worker 抢到锁之前各拉起一个窗口。 $spawnLock = Enter-FileLock $SpawnLock 8000