From a4404dfb184ce31622925a09c64b9ff45cfc072f Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Mon, 14 Mar 2022 14:55:02 +0100
Subject: [PATCH 01/11] Start cleaning
---
.../functions/Get-ExcludedApps.ps1 | 5 +
.../functions/Get-NotifLocal.ps1 | 24 ++
.../functions/Get-WingetOutdated.ps1 | 75 ++++
Winget-AutoUpdate/functions/Start-Init.ps1 | 30 ++
.../functions/Start-NotifTask.ps1 | 52 +++
.../functions/Start-WAUUpdateCheck.ps1 | 32 ++
Winget-AutoUpdate/functions/Test-Network.ps1 | 36 ++
Winget-AutoUpdate/functions/Update-WAU.ps1 | 66 ++++
Winget-AutoUpdate/functions/Write-Log.ps1 | 9 +
Winget-AutoUpdate/winget-upgrade.ps1 | 339 +-----------------
10 files changed, 339 insertions(+), 329 deletions(-)
create mode 100644 Winget-AutoUpdate/functions/Get-ExcludedApps.ps1
create mode 100644 Winget-AutoUpdate/functions/Get-NotifLocal.ps1
create mode 100644 Winget-AutoUpdate/functions/Get-WingetOutdated.ps1
create mode 100644 Winget-AutoUpdate/functions/Start-Init.ps1
create mode 100644 Winget-AutoUpdate/functions/Start-NotifTask.ps1
create mode 100644 Winget-AutoUpdate/functions/Start-WAUUpdateCheck.ps1
create mode 100644 Winget-AutoUpdate/functions/Test-Network.ps1
create mode 100644 Winget-AutoUpdate/functions/Update-WAU.ps1
create mode 100644 Winget-AutoUpdate/functions/Write-Log.ps1
diff --git a/Winget-AutoUpdate/functions/Get-ExcludedApps.ps1 b/Winget-AutoUpdate/functions/Get-ExcludedApps.ps1
new file mode 100644
index 0000000..efe9409
--- /dev/null
+++ b/Winget-AutoUpdate/functions/Get-ExcludedApps.ps1
@@ -0,0 +1,5 @@
+function Get-ExcludedApps{
+ if (Test-Path "$WorkingDir\excluded_apps.txt"){
+ return Get-Content -Path "$WorkingDir\excluded_apps.txt"
+ }
+}
\ No newline at end of file
diff --git a/Winget-AutoUpdate/functions/Get-NotifLocal.ps1 b/Winget-AutoUpdate/functions/Get-NotifLocal.ps1
new file mode 100644
index 0000000..483edab
--- /dev/null
+++ b/Winget-AutoUpdate/functions/Get-NotifLocal.ps1
@@ -0,0 +1,24 @@
+#Get locale file for Notification.
+
+Function Get-NotifLocal {
+ #Get OS locale
+ $OSLocale = (Get-Culture).Parent
+
+ #Test if OS locale notif file exists
+ $TestOSLocalPath = "$WorkingDir\locale\$($OSLocale.Name).xml"
+
+ #Set OS Local if file exists
+ if(Test-Path $TestOSLocalPath){
+ $LocaleDisplayName = $OSLocale.DisplayName
+ $LocaleFile = $TestOSLocalPath
+ }
+ #Set English if file doesn't exist
+ else{
+ $LocaleDisplayName = "English"
+ $LocaleFile = "$WorkingDir\locale\en.xml"
+ }
+
+ #Get locale XML file content
+ Write-Log "Notification Langugage : $LocaleDisplayName" "Cyan"
+ [xml]$Script:NotifLocale = Get-Content $LocaleFile -Encoding UTF8 -ErrorAction SilentlyContinue
+}
\ No newline at end of file
diff --git a/Winget-AutoUpdate/functions/Get-WingetOutdated.ps1 b/Winget-AutoUpdate/functions/Get-WingetOutdated.ps1
new file mode 100644
index 0000000..11ff4bf
--- /dev/null
+++ b/Winget-AutoUpdate/functions/Get-WingetOutdated.ps1
@@ -0,0 +1,75 @@
+function Get-WingetOutdated {
+ class Software {
+ [string]$Name
+ [string]$Id
+ [string]$Version
+ [string]$AvailableVersion
+ }
+
+ #Get WinGet Location
+ $WingetCmd = Get-Command winget.exe -ErrorAction SilentlyContinue
+ if ($WingetCmd){
+ $script:upgradecmd = $WingetCmd.Source
+ }
+ elseif (Test-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\AppInstallerCLI.exe"){
+ #WinGet < 1.17
+ $script:upgradecmd = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\AppInstallerCLI.exe" | Select-Object -ExpandProperty Path
+ }
+ elseif (Test-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"){
+ #WinGet > 1.17
+ $script:upgradecmd = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe" | Select-Object -ExpandProperty Path
+ }
+ else{
+ Write-Log "Winget not installed !"
+ return
+ }
+
+ #Run winget to list apps and accept source agrements (necessary on first run)
+ & $upgradecmd list --accept-source-agreements | Out-Null
+
+ #Get list of available upgrades on winget format
+ $upgradeResult = & $upgradecmd upgrade | Out-String
+
+ #Start Convertion of winget format to an array. Check if "-----" exists
+ if (!($upgradeResult -match "-----")){
+ return
+ }
+
+ #Split winget output to lines
+ $lines = $upgradeResult.Split([Environment]::NewLine).Replace("¦ ","")
+
+ # Find the line that starts with "------"
+ $fl = 0
+ while (-not $lines[$fl].StartsWith("-----")){
+ $fl++
+ }
+
+ #Get header line
+ $fl = $fl - 2
+
+ #Get header titles
+ $index = $lines[$fl] -split '\s+'
+
+ # Line $i 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])
+ $sourceStart = $lines[$fl].IndexOf($index[4])
+
+ # Now cycle in real package and split accordingly
+ $upgradeList = @()
+ For ($i = $fl + 2; $i -le $lines.Length; $i++){
+ $line = $lines[$i]
+ if ($line.Length -gt ($sourceStart+5) -and -not $line.StartsWith('-')){
+ $software = [Software]::new()
+ $software.Name = $line.Substring(0, $idStart).TrimEnd()
+ $software.Id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()
+ $software.Version = $line.Substring($versionStart, $availableStart - $versionStart).TrimEnd()
+ $software.AvailableVersion = $line.Substring($availableStart, $sourceStart - $availableStart).TrimEnd()
+ #add formated soft to list
+ $upgradeList += $software
+ }
+ }
+
+ return $upgradeList
+}
\ No newline at end of file
diff --git a/Winget-AutoUpdate/functions/Start-Init.ps1 b/Winget-AutoUpdate/functions/Start-Init.ps1
new file mode 100644
index 0000000..f7ee0b7
--- /dev/null
+++ b/Winget-AutoUpdate/functions/Start-Init.ps1
@@ -0,0 +1,30 @@
+#Initialisation
+
+function Start-Init {
+ #Config console output encoding
+ [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
+
+ #Log Header
+ $Log = "`n##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format 'dd/MM/yyyy')`n##################################################"
+ $Log | Write-host
+
+ #Logs initialisation if admin
+ try{
+ $LogPath = "$WorkingDir\logs"
+ if (!(Test-Path $LogPath)){
+ New-Item -ItemType Directory -Force -Path $LogPath
+ }
+ #Log file
+ $Script:LogFile = "$LogPath\updates.log"
+ $Log | out-file -filepath $LogFile -Append
+ }
+ #Logs initialisation if non-admin
+ catch{
+ $LogPath = "$env:USERPROFILE\Winget-AutoUpdate\logs"
+ if (!(Test-Path $LogPath)){
+ New-Item -ItemType Directory -Force -Path $LogPath
+ }
+ $Script:LogFile = "$LogPath\updates.log"
+ $Log | out-file -filepath $LogFile -Append
+ }
+}
\ No newline at end of file
diff --git a/Winget-AutoUpdate/functions/Start-NotifTask.ps1 b/Winget-AutoUpdate/functions/Start-NotifTask.ps1
new file mode 100644
index 0000000..feb8532
--- /dev/null
+++ b/Winget-AutoUpdate/functions/Start-NotifTask.ps1
@@ -0,0 +1,52 @@
+function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
+
+ #Add XML variables
+ [xml]$ToastTemplate = @"
+
+
+
+ $Title
+ $Message
+
+
+
+ $Balise
+
+"@
+
+ #Check if running account is system or interactive logon
+ $currentPrincipal = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-4")
+ #if not "Interactive" user, run as system
+ if ($currentPrincipal -eq $false){
+ #Save XML to File
+ $ToastTemplateLocation = "$env:ProgramData\Winget-AutoUpdate\"
+ if (!(Test-Path $ToastTemplateLocation)){
+ New-Item -ItemType Directory -Force -Path $ToastTemplateLocation
+ }
+ $ToastTemplate.Save("$ToastTemplateLocation\notif.xml")
+
+ #Run Notify scheduled task to notify conneted users
+ Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
+ }
+ #else, run as connected user
+ else{
+ #Load Assemblies
+ [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
+ [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
+
+ #Prepare XML
+ $ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New()
+ $ToastXml.LoadXml($ToastTemplate.OuterXml)
+
+ #Specify Launcher App ID
+ $LauncherID = "Windows.SystemToast.Winget.Notification"
+
+ #Prepare and Create Toast
+ $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXml)
+ $ToastMessage.Tag = $ToastTemplate.toast.tag
+ [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage)
+ }
+
+ #Wait for notification to display
+ Start-Sleep 3
+}
\ No newline at end of file
diff --git a/Winget-AutoUpdate/functions/Start-WAUUpdateCheck.ps1 b/Winget-AutoUpdate/functions/Start-WAUUpdateCheck.ps1
new file mode 100644
index 0000000..d072075
--- /dev/null
+++ b/Winget-AutoUpdate/functions/Start-WAUUpdateCheck.ps1
@@ -0,0 +1,32 @@
+function Start-WAUUpdateCheck{
+ #Get AutoUpdate status
+ [xml]$UpdateStatus = Get-Content "$WorkingDir\config\config.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
+ $AutoUpdateStatus = $UpdateStatus.app.WAUautoupdate
+
+ #Get current installed version
+ [xml]$About = Get-Content "$WorkingDir\config\about.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
+ [version]$Script:CurrentVersion = $About.app.version
+
+ #Check if AutoUpdate is enabled
+ if ($AutoUpdateStatus -eq $false){
+ Write-Log "WAU Current version: $CurrentVersion. AutoUpdate is disabled." "Cyan"
+ return $false
+ }
+ #If enabled, check online available version
+ else{
+ #Get Github latest version
+ $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases/latest'
+ $LatestVersion = (Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name
+ [version]$AvailableVersion = $LatestVersion.Replace("v","")
+
+ #If newer version is avalable, return $True
+ if ($AvailableVersion -gt $CurrentVersion){
+ Write-Log "WAU Current version: $CurrentVersion. Version $AvailableVersion is available." "Yellow"
+ return $true
+ }
+ else{
+ Write-Log "WAU Current version: $CurrentVersion. Up to date." "Green"
+ return $false
+ }
+ }
+}
diff --git a/Winget-AutoUpdate/functions/Test-Network.ps1 b/Winget-AutoUpdate/functions/Test-Network.ps1
new file mode 100644
index 0000000..422235a
--- /dev/null
+++ b/Winget-AutoUpdate/functions/Test-Network.ps1
@@ -0,0 +1,36 @@
+function Test-Network {
+ #init
+ $timeout = 0
+
+ #test connectivity during 30 min then timeout
+ Write-Log "Checking internet connection..." "Yellow"
+ While ($timeout -lt 1800){
+ try{
+ Invoke-RestMethod -Uri "https://api.github.com/zen"
+ Write-Log "Connected !" "Green"
+ return $true
+ }
+ catch{
+ Start-Sleep 10
+ $timeout += 10
+ Write-Log "Checking internet connection. $($timeout)s." "Yellow"
+ #Send Notif if no connection for 5 min
+ if ($timeout -eq 300){
+ Write-Log "Notify 'No connection' sent." "Yellow"
+ $Title = $NotifLocale.local.outputs.output[0].title
+ $Message = $NotifLocale.local.outputs.output[0].message
+ $MessageType = "warning"
+ $Balise = "connection"
+ Start-NotifTask $Title $Message $MessageType $Balise
+ }
+ }
+ }
+ Write-Log "Timeout. No internet connection !" "Red"
+ #Send Notif if no connection for 30 min
+ $Title = $NotifLocale.local.outputs.output[1].title
+ $Message = $NotifLocale.local.outputs.output[1].message
+ $MessageType = "error"
+ $Balise = "connection"
+ Start-NotifTask $Title $Message $MessageType $Balise
+ return $false
+}
\ No newline at end of file
diff --git a/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Winget-AutoUpdate/functions/Update-WAU.ps1
new file mode 100644
index 0000000..198c234
--- /dev/null
+++ b/Winget-AutoUpdate/functions/Update-WAU.ps1
@@ -0,0 +1,66 @@
+
+function Update-WAU{
+ #Get WAU Github latest version
+ $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases/latest'
+ $LatestVersion = (Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name
+
+ #Send available update notification
+ $Title = $NotifLocale.local.outputs.output[2].title -f "Winget-AutoUpdate"
+ $Message = $NotifLocale.local.outputs.output[2].message -f $CurrentVersion, $LatestVersion.Replace("v","")
+ $MessageType = "info"
+ $Balise = "Winget-AutoUpdate"
+ Start-NotifTask $Title $Message $MessageType $Balise
+
+ #Run WAU update
+ try{
+ #Force to create a zip file
+ $ZipFile = "$WorkingDir\WAU_update.zip"
+ New-Item $ZipFile -ItemType File -Force | Out-Null
+
+ #Download the zip
+ Write-Log "Starting downloading the GitHub Repository"
+ Invoke-RestMethod -Uri "https://api.github.com/repos/Romanitho/Winget-AutoUpdate/zipball/$($LatestVersion)" -OutFile $ZipFile
+ Write-Log 'Download finished'
+
+ #Extract Zip File
+ Write-Log "Starting unzipping the WAU GitHub Repository"
+ $location = "$WorkingDir\WAU_update"
+ Expand-Archive -Path $ZipFile -DestinationPath $location -Force
+ Get-ChildItem -Path $location -Recurse | Unblock-File
+ Write-Log "Unzip finished"
+ $TempPath = (Resolve-Path "$location\Romanitho-Winget-AutoUpdate*\Winget-AutoUpdate\").Path
+ Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Recurse -Force
+
+ #Remove update zip file
+ Write-Log "Cleaning temp files"
+ Remove-Item -Path $ZipFile -Force -ErrorAction SilentlyContinue
+ #Remove update folder
+ Remove-Item -Path $location -Recurse -Force -ErrorAction SilentlyContinue
+
+ #Set new version to conf.xml
+ [xml]$XMLconf = Get-content "$WorkingDir\config\about.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
+ $XMLconf.app.version = $LatestVersion.Replace("v","")
+ $XMLconf.Save("$WorkingDir\config\about.xml")
+
+ #Send success Notif
+ $Title = $NotifLocale.local.outputs.output[3].title -f "Winget-AutoUpdate"
+ $Message = $NotifLocale.local.outputs.output[3].message -f $LatestVersion
+ $MessageType = "success"
+ $Balise = "Winget-AutoUpdate"
+ Start-NotifTask $Title $Message $MessageType $Balise
+
+ #Rerun with newer version
+ Write-Log "Re-run WAU"
+ Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade`""
+ exit
+ }
+ catch{
+ #Send Error Notif
+ $Title = $NotifLocale.local.outputs.output[4].title -f "Winget-AutoUpdate"
+ $Message = $NotifLocale.local.outputs.output[4].message
+ $MessageType = "error"
+ $Balise = "Winget-AutoUpdate"
+ Start-NotifTask $Title $Message $MessageType $Balise
+ Write-Log "WAU Update failed"
+ }
+}
\ No newline at end of file
diff --git a/Winget-AutoUpdate/functions/Write-Log.ps1 b/Winget-AutoUpdate/functions/Write-Log.ps1
new file mode 100644
index 0000000..8b70103
--- /dev/null
+++ b/Winget-AutoUpdate/functions/Write-Log.ps1
@@ -0,0 +1,9 @@
+
+function Write-Log ($LogMsg,$LogColor = "White") {
+ #Get log
+ $Log = "$(Get-Date -UFormat "%T") - $LogMsg"
+ #Echo log
+ $Log | Write-host -ForegroundColor $LogColor
+ #Write log to file
+ $Log | Out-File -filepath $LogFile -Append
+}
diff --git a/Winget-AutoUpdate/winget-upgrade.ps1 b/Winget-AutoUpdate/winget-upgrade.ps1
index 3a79517..8831239 100644
--- a/Winget-AutoUpdate/winget-upgrade.ps1
+++ b/Winget-AutoUpdate/winget-upgrade.ps1
@@ -1,336 +1,17 @@
-<# FUNCTIONS #>
+<# LOAD FUNCTIONS #>
-function Init {
- #Var
- $Script:WorkingDir = $PSScriptRoot
-
- #Log Header
- $Log = "##################################################`n# CHECK FOR APP UPDATES - $(Get-Date -Format 'dd/MM/yyyy')`n##################################################"
- $Log | Write-host
- try{
- #Logs initialisation
- [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
- $LogPath = "$WorkingDir\logs"
- if (!(Test-Path $LogPath)){
- New-Item -ItemType Directory -Force -Path $LogPath
- }
- #Log file
- $Script:LogFile = "$LogPath\updates.log"
- $Log | out-file -filepath $LogFile -Append
- }
- catch{
- #Logs initialisation
- $LogPath = "$env:USERPROFILE\Winget-AutoUpdate\logs"
- if (!(Test-Path $LogPath)){
- New-Item -ItemType Directory -Force -Path $LogPath
- }
- $Script:LogFile = "$LogPath\updates.log"
- $Log | out-file -filepath $LogFile -Append
- }
-
- #Get locale file for Notification
- #Default english
- $DefaultLocale = "$WorkingDir\locale\en.xml"
- #Get OS locale
- $Locale = (Get-Culture).Parent
- #Test if OS locale config file exists
- $LocaleFile = "$WorkingDir\locale\$($locale.Name).xml"
- if(Test-Path $LocaleFile){
- [xml]$Script:NotifLocale = Get-Content $LocaleFile -Encoding UTF8 -ErrorAction SilentlyContinue
- $LocaleNotif = "Notification Langugage : $($locale.DisplayName)"
- }
- else{
- [xml]$Script:NotifLocale = Get-Content $DefaultLocale -Encoding UTF8 -ErrorAction SilentlyContinue
- $LocaleNotif = "Notification Langugage : English"
- }
- Write-Log $LocaleNotif "Cyan"
-}
-
-function Write-Log ($LogMsg,$LogColor = "White") {
- #Get log
- $Log = "$(Get-Date -UFormat "%T") - $LogMsg"
- #Echo log
- $Log | Write-host -ForegroundColor $LogColor
- #Write log to file
- $Log | Out-File -filepath $LogFile -Append
-}
-
-function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
-
- #Add XML variables
- [xml]$ToastTemplate = @"
-
-
-
- $Title
- $Message
-
-
-
- $Balise
-
-"@
-
- #Check if running account is system or interactive logon
- $currentPrincipal = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-4")
- #if not "Interactive" user, run as system
- if ($currentPrincipal -eq $false){
- #Save XML to File
- $ToastTemplateLocation = "$env:ProgramData\Winget-AutoUpdate\"
- if (!(Test-Path $ToastTemplateLocation)){
- New-Item -ItemType Directory -Force -Path $ToastTemplateLocation
- }
- $ToastTemplate.Save("$ToastTemplateLocation\notif.xml")
-
- #Run Notify scheduled task to notify conneted users
- Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
- }
- #else, run as connected user
- else{
- #Load Assemblies
- [Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null
- [Windows.Data.Xml.Dom.XmlDocument, Windows.Data.Xml.Dom.XmlDocument, ContentType = WindowsRuntime] | Out-Null
-
- #Prepare XML
- $ToastXml = [Windows.Data.Xml.Dom.XmlDocument]::New()
- $ToastXml.LoadXml($ToastTemplate.OuterXml)
-
- #Specify Launcher App ID
- $LauncherID = "Windows.SystemToast.Winget.Notification"
-
- #Prepare and Create Toast
- $ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXml)
- $ToastMessage.Tag = $ToastTemplate.toast.tag
- [Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage)
- }
-
- #Wait for notification to display
- Start-Sleep 3
-}
-
-function Test-Network {
- #init
- $timeout = 0
- $ping = $false
-
- #test connectivity during 30 min then timeout
- Write-Log "Checking internet connection..." "Yellow"
- while (!$ping -and $timeout -lt 1800){
- try{
- Invoke-RestMethod -Uri "https://api.github.com/zen"
- Write-Log "Connected !" "Green"
- return $true
- }
- catch{
- Start-Sleep 10
- $timeout += 10
- Write-Log "Checking internet connection. $($timeout)s." "Yellow"
- #Send Notif if no connection for 5 min
- if ($timeout -eq 300){
- Write-Log "Notify 'No connection'" "Yellow"
- $Title = $NotifLocale.local.outputs.output[0].title
- $Message = $NotifLocale.local.outputs.output[0].message
- $MessageType = "warning"
- $Balise = "connection"
- Start-NotifTask $Title $Message $MessageType $Balise
- }
- }
- }
- Write-Log "Timeout. No internet connection !" "Red"
- #Send Notif if no connection for 30 min
- $Title = $NotifLocale.local.outputs.output[1].title
- $Message = $NotifLocale.local.outputs.output[1].message
- $MessageType = "error"
- $Balise = "connection"
- Start-NotifTask $Title $Message $MessageType $Balise
- return $ping
-}
-
-function Get-WingetOutdated {
- class Software {
- [string]$Name
- [string]$Id
- [string]$Version
- [string]$AvailableVersion
- }
-
- #Get WinGet Location
- $WingetCmd = Get-Command winget.exe -ErrorAction SilentlyContinue
- if ($WingetCmd){
- $script:upgradecmd = $WingetCmd.Source
- }
- elseif (Test-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\AppInstallerCLI.exe"){
- #WinGet < 1.17
- $script:upgradecmd = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\AppInstallerCLI.exe" | Select-Object -ExpandProperty Path
- }
- elseif (Test-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"){
- #WinGet > 1.17
- $script:upgradecmd = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe" | Select-Object -ExpandProperty Path
- }
- else{
- Write-Log "Winget not installed !"
- return
- }
-
- #Run winget to list apps and accept source agrements (necessary on first run)
- & $upgradecmd list --accept-source-agreements | Out-Null
-
- #Get list of available upgrades on winget format
- $upgradeResult = & $upgradecmd upgrade | Out-String
-
- #Start Convertion of winget format to an array. Check if "-----" exists
- if (!($upgradeResult -match "-----")){
- return
- }
-
- #Split winget output to lines
- $lines = $upgradeResult.Split([Environment]::NewLine).Replace("¦ ","")
-
- # Find the line that starts with "------"
- $fl = 0
- while (-not $lines[$fl].StartsWith("-----")){
- $fl++
- }
-
- #Get header line
- $fl = $fl - 2
-
- #Get header titles
- $index = $lines[$fl] -split '\s+'
-
- # Line $i 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])
- $sourceStart = $lines[$fl].IndexOf($index[4])
-
- # Now cycle in real package and split accordingly
- $upgradeList = @()
- For ($i = $fl + 2; $i -le $lines.Length; $i++){
- $line = $lines[$i]
- if ($line.Length -gt ($sourceStart+5) -and -not $line.StartsWith('-')){
- $software = [Software]::new()
- $software.Name = $line.Substring(0, $idStart).TrimEnd()
- $software.Id = $line.Substring($idStart, $versionStart - $idStart).TrimEnd()
- $software.Version = $line.Substring($versionStart, $availableStart - $versionStart).TrimEnd()
- $software.AvailableVersion = $line.Substring($availableStart, $sourceStart - $availableStart).TrimEnd()
- #add formated soft to list
- $upgradeList += $software
- }
- }
-
- return $upgradeList
-}
-
-function Get-ExcludedApps{
- if (Test-Path "$WorkingDir\excluded_apps.txt"){
- return Get-Content -Path "$WorkingDir\excluded_apps.txt"
- }
-}
-
-function Start-WAUUpdateCheck{
- #Get AutoUpdate status
- [xml]$UpdateStatus = Get-Content "$WorkingDir\config\config.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
- $AutoUpdateStatus = $UpdateStatus.app.WAUautoupdate
-
- #Get current installed version
- [xml]$About = Get-Content "$WorkingDir\config\about.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
- [version]$Script:CurrentVersion = $About.app.version
-
- #Check if AutoUpdate is enabled
- if ($AutoUpdateStatus -eq $false){
- Write-Log "WAU Current version: $CurrentVersion. AutoUpdate is disabled." "Cyan"
- return $false
- }
- #If enabled, check online available version
- else{
- #Get Github latest version
- $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases/latest'
- $LatestVersion = (Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name
- [version]$AvailableVersion = $LatestVersion.Replace("v","")
-
- #If newer version is avalable, return $True
- if ($AvailableVersion -gt $CurrentVersion){
- Write-Log "WAU Current version: $CurrentVersion. Version $AvailableVersion is available." "Yellow"
- return $true
- }
- else{
- Write-Log "WAU Current version: $CurrentVersion. Up to date." "Green"
- return $false
- }
- }
-}
-
-function Update-WAU{
- #Get WAU Github latest version
- $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases/latest'
- $LatestVersion = (Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name
-
- #Send available update notification
- $Title = $NotifLocale.local.outputs.output[2].title -f "Winget-AutoUpdate"
- $Message = $NotifLocale.local.outputs.output[2].message -f $CurrentVersion, $LatestVersion.Replace("v","")
- $MessageType = "info"
- $Balise = "Winget-AutoUpdate"
- Start-NotifTask $Title $Message $MessageType $Balise
-
- #Run WAU update
- try{
- #Force to create a zip file
- $ZipFile = "$WorkingDir\WAU_update.zip"
- New-Item $ZipFile -ItemType File -Force | Out-Null
-
- #Download the zip
- Write-Log "Starting downloading the GitHub Repository"
- Invoke-RestMethod -Uri "https://api.github.com/repos/Romanitho/Winget-AutoUpdate/zipball/$($LatestVersion)" -OutFile $ZipFile
- Write-Log 'Download finished'
-
- #Extract Zip File
- Write-Log "Starting unzipping the WAU GitHub Repository"
- $location = "$WorkingDir\WAU_update"
- Expand-Archive -Path $ZipFile -DestinationPath $location -Force
- Get-ChildItem -Path $location -Recurse | Unblock-File
- Write-Log "Unzip finished"
- $TempPath = (Resolve-Path "$location\Romanitho-Winget-AutoUpdate*\Winget-AutoUpdate\").Path
- Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Recurse -Force
-
- #Remove update zip file
- Write-Log "Cleaning temp files"
- Remove-Item -Path $ZipFile -Force -ErrorAction SilentlyContinue
- #Remove update folder
- Remove-Item -Path $location -Recurse -Force -ErrorAction SilentlyContinue
-
- #Set new version to conf.xml
- [xml]$XMLconf = Get-content "$WorkingDir\config\about.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
- $XMLconf.app.version = $LatestVersion.Replace("v","")
- $XMLconf.Save("$WorkingDir\config\about.xml")
-
- #Send success Notif
- $Title = $NotifLocale.local.outputs.output[3].title -f "Winget-AutoUpdate"
- $Message = $NotifLocale.local.outputs.output[3].message -f $LatestVersion
- $MessageType = "success"
- $Balise = "Winget-AutoUpdate"
- Start-NotifTask $Title $Message $MessageType $Balise
-
- #Rerun with newer version
- Write-Log "Re-run WAU"
- Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade`""
- exit
- }
- catch{
- #Send Error Notif
- $Title = $NotifLocale.local.outputs.output[4].title -f "Winget-AutoUpdate"
- $Message = $NotifLocale.local.outputs.output[4].message
- $MessageType = "error"
- $Balise = "Winget-AutoUpdate"
- Start-NotifTask $Title $Message $MessageType $Balise
- Write-Log "WAU Update failed"
- }
-}
+#Get Working Dir
+$Script:WorkingDir = $PSScriptRoot
+#Get Functions
+Get-ChildItem "$WorkingDir\functions" | ForEach-Object {. $_.FullName}
<# MAIN #>
-#Run initialisation
-Init
+#Run log initialisation function
+Start-Init
+
+#Get Notif Locale function
+Get-NotifLocal
#Check network connectivity
if (Test-Network){
From 86caa304de954129c2a0ef0459a962462c2311d5 Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Mon, 14 Mar 2022 15:49:38 +0100
Subject: [PATCH 02/11] Change notif.xml path to config folder
---
Winget-AutoUpdate/functions/Start-NotifTask.ps1 | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Winget-AutoUpdate/functions/Start-NotifTask.ps1 b/Winget-AutoUpdate/functions/Start-NotifTask.ps1
index feb8532..3de8efe 100644
--- a/Winget-AutoUpdate/functions/Start-NotifTask.ps1
+++ b/Winget-AutoUpdate/functions/Start-NotifTask.ps1
@@ -23,7 +23,7 @@ function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
if (!(Test-Path $ToastTemplateLocation)){
New-Item -ItemType Directory -Force -Path $ToastTemplateLocation
}
- $ToastTemplate.Save("$ToastTemplateLocation\notif.xml")
+ $ToastTemplate.Save("$ToastTemplateLocation\config\notif.xml")
#Run Notify scheduled task to notify conneted users
Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
@@ -49,4 +49,4 @@ function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
#Wait for notification to display
Start-Sleep 3
-}
\ No newline at end of file
+}
From dff96f3cc9dd59e11cf2f6575fa0a1becdc9d583 Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Mon, 14 Mar 2022 15:51:27 +0100
Subject: [PATCH 03/11] Update Start-NotifTask.ps1
---
Winget-AutoUpdate/functions/Start-NotifTask.ps1 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Winget-AutoUpdate/functions/Start-NotifTask.ps1 b/Winget-AutoUpdate/functions/Start-NotifTask.ps1
index 3de8efe..46c8a68 100644
--- a/Winget-AutoUpdate/functions/Start-NotifTask.ps1
+++ b/Winget-AutoUpdate/functions/Start-NotifTask.ps1
@@ -23,7 +23,7 @@ function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
if (!(Test-Path $ToastTemplateLocation)){
New-Item -ItemType Directory -Force -Path $ToastTemplateLocation
}
- $ToastTemplate.Save("$ToastTemplateLocation\config\notif.xml")
+ $ToastTemplate.Save("$ToastTemplateLocation\notif.xml")
#Run Notify scheduled task to notify conneted users
Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
From 57601cf97c54601ee28389866523c3cf37355eaa Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Mon, 14 Mar 2022 16:03:46 +0100
Subject: [PATCH 04/11] Update notif config to config folder
---
Winget-AutoUpdate/functions/Start-NotifTask.ps1 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Winget-AutoUpdate/functions/Start-NotifTask.ps1 b/Winget-AutoUpdate/functions/Start-NotifTask.ps1
index 46c8a68..3de8efe 100644
--- a/Winget-AutoUpdate/functions/Start-NotifTask.ps1
+++ b/Winget-AutoUpdate/functions/Start-NotifTask.ps1
@@ -23,7 +23,7 @@ function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
if (!(Test-Path $ToastTemplateLocation)){
New-Item -ItemType Directory -Force -Path $ToastTemplateLocation
}
- $ToastTemplate.Save("$ToastTemplateLocation\notif.xml")
+ $ToastTemplate.Save("$ToastTemplateLocation\config\notif.xml")
#Run Notify scheduled task to notify conneted users
Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
From d18dbd8e6739b61ecd47efa54a11eb003650beae Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Mon, 14 Mar 2022 16:04:02 +0100
Subject: [PATCH 05/11] Update notif config to config folder
---
Winget-AutoUpdate/winget-notify.ps1 | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Winget-AutoUpdate/winget-notify.ps1 b/Winget-AutoUpdate/winget-notify.ps1
index 7e6c517..c7034fb 100644
--- a/Winget-AutoUpdate/winget-notify.ps1
+++ b/Winget-AutoUpdate/winget-notify.ps1
@@ -1,7 +1,7 @@
#Send Notif Script
#get xml notif config
-[xml]$NotifConf = Get-Content "$env:ProgramData\Winget-AutoUpdate\notif.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
+[xml]$NotifConf = Get-Content "$env:ProgramData\Winget-AutoUpdate\config\notif.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
if (!($NotifConf)) {break}
#Load Assemblies
@@ -18,4 +18,4 @@ $LauncherID = "Windows.SystemToast.Winget.Notification"
#Prepare and Create Toast
$ToastMessage = [Windows.UI.Notifications.ToastNotification]::New($ToastXML)
$ToastMessage.Tag = $NotifConf.toast.tag
-[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage)
\ No newline at end of file
+[Windows.UI.Notifications.ToastNotificationManager]::CreateToastNotifier($LauncherID).Show($ToastMessage)
From f591d02170597422b239d1d89fcb1b6d2b2efcb1 Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Mon, 14 Mar 2022 16:14:41 +0100
Subject: [PATCH 06/11] v1.6.0
---
Winget-AutoUpdate/config/about.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Winget-AutoUpdate/config/about.xml b/Winget-AutoUpdate/config/about.xml
index b9af99a..d0c16b9 100644
--- a/Winget-AutoUpdate/config/about.xml
+++ b/Winget-AutoUpdate/config/about.xml
@@ -1,7 +1,7 @@
Winget-AutoUpdate (WAU)
- 1.5.3
+ 1.6.0
Romanitho
https://github.com/Romanitho/Winget-AutoUpdate
From 8b70447f6949662ca87b3c62a2ec01d2c601fbdd Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Mon, 21 Mar 2022 16:33:45 +0100
Subject: [PATCH 07/11] Update excluded_apps.txt
---
excluded_apps.txt | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/excluded_apps.txt b/excluded_apps.txt
index 225371a..de8b679 100644
--- a/excluded_apps.txt
+++ b/excluded_apps.txt
@@ -1,8 +1,11 @@
Google.Chrome
-Mozilla.Firefox
-Mozilla.Firefox.ESR
Microsoft.Edge
Microsoft.EdgeWebView2Runtime
Microsoft.Office
Microsoft.OneDrive
-Microsoft.Teams
\ No newline at end of file
+Microsoft.Teams
+Mozilla.Firefox
+Mozilla.Firefox.DeveloperEdition
+Mozilla.Firefox.ESR
+TeamViewer.TeamViewer
+TeamViewer.TeamViewer.Host
From 5a85b7433c8a49c8b3eb4368df4f7b9065309ab4 Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Mon, 21 Mar 2022 23:37:39 +0100
Subject: [PATCH 08/11] Update Update-WAU.ps1
---
Winget-AutoUpdate/functions/Update-WAU.ps1 | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Winget-AutoUpdate/functions/Update-WAU.ps1
index 198c234..297f04b 100644
--- a/Winget-AutoUpdate/functions/Update-WAU.ps1
+++ b/Winget-AutoUpdate/functions/Update-WAU.ps1
@@ -50,7 +50,7 @@ function Update-WAU{
Start-NotifTask $Title $Message $MessageType $Balise
#Rerun with newer version
- Write-Log "Re-run WAU"
+ Write-Log "Re-run WAU"
Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade`""
exit
}
@@ -63,4 +63,4 @@ function Update-WAU{
Start-NotifTask $Title $Message $MessageType $Balise
Write-Log "WAU Update failed"
}
-}
\ No newline at end of file
+}
From f4cbf05e7c4c53d71f425154ef6fd8634a943288 Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Tue, 22 Mar 2022 00:23:44 +0100
Subject: [PATCH 09/11] Update Update-WAU.ps1
---
Winget-AutoUpdate/functions/Update-WAU.ps1 | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Winget-AutoUpdate/functions/Update-WAU.ps1
index 297f04b..a025cbb 100644
--- a/Winget-AutoUpdate/functions/Update-WAU.ps1
+++ b/Winget-AutoUpdate/functions/Update-WAU.ps1
@@ -29,7 +29,7 @@ function Update-WAU{
Get-ChildItem -Path $location -Recurse | Unblock-File
Write-Log "Unzip finished"
$TempPath = (Resolve-Path "$location\Romanitho-Winget-AutoUpdate*\Winget-AutoUpdate\").Path
- Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Recurse -Force
+ Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Exclude "icons" -Recurse -Force
#Remove update zip file
Write-Log "Cleaning temp files"
From a57f7d838aefa469b9a94d8d8be68576b7376035 Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Tue, 22 Mar 2022 08:29:19 +0100
Subject: [PATCH 10/11] Update Winget-AutoUpdate-Install.ps1
---
Winget-AutoUpdate-Install.ps1 | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1
index df92a1f..3edb337 100644
--- a/Winget-AutoUpdate-Install.ps1
+++ b/Winget-AutoUpdate-Install.ps1
@@ -102,7 +102,7 @@ function Install-WingetAutoUpdate{
& reg add "HKCR\AppUserModelId\Windows.SystemToast.Winget.Notification" /v IconUri /t REG_EXPAND_SZ /d %SystemRoot%\system32\@WindowsUpdateToastIcon.png /f | Out-Null
# Settings for the scheduled task for Updates
- $taskAction = New-ScheduledTaskAction –Execute "powershell.exe" -Argument "-ExecutionPolicy Bypass -File `"$($WingetUpdatePath)\winget-upgrade.ps1`""
+ $taskAction = New-ScheduledTaskAction –Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$($WingetUpdatePath)\winget-upgrade.ps1`""
$taskTrigger1 = New-ScheduledTaskTrigger -AtLogOn
$taskTrigger2 = New-ScheduledTaskTrigger -Daily -At 6AM
$taskUserPrincipal = New-ScheduledTaskPrincipal -UserId S-1-5-18 -RunLevel Highest
@@ -113,7 +113,7 @@ function Install-WingetAutoUpdate{
Register-ScheduledTask -TaskName 'Winget-AutoUpdate' -InputObject $task -Force
# Settings for the scheduled task for Notifications
- $taskAction = New-ScheduledTaskAction –Execute "wscript.exe" -Argument "`"$($WingetUpdatePath)\Invisible.vbs`" `"powershell.exe -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`"`""
$taskUserPrincipal = New-ScheduledTaskPrincipal -GroupId S-1-5-11
$taskSettings = New-ScheduledTaskSettingsSet -Compatibility Win8 -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -ExecutionTimeLimit 00:05:00
From 94ca44bc495ae8f13c7290a1bcb4929a5c14c530 Mon Sep 17 00:00:00 2001
From: Romain <96626929+Romanitho@users.noreply.github.com>
Date: Tue, 22 Mar 2022 14:39:01 +0100
Subject: [PATCH 11/11] Cleanning
---
...Get-NotifLocal.ps1 => Get-NotifLocale.ps1} | 2 +-
.../functions/Get-WAUAvailableVersion.ps1 | 6 ++++
.../functions/Get-WAUCurrentVersion.ps1 | 6 ++++
.../functions/Get-WAUUpdateStatus.ps1 | 12 +++++++
...utdated.ps1 => Get-WingetOutdatedApps.ps1} | 2 +-
.../functions/Start-WAUUpdateCheck.ps1 | 32 -------------------
Winget-AutoUpdate/functions/Test-Network.ps1 | 17 +++++-----
Winget-AutoUpdate/functions/Update-WAU.ps1 | 22 ++++++-------
Winget-AutoUpdate/winget-upgrade.ps1 | 29 +++++++++++------
9 files changed, 63 insertions(+), 65 deletions(-)
rename Winget-AutoUpdate/functions/{Get-NotifLocal.ps1 => Get-NotifLocale.ps1} (95%)
create mode 100644 Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1
create mode 100644 Winget-AutoUpdate/functions/Get-WAUCurrentVersion.ps1
create mode 100644 Winget-AutoUpdate/functions/Get-WAUUpdateStatus.ps1
rename Winget-AutoUpdate/functions/{Get-WingetOutdated.ps1 => Get-WingetOutdatedApps.ps1} (98%)
delete mode 100644 Winget-AutoUpdate/functions/Start-WAUUpdateCheck.ps1
diff --git a/Winget-AutoUpdate/functions/Get-NotifLocal.ps1 b/Winget-AutoUpdate/functions/Get-NotifLocale.ps1
similarity index 95%
rename from Winget-AutoUpdate/functions/Get-NotifLocal.ps1
rename to Winget-AutoUpdate/functions/Get-NotifLocale.ps1
index 483edab..388f254 100644
--- a/Winget-AutoUpdate/functions/Get-NotifLocal.ps1
+++ b/Winget-AutoUpdate/functions/Get-NotifLocale.ps1
@@ -1,6 +1,6 @@
#Get locale file for Notification.
-Function Get-NotifLocal {
+Function Get-NotifLocale {
#Get OS locale
$OSLocale = (Get-Culture).Parent
diff --git a/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 b/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1
new file mode 100644
index 0000000..bfe0af0
--- /dev/null
+++ b/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1
@@ -0,0 +1,6 @@
+function Get-WAUAvailableVersion{
+ #Get Github latest version
+ $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases/latest'
+ $Script:WAULatestVersion = ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v","")
+ return [version]$WAULatestVersion
+}
\ No newline at end of file
diff --git a/Winget-AutoUpdate/functions/Get-WAUCurrentVersion.ps1 b/Winget-AutoUpdate/functions/Get-WAUCurrentVersion.ps1
new file mode 100644
index 0000000..49e3e2d
--- /dev/null
+++ b/Winget-AutoUpdate/functions/Get-WAUCurrentVersion.ps1
@@ -0,0 +1,6 @@
+function Get-WAUCurrentVersion{
+ #Get current installed version
+ [xml]$About = Get-Content "$WorkingDir\config\about.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
+ $Script:WAUCurrentVersion = $About.app.version
+ return [version]$WAUCurrentVersion
+}
\ No newline at end of file
diff --git a/Winget-AutoUpdate/functions/Get-WAUUpdateStatus.ps1 b/Winget-AutoUpdate/functions/Get-WAUUpdateStatus.ps1
new file mode 100644
index 0000000..477ac37
--- /dev/null
+++ b/Winget-AutoUpdate/functions/Get-WAUUpdateStatus.ps1
@@ -0,0 +1,12 @@
+function Get-WAUUpdateStatus{
+ #Get AutoUpdate status
+ [xml]$UpdateStatus = Get-Content "$WorkingDir\config\config.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
+ if ($true -eq $UpdateStatus.app.WAUautoupdate){
+ Write-Log "WAU AutoUpdate is Enabled" "Green"
+ return $true
+ }
+ else{
+ Write-Log "WAU AutoUpdate is Disabled" "Grey"
+ return $false
+ }
+}
\ No newline at end of file
diff --git a/Winget-AutoUpdate/functions/Get-WingetOutdated.ps1 b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1
similarity index 98%
rename from Winget-AutoUpdate/functions/Get-WingetOutdated.ps1
rename to Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1
index 11ff4bf..b6ab413 100644
--- a/Winget-AutoUpdate/functions/Get-WingetOutdated.ps1
+++ b/Winget-AutoUpdate/functions/Get-WingetOutdatedApps.ps1
@@ -1,4 +1,4 @@
-function Get-WingetOutdated {
+function Get-WingetOutdatedApps {
class Software {
[string]$Name
[string]$Id
diff --git a/Winget-AutoUpdate/functions/Start-WAUUpdateCheck.ps1 b/Winget-AutoUpdate/functions/Start-WAUUpdateCheck.ps1
deleted file mode 100644
index d072075..0000000
--- a/Winget-AutoUpdate/functions/Start-WAUUpdateCheck.ps1
+++ /dev/null
@@ -1,32 +0,0 @@
-function Start-WAUUpdateCheck{
- #Get AutoUpdate status
- [xml]$UpdateStatus = Get-Content "$WorkingDir\config\config.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
- $AutoUpdateStatus = $UpdateStatus.app.WAUautoupdate
-
- #Get current installed version
- [xml]$About = Get-Content "$WorkingDir\config\about.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
- [version]$Script:CurrentVersion = $About.app.version
-
- #Check if AutoUpdate is enabled
- if ($AutoUpdateStatus -eq $false){
- Write-Log "WAU Current version: $CurrentVersion. AutoUpdate is disabled." "Cyan"
- return $false
- }
- #If enabled, check online available version
- else{
- #Get Github latest version
- $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases/latest'
- $LatestVersion = (Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name
- [version]$AvailableVersion = $LatestVersion.Replace("v","")
-
- #If newer version is avalable, return $True
- if ($AvailableVersion -gt $CurrentVersion){
- Write-Log "WAU Current version: $CurrentVersion. Version $AvailableVersion is available." "Yellow"
- return $true
- }
- else{
- Write-Log "WAU Current version: $CurrentVersion. Up to date." "Green"
- return $false
- }
- }
-}
diff --git a/Winget-AutoUpdate/functions/Test-Network.ps1 b/Winget-AutoUpdate/functions/Test-Network.ps1
index 422235a..9ce37e8 100644
--- a/Winget-AutoUpdate/functions/Test-Network.ps1
+++ b/Winget-AutoUpdate/functions/Test-Network.ps1
@@ -1,20 +1,20 @@
function Test-Network {
- #init
+ #Init
$timeout = 0
- #test connectivity during 30 min then timeout
+ #Test connectivity during 30 min then timeout
Write-Log "Checking internet connection..." "Yellow"
While ($timeout -lt 1800){
- try{
- Invoke-RestMethod -Uri "https://api.github.com/zen"
+ $TestNetwork = Test-NetConnection 8.8.8.8 -Port 443 -InformationLevel Quiet
+ if ($TestNetwork){
Write-Log "Connected !" "Green"
return $true
}
- catch{
+ else{
Start-Sleep 10
$timeout += 10
- Write-Log "Checking internet connection. $($timeout)s." "Yellow"
- #Send Notif if no connection for 5 min
+
+ #Send Warning Notif if no connection for 5 min
if ($timeout -eq 300){
Write-Log "Notify 'No connection' sent." "Yellow"
$Title = $NotifLocale.local.outputs.output[0].title
@@ -25,8 +25,9 @@ function Test-Network {
}
}
}
+
+ #Send Timeout Notif if no connection for 30 min
Write-Log "Timeout. No internet connection !" "Red"
- #Send Notif if no connection for 30 min
$Title = $NotifLocale.local.outputs.output[1].title
$Message = $NotifLocale.local.outputs.output[1].message
$MessageType = "error"
diff --git a/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Winget-AutoUpdate/functions/Update-WAU.ps1
index a025cbb..23f2540 100644
--- a/Winget-AutoUpdate/functions/Update-WAU.ps1
+++ b/Winget-AutoUpdate/functions/Update-WAU.ps1
@@ -1,9 +1,5 @@
-function Update-WAU{
- #Get WAU Github latest version
- $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases/latest'
- $LatestVersion = (Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name
-
+function Update-WAU ($VersionToUpdate){
#Send available update notification
$Title = $NotifLocale.local.outputs.output[2].title -f "Winget-AutoUpdate"
$Message = $NotifLocale.local.outputs.output[2].message -f $CurrentVersion, $LatestVersion.Replace("v","")
@@ -18,16 +14,16 @@ function Update-WAU{
New-Item $ZipFile -ItemType File -Force | Out-Null
#Download the zip
- Write-Log "Starting downloading the GitHub Repository"
- Invoke-RestMethod -Uri "https://api.github.com/repos/Romanitho/Winget-AutoUpdate/zipball/$($LatestVersion)" -OutFile $ZipFile
- Write-Log 'Download finished'
+ Write-Log "Starting downloading the GitHub Repository version $VersionToUpdate"
+ Invoke-RestMethod -Uri "https://github.com/Romanitho/Winget-AutoUpdate/archive/refs/tags/v$($VersionToUpdate).zip/" -OutFile $ZipFile
+ Write-Log "Download finished" "Green"
#Extract Zip File
Write-Log "Starting unzipping the WAU GitHub Repository"
$location = "$WorkingDir\WAU_update"
Expand-Archive -Path $ZipFile -DestinationPath $location -Force
Get-ChildItem -Path $location -Recurse | Unblock-File
- Write-Log "Unzip finished"
+ Write-Log "Unzip finished" "Green"
$TempPath = (Resolve-Path "$location\Romanitho-Winget-AutoUpdate*\Winget-AutoUpdate\").Path
Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Exclude "icons" -Recurse -Force
@@ -37,9 +33,9 @@ function Update-WAU{
#Remove update folder
Remove-Item -Path $location -Recurse -Force -ErrorAction SilentlyContinue
- #Set new version to conf.xml
+ #Set new version to about.xml
[xml]$XMLconf = Get-content "$WorkingDir\config\about.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
- $XMLconf.app.version = $LatestVersion.Replace("v","")
+ $XMLconf.app.version = $VersionToUpdate
$XMLconf.Save("$WorkingDir\config\about.xml")
#Send success Notif
@@ -50,8 +46,8 @@ function Update-WAU{
Start-NotifTask $Title $Message $MessageType $Balise
#Rerun with newer version
- Write-Log "Re-run WAU"
- Start-Process powershell -ArgumentList "-ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade`""
+ Write-Log "Re-run WAU"
+ Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade`""
exit
}
catch{
diff --git a/Winget-AutoUpdate/winget-upgrade.ps1 b/Winget-AutoUpdate/winget-upgrade.ps1
index 8831239..c890b25 100644
--- a/Winget-AutoUpdate/winget-upgrade.ps1
+++ b/Winget-AutoUpdate/winget-upgrade.ps1
@@ -5,21 +5,30 @@ $Script:WorkingDir = $PSScriptRoot
#Get Functions
Get-ChildItem "$WorkingDir\functions" | ForEach-Object {. $_.FullName}
+
<# MAIN #>
#Run log initialisation function
Start-Init
#Get Notif Locale function
-Get-NotifLocal
+Get-NotifLocale
#Check network connectivity
if (Test-Network){
- #Check if WAU is up to date
- $CheckWAUupdate = Start-WAUUpdateCheck
- #If AutoUpdate is enabled and Update is avalaible, then run WAU update
- if ($CheckWAUupdate){
- Update-WAU
+ #Check if WAU update feature is enabled
+ $WAUAutoUpdateEnabled = Get-WAUUpdateStatus
+ #If yes then check WAU update
+ if ($WAUAutoUpdateEnabled){
+ #Get Current Version
+ $WAUCurrentVersion = Get-WAUCurrentVersion
+ #Get Available Version
+ $WAUAvailableVersion = Get-WAUAvailableVersion
+ #Compare
+ if ($WAUAvailableVersion -gt $WAUCurrentVersion){
+ #If new version is available, update it
+ Update-WAU $WAUAvailableVersion
+ }
}
#Get exclude apps list
@@ -27,7 +36,7 @@ if (Test-Network){
#Get outdated Winget packages
Write-Log "Checking available updates..." "yellow"
- $outdated = Get-WingetOutdated
+ $outdated = Get-WingetOutdatedApps
#Log list of app to update
foreach ($app in $outdated){
@@ -37,7 +46,7 @@ if (Test-Network){
$Log | out-file -filepath $LogFile -Append
}
- #Count good update installs
+ #Count good update installations
$InstallOK = 0
#For each app, notify and update
@@ -59,14 +68,14 @@ if (Test-Network){
& $UpgradeCmd upgrade --id $($app.Id) --all --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
#Check if application updated properly
- $CheckOutdated = Get-WingetOutdated
+ $CheckOutdated = Get-WingetOutdatedApps
$FailedToUpgrade = $false
foreach ($CheckApp in $CheckOutdated){
if ($($CheckApp.Id) -eq $($app.Id)) {
#If app failed to upgrade, run Install command
& $upgradecmd install --id $($app.Id) --accept-package-agreements --accept-source-agreements -h | Tee-Object -file $LogFile -Append
#Check if application installed properly
- $CheckOutdated2 = Get-WingetOutdated
+ $CheckOutdated2 = Get-WingetOutdatedApps
foreach ($CheckApp2 in $CheckOutdated2){
if ($($CheckApp2.Id) -eq $($app.Id)) {
$FailedToUpgrade = $true