From 06a1a6ada3e465958f27d57f7af45ba3141fe754 Mon Sep 17 00:00:00 2001 From: Rephl3x Date: Thu, 29 Jan 2026 11:28:39 +1300 Subject: [PATCH] Handle preview without file path --- certy.ps1 | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/certy.ps1 b/certy.ps1 index e8354e9..095e099 100644 --- a/certy.ps1 +++ b/certy.ps1 @@ -60,6 +60,7 @@ function Get-FilePreview { [int]$MaxLines = 200 ) + if ([string]::IsNullOrWhiteSpace($Path)) { return "" } if (-not (Test-Path -Path $Path -PathType Leaf)) { return "" } try { $lines = Get-Content -Path $Path -TotalCount $MaxLines -ErrorAction Stop @@ -849,9 +850,21 @@ $replicationEnabledBox.Add_CheckedChanged({ }) $filePreviewBtn.Add_Click({ - $filePreviewBox.Text = Get-FilePreview -Path $fileBox.Text.Trim() - if (Test-Path -Path $fileBox.Text.Trim() -PathType Leaf) { - $fileHosts = Get-Content -Path $fileBox.Text.Trim() | ForEach-Object { $_.Trim() } | Where-Object { $_ } + $path = $fileBox.Text.Trim() + if ([string]::IsNullOrWhiteSpace($path)) { + $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 if ($zoneGuess) { $zoneBox.Text = $zoneGuess