From 61f7afb9f7e296f4831aa49b73c20722793c9e98 Mon Sep 17 00:00:00 2001 From: onyx-and-iris Date: Wed, 29 Nov 2023 22:54:52 +0000 Subject: [PATCH] add script entry point --- examples/gui.ps1 | 35 +++++++++++++++++++++-------------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/examples/gui.ps1 b/examples/gui.ps1 index e20f661..46a03df 100644 --- a/examples/gui.ps1 +++ b/examples/gui.ps1 @@ -75,20 +75,27 @@ Function Get-ConnFromPSD1 { return Import-PowerShellDataFile -Path $configpath } -try { - $conn = Get-ConnFromPSD1 - $rcon = Connect-Rcon -hostname $conn.host -port $conn.port -passwd $conn.passwd - Write-Host $rcon.base.ToString() -ForegroundColor Green +Function Main { + try { + $conn = Get-ConnFromPSD1 + $rcon = Connect-Rcon -hostname $conn.host -port $conn.port -passwd $conn.passwd + Write-Host $rcon.base.ToString() -ForegroundColor Green - $form = InitForm - AddOkButton -form $form -rcon $rcon - AddCloseButton($form) - AddLabel($form) - AddTextBox -form $form -rcon $rcon - FinalizeForm($form) + $form = InitForm + AddOkButton -form $form -rcon $rcon + AddCloseButton($form) + AddLabel($form) + AddTextBox -form $form -rcon $rcon + FinalizeForm($form) - [void] $form.ShowDialog() -} -finally { - Disconnect-Rcon -rcon $rcon + [void] $form.ShowDialog() + } + finally { + Disconnect-Rcon -rcon $rcon + } } + + +if ($MyInvocation.InvocationName -ne '.') { + Main +} \ No newline at end of file