- diagnostics/ 11 个:环境/配置/依赖诊断 - logs/ 7 个:日志分析与查看 - coords/ 6 个:坐标拾取与区域选择 - cleanup/ 3 个:代码清理工具 - adb/ 2 个:ADB / 输入法相关 - windows/ 4 个:Windows 系统修复(备份) - dev/ 9 个:开发辅助 / 运行时探测 并更新 tools/README.md 描述新结构。 删除 3 个明显的临时调试脚本 (_dump_lines.py / tmp_*.py)。 tools/ 不被业务代码 import,分组仅为人工浏览方便。 Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
108 lines
2.7 KiB
PowerShell
108 lines
2.7 KiB
PowerShell
[CmdletBinding()]
|
|
param(
|
|
[switch]$WhatIf
|
|
)
|
|
|
|
$ErrorActionPreference = 'Stop'
|
|
|
|
function Write-Section([string]$title) {
|
|
Write-Host ""
|
|
Write-Host "=== $title ==="
|
|
}
|
|
|
|
$programsUser = Join-Path $env:APPDATA 'Microsoft\Windows\Start Menu\Programs'
|
|
$programsCommon = Join-Path $env:ProgramData 'Microsoft\Windows\Start Menu\Programs'
|
|
|
|
Write-Section 'Targets'
|
|
Write-Host "ProgramsUser: $programsUser"
|
|
Write-Host "ProgramsCommon: $programsCommon"
|
|
Write-Host "WhatIf: $WhatIf"
|
|
|
|
Write-Section 'Enumerate Recycle Bin'
|
|
$shell = New-Object -ComObject Shell.Application
|
|
$recycle = $shell.Namespace(0xA)
|
|
if ($null -eq $recycle) {
|
|
throw 'Failed to open Recycle Bin namespace.'
|
|
}
|
|
|
|
$items = @($recycle.Items())
|
|
Write-Host "RecycleBin items: $($items.Count)"
|
|
|
|
function Get-DeletedFrom($item) {
|
|
try { return $item.ExtendedProperty('System.Recycle.DeletedFrom') } catch { return $null }
|
|
}
|
|
|
|
function Get-OriginalName($item) {
|
|
try { return $item.Name } catch { return $null }
|
|
}
|
|
|
|
function Find-RestoreVerb($item) {
|
|
try {
|
|
$verbs = @($item.Verbs())
|
|
foreach ($v in $verbs) {
|
|
$name = ($v.Name -as [string])
|
|
if ([string]::IsNullOrWhiteSpace($name)) { continue }
|
|
$n = $name.Replace('&','').Trim()
|
|
if ($n -match '(?i)restore' -or $n -match '还原') {
|
|
return $n
|
|
}
|
|
}
|
|
} catch { }
|
|
return $null
|
|
}
|
|
|
|
$matches = @()
|
|
foreach ($it in $items) {
|
|
$deletedFrom = Get-DeletedFrom $it
|
|
$name = Get-OriginalName $it
|
|
if ([string]::IsNullOrWhiteSpace($name)) { continue }
|
|
|
|
$isLnk = $name.ToLowerInvariant().EndsWith('.lnk')
|
|
if (!$isLnk) { continue }
|
|
|
|
if ($deletedFrom -and (
|
|
$deletedFrom -like "$programsUser*" -or
|
|
$deletedFrom -like "$programsCommon*" -or
|
|
$deletedFrom -like '*\\Microsoft\\Windows\\Start Menu\\Programs*'
|
|
)) {
|
|
$matches += [pscustomobject]@{ Name = $name; DeletedFrom = $deletedFrom; Item = $it }
|
|
}
|
|
}
|
|
|
|
Write-Section 'Matches'
|
|
Write-Host "Matching .lnk from Start Menu Programs: $($matches.Count)"
|
|
$matches | Select-Object -First 50 Name,DeletedFrom | Format-List
|
|
|
|
if ($matches.Count -eq 0) {
|
|
Write-Host 'No matching shortcuts found in Recycle Bin.'
|
|
exit 0
|
|
}
|
|
|
|
if ($WhatIf) {
|
|
Write-Host 'WhatIf set; not restoring.'
|
|
exit 0
|
|
}
|
|
|
|
Write-Section 'Restore'
|
|
$restored = 0
|
|
$skipped = 0
|
|
foreach ($m in $matches) {
|
|
$it = $m.Item
|
|
$verb = Find-RestoreVerb $it
|
|
if ([string]::IsNullOrWhiteSpace($verb)) {
|
|
$skipped++
|
|
continue
|
|
}
|
|
|
|
try {
|
|
$it.InvokeVerb($verb)
|
|
$restored++
|
|
} catch {
|
|
$skipped++
|
|
}
|
|
}
|
|
|
|
Write-Host "Restored: $restored"
|
|
Write-Host "Skipped: $skipped"
|
|
Write-Host 'Tip: If restore succeeded, restart Explorer / Start menu.'
|