Merge pull request #46 from Romanitho/dev
First changes regarding winget v1.3.0-previewpull/49/head
commit
d0a1fd4fa2
|
@ -55,15 +55,23 @@ function Install-Prerequisites{
|
||||||
if (!($path)){
|
if (!($path)){
|
||||||
#If -silent option, force installation
|
#If -silent option, force installation
|
||||||
if ($Silent){
|
if ($Silent){
|
||||||
$InstallApp = "y"
|
$InstallApp = 1
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
#Ask for installation
|
#Ask for installation
|
||||||
while("y","n" -notcontains $InstallApp){
|
$MsgBoxTitle = "Winget Prerequisites"
|
||||||
$InstallApp = Read-Host "[Prerequisite for Winget] Microsoft Visual C++ 2019 is not installed. Would you like to install it? [Y/N]"
|
$MsgBoxContent = "Microsoft Visual C++ 2015-2019 is required. Would you like to install it?"
|
||||||
|
$MsgBoxTimeOut = 60
|
||||||
|
$MsgBoxReturn = (New-Object -ComObject "Wscript.Shell").Popup($MsgBoxContent,$MsgBoxTimeOut,$MsgBoxTitle,4+32)
|
||||||
|
if ($MsgBoxReturn -ne 7) {
|
||||||
|
$InstallApp = 1
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$InstallApp = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($InstallApp -eq "y"){
|
#Install if approved
|
||||||
|
if ($InstallApp -eq 1){
|
||||||
try{
|
try{
|
||||||
if((Get-CimInStance Win32_OperatingSystem).OSArchitecture -like "*64*"){
|
if((Get-CimInStance Win32_OperatingSystem).OSArchitecture -like "*64*"){
|
||||||
$OSArch = "x64"
|
$OSArch = "x64"
|
||||||
|
@ -86,6 +94,9 @@ function Install-Prerequisites{
|
||||||
Start-Sleep 3
|
Start-Sleep 3
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
Write-host "MS Visual C++ 2015-2019 wil not be installed." -ForegroundColor Magenta
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
Write-Host "Prerequisites checked. OK" -ForegroundColor Green
|
Write-Host "Prerequisites checked. OK" -ForegroundColor Green
|
||||||
|
@ -126,7 +137,7 @@ function Install-WingetAutoUpdate{
|
||||||
|
|
||||||
# Set up the task, and register it
|
# Set up the task, and register it
|
||||||
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings -Trigger $taskTrigger2,$taskTrigger1
|
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings -Trigger $taskTrigger2,$taskTrigger1
|
||||||
Register-ScheduledTask -TaskName 'Winget-AutoUpdate' -InputObject $task -Force
|
Register-ScheduledTask -TaskName 'Winget-AutoUpdate' -InputObject $task -Force | Out-Null
|
||||||
|
|
||||||
# Settings for the scheduled task for Notifications
|
# Settings for the scheduled task for Notifications
|
||||||
$taskAction = New-ScheduledTaskAction –Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-notify.ps1`"`""
|
$taskAction = New-ScheduledTaskAction –Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -NoProfile -ExecutionPolicy Bypass -File `"`"`"$($WingetUpdatePath)\winget-notify.ps1`"`""
|
||||||
|
@ -135,7 +146,7 @@ function Install-WingetAutoUpdate{
|
||||||
|
|
||||||
# Set up the task, and register it
|
# Set up the task, and register it
|
||||||
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
|
$task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings
|
||||||
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Notify' -InputObject $task -Force
|
Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Notify' -InputObject $task -Force | Out-Null
|
||||||
|
|
||||||
# Install config file
|
# Install config file
|
||||||
[xml]$ConfigXML = @"
|
[xml]$ConfigXML = @"
|
||||||
|
@ -162,7 +173,6 @@ function Install-WingetAutoUpdate{
|
||||||
}
|
}
|
||||||
|
|
||||||
function Uninstall-WingetAutoUpdate{
|
function Uninstall-WingetAutoUpdate{
|
||||||
Write-Host "Starting uninstall"
|
|
||||||
try{
|
try{
|
||||||
#Check if installed location exists and delete
|
#Check if installed location exists and delete
|
||||||
if (Test-Path ($WingetUpdatePath)){
|
if (Test-Path ($WingetUpdatePath)){
|
||||||
|
@ -189,15 +199,22 @@ function Start-WingetAutoUpdate{
|
||||||
if (!($DoNotUpdate)){
|
if (!($DoNotUpdate)){
|
||||||
#If -Silent, run Winget-AutoUpdate now
|
#If -Silent, run Winget-AutoUpdate now
|
||||||
if ($Silent){
|
if ($Silent){
|
||||||
$RunWinget = "y"
|
$RunWinget = 1
|
||||||
}
|
}
|
||||||
#Ask for WingetAutoUpdate
|
#Ask for WingetAutoUpdate
|
||||||
else{
|
else{
|
||||||
while("y","n" -notcontains $RunWinget){
|
$MsgBoxTitle = "Winget-AutoUpdate"
|
||||||
$RunWinget = Read-Host "Start Winget-AutoUpdate now? [Y/N]"
|
$MsgBoxContent = "Would you like to run Winget-AutoUpdate now?"
|
||||||
|
$MsgBoxTimeOut = 60
|
||||||
|
$MsgBoxReturn = (New-Object -ComObject "Wscript.Shell").Popup($MsgBoxContent,$MsgBoxTimeOut,$MsgBoxTitle,4+32)
|
||||||
|
if ($MsgBoxReturn -ne 7) {
|
||||||
|
$RunWinget = 1
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$RunWinget = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ($RunWinget -eq "y"){
|
if ($RunWinget -eq 1){
|
||||||
try{
|
try{
|
||||||
Write-host "Running Winget-AutoUpdate..." -ForegroundColor Yellow
|
Write-host "Running Winget-AutoUpdate..." -ForegroundColor Yellow
|
||||||
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
|
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
|
||||||
|
@ -227,11 +244,12 @@ Write-Host "`t###################################"
|
||||||
Write-Host "`n"
|
Write-Host "`n"
|
||||||
|
|
||||||
if (!$Uninstall){
|
if (!$Uninstall){
|
||||||
Write-host "Installing to $WingetUpdatePath\"
|
Write-host "Installing WAU to $WingetUpdatePath\"
|
||||||
Install-Prerequisites
|
Install-Prerequisites
|
||||||
Install-WingetAutoUpdate
|
Install-WingetAutoUpdate
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Write-Host "Uninstall WAU"
|
||||||
Uninstall-WingetAutoUpdate
|
Uninstall-WingetAutoUpdate
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -14,8 +14,9 @@ function Get-WingetOutdatedApps {
|
||||||
}
|
}
|
||||||
|
|
||||||
#Get Winget Location in User context
|
#Get Winget Location in User context
|
||||||
|
$WingetCmd = Get-Command winget.exe -ErrorAction SilentlyContinue
|
||||||
if ($WingetCmd){
|
if ($WingetCmd){
|
||||||
$Script:Winget = (Get-Command winget.exe -ErrorAction SilentlyContinue).Source
|
$Script:Winget = $WingetCmd.Source
|
||||||
}
|
}
|
||||||
#Get Winget Location in System context (WinGet < 1.17)
|
#Get Winget Location in System context (WinGet < 1.17)
|
||||||
elseif (Test-Path "$WingetPath\AppInstallerCLI.exe"){
|
elseif (Test-Path "$WingetPath\AppInstallerCLI.exe"){
|
||||||
|
@ -33,7 +34,12 @@ function Get-WingetOutdatedApps {
|
||||||
#Run winget to list apps and accept source agrements (necessary on first run)
|
#Run winget to list apps and accept source agrements (necessary on first run)
|
||||||
& $Winget list --accept-source-agreements | Out-Null
|
& $Winget list --accept-source-agreements | Out-Null
|
||||||
|
|
||||||
|
#Log Winget installed version
|
||||||
|
$WingerVer = & $Winget --version
|
||||||
|
Write-Log "Winget Version: $WingerVer"
|
||||||
|
|
||||||
#Get list of available upgrades on winget format
|
#Get list of available upgrades on winget format
|
||||||
|
Write-Log "Checking application updates on Winget Repository..." "yellow"
|
||||||
$upgradeResult = & $Winget upgrade | Out-String
|
$upgradeResult = & $Winget upgrade | Out-String
|
||||||
|
|
||||||
#Start Convertion of winget format to an array. Check if "-----" exists
|
#Start Convertion of winget format to an array. Check if "-----" exists
|
||||||
|
@ -42,7 +48,7 @@ function Get-WingetOutdatedApps {
|
||||||
}
|
}
|
||||||
|
|
||||||
#Split winget output to lines
|
#Split winget output to lines
|
||||||
$lines = $upgradeResult.Split([Environment]::NewLine).Replace("¦ ","")
|
$lines = $upgradeResult.Split([Environment]::NewLine) | Where-Object {$_}
|
||||||
|
|
||||||
# Find the line that starts with "------"
|
# Find the line that starts with "------"
|
||||||
$fl = 0
|
$fl = 0
|
||||||
|
@ -50,13 +56,13 @@ function Get-WingetOutdatedApps {
|
||||||
$fl++
|
$fl++
|
||||||
}
|
}
|
||||||
|
|
||||||
#Get header line
|
#Get header line
|
||||||
$fl = $fl - 2
|
$fl = $fl - 1
|
||||||
|
|
||||||
#Get header titles
|
#Get header titles
|
||||||
$index = $lines[$fl] -split '\s+'
|
$index = $lines[$fl] -split '\s+'
|
||||||
|
|
||||||
# Line $i has the header, we can find char where we find ID and Version
|
# Line $fl has the header, we can find char where we find ID and Version
|
||||||
$idStart = $lines[$fl].IndexOf($index[1])
|
$idStart = $lines[$fl].IndexOf($index[1])
|
||||||
$versionStart = $lines[$fl].IndexOf($index[2])
|
$versionStart = $lines[$fl].IndexOf($index[2])
|
||||||
$availableStart = $lines[$fl].IndexOf($index[3])
|
$availableStart = $lines[$fl].IndexOf($index[3])
|
||||||
|
@ -66,7 +72,7 @@ function Get-WingetOutdatedApps {
|
||||||
$upgradeList = @()
|
$upgradeList = @()
|
||||||
For ($i = $fl + 2; $i -le $lines.Length; $i++){
|
For ($i = $fl + 2; $i -le $lines.Length; $i++){
|
||||||
$line = $lines[$i]
|
$line = $lines[$i]
|
||||||
if ($line.Length -gt ($sourceStart+5) -and -not $line.StartsWith('-')){
|
if ($line.Length -gt ($sourceStart+5) -and -not $line.Contains("--include-unknown")){
|
||||||
$software = [Software]::new()
|
$software = [Software]::new()
|
||||||
$software.Name = $line.Substring(0, $idStart).TrimEnd()
|
$software.Name = $line.Substring(0, $idStart).TrimEnd()
|
||||||
$software.Id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()
|
$software.Id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()
|
||||||
|
|
|
@ -45,7 +45,6 @@ if (Test-Network){
|
||||||
}
|
}
|
||||||
|
|
||||||
#Get outdated Winget packages
|
#Get outdated Winget packages
|
||||||
Write-Log "Checking application updates on Winget Repository..." "yellow"
|
|
||||||
$outdated = Get-WingetOutdatedApps
|
$outdated = Get-WingetOutdatedApps
|
||||||
|
|
||||||
#Log list of app to update
|
#Log list of app to update
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
@echo off
|
@echo off
|
||||||
powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -Silent'" -Verb RunAs
|
powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" '" -Verb RunAs
|
||||||
|
|
Loading…
Reference in New Issue