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,58 +1,41 @@
|
||||||
#Function to ask user consent before updating apps
|
#Function to ask user consent before updating apps
|
||||||
|
|
||||||
function Invoke-UserApproval ($outdated){
|
function Invoke-UserApproval ($Apps){
|
||||||
|
|
||||||
#Create / Update WAU Class for notification action
|
$WAUNotifApproved = "$WorkingDir/Config/NotifApproved.txt"
|
||||||
if ($IsSystem) {
|
$WAUNotifAppList = "$WorkingDir/Config/NotifAppList.csv"
|
||||||
$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"
|
|
||||||
$OnClickAction = "wau:systemDialogBox"
|
|
||||||
}
|
|
||||||
else{
|
|
||||||
$Button1Action = "wau:user"
|
|
||||||
$OnClickAction = "wau:userDialogBox"
|
|
||||||
}
|
|
||||||
|
|
||||||
$OutdatedApps = @()
|
#Check for approved file
|
||||||
#If White List
|
if (Test-Path $WAUNotifApproved) {
|
||||||
if ($WAUConfig.WAU_UseWhiteList -eq 1) {
|
Write-ToLog "-> User approved update notification."
|
||||||
$toUpdate = Get-IncludedApps
|
$AppListToUpdate = Import-Csv $WAUNotifAppList
|
||||||
foreach ($app in $Outdated) {
|
Remove-Item $WAUNotifApproved -Force -Confirm:$false
|
||||||
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown") {
|
Remove-Item $WAUNotifAppList -Force -Confirm:$false
|
||||||
$OutdatedApps += "- $($app.Name)"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
#If Black List or default
|
#Otherwise generate AppList and send notif
|
||||||
else {
|
else {
|
||||||
$toSkip = Get-ExcludedApps
|
Write-ToLog "-> Creating AppList user must approve"
|
||||||
foreach ($app in $Outdated) {
|
$Apps | Export-Csv -Path $WAUNotifAppList -NoTypeInformation -Encoding UTF8
|
||||||
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown") {
|
|
||||||
$OutdatedApps += "- $($app.Name)"
|
if ($IsSystem) {
|
||||||
}
|
$Button1Action = "wau:system"
|
||||||
}
|
$OnClickAction = "wau:systemDialogBox"
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
|
$Button1Action = "wau:user"
|
||||||
|
$OnClickAction = "wau:userDialogBox"
|
||||||
|
}
|
||||||
|
|
||||||
$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