minor changes

pull/2/head
Romain 2022-01-27 21:56:45 +01:00 committed by GitHub
parent b4adb584dd
commit b2068b37ac
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 26 deletions

View File

@ -1,7 +1,7 @@
#Send Notif Script #Send Notif Script
#get xml notif config #get xml notif config
[xml]$NotifConf = Get-Content "C:\ProgramData\winget-update\notif.xml" -Encoding UTF8 -ErrorAction SilentlyContinue [xml]$NotifConf = Get-Content "$env:ProgramData\winget-update\notif.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
if (!($NotifConf)) {break} if (!($NotifConf)) {break}
#Load Assemblies #Load Assemblies

View File

@ -1,4 +1,4 @@
### FUNCTIONS ### <# FUNCTIONS #>
function Init { function Init {
#Var #Var
@ -62,7 +62,7 @@ function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
"@ "@
#Save XML File #Save XML File
$ToastTemplateLocation = "C:\ProgramData\winget-update\" $ToastTemplateLocation = "$env:ProgramData\winget-update\"
if (!(Test-Path $ToastTemplateLocation)){ if (!(Test-Path $ToastTemplateLocation)){
New-Item -ItemType Directory -Force -Path $ToastTemplateLocation New-Item -ItemType Directory -Force -Path $ToastTemplateLocation
} }
@ -101,9 +101,8 @@ function Test-Network {
Start-Sleep 10 Start-Sleep 10
$timeout += 10 $timeout += 10
Write-Log "Checking internet connection. $($timeout)s." "Yellow" Write-Log "Checking internet connection. $($timeout)s." "Yellow"
}
if ($timeout -eq 300){
#Send Notif if no connection for 5 min #Send Notif if no connection for 5 min
if ($timeout -eq 300){
Write-Log "Notify 'No connection'" "Yellow" Write-Log "Notify 'No connection'" "Yellow"
$Title = $NotifLocale.local.outputs.output[0].title $Title = $NotifLocale.local.outputs.output[0].title
$Message = $NotifLocale.local.outputs.output[0].message $Message = $NotifLocale.local.outputs.output[0].message
@ -112,6 +111,7 @@ function Test-Network {
Start-NotifTask $Title $Message $MessageType $Balise Start-NotifTask $Title $Message $MessageType $Balise
} }
} }
}
Write-Log "Timeout. No internet connection !" "Red" Write-Log "Timeout. No internet connection !" "Red"
#Send Notif if no connection for 30 min #Send Notif if no connection for 30 min
$Title = $NotifLocale.local.outputs.output[1].title $Title = $NotifLocale.local.outputs.output[1].title
@ -207,16 +207,13 @@ function Get-ExcludedApps{
} }
<# MAIN #>
### MAIN ###
#Run initialisation #Run initialisation
Init Init
#Check network connectivity #Check network connectivity
$ping = Test-Network if (Test-Network){
if ($ping){
#Get exclude apps list #Get exclude apps list
$toSkip = Get-ExcludedApps $toSkip = Get-ExcludedApps
@ -249,17 +246,10 @@ if ($ping){
$Balise = $($app.Name) $Balise = $($app.Name)
Start-NotifTask $Title $Message $MessageType $Balise Start-NotifTask $Title $Message $MessageType $Balise
#Install update
$Log = "#--- Winget - $($app.Name) Upgrade Starts ---"
$Log | Write-host -ForegroundColor Gray
$Log | out-file -filepath $LogFile -Append
#Winget upgrade #Winget upgrade
Write-Log "------ Winget - $($app.Name) Upgrade Starts ------" "Gray"
& $upgradecmd upgrade -e --id $($app.Id) --accept-package-agreements --accept-source-agreements -h & $upgradecmd upgrade -e --id $($app.Id) --accept-package-agreements --accept-source-agreements -h
Write-Log "----- Winget - $($app.Name) Upgrade Finished -----" "Gray"
$Log = "#--- Winget - $($app.Name) Upgrade Finished ---"
$Log | Write-host -ForegroundColor Gray
$Log | out-file -filepath $LogFile -Append
#Check installed version #Check installed version
$checkoutdated = Get-WingetOutdated $checkoutdated = Get-WingetOutdated