feat(menu): 右键菜单收敛为五项,支持多选一次确认与文件回溯剧集根

This commit is contained in:
ali
2026-11-21 21:09:29 +08:00
parent 1d880ba542
commit 2da1e643af
3 changed files with 378 additions and 50 deletions
+92 -14
View File
@@ -5,10 +5,11 @@
.DESCRIPTION
默认注册成「SceneMarshal ▸」级联子菜单,子项:
1. 重命名(自动) → auto
2. 归档… → media-archive(交互选分类)
3. 补外挂字幕(转码片源) → extract-subs
4. 入库前体检(只读) → check
1. 整理入库 → auto(预览确认 → 整理 → 单目录自动归档)
2. 归档入库 → archive(交互选分类)
3. 综艺整理 → variety(排集 → 特典放置)
4. 补外挂字幕 → extract-subs
5. 兼容性校验 → check(只读,出报告)
级联写法与 Windows 自带项(UpdateEncryptionSettingsWork)一致:
父键上写 ExtendedSubCommandsKey = 该键自身的 HKCR 相对路径,子项放在父键的 Shell\ 下。
@@ -17,10 +18,17 @@
HKCU\Software\Classes\Directory\shell\SceneMarshal (文件夹右键)
HKCU\Software\Classes\Directory\Background\shell\SceneMarshal (文件夹空白处右键)
HKCU\Software\Classes\SystemFileAssociations\.mkv\shell\SceneMarshal
... 同上 .mp4 / .avi(文件右键,取其所在目录)
... 同上 .mp4 / .avi(文件右键,自动回溯到剧集根目录)
.PARAMETER Flat
兜底模式:不级联,直接注册 4 个平级菜单项(名称带「SceneMarshal ▸ 」前缀)。
兜底模式:不级联,直接注册 5 个平级菜单项(名称带「SceneMarshal ▸ 」前缀)。
.PARAMETER Verify
只读自检:校验 5 处父键、自引用、子项文案、图标、命令里的 wscript/vbs/pwsh 是否存在。
不写注册表;退出码 0 全绿,1 有问题。
.PARAMETER Repair
等价于重新安装(先清理再注册)。
.EXAMPLE
.\install-explorer-menu.ps1
@@ -29,7 +37,9 @@
#>
[CmdletBinding()]
param(
[switch]$Flat
[switch]$Flat,
[switch]$Verify,
[switch]$Repair
)
$ErrorActionPreference = 'Stop'
@@ -63,12 +73,13 @@ function Get-ItemIcon([string]$name) {
}
# 级联子项:ExtendedSubCommandsKey 模式下 Explorer 取 MUIVerb 作为显示名
# Key 决定菜单排序(字典序),改文案不影响顺序;插新项才需要重排 01…NN
$items = @(
@{ Key = '01-rename'; Text = '媒体整理'; Action = 'rename'; Icon = (Get-ItemIcon 'rename.ico') },
@{ Key = '02-archive'; Text = '媒体归档'; Action = 'archive'; Icon = (Get-ItemIcon 'archive.ico') },
@{ Key = '01-rename'; Text = '整理入库'; Action = 'rename'; Icon = (Get-ItemIcon 'rename.ico') },
@{ Key = '02-archive'; Text = '归档入库'; Action = 'archive'; Icon = (Get-ItemIcon 'archive.ico') },
@{ Key = '03-variety'; Text = '综艺整理'; Action = 'variety'; Icon = (Get-ItemIcon 'variety.ico') },
@{ Key = '04-extract-subs'; Text = '补外挂字幕'; Action = 'extract-subs'; Icon = (Get-ItemIcon 'subtitle.ico') },
@{ Key = '05-check'; Text = '入库校验'; Action = 'check'; Icon = (Get-ItemIcon 'check.ico') }
@{ Key = '05-check'; Text = '兼容性校验'; Action = 'check'; Icon = (Get-ItemIcon 'check.ico') }
)
# Relative = ExtendedSubCommandsKey 的值(相对 HKEY_CLASSES_ROOT),同时用于定位注册表路径
@@ -80,18 +91,85 @@ $locations = @(
@{ Relative = 'SystemFileAssociations\.avi\shell\SceneMarshal'; Token = '%1' }
)
$vbsPath = $enqueueVbs
$wscriptPath = Join-Path $env:SystemRoot 'System32\wscript.exe'
function New-MenuCommand([string]$Action, [string]$Token) {
# 经 wscript 调 VBS:无控制台窗口,只把任务写进队列,
# 由唯一的 worker 窗口按顺序处理(多选时不会弹多个终端)
$vbs = Join-Path $PSScriptRoot 'scenemarshal-enqueue.vbs'
$wscript = Join-Path $env:SystemRoot 'System32\wscript.exe'
'"' + $wscript + '" //nologo "' + $vbs + '" ' + $Action + ' "' + $pwsh + '" "' + $Token + '"'
'"' + $wscriptPath + '" //nologo "' + $vbsPath + '" ' + $Action + ' "' + $pwsh + '" "' + $Token + '"'
}
function Get-RegPath([string]$relative) {
return "HKCU:\Software\Classes\$relative"
}
# ---------------------------------------------------------------- 自检(只读)
if ($Verify) {
$problems = New-Object System.Collections.Generic.List[string]
if (-not (Test-Path -LiteralPath $wscriptPath)) { $problems.Add("wscript 不存在: $wscriptPath") }
if (-not (Test-Path -LiteralPath $vbsPath)) { $problems.Add("入队 VBS 不存在: $vbsPath") }
if (-not (Test-Path -LiteralPath $pwsh)) { $problems.Add("pwsh 不存在: $pwsh") }
foreach ($loc in $locations) {
$parent = Get-RegPath $loc.Relative
if (-not (Test-Path -LiteralPath $parent)) {
$problems.Add("缺少父键: HKCU\Software\Classes\$($loc.Relative)")
continue
}
$props = Get-ItemProperty -LiteralPath $parent
if ($props.MUIVerb -ne $menuName) {
$problems.Add("$($loc.Relative): MUIVerb 应为「$menuName」,实际「$($props.MUIVerb)」")
}
if ($props.ExtendedSubCommandsKey -ne $loc.Relative) {
$problems.Add("$($loc.Relative): ExtendedSubCommandsKey 不是自引用($($props.ExtendedSubCommandsKey))")
}
if ($props.Icon -and -not (Test-Path -LiteralPath $props.Icon)) {
$problems.Add("$($loc.Relative): 父菜单图标不存在 $($props.Icon)")
}
foreach ($item in $items) {
$child = Join-Path (Join-Path $parent 'Shell') $item.Key
if (-not (Test-Path -LiteralPath $child)) {
$problems.Add("$($loc.Relative): 缺少子项 $($item.Key)")
continue
}
$cp = Get-ItemProperty -LiteralPath $child
if ($cp.MUIVerb -ne $item.Text) {
$problems.Add("$($loc.Relative)\$($item.Key): 文案应为「$($item.Text)」,实际「$($cp.MUIVerb)」")
}
if ($cp.Icon -and -not (Test-Path -LiteralPath $cp.Icon)) {
$problems.Add("$($loc.Relative)\$($item.Key): 图标不存在 $($cp.Icon)")
}
$cmd = (Get-ItemProperty -LiteralPath (Join-Path $child 'command')).'(default)'
if (-not $cmd) {
$problems.Add("$($loc.Relative)\$($item.Key): command 为空")
continue
}
# 仓库移盘 / 换 pwsh 安装后,写死的绝对路径会失效
foreach ($needle in @($wscriptPath, $vbsPath, $pwsh)) {
if ($cmd -notlike "*$needle*") {
$problems.Add("$($loc.Relative)\$($item.Key): command 未包含 $needle")
}
}
if ($cmd -notmatch ('\s' + [regex]::Escape($item.Action) + '\s')) {
$problems.Add("$($loc.Relative)\$($item.Key): command 里的动作不是 $($item.Action)")
}
}
}
if ($problems.Count) {
Write-Host ("✘ 菜单自检发现 {0} 个问题:" -f $problems.Count) -ForegroundColor Red
$problems | ForEach-Object { Write-Host " - $_" -ForegroundColor Red }
Write-Host '修复:.\install-explorer-menu.ps1 -Repair' -ForegroundColor Yellow
exit 1
}
Write-Host '✔ 菜单自检通过:5 处父键 / 自引用 / 子项文案与图标 / 命令路径均正常' -ForegroundColor Green
exit 0
}
if ($Repair) { Write-Host '▶ 重新安装(-Repair)' -ForegroundColor Cyan }
# ---------------------------------------------------------------- 清理旧结构
foreach ($loc in $locations) {
foreach ($name in @($menuName, 'SceneMarshalArchive')) {
@@ -116,7 +194,7 @@ foreach ($loc in $locations) {
if (-not (Test-Path -LiteralPath $parent)) { New-Item -Path $parent -Force | Out-Null }
if ($Flat) {
# 兜底:每个位置注册 4 个平级项
# 兜底:每个位置注册 5 个平级项
foreach ($item in $items) {
$key = Join-Path $parent ("SceneMarshal-{0}" -f $item.Action)
$commandKey = Join-Path $key 'command'