# WizardKit: Install winget (if needed)

#Requires -Version 3.0
if (Test-Path Env:\DEBUG) {
  Set-PSDebug -Trace 1
}
$Host.UI.RawUI.WindowTitle = "WizardKit: Winget installer"
$Host.UI.RawUI.BackgroundColor = "black"
$Host.UI.RawUI.ForegroundColor = "white"
$ProgressPreference = "SilentlyContinue"

# STATIC VARIABLES
$EXIT_OK = 0
$EXIT_INSTALLED = 1
$EXIT_FAILED_TO_INSTALL = 2

# Main
$NeedsInstalled = $false
try {
  $_ = $(winget --version)
}
catch {
  $NeedsInstalled = $true
}

# Install
if (! $NeedsInstalled) {
  exit $EXIT_INSTALLED
  }
try {
  Add-AppxPackage -ErrorAction Stop -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe
}
catch {
  exit $EXIT_FAILED_TO_INSTALL
}

exit $EXIT_OK
