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 -silent option, force installation
|
||||
if ($Silent){
|
||||
$InstallApp = "y"
|
||||
$InstallApp = 1
|
||||
}
|
||||
else{
|
||||
#Ask for installation
|
||||
while("y","n" -notcontains $InstallApp){
|
||||
$InstallApp = Read-Host "[Prerequisite for Winget] Microsoft Visual C++ 2019 is not installed. Would you like to install it? [Y/N]"
|
||||
$MsgBoxTitle = "Winget Prerequisites"
|
||||
$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{
|
||||
if((Get-CimInStance Win32_OperatingSystem).OSArchitecture -like "*64*"){
|
||||
$OSArch = "x64"
|
||||
|
@ -86,6 +94,9 @@ function Install-Prerequisites{
|
|||
Start-Sleep 3
|
||||
}
|
||||
}
|
||||
else{
|
||||
Write-host "MS Visual C++ 2015-2019 wil not be installed." -ForegroundColor Magenta
|
||||
}
|
||||
}
|
||||
else{
|
||||
Write-Host "Prerequisites checked. OK" -ForegroundColor Green
|
||||
|
@ -126,7 +137,7 @@ function Install-WingetAutoUpdate{
|
|||
|
||||
# Set up the task, and register it
|
||||
$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
|
||||
$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
|
||||
$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
|
||||
[xml]$ConfigXML = @"
|
||||
|
@ -162,7 +173,6 @@ function Install-WingetAutoUpdate{
|
|||
}
|
||||
|
||||
function Uninstall-WingetAutoUpdate{
|
||||
Write-Host "Starting uninstall"
|
||||
try{
|
||||
#Check if installed location exists and delete
|
||||
if (Test-Path ($WingetUpdatePath)){
|
||||
|
@ -189,15 +199,22 @@ function Start-WingetAutoUpdate{
|
|||
if (!($DoNotUpdate)){
|
||||
#If -Silent, run Winget-AutoUpdate now
|
||||
if ($Silent){
|
||||
$RunWinget = "y"
|
||||
$RunWinget = 1
|
||||
}
|
||||
#Ask for WingetAutoUpdate
|
||||
else{
|
||||
while("y","n" -notcontains $RunWinget){
|
||||
$RunWinget = Read-Host "Start Winget-AutoUpdate now? [Y/N]"
|
||||
$MsgBoxTitle = "Winget-AutoUpdate"
|
||||
$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{
|
||||
Write-host "Running Winget-AutoUpdate..." -ForegroundColor Yellow
|
||||
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
|
||||
|
@ -227,11 +244,12 @@ Write-Host "`t###################################"
|
|||
Write-Host "`n"
|
||||
|
||||
if (!$Uninstall){
|
||||
Write-host "Installing to $WingetUpdatePath\"
|
||||
Write-host "Installing WAU to $WingetUpdatePath\"
|
||||
Install-Prerequisites
|
||||
Install-WingetAutoUpdate
|
||||
}
|
||||
else {
|
||||
Write-Host "Uninstall WAU"
|
||||
Uninstall-WingetAutoUpdate
|
||||
}
|
||||
|
||||
|
|
|
@ -14,8 +14,9 @@ function Get-WingetOutdatedApps {
|
|||
}
|
||||
|
||||
#Get Winget Location in User context
|
||||
$WingetCmd = Get-Command winget.exe -ErrorAction SilentlyContinue
|
||||
if ($WingetCmd){
|
||||
$Script:Winget = (Get-Command winget.exe -ErrorAction SilentlyContinue).Source
|
||||
$Script:Winget = $WingetCmd.Source
|
||||
}
|
||||
#Get Winget Location in System context (WinGet < 1.17)
|
||||
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)
|
||||
& $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
|
||||
Write-Log "Checking application updates on Winget Repository..." "yellow"
|
||||
$upgradeResult = & $Winget upgrade | Out-String
|
||||
|
||||
#Start Convertion of winget format to an array. Check if "-----" exists
|
||||
|
@ -42,7 +48,7 @@ function Get-WingetOutdatedApps {
|
|||
}
|
||||
|
||||
#Split winget output to lines
|
||||
$lines = $upgradeResult.Split([Environment]::NewLine).Replace("¦ ","")
|
||||
$lines = $upgradeResult.Split([Environment]::NewLine) | Where-Object {$_}
|
||||
|
||||
# Find the line that starts with "------"
|
||||
$fl = 0
|
||||
|
@ -50,13 +56,13 @@ function Get-WingetOutdatedApps {
|
|||
$fl++
|
||||
}
|
||||
|
||||
#Get header line
|
||||
$fl = $fl - 2
|
||||
#Get header line
|
||||
$fl = $fl - 1
|
||||
|
||||
#Get header titles
|
||||
$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])
|
||||
$versionStart = $lines[$fl].IndexOf($index[2])
|
||||
$availableStart = $lines[$fl].IndexOf($index[3])
|
||||
|
@ -66,7 +72,7 @@ function Get-WingetOutdatedApps {
|
|||
$upgradeList = @()
|
||||
For ($i = $fl + 2; $i -le $lines.Length; $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.Name = $line.Substring(0, $idStart).TrimEnd()
|
||||
$software.Id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()
|
||||
|
|
|
@ -45,7 +45,6 @@ if (Test-Network){
|
|||
}
|
||||
|
||||
#Get outdated Winget packages
|
||||
Write-Log "Checking application updates on Winget Repository..." "yellow"
|
||||
$outdated = Get-WingetOutdatedApps
|
||||
|
||||
#Log list of app to update
|
||||
|
|
|
@ -1,2 +1,2 @@
|
|||
@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