better way
parent
ddcd23b2d6
commit
25e02c23d9
|
@ -62,7 +62,7 @@ elseif ($Help) {
|
||||||
}
|
}
|
||||||
elseif ($NotifApproved){
|
elseif ($NotifApproved){
|
||||||
$MessageBody = "Do you want to update these apps ?`n`n"
|
$MessageBody = "Do you want to update these apps ?`n`n"
|
||||||
$MessageBody += Get-Content "$WorkingDir/config/NotifContent.txt" -Raw
|
$MessageBody += (Import-Csv "$WorkingDir/Config/NotifAppList.csv").name
|
||||||
$Title = "Winget-AutoUpdate"
|
$Title = "Winget-AutoUpdate"
|
||||||
if ($NotifApproved -eq "wau:systemDialogBox"){
|
if ($NotifApproved -eq "wau:systemDialogBox"){
|
||||||
Add-Type -AssemblyName PresentationCore,PresentationFramework
|
Add-Type -AssemblyName PresentationCore,PresentationFramework
|
||||||
|
|
|
@ -236,29 +236,6 @@ if (Test-Network) {
|
||||||
$Log | out-file -filepath $LogFile -Append
|
$Log | out-file -filepath $LogFile -Append
|
||||||
}
|
}
|
||||||
|
|
||||||
#Ask user to approve, if configured
|
|
||||||
if ($WAUConfig.WAU_UserApproval -eq 1){
|
|
||||||
Write-ToLog "User Approval feature enabled."
|
|
||||||
|
|
||||||
#Check for approved tag
|
|
||||||
$WAUNotifApproved = "$WorkingDir/Config/NotifApproved.txt"
|
|
||||||
if (Test-Path $WAUNotifApproved) {
|
|
||||||
Write-ToLog "-> User approved update notification."
|
|
||||||
Remove-Item $WAUNotifApproved -Force -Confirm:$false
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$UserApprovalReturn = Invoke-UserApproval $outdated
|
|
||||||
if ($UserApprovalReturn -eq 0){
|
|
||||||
Write-ToLog "-> User approval requested. Waiting for user to approve available updates... Closing for now."
|
|
||||||
#Closing job, waiting for user approval
|
|
||||||
Exit 0
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
Write-ToLog "-> No update to request to user."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#Count good update installations
|
#Count good update installations
|
||||||
$Script:InstallOK = 0
|
$Script:InstallOK = 0
|
||||||
|
|
||||||
|
@ -269,12 +246,14 @@ if (Test-Network) {
|
||||||
$toSkip = $null
|
$toSkip = $null
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#Generate App List to update
|
||||||
|
$Script:AppListToUpdate = @()
|
||||||
#If White List
|
#If White List
|
||||||
if ($UseWhiteList) {
|
if ($UseWhiteList) {
|
||||||
#For each app, notify and update
|
#For each app, notify and update
|
||||||
foreach ($app in $outdated) {
|
foreach ($app in $outdated) {
|
||||||
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown") {
|
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown") {
|
||||||
Update-App $app
|
$AppListToUpdate += $app
|
||||||
}
|
}
|
||||||
#if current app version is unknown
|
#if current app version is unknown
|
||||||
elseif ($($app.Version) -eq "Unknown") {
|
elseif ($($app.Version) -eq "Unknown") {
|
||||||
|
@ -291,7 +270,7 @@ if (Test-Network) {
|
||||||
#For each app, notify and update
|
#For each app, notify and update
|
||||||
foreach ($app in $outdated) {
|
foreach ($app in $outdated) {
|
||||||
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown") {
|
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown") {
|
||||||
Update-App $app
|
$AppListToUpdate += $app
|
||||||
}
|
}
|
||||||
#if current app version is unknown
|
#if current app version is unknown
|
||||||
elseif ($($app.Version) -eq "Unknown") {
|
elseif ($($app.Version) -eq "Unknown") {
|
||||||
|
@ -304,6 +283,19 @@ if (Test-Network) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#Ask user to approve, if configured
|
||||||
|
if ($WAUConfig.WAU_UserApproval -eq 1){
|
||||||
|
Write-ToLog "User Approval feature enabled."
|
||||||
|
if ($AppListToUpdate){
|
||||||
|
Invoke-UserApproval $AppListToUpdate
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Update apps
|
||||||
|
foreach ($App in $AppListToUpdate){
|
||||||
|
Update-App $App
|
||||||
|
}
|
||||||
|
|
||||||
if ($InstallOK -gt 0) {
|
if ($InstallOK -gt 0) {
|
||||||
Write-ToLog "$InstallOK apps updated ! No more update." "Green"
|
Write-ToLog "$InstallOK apps updated ! No more update." "Green"
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,17 +1,23 @@
|
||||||
#Function to ask user consent before updating apps
|
#Function to ask user consent before updating apps
|
||||||
|
|
||||||
function Invoke-UserApproval ($outdated){
|
function Invoke-UserApproval ($Apps){
|
||||||
|
|
||||||
|
$WAUNotifApproved = "$WorkingDir/Config/NotifApproved.txt"
|
||||||
|
$WAUNotifAppList = "$WorkingDir/Config/NotifAppList.csv"
|
||||||
|
|
||||||
|
#Check for approved file
|
||||||
|
if (Test-Path $WAUNotifApproved) {
|
||||||
|
Write-ToLog "-> User approved update notification."
|
||||||
|
$AppListToUpdate = Import-Csv $WAUNotifAppList
|
||||||
|
Remove-Item $WAUNotifApproved -Force -Confirm:$false
|
||||||
|
Remove-Item $WAUNotifAppList -Force -Confirm:$false
|
||||||
|
}
|
||||||
|
#Otherwise generate AppList and send notif
|
||||||
|
else {
|
||||||
|
Write-ToLog "-> Creating AppList user must approve"
|
||||||
|
$Apps | Export-Csv -Path $WAUNotifAppList -NoTypeInformation -Encoding UTF8
|
||||||
|
|
||||||
#Create / Update WAU Class for notification action
|
|
||||||
if ($IsSystem) {
|
if ($IsSystem) {
|
||||||
$WAUClass = "HKLM:\Software\Classes\WAU"
|
|
||||||
$WAUClassCmd = "$WAUClass\shell\open\command"
|
|
||||||
$WAUClassRun = "Wscript.exe ""$WorkingDir\Invisible.vbs"" ""powershell.exe -NoProfile -ExecutionPolicy Bypass -Command & '$WorkingDir\User-Run.ps1' -NotifApproved %1"""
|
|
||||||
New-Item $WAUClassCmd -Force -ErrorAction SilentlyContinue | Out-Null
|
|
||||||
New-ItemProperty -LiteralPath $WAUClass -Name 'URL Protocol' -Value '' -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
|
|
||||||
New-ItemProperty -LiteralPath $WAUClass -Name '(default)' -Value "URL:WAU" -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
|
|
||||||
New-ItemProperty -LiteralPath $WAUClass -Name 'EditFlags' -Value '2162688' -PropertyType DWord -Force -ErrorAction SilentlyContinue | Out-Null
|
|
||||||
New-ItemProperty -LiteralPath $WAUClassCmd -Name '(default)' -Value $WAUClassRun -PropertyType String -Force -ErrorAction SilentlyContinue | Out-Null
|
|
||||||
$Button1Action = "wau:system"
|
$Button1Action = "wau:system"
|
||||||
$OnClickAction = "wau:systemDialogBox"
|
$OnClickAction = "wau:systemDialogBox"
|
||||||
}
|
}
|
||||||
|
@ -20,39 +26,16 @@ function Invoke-UserApproval ($outdated){
|
||||||
$OnClickAction = "wau:userDialogBox"
|
$OnClickAction = "wau:userDialogBox"
|
||||||
}
|
}
|
||||||
|
|
||||||
$OutdatedApps = @()
|
|
||||||
#If White List
|
|
||||||
if ($WAUConfig.WAU_UseWhiteList -eq 1) {
|
|
||||||
$toUpdate = Get-IncludedApps
|
|
||||||
foreach ($app in $Outdated) {
|
|
||||||
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown") {
|
|
||||||
$OutdatedApps += "- $($app.Name)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
#If Black List or default
|
|
||||||
else {
|
|
||||||
$toSkip = Get-ExcludedApps
|
|
||||||
foreach ($app in $Outdated) {
|
|
||||||
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown") {
|
|
||||||
$OutdatedApps += "- $($app.Name)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$body = $OutdatedApps | Out-String
|
|
||||||
if ($body) {
|
|
||||||
#Ask user to update apps
|
#Ask user to update apps
|
||||||
|
|
||||||
|
$body = $Apps.Name | Out-String
|
||||||
$Message = "Do you want to update these apps ?"
|
$Message = "Do you want to update these apps ?"
|
||||||
$body += "`nPlease save your work and close theses apps"
|
$body += "`nPlease save your work and close theses apps"
|
||||||
$WAUNotifContent = "$WorkingDir\config\NotifContent.txt"
|
|
||||||
New-Item -Path $WAUNotifContent -ItemType File -Force | Out-Null
|
|
||||||
Set-Content -Path $WAUNotifContent -Value $body
|
|
||||||
Start-NotifTask -Title "New available updates" -Message $Message -Body $body -ButtonDismiss -Button1Text "Yes" -Button1Action $Button1Action -OnClickAction $OnClickAction -MessageType "info"
|
Start-NotifTask -Title "New available updates" -Message $Message -Body $body -ButtonDismiss -Button1Text "Yes" -Button1Action $Button1Action -OnClickAction $OnClickAction -MessageType "info"
|
||||||
Return 0
|
|
||||||
}
|
Write-ToLog "-> User approval requested. Waiting for user to approve available updates... Closing for now."
|
||||||
else {
|
#Closing job, waiting for user approval
|
||||||
Return 1
|
Exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue