Files
cbb-refresh-verify-795/CBBRefresh.UiProbe.ps1
阿白叔 11a2b2e46e Import CBB refresh verify r4 stability baseline
Preserve tested Verify source, authoritative READY checks, bounded bridge retries, diagnostics and failure-only reporting. Include 336-test suite and packaging assets; exclude live Mentor samples, field logs, backups and distributions.
2026-09-29 15:05:20 +08:00

74 lines
2.5 KiB
PowerShell

[CmdletBinding()]
param(
[string]$WindowTitlePattern = 'Library Manager',
[int]$ProcessId = 0,
[Parameter(Mandatory)][string]$OutputJson
)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
Add-Type -AssemblyName UIAutomationClient
Add-Type -AssemblyName UIAutomationTypes
$root = [System.Windows.Automation.AutomationElement]::RootElement
$windows = @($root.FindAll(
[System.Windows.Automation.TreeScope]::Children,
[System.Windows.Automation.Condition]::TrueCondition
) | Where-Object {
[string]$_.Current.Name -match $WindowTitlePattern
})
if ($ProcessId -gt 0) {
$windows = @($windows | Where-Object {
[int]$_.Current.ProcessId -eq $ProcessId
})
}
if ($windows.Count -ne 1) {
throw "Expected exactly one Library Manager window, found $($windows.Count)."
}
function Get-ElementRecord {
param([Parameter(Mandatory)]$Element)
$patterns = New-Object 'System.Collections.Generic.List[string]'
foreach ($pattern in @(
[System.Windows.Automation.InvokePattern]::Pattern,
[System.Windows.Automation.ExpandCollapsePattern]::Pattern
)) {
try {
if ($null -ne $Element.GetCurrentPattern($pattern)) {
[void]$patterns.Add([string]$pattern.ProgrammaticName)
}
}
catch { }
}
[pscustomobject]@{
name = [string]$Element.Current.Name
automationId = [string]$Element.Current.AutomationId
controlType = [string]$Element.Current.ControlType.ProgrammaticName
className = [string]$Element.Current.ClassName
processId = [int]$Element.Current.ProcessId
nativeWindowHandle = [int]$Element.Current.NativeWindowHandle
isEnabled = [bool]$Element.Current.IsEnabled
patterns = @($patterns)
}
}
$tree = @($windows[0].FindAll(
[System.Windows.Automation.TreeScope]::Descendants,
[System.Windows.Automation.Condition]::TrueCondition
) | ForEach-Object { Get-ElementRecord -Element $_ })
$document = [ordered]@{
schemaVersion = 1
capturedAtUtc = [datetime]::UtcNow.ToString('o')
windowTitlePattern = $WindowTitlePattern
processId = [int]$windows[0].Current.ProcessId
window = Get-ElementRecord -Element $windows[0]
elements = $tree
}
$parent = Split-Path -Parent ([IO.Path]::GetFullPath($OutputJson))
if ($parent -and -not (Test-Path -LiteralPath $parent -PathType Container)) {
New-Item -ItemType Directory -Path $parent -Force | Out-Null
}
$document | ConvertTo-Json -Depth 8 | Set-Content -LiteralPath $OutputJson -Encoding UTF8
$document | ConvertTo-Json -Depth 8