Rob van der Woude's Scripting Pages
Powered by GeSHi

Source code for airreggui.ps

(view source code of airreggui.ps as plain text)

  1. <#
  2. .SYNOPSIS
  3. Search for aircraft photos on Airport-data.com by the aircraft's registration number
  4.  
  5. .DESCRIPTION
  6. This simple GUI script allows you to enter an aircraft registration and then search Airport-data.com for photos and specifications of that aircraft.
  7. Interactive usage: enter an aircraft registration in the input texbox and press Enter or click the Search button to search Airport-data.com's website for photos and detailed specifications.
  8. Command line usage: run this script with -Help parameter to view its command line syntax.
  9.  
  10. .NOTES
  11. Dashes are mandatory in many aircraft registrations, but not all, e.g. PH-PBY and N1944S will work, but PHPBY and N-1944S won't.
  12.  
  13. Invalid command line switches starting with a dash will trigger a PowerShell error message.
  14.  
  15. All command line switches starting with a slash will trigger this script's help screen.
  16.  
  17. This script can be extended by using downloaded local aircraft registration databases; see this script's web page (see links section) for details.
  18.  
  19. Return code ("ErrorLevel") is 1 in case of errors, otherwise 0.
  20.  
  21. .PARAMETER AircraftRegistration
  22. (optional) A valid aircraft registration, e.g. PH-PBY or N1944S or OK-NUL.
  23. Aircraft registration may be entered in the GUI if not specified on the command line.
  24.  
  25. .PARAMETER SearchEngine
  26. (optional) Alternative search engine if no match was found on Airport-data.com.
  27. Valid SearchEngine values are 'DuckDuckGo', 'Google' (default) or 'StartPage'.
  28. Useful only if local database extension scripts are installed.
  29. Command line only, cannot be changed interactively in the GUI.
  30.  
  31. .PARAMETER Hide
  32. Hides the console window (GUI remains visible).
  33. Command line only, cannot be changed interactively in the GUI.
  34.  
  35. .PARAMETER Debug
  36. Shows some progress messages, especially usefull when using local databases.
  37. Command line only, cannot be changed interactively in the GUI.
  38.  
  39. .PARAMETER Version
  40. Show this script's version number.
  41. If combined with -Verbose show full script path, version number and last/modified/release date.
  42.  
  43. .PARAMETER Help
  44. Shows this script's help screen, with more details than the Help button's help text.
  45.  
  46. .EXAMPLE
  47. powershell . ./AirRegGUI.ps1
  48. Will open the GUI with empty input textbox, the console remains visible
  49.  
  50. .EXAMPLE
  51. powershell . ./AirRegGUI.ps1 -Hide
  52. Will open the GUI with empty input textbox and hide the console
  53.  
  54. .EXAMPLE
  55. powershell . ./AirRegGUI.ps1 N1944S
  56. Will open the GUI with N1944S in input textbox, and start search immediately, the console remains visible
  57.  
  58. .EXAMPLE
  59. powershell . ./AirRegGUI.ps1 -AircraftRegistration N1944S
  60. Will open the GUI with N1944S in input textbox, and start search immediately, the console remains visible
  61.  
  62. .EXAMPLE
  63. powershell . ./AirRegGUI.ps1 PH-PBY -Hide
  64. Will open the GUI with PH-PBY in input textbox, start search immediately, and hide the console
  65.  
  66. .EXAMPLE
  67. powershell . ./AirRegGUI.ps1 -AircraftRegistration PH-PBY -Hide
  68. Will open the GUI with PH-PBY in input textbox, start search immediately, and hide the console
  69.  
  70. .LINK
  71. Script written by Rob van der Woude:
  72. https://www.robvanderwoude.com/airreg.php
  73.  
  74. .LINK
  75. Airport-data API courtesy of Airport-data.com:
  76. http://www.airport-data.com/api/doc.php
  77.  
  78. .LINK
  79. Script created in Visual Studio Community 2019 with a trial version of Ironman Software's PowerShell Pro Tools Suite:
  80. https://ironmansoftware.com/powershell-pro-tools/
  81.  
  82. .LINK
  83. Capturing Enter key (as a work-around for the form's AcceptButton not working as expected) by sodawillow on StackOverflow.com:
  84. https://stackoverflow.com/a/41441704
  85.  
  86. .LINK
  87. Code to hide console window by Anthony on StackOverflow.com:
  88. http://stackoverflow.com/a/15079092
  89.  
  90. .LINK
  91. Use of Shown event (to make sure the GUI is visible before starting an optional immediate search) by Matthias Schippling on StackOverflow.com:
  92. https://stackoverflow.com/a/219155
  93.  
  94. .LINK
  95. Capture -Debug and -Verbose parameter by mklement0 on StackOverflow.com:
  96. https://stackoverflow.com/a/48643616
  97.  
  98. .LINK
  99. Embedded icon based on code by Theo on StackOverflow.com:
  100. https://stackoverflow.com/a/53377253
  101.  
  102. .LINK
  103. Airplane icon image courtesy of Icons8.com:
  104. https://icons8.com/
  105. #>
  106.  
  107. param (
  108. 	[parameter( ValueFromPipeline )]
  109. 	[ValidatePattern("(^\s*$|[\?/]|^\w[\w-]{2,3}\w+)")]
  110. 	[string]$AircraftRegistration = '',
  111. 	[parameter( ValueFromPipeline )]
  112. 	[ValidateSet('DuckDuckGo','Google','StartPage')]
  113. 	[string]$SearchEngine = 'Google',
  114. 	[switch]$Hide,
  115. 	[switch]$Help,
  116. 	[switch]$Version
  117. )
  118.  
  119. $progver = "2.14"
  120.  
  121. $AircraftRegistration = $AircraftRegistration.ToUpper( )
  122. $Manufacturer = ''
  123. $Model = ''
  124. [bool]$Debug = ( $PSBoundParameters.ContainsKey( 'Debug' ) )
  125. [bool]$Verbose = ( $PSBoundParameters.ContainsKey( 'Verbose' ) )
  126. $global:notfound = $true
  127.  
  128. if ( $Version ) {
  129. 	if ( $Verbose ) {
  130. 		$lastmod = ( [System.IO.File]::GetLastWriteTime( $PSCommandPath ) )
  131. 		if ( $lastmod.ToString( "h.mm" ) -eq $progver ) {
  132. 			"`"{0}`", Version {1}, release date {2}" -f $PSCommandPath, $progver, $lastmod.ToString( "yyyy-MM-dd" )
  133. 		} else {
  134. 			# if last modified time is not equal to program version, the script has been tampered with
  135. 			"`"{0}`", Version {1}, last modified date {2}" -f $PSCommandPath, $progver, $lastmod.ToString( "yyyy-MM-dd" )
  136. 		}
  137. 	} else {
  138. 		$progver
  139. 	}
  140. 	exit 0
  141. }
  142.  
  143. if ( $Help -or ( $AircraftRegistration -match "[/\?]" ) ) {
  144. 	Clear-Host
  145. 	Write-Host ( "`"{0}`", Version {1}" -f ( "$PSCommandPath" -replace "$PSScriptRoot","" ), $progver ) -NoNewline
  146. 	$lastmod = ( [System.IO.File]::GetLastWriteTime( $PSCommandPath ) )
  147. 	if ( $lastmod.ToString( "h.mm" ) -eq $progver ) {
  148. 		Write-Host ", release date " -NoNewline
  149. 	} else {
  150. 		# if last modified time is not equal to program version, the script has been tampered with
  151. 		Write-Host ", last modified date " -NoNewline
  152. 	}
  153. 	Write-Host $lastmod.ToString( "yyyy-MM-dd" )
  154. 	Write-Host
  155. 	Get-Help $PSCommandPath -Full
  156. 	exit -1
  157. }
  158.  
  159. $global:airportdatalink = ''
  160. $Debug = ( $PSBoundParameters.ContainsKey( 'Debug' ) )
  161. $defaulthelptext = "Enter an aircraft registration number, e.g. `"PH-PBY`" and click the Search button.`n`n" + `
  162.                    "This script will then search Airport-Data.com for photos of the aircraft with that registration.`n`n" + `
  163.                    "If found, a thumbnail of the photo will be displayed in this script's window, plus a button to view the photo full size in your default browser.`n`n" + `
  164.                    "{0} 2020 Rob van der Woude`nhttps://www.robvanderwoude.com" -f [char]0x00A9
  165.  
  166. # Search query templates
  167. if ( $SearchEngine -match '^DuckDuckGo$' ) {
  168. 	$SearchEngine = 'DuckDuckGo'
  169. 	$searchtemplate = "https://duckduckgo.com/html/?q=x{0}"
  170. } elseif ( $SearchEngine -match '^Google$' ) {
  171. 	$SearchEngine = 'Google'
  172. 	$searchtemplate = "https://www.google.com/search?q={0}"
  173. } elseif ( $SearchEngine -match '^Startpage$' ) {
  174. 	$SearchEngine = 'StartPage'
  175. 	$searchtemplate = "https://startpage.com/do/search?cat=web&cmd=process_search&language=english&engine0=v1all&query={0}"
  176. } else {
  177. 	$SearchEngine = 'Google'
  178. 	$searchtemplate = "https://www.google.com/search?q={0}" # Google by default
  179. 	if ( -not $Quiet ) {
  180. 		Write-Host ( "Invalid -SearchEngine value `"{0}`", using Google instead" -f $SearchEngine )
  181. 	}
  182. }
  183. if ( $Debug ) {
  184. 	Write-Host ( "Search Engine: {0}" -f $SearchEngine )
  185. 	Write-Host ( "Search template: {0}" -f $searchtemplate )
  186. }
  187.  
  188. #######################################
  189. # Hide console window                 #
  190. # by Anthony on StackOverflow.com     #
  191. # http://stackoverflow.com/a/15079092 #
  192. #######################################
  193.  
  194. $signature1 = @'
  195. public static void ShowConsoleWindow( int state )
  196. {
  197. 	var handle = GetConsoleWindow( );
  198. 	ShowWindow( handle, state );
  199. }
  200.  
  201. [System.Runtime.InteropServices.DllImport( "kernel32.dll" )]
  202. static extern IntPtr GetConsoleWindow( );
  203.  
  204. [System.Runtime.InteropServices.DllImport( "user32.dll" )]
  205. static extern bool ShowWindow( IntPtr hWnd, int nCmdShow );
  206. '@
  207.  
  208. # Hide console if requested
  209. if ( $Hide ) {
  210. 	$hideconsole = Add-Type -MemberDefinition $signature1 -Name Hide -Namespace HideConsole -ReferencedAssemblies System.Runtime.InteropServices -PassThru
  211. 	$hideconsole::ShowConsoleWindow( 0 )
  212. }
  213.  
  214. #######################
  215. # End of Hide console #
  216. #######################
  217.  
  218. ###########################
  219. # Start of Event handlers #
  220. ###########################
  221.  
  222. $ButtonHelp_Click = {
  223. 	$scriptname = $PSCommandPath.Substring( $PSScriptRoot.Length )
  224. 	$inserttext = "If local database extensions are installed, a local search will be initiated if no match was found online on Airport-data.com.`n" + `
  225. 	              "Local searches take considerably longer than online searches!`n" + `
  226. 	              "See https://www.robvanderwoude.com/airreg.php for details on local database extensions.`n`n" + `
  227. 	              "For detailed help use the command:`n`n" + `
  228. 	              "      . '.{0}' -Help`n`nor:`n`n" -f $scriptname + `
  229. 				  "      . '.{0}' /?`n`nor:`n`n" -f $scriptname + `
  230. 	              "      Get-Help '.{0}' -Full`n`n" -f $scriptname + `
  231. 				  "Do you want to open this script's web page now?`n`n{1}" -f $scriptname, [char]0x00A9
  232. 	$helptext = $defaulthelptext -replace [char]0x00A9, $inserttext
  233. 	$title = "Help for {0}" -f $AirRegGUI.Text
  234. 	$answer = [System.Windows.Forms.MessageBox]::Show( $helptext, $title, 'YesNo' )
  235. 	if ( $answer -eq 'Yes' ) {
  236. 		Start-Process 'https://www.robvanderwoude.com/airreg.php'
  237. 	}
  238. }
  239.  
  240. $ButtonOpenLink_Click = {
  241. 	Start-Process $global:airportdatalink -WindowStyle 1
  242. }
  243.  
  244. $ButtonSearch_Click = {
  245. 	Search-Aircraft
  246. }
  247.  
  248. $TextboxReg_KeyUp = {
  249. 	Validate-Input( $_.KeyCode )
  250. }
  251.  
  252. $TextboxReg_TextChanged = {
  253. 	Validate-Input
  254. }
  255.  
  256. $Window_Load = {
  257. 	$AirRegGUI.Text = "AirRegGUI.ps1 - Version {0}" -f $progver # window title
  258. 	$LabelHelptext.Text = $defaulthelptext # help text in window
  259. }
  260.  
  261. $Window_Shown = {
  262. 	if ( ![string]::IsNullOrWhiteSpace( $AircraftRegistration ) ) {
  263. 		$TextboxReg.Text = $AircraftRegistration # enter specified aircraft registration in input textbox
  264. 		$TextboxReg.SelectionStart = $TextboxReg.Text.Length # move cursor to end of input text
  265. 		$TextboxReg.SelectionLength = 0
  266. 		# Start search immediately
  267. 		[System.Windows.Forms.Application]::DoEvents( ) # start updating GUI
  268. 		Start-Sleep -Seconds 1 # allow GUI update to complete
  269. 		Validate-Input( 'Return' )
  270. 	}
  271. }
  272.  
  273. #########################
  274. # End of Event handlers #
  275. #########################
  276.  
  277. function Check-Update( ) {
  278. 	$ProgressPreference = 'SilentlyContinue'
  279. 	$checkupdate = ( Invoke-WebRequest -Uri 'https://www.robvanderwoude.com/updates/airreg.txt' -TimeoutSec 10 )
  280. 	$ProgressPreference = 'Continue'
  281. 	if ( $checkupdate.StatusCode -eq 200 ) {
  282. 		$latestversion = [float]$checkupdate.Content
  283. 		$currentversion = [float]$progver
  284. 		if ( $latestversion -gt $currentversion ) {
  285. 			$title = 'Update Available'
  286. 			$message = ( "An update for this script is available.`nYour current version is {0}, the latest version available is {1}.`n`n" + `
  287. 			             "Do you want to open the download page for the update?" -f ( $currentversion -replace ",","." ), ( $latestversion -replace ",","." ) )
  288. 			$buttons = [System.Windows.Forms.MessageBoxButtons]::YesNo
  289. 			if ( [System.Windows.Forms.MessageBox]::Show( $message, $title, $buttons ) -eq 'Yes' ) {
  290. 				Start-Process 'https://www.robvanderwoude.com/airreg.php'
  291. 			}
  292. 		}
  293. 	}
  294. }
  295.  
  296. function Search-LocalDB( $message = 'Not found' ) {
  297. 	[OutputType([bool])]
  298. 	$prefix = ''
  299. 	$registration = $TextboxReg.Text
  300. 	$found = $false
  301. 	if ( $registration.Contains( '-' ) ) {
  302. 		$prefix = $registration.Split( '-' )[0]
  303. 	} else {
  304. 		$prefix = $registration.Substring( 0, 1 )
  305. 	}
  306. 	$localDBscript = ( Join-Path -Path $PSScriptRoot -ChildPath ( "AirReg{0}Cmd.ps1" -f $prefix ) )
  307. 	if ( Test-Path $localDBscript -PathType 'Leaf' ) {
  308. 		if ( $Debug ) {
  309. 			Write-Host ( "Found local '{0}' database file `"{1}`"" -f $prefix, $localDBscript )
  310. 		}
  311. 		$ButtonOpenLink.Visible = $false
  312. 		$LabelPhotographer.Visible = $false
  313. 		$PictureboxThumbnail.Visible = $false
  314. 		$ButtonOpenLink.Enabled = $false
  315. 		$LabelHelptext.Text = "Searching local database, this may take a while..."
  316. 		$LabelHelptext.Visible = $true
  317. 		[System.Windows.Forms.Application]::DoEvents( ) # update GUI
  318.  
  319. 		$Manufacturer = ''
  320. 		$Model = ''
  321.  
  322. 		if ( $Debug ) {
  323. 			$Stopwatch = [System.Diagnostics.Stopwatch]::StartNew( )
  324. 			Write-Host ( "Start searching local database at {0}" -f ( Get-Date ) )
  325. 			if ( ( Get-Content $localDBscript ) -match 'TerminateExcel' ) {
  326. 				. "$localDBscript" -Registration $registration -TerminateExcel -Debug
  327. 			} else {
  328. 				. "$localDBscript" -Registration $registration -Debug
  329. 			}
  330. 			Write-Host ( "Finished at {0} (time elapsed {1})" -f ( Get-Date ), $Stopwatch.Elapsed )
  331. 			$Stopwatch.Stop( )
  332. 			Write-Host ( "Registration = {0}" -f $registration )
  333. 			Write-Host ( "Manufacturer = {0}" -f $Manufacturer )
  334. 			Write-Host ( "Model        = {0}" -f $Model )
  335. 		} else {
  336. 			if ( ( Get-Help "$localDBscript" ) -match '[-TerminateExcel]' ) {
  337. 				. "$localDBscript" -Registration $registration -TerminateExcel
  338. 			} else {
  339. 				. "$localDBscript" -Registration $registration
  340. 			}
  341. 		}
  342. 		if ( $Model ) {
  343. 			if ( $Manufacturer ) {
  344. 				$LabelHelptext.Text = ( "{0} {1}" -f $Manufacturer, $Model )
  345. 				$searchquery = ( ( ( "{0} {1} {2}" -f $Manufacturer, $Model, $registration ) -replace " ","+" ) -replace ",","" )
  346. 			} else {
  347. 				$LabelHelptext.Text = $Model
  348. 				$searchquery = ( ( ( "{0} {1}" -f $Model, $registration ) -replace " ","+" ) -replace ",","" )
  349. 			}
  350. 			$global:airportdatalink = ( $searchtemplate -f $searchquery )
  351. 			$ButtonOpenLink.Enabled = $true
  352. 			$ButtonOpenLink.Text = ( 'Search on {0}' -f $SearchEngine )
  353. 			$ButtonOpenLink.Visible = $true
  354. 			[System.Windows.Forms.Application]::DoEvents( ) # start updating GUI
  355. 			Start-Sleep -Seconds 1 # allow GUI update to complete
  356. 			$found = $true
  357. 			$global:notfound = $false
  358. 		} else {
  359. 			$message = ( "$message, and not found in local {0} database either" -f $prefix )
  360. 			$LabelHelptext.Text = $message
  361. 			[System.Windows.Forms.Application]::DoEvents( ) # start updating GUI
  362. 			Start-Sleep -Seconds 1 # allow GUI update to complete
  363. 			if ( Search-OpenSky $message ) {
  364. 				$true
  365. 			}
  366. 		}
  367. 	} else {
  368. 		$message = ( "$message, no local {0} database found" -f $prefix )
  369. 		$LabelHelptext.Text = $message
  370. 		[System.Windows.Forms.Application]::DoEvents( ) # start updating GUI
  371. 		Start-Sleep -Seconds 1 # allow GUI update to complete
  372. 		if ( Search-OpenSky $message ) {
  373. 			$true
  374. 		}
  375. 	}
  376. 	$found
  377. }
  378.  
  379. function Search-OpenSky( $message = 'Not found' ) {
  380. 	[OutputType([bool])]
  381. 	$registration = $TextboxReg.Text
  382. 	$found = $false
  383. 	$openskyscript = ( Join-Path $PSScriptRoot 'AirRegOpenSkyCmd.ps1' )
  384. 	if ( Test-Path -Path $openskyscript -PathType 'Leaf' ) {
  385. 		$LabelHelptext.Text = ( "{0}, searching OpenSky database, this may take a minute..." -f $LabelHelptext.Text )
  386. 		[System.Windows.Forms.Application]::DoEvents( ) # start updating GUI
  387. 		Start-Sleep -Seconds 1 # allow GUI update to complete
  388. 		if ( $Debug ) {
  389. 			Write-Host ( "Found OpenSky extension `"{0}`"" -f $openskyscript )
  390. 			. "$openskyscript" -Registration $registration -NoBreak -Debug
  391. 		} else {
  392. 			. "$openskyscript" -Registration $registration -NoBreak
  393. 		}
  394. 		if ( $Model ) {
  395. 			if ( $Manufacturer ) {
  396. 				$LabelHelptext.Text = ( ( "{0} {1}" -f $Manufacturer, $Model ) -replace "`"","" )
  397. 				$searchquery = ( ( ( ( "{0} {1} {2}" -f $Manufacturer, $Model, $registration ) -replace " ","+" ) -replace ",","" ) -replace "`"","" )
  398. 			} else {
  399. 				$LabelHelptext.Text = $Model
  400. 				$searchquery = ( ( ( ( "{0} {1}" -f $Model, $registration ) -replace " ","+" ) -replace ",","" ) -replace "`"","" )
  401. 			}
  402. 			$global:airportdatalink = ( $searchtemplate -f $searchquery )
  403. 			$ButtonOpenLink.Enabled = $true
  404. 			$ButtonOpenLink.Text = ( 'Search on {0}' -f $SearchEngine )
  405. 			$ButtonOpenLink.Visible = $true
  406. 			$found = $true
  407. 			$global:notfound = $false
  408. 		} else {
  409. 			$LabelHelptext.Text = "$message, nor in OpenSky database"
  410. 		}
  411. 	} else {
  412. 		$LabelHelptext.Text = $message
  413. 	}
  414. 	$global:notfound
  415. }
  416.  
  417. function Search-Aircraft( ) {
  418. 	$url = ( 'http://www.airport-data.com/api/ac_thumb.json?r={0}' -f $TextboxReg.Text )
  419. 	$ProgressPreference = 'SilentlyContinue'
  420. 	$json = ( Invoke-WebRequest -Uri $url -TimeoutSec 10 ).Content | ConvertFrom-Json -ErrorAction Stop
  421. 	$ProgressPreference = 'Continue'
  422. 	if ( $json.status -eq 200 ) {
  423. 		$LabelHelptext.Visible = $false
  424. 		$PictureboxThumbnail.ImageLocation = $json.data.image
  425. 		$LabelPhotographer.Visible = $true
  426. 		$LabelPhotographer.Text = ( "Photographer: {0}" -f $json.data.photographer )
  427. 		$ButtonOpenLink.Enabled = $true
  428. 		$global:airportdatalink = $json.data.link
  429. 		$PictureboxThumbnail.Visible = $true
  430. 		$ButtonOpenLink.Visible = $true
  431. 	} else {
  432. 		$ButtonOpenLink.Visible = $false
  433. 		$LabelPhotographer.Visible = $false
  434. 		$PictureboxThumbnail.Visible = $false
  435. 		$ButtonOpenLink.Enabled = $false
  436. 		if ( Search-LocalDB( ( 'Status {0}, error {1} (aircraft registration not found on Airport-Data.com)' -f $json.status, $json.error ) ) ) {
  437. 			if ( $global:notfound ) {
  438. 				[console]::Beep( 500, 500 ) # beep if registration not found
  439. 			}
  440. 		}
  441. 		$LabelHelptext.Visible = $true
  442. 	}
  443. }
  444.  
  445. function Validate-Input( $key = $null ) {
  446. 	if ( $key -eq 'Return' ) {
  447. 		Search-Aircraft
  448. 	} else {
  449. 		$cursorpos = $TextboxReg.SelectionStart + $TextboxReg.SelectionLength
  450. 		$inputtext = $TextboxReg.Text.ToUpper( )
  451. 		$inputtext = $inputtext -replace "[^A-Z\d\-]",""
  452. 		if ( $inputtext -cne $TextboxReg.Text ) {
  453. 			if ( $inputtext -cne $TextboxReg.Text.ToUpper( ) ) {
  454. 				[console]::Beep( 500, 500 ) # beep in case of invalid character
  455. 			}
  456. 			$TextboxReg.Text = $inputtext
  457. 			$TextboxReg.SelectionStart = [Math]::Min( $cursorpos, $inputtext.Length )
  458. 			$TextboxReg.SelectionLength = 0
  459. 		}
  460. 		if ( ( $inputtext -replace "-","" ).Length -ge 4 ) {
  461. 			$ButtonSearch.Enabled = $true
  462. 		} else {
  463. 			$ButtonSearch.Enabled = $false
  464. 		}
  465. 		$LabelHelptext.Visible = $true
  466. 		$LabelHelptext.Text = $defaulthelptext
  467. 		$LabelPhotographer.Visible = $false
  468. 		$PictureboxThumbnail.Visible = $false
  469. 		$ButtonOpenLink.Text = 'View photo on Airport-data.com'
  470. 		$ButtonOpenLink.Enabled = $false
  471. 		$ButtonOpenLink.Visible = $false
  472. 	}
  473. }
  474.  
  475. ############################################
  476. # GUI form design was saved separately by  #
  477. # Visual Studio/Ironman Software's         #
  478. # PowerShell Pro Tools Suite as            #
  479. # AirRegGUI.designer.ps1 and then manually #
  480. # embedded in AirRegGUI.ps1 by yours truly #
  481. #                                          #
  482. # Start of embedded AirRegGUI.designer.ps1 #
  483. ############################################
  484.  
  485. [void][System.Reflection.Assembly]::Load( 'System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' )
  486. [void][System.Reflection.Assembly]::Load( 'System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' )
  487.  
  488. $AirRegGUI = New-Object -TypeName System.Windows.Forms.Form
  489. [System.Windows.Forms.TextBox]$TextboxReg = ( New-Object -TypeName System.Windows.Forms.TextBox )
  490. [System.Windows.Forms.Button]$ButtonSearch = ( New-Object -TypeName System.Windows.Forms.Button )
  491. [System.Windows.Forms.Button]$ButtonHelp = ( New-Object -TypeName System.Windows.Forms.Button )
  492. [System.Windows.Forms.Button]$ButtonOpenLink = ( New-Object -TypeName System.Windows.Forms.Button )
  493. [System.Windows.Forms.PictureBox]$PictureboxThumbnail = ( New-Object -TypeName System.Windows.Forms.PictureBox )
  494. [System.Windows.Forms.Label]$LabelHelptext = ( New-Object -TypeName System.Windows.Forms.Label )
  495. [System.Windows.Forms.Label]$LabelPhotographer = ( New-Object -TypeName System.Windows.Forms.Label )
  496. ( [System.ComponentModel.ISupportInitialize]$PictureboxThumbnail ).BeginInit( )
  497. $AirRegGUI.SuspendLayout( )
  498.  
  499. $TextboxReg.Location = (New-Object -TypeName System.Drawing.Point -ArgumentList @( [System.Int32]37, [System.Int32]41 ) )
  500. $TextboxReg.MaxLength = [System.Int32]8
  501. $TextboxReg.Name = [System.String]'TextboxReg'
  502. $TextboxReg.Size = (New-Object -TypeName System.Drawing.Size -ArgumentList @( [System.Int32]100, [System.Int32]26 ) )
  503. $TextboxReg.TabIndex = [System.Int32]0
  504. $TextboxReg.Add_TextChanged( $TextboxReg_TextChanged )
  505. $TextboxReg.Add_KeyUp( $TextboxReg_KeyUp )
  506.  
  507. $ButtonSearch.Location = ( New-Object -TypeName System.Drawing.Point -ArgumentList @( [System.Int32]159, [System.Int32]40 ) )
  508. $ButtonSearch.Name = [System.String]'ButtonSearch'
  509. $ButtonSearch.Size = ( New-Object -TypeName System.Drawing.Size -ArgumentList @( [System.Int32]75, [System.Int32]28 ) )
  510. $ButtonSearch.TabIndex = [System.Int32]1
  511. $ButtonSearch.Text = [System.String]'Search'
  512. $ButtonSearch.UseVisualStyleBackColor = $true
  513. $ButtonSearch.Add_Click( $ButtonSearch_Click )
  514. $ButtonSearch.Enabled = $false
  515.  
  516. $ButtonHelp.Location = ( New-Object -TypeName System.Drawing.Point -ArgumentList @( [System.Int32]256, [System.Int32]40 ) )
  517. $ButtonHelp.Name = [System.String]'ButtonHelp'
  518. $ButtonHelp.Size = ( New-Object -TypeName System.Drawing.Size -ArgumentList @( [System.Int32]75, [System.Int32]28 ) )
  519. $ButtonHelp.TabIndex = [System.Int32]2
  520. $ButtonHelp.Text = [System.String]'Help'
  521. $ButtonHelp.UseVisualStyleBackColor = $true
  522. $ButtonHelp.Add_Click( $ButtonHelp_Click )
  523.  
  524. $ButtonOpenLink.Enabled = $false
  525. $ButtonOpenLink.Location = ( New-Object -TypeName System.Drawing.Point -ArgumentList @( [System.Int32]37, [System.Int32]315 ) )
  526. $ButtonOpenLink.Name = [System.String]'ButtonOpenLink'
  527. $ButtonOpenLink.Size = ( New-Object -TypeName System.Drawing.Size -ArgumentList @( [System.Int32]294, [System.Int32]28 ) )
  528. $ButtonOpenLink.TabIndex = [System.Int32]4
  529. $ButtonOpenLink.Text = [System.String]'View photo on Airport-data.com'
  530. $ButtonOpenLink.UseVisualStyleBackColor = $true
  531. $ButtonOpenLink.Add_Click( $ButtonOpenLink_Click )
  532. $ButtonOpenLink.Visible = $false
  533.  
  534. $PictureboxThumbnail.Location = ( New-Object -TypeName System.Drawing.Point -ArgumentList @( [System.Int32]82, [System.Int32]101 ) )
  535. $PictureboxThumbnail.Name = [System.String]'PictureboxThumbnail'
  536. $PictureboxThumbnail.Size = ( New-Object -TypeName System.Drawing.Size -ArgumentList @( [System.Int32]200, [System.Int32]150 ) )
  537. $PictureboxThumbnail.TabIndex = [System.Int32]3
  538. $PictureboxThumbnail.TabStop = $false
  539. $PictureboxThumbnail.Visible = $false
  540.  
  541. $LabelHelptext.AutoSize = $true
  542. $LabelHelptext.Location = ( New-Object -TypeName System.Drawing.Point -ArgumentList @( [System.Int32]37, [System.Int32]101 ) )
  543. $LabelHelptext.MaximumSize = ( New-Object -TypeName System.Drawing.Size -ArgumentList @( [System.Int32]294, [System.Int32]0 ) )
  544. $LabelHelptext.Name = [System.String]'LabelHelptext'
  545. $LabelHelptext.Size = ( New-Object -TypeName System.Drawing.Size -ArgumentList @( [System.Int32]275, [System.Int32]60 ) )
  546. $LabelHelptext.TabIndex = [System.Int32]6
  547. $LabelHelptext.Text = [System.String]''
  548.  
  549. $LabelPhotographer.AutoSize = $true
  550. $LabelPhotographer.Location = ( New-Object -TypeName System.Drawing.Point -ArgumentList @( [System.Int32]33, [System.Int32]273 ) )
  551. $LabelPhotographer.Name = [System.String]'label1'
  552. $LabelPhotographer.Size = ( New-Object -TypeName System.Drawing.Size -ArgumentList @( [System.Int32]110, [System.Int32]20 ) )
  553. $LabelPhotographer.TabIndex = [System.Int32]5
  554. $LabelPhotographer.Text = [System.String]'Photographer:'
  555. $LabelPhotographer.Visible = $false
  556.  
  557. # Icon embedding code by Theo on https://stackoverflow.com/a/53377253
  558. # Airplane icon image courtesy of https://icons8.com/
  559. $iconBase64 = 'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAYAAABzenr0AAABY0lEQVR42mNkGGDAiEduIhDbAfFfIE4F4vP0doA5EB+HqnkO5T+mpwNAYD0QB0DZV4HYCog/0dMBmkB8BYiZoPw9QOwFxL/p5QAQmA/ECUj8BUCcSE8HyAHxbSBmQxKrB+ImejkABCYAcT4S/z80VBZRwwEgg/cyQOIaFxAF4ntAzIMk9guIPYF4H6UOeMgAyetGQPwBj9oGBkjQI4OPDJCccY0SB2wHYg8GSJYLwqOWFxoKImjiIA9YAPELch3QC8RFUH4BA6QExAUKgbgPi/g5ILYF4m/kOACUpeZB+aB4tQHi0zjUcwDxTQZIzkAHW4HYD4j/keoAUBF7AknsAQMkr+MCzlDfYgOgaLxIhL2gNHcKiHeBHACKW6oWrySAOlg5AEpIcpSYRCb4MigcMOBRMOCJcMCz4YAXRANeFA94ZTTg1TExgKYNEkJgwJtkA9ooHfBm+YB2TAa8azbgnVO6AAAjEXEBu6DybwAAAABJRU5ErkJggg=='
  560. $iconBytes  = [Convert]::FromBase64String( $iconBase64 )
  561. $stream     = New-Object IO.MemoryStream( $iconBytes, 0, $iconBytes.Length )
  562. $stream.Write( $iconBytes, 0, $iconBytes.Length );
  563. $iconImage  = [System.Drawing.Image]::FromStream( $stream, $true )
  564.  
  565. $AirRegGUI.ClientSize = ( New-Object -TypeName System.Drawing.Size -ArgumentList @( [System.Int32]384, [System.Int32]441 ) )
  566. $AirRegGUI.Controls.Add( $LabelHelptext )
  567. $AirRegGUI.Controls.Add( $LabelPhotographer )
  568. $AirRegGUI.Controls.Add( $ButtonOpenLink )
  569. $AirRegGUI.Controls.Add( $PictureboxThumbnail )
  570. $AirRegGUI.Controls.Add( $ButtonHelp )
  571. $AirRegGUI.Controls.Add( $ButtonSearch )
  572. $AirRegGUI.Controls.Add( $TextboxReg )
  573. $AirRegGUI.Font = ( New-Object -TypeName System.Drawing.Font -ArgumentList @( [System.String]'Microsoft Sans Serif', [System.Single]12, [System.Drawing.FontStyle]::Regular, [System.Drawing.GraphicsUnit]::Point, ( [System.Byte][System.Byte]0) ) )
  574. $AirRegGUI.FormBorderStyle = [System.Windows.Forms.FormBorderStyle]::FixedDialog
  575. $AirRegGUI.MaximizeBox = $false
  576. $AirRegGUI.Name = [System.String]'AirRegGUI'
  577. $AirRegGUI.SizeGripStyle = [System.Windows.Forms.SizeGripStyle]::Hide
  578. $AirRegGUI.StartPosition = 'CenterScreen'
  579. $AirRegGUI.Icon = [System.Drawing.Icon]::FromHandle( ( New-Object System.Drawing.Bitmap -Argument $stream ).GetHIcon( ) ) # Icon embedding code by Theo on https://stackoverflow.com/a/53377253
  580. $AirRegGUI.Text = [System.String]'AirRegGUI.ps1'
  581. $AirRegGUI.Add_Load( $Window_Load )
  582. $AirRegGUI.Add_Shown( $Window_Shown )
  583. $AirRegGUI.Add_HelpRequested( $ButtonHelp_Click )
  584. ( [System.ComponentModel.ISupportInitialize]$PictureboxThumbnail ).EndInit( )
  585. $AirRegGUI.ResumeLayout( $false )
  586. $AirRegGUI.PerformLayout( )
  587.  
  588. Add-Member -InputObject $AirRegGUI -Name base -Value $base -MemberType NoteProperty
  589. Add-Member -InputObject $AirRegGUI -Name TextboxReg -Value $TextboxReg -MemberType NoteProperty
  590. Add-Member -InputObject $AirRegGUI -Name ButtonSearch -Value $ButtonSearch -MemberType NoteProperty
  591. Add-Member -InputObject $AirRegGUI -Name ButtonHelp -Value $ButtonHelp -MemberType NoteProperty
  592. Add-Member -InputObject $AirRegGUI -Name PictureboxThumbnail -Value $PictureboxThumbnail -MemberType NoteProperty
  593. Add-Member -InputObject $AirRegGUI -Name ButtonOpenLink -Value $ButtonOpenLink -MemberType NoteProperty
  594. Add-Member -InputObject $AirRegGUI -Name LabelHelptext -Value $LabelHelptext -MemberType NoteProperty
  595. Add-Member -InputObject $AirRegGUI -Name LabelPhotographer -Value $LabelPhotographer -MemberType NoteProperty
  596.  
  597. ##########################################
  598. # End of embedded AirRegGUI.designer.ps1 #
  599. ##########################################
  600.  
  601. # Check for program updates and notify user if available
  602. Check-Update
  603.  
  604. # Open GUI window
  605. [void] $AirRegGUI.ShowDialog( )
  606.  
  607. # Clean up (ShowDialog does not always clean up by itself)
  608. [void] $AirRegGUI.Dispose( )
  609.  

page last uploaded: 2019-01-21, 22:48