# KVM Virt Viewer for Windows
# 2011-2020 foo.li systeme + software

$packageName	= 'virt-viewer'
$version        = '9.0'
$fullversion	= '9.0.256'
$installerType	= 'msi'
$silentArgs	= '/qn /l*v ' + $env:Temp + '\virtviewer-setup.log'
$packageSearch  = 'VirtViewer*'
$validExitCodes	= @(0,3010)
$url		= 'https://virt-manager.org/download/sources/virt-viewer/virt-viewer-x86-' + $version + '.msi'
$url64		= 'https://virt-manager.org/download/sources/virt-viewer/virt-viewer-x64-' + $version + '.msi'
$checksum	= 'dfb1c9cd3c1c9f66758b66e6f5850980fcacb3be'
$checksumType	= 'sha1'
$checksum64	= 'c4937d737b0982b424e66d8446c586e5b84a8570'
$checksumType64 = $checksumType

try {
  $app = Get-ItemProperty -Path @('HKLM:\Software\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\*',
                                  'HKLM:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*',
				  'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*' ) `
	    -ErrorAction:SilentlyContinue | Where-Object { $_.DisplayName -like $packageSearch }
  if ($app -and ([version]$app.DisplayVersion -ge [version]$fullversion)) {
    Write-Host $(
      "Virt Viewer " + [version]$app.DisplayVersion + " is already installed.`r`n`a"
    )
  } else {
    Install-ChocolateyPackage $packageName $installerType $silentArgs $url $url64 `
      -checksum $checksum `
      -checksumType $checksumType `
      -checksum64 $checksum64 `
      -checksumType64 $checksumType64 `
      -validExitCodes $validExitCodes
  }
} catch {
  throw $_.Exception
}
