Handle preview without file path

This commit is contained in:
2026-01-29 11:28:39 +13:00
parent a1c27c1976
commit 06a1a6ada3

View File

@@ -60,6 +60,7 @@ function Get-FilePreview {
[int]$MaxLines = 200 [int]$MaxLines = 200
) )
if ([string]::IsNullOrWhiteSpace($Path)) { return "" }
if (-not (Test-Path -Path $Path -PathType Leaf)) { return "" } if (-not (Test-Path -Path $Path -PathType Leaf)) { return "" }
try { try {
$lines = Get-Content -Path $Path -TotalCount $MaxLines -ErrorAction Stop $lines = Get-Content -Path $Path -TotalCount $MaxLines -ErrorAction Stop
@@ -849,9 +850,21 @@ $replicationEnabledBox.Add_CheckedChanged({
}) })
$filePreviewBtn.Add_Click({ $filePreviewBtn.Add_Click({
$filePreviewBox.Text = Get-FilePreview -Path $fileBox.Text.Trim() $path = $fileBox.Text.Trim()
if (Test-Path -Path $fileBox.Text.Trim() -PathType Leaf) { if ([string]::IsNullOrWhiteSpace($path)) {
$fileHosts = Get-Content -Path $fileBox.Text.Trim() | ForEach-Object { $_.Trim() } | Where-Object { $_ } $previewHosts = Split-List $hostsBox.Text
if ($previewHosts.Count -gt 0) {
$filePreviewBox.Text = ($previewHosts | Select-Object -First 200) -join [Environment]::NewLine
return
}
$filePreviewBox.Text = ""
& $logAction "No file selected and no hostnames to preview."
return
}
$filePreviewBox.Text = Get-FilePreview -Path $path
if (Test-Path -Path $path -PathType Leaf) {
$fileHosts = Get-Content -Path $path | ForEach-Object { $_.Trim() } | Where-Object { $_ }
$zoneGuess = Get-CommonZoneFromHosts -Hosts $fileHosts $zoneGuess = Get-CommonZoneFromHosts -Hosts $fileHosts
if ($zoneGuess) { if ($zoneGuess) {
$zoneBox.Text = $zoneGuess $zoneBox.Text = $zoneGuess