diff --git a/scripts/winget.ps1 b/scripts/winget.ps1 new file mode 100644 index 00000000..d1aaf40d --- /dev/null +++ b/scripts/winget.ps1 @@ -0,0 +1,54 @@ +#Requires -Version 3.0 +if (Test-Path Env:\DEBUG) { + Set-PSDebug -Trace 1 +} +$Host.UI.RawUI.WindowTitle = "WizardKit: Winget wrapper" +$Host.UI.RawUI.BackgroundColor = "black" +$Host.UI.RawUI.ForegroundColor = "white" + + +## Functions ## +function Abort { + Write-Host -ForegroundColor "Red" "`nAborted." + WKPause "Press Enter to exit..." + exit +} +function WKPause ($Message = "Press Enter to continue... ") { + Write-Host $Message -NoNewLine + Read-Host +} + +## PowerShell equivalent of Python's "if __name__ == '__main__'" +# Code based on StackOverflow comments +# Question: https://stackoverflow.com/q/4693947 +# Using answer: https://stackoverflow.com/a/5582692 +# Asked by: https://stackoverflow.com/users/65164/mark-mascolino +# Answer by: https://stackoverflow.com/users/696808/bacon-bits +if ($MyInvocation.InvocationName -ne ".") { + Clear-Host + + # Check for winget and install if missing + Write-Host "WizardKit: winget wrapper`n`n`n`n`nInitializing..." + try { + $_ = $(winget --version) + } + catch { + Write-Host (" ERROR: Failed to run winget." ) -ForegroundColor "Red" + Write-Host " Installing winget..." + Add-AppxPackage -RegisterByFamilyName -MainPackage Microsoft.DesktopAppInstaller_8wekyb3d8bbwe + } + try { + $_ = $(winget --version) + } + catch { + Write-Host (" ERROR: Failed to run or install winget." ) -ForegroundColor "Red" + Abort + } + + # List available upgrades + Start-Process -FilePath "winget" -ArgumentList @("upgrade") -NoNewWindow -Wait + WKPause "`nPress Enter to install listed applications... " + + # Install upgrades + Start-Process -FilePath "winget" -ArgumentList @("upgrade", "--all") -NoNewWindow -Wait +} diff --git a/scripts/wk/cfg/launchers.py b/scripts/wk/cfg/launchers.py index bba27a66..2c5eb4e6 100644 --- a/scripts/wk/cfg/launchers.py +++ b/scripts/wk/cfg/launchers.py @@ -22,6 +22,12 @@ LAUNCHERS = { 'L_ARGS': 'update', 'Extra Code': ['explorer ms-windows-store:updates'], }, + '2b) Winget Updates (EXPERIMENTAL)': { + 'L_TYPE': 'PSScript', + 'L_PATH': 'Scripts', + 'L_ITEM': 'winget.ps1', + 'L_ELEV': 'True', + }, '3) Snappy Driver Installer Origin': { 'L_TYPE': 'PyScript', 'L_PATH': 'Scripts',