Merge pull request #102 from Romanitho/VSCode-Format

VSCode Format
pull/105/head
Romain 2022-06-10 10:27:16 +02:00 committed by GitHub
commit c8dde11134
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
18 changed files with 152 additions and 152 deletions

View File

@ -47,44 +47,44 @@ Specify the update frequency: Daily (Default), Weekly, Biweekly or Monthly.
[CmdletBinding()]
param(
[Parameter(Mandatory=$False)] [Alias('S')] [Switch] $Silent = $false,
[Parameter(Mandatory=$False)] [Alias('Path')] [String] $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate",
[Parameter(Mandatory=$False)] [Switch] $DoNotUpdate = $false,
[Parameter(Mandatory=$False)] [Switch] $DisableWAUAutoUpdate = $false,
[Parameter(Mandatory=$False)] [Switch] $Uninstall = $false,
[Parameter(Mandatory=$False)] [Switch] $UseWhiteList = $false,
[Parameter(Mandatory=$False)] [ValidateSet("Full","SuccessOnly","None")] [String] $NotificationLevel = "Full",
[Parameter(Mandatory=$False)] [Switch] $UpdatesAtLogon = $false,
[Parameter(Mandatory=$False)] [ValidateSet("Daily","Weekly","BiWeekly","Monthly")] [String] $UpdatesInterval = "Daily"
[Parameter(Mandatory = $False)] [Alias('S')] [Switch] $Silent = $false,
[Parameter(Mandatory = $False)] [Alias('Path')] [String] $WingetUpdatePath = "$env:ProgramData\Winget-AutoUpdate",
[Parameter(Mandatory = $False)] [Switch] $DoNotUpdate = $false,
[Parameter(Mandatory = $False)] [Switch] $DisableWAUAutoUpdate = $false,
[Parameter(Mandatory = $False)] [Switch] $Uninstall = $false,
[Parameter(Mandatory = $False)] [Switch] $UseWhiteList = $false,
[Parameter(Mandatory = $False)] [ValidateSet("Full", "SuccessOnly", "None")] [String] $NotificationLevel = "Full",
[Parameter(Mandatory = $False)] [Switch] $UpdatesAtLogon = $false,
[Parameter(Mandatory = $False)] [ValidateSet("Daily", "Weekly", "BiWeekly", "Monthly")] [String] $UpdatesInterval = "Daily"
)
<# APP INFO #>
$WAUVersion = "1.11.4"
$WAUVersion = "1.11.4"
<# FUNCTIONS #>
function Install-Prerequisites{
function Install-Prerequisites {
Write-Host "`nChecking prerequisites..." -ForegroundColor Yellow
#Check if Visual C++ 2019 or 2022 installed
$Visual2019 = "Microsoft Visual C++ 2015-2019 Redistributable*"
$Visual2022 = "Microsoft Visual C++ 2015-2022 Redistributable*"
$path = Get-Item HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object {$_.GetValue("DisplayName") -like $Visual2019 -or $_.GetValue("DisplayName") -like $Visual2022}
$path = Get-Item HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\*, HKLM:\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall\* | Where-Object { $_.GetValue("DisplayName") -like $Visual2019 -or $_.GetValue("DisplayName") -like $Visual2022 }
#If not installed, ask for installation
if (!($path)){
if (!($path)) {
#If -silent option, force installation
if ($Silent){
if ($Silent) {
$InstallApp = 1
}
else{
else {
#Ask for installation
$MsgBoxTitle = "Winget Prerequisites"
$MsgBoxContent = "Microsoft Visual C++ 2015-2022 is required. Would you like to install it?"
$MsgBoxTimeOut = 60
$MsgBoxReturn = (New-Object -ComObject "Wscript.Shell").Popup($MsgBoxContent,$MsgBoxTimeOut,$MsgBoxTitle,4+32)
$MsgBoxReturn = (New-Object -ComObject "Wscript.Shell").Popup($MsgBoxContent, $MsgBoxTimeOut, $MsgBoxTitle, 4 + 32)
if ($MsgBoxReturn -ne 7) {
$InstallApp = 1
}
@ -93,12 +93,12 @@ function Install-Prerequisites{
}
}
#Install if approved
if ($InstallApp -eq 1){
try{
if((Get-CimInStance Win32_OperatingSystem).OSArchitecture -like "*64*"){
if ($InstallApp -eq 1) {
try {
if ((Get-CimInStance Win32_OperatingSystem).OSArchitecture -like "*64*") {
$OSArch = "x64"
}
else{
else {
$OSArch = "x86"
}
Write-host "-> Downloading VC_redist.$OSArch.exe..."
@ -111,47 +111,47 @@ function Install-Prerequisites{
Remove-Item $Installer -ErrorAction Ignore
Write-host "-> MS Visual C++ 2015-2022 installed successfully" -ForegroundColor Green
}
catch{
catch {
Write-host "-> MS Visual C++ 2015-2022 installation failed." -ForegroundColor Red
Start-Sleep 3
}
}
else{
else {
Write-host "-> MS Visual C++ 2015-2022 will not be installed." -ForegroundColor Magenta
}
}
else{
else {
Write-Host "Prerequisites checked. OK" -ForegroundColor Green
}
}
function Install-WinGet{
function Install-WinGet {
Write-Host "`nChecking if Winget is installed" -ForegroundColor Yellow
#Check Package Install
$TestWinGet = Get-AppxProvisionedPackage -Online | Where-Object {$_.DisplayName -eq "Microsoft.DesktopAppInstaller"}
$TestWinGet = Get-AppxProvisionedPackage -Online | Where-Object { $_.DisplayName -eq "Microsoft.DesktopAppInstaller" }
If([Version]$TestWinGet.Version -ge "2022.519.1908.0") {
If ([Version]$TestWinGet.Version -ge "2022.519.1908.0") {
Write-Host "WinGet is Installed" -ForegroundColor Green
}
Else{
Else {
#Download WinGet MSIXBundle
Write-Host "-> Not installed. Downloading WinGet..."
$WinGetURL = "https://github.com/microsoft/winget-cli/releases/download/v1.3.1391-preview/Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle"
$WebClient=New-Object System.Net.WebClient
$WebClient = New-Object System.Net.WebClient
$WebClient.DownloadFile($WinGetURL, "$PSScriptRoot\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle")
#Install WinGet MSIXBundle
try{
try {
Write-Host "-> Installing Winget MSIXBundle for App Installer..."
Add-AppxProvisionedPackage -Online -PackagePath "$PSScriptRoot\Microsoft.DesktopAppInstaller_8wekyb3d8bbwe.msixbundle" -SkipLicense | Out-Null
Write-Host "Installed Winget MSIXBundle for App Installer" -ForegroundColor Green
}
catch{
catch {
Write-Host "Failed to intall Winget MSIXBundle for App Installer..." -ForegroundColor Red
}
@ -162,13 +162,13 @@ function Install-WinGet{
}
function Install-WingetAutoUpdate{
function Install-WingetAutoUpdate {
Write-Host "`nInstalling WAU..." -ForegroundColor Yellow
try{
try {
#Copy files to location (and clean old install)
if (!(Test-Path $WingetUpdatePath)){
if (!(Test-Path $WingetUpdatePath)) {
New-Item -ItemType Directory -Force -Path $WingetUpdatePath | Out-Null
}
else {
@ -177,11 +177,11 @@ function Install-WingetAutoUpdate{
Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
#White List or Black List apps
if ($UseWhiteList){
if (Test-Path "$PSScriptRoot\included_apps.txt"){
if ($UseWhiteList) {
if (Test-Path "$PSScriptRoot\included_apps.txt") {
Copy-Item -Path "$PSScriptRoot\included_apps.txt" -Destination $WingetUpdatePath -Recurse -Force -ErrorAction SilentlyContinue
}
else{
else {
New-Item -Path $WingetUpdatePath -Name "included_apps.txt" -ItemType "file" -ErrorAction SilentlyContinue | Out-Null
}
}
@ -196,19 +196,19 @@ function Install-WingetAutoUpdate{
# Settings for the scheduled task for Updates
$taskAction = New-ScheduledTaskAction Execute "powershell.exe" -Argument "-NoProfile -ExecutionPolicy Bypass -File `"$($WingetUpdatePath)\winget-upgrade.ps1`""
$taskTriggers = @()
if ($UpdatesAtLogon){
if ($UpdatesAtLogon) {
$tasktriggers += New-ScheduledTaskTrigger -AtLogOn
}
if ($UpdatesInterval -eq "Daily"){
if ($UpdatesInterval -eq "Daily") {
$tasktriggers += New-ScheduledTaskTrigger -Daily -At 6AM
}
elseif ($UpdatesInterval -eq "Weekly"){
elseif ($UpdatesInterval -eq "Weekly") {
$tasktriggers += New-ScheduledTaskTrigger -Weekly -At 6AM -DaysOfWeek 2
}
elseif ($UpdatesInterval -eq "BiWeekly"){
elseif ($UpdatesInterval -eq "BiWeekly") {
$tasktriggers += New-ScheduledTaskTrigger -Weekly -At 6AM -DaysOfWeek 2 -WeeksInterval 2
}
elseif ($UpdatesInterval -eq "Monthly"){
elseif ($UpdatesInterval -eq "Monthly") {
$tasktriggers += New-ScheduledTaskTrigger -Weekly -At 6AM -DaysOfWeek 2 -WeeksInterval 4
}
$taskUserPrincipal = New-ScheduledTaskPrincipal -UserId S-1-5-18 -RunLevel Highest
@ -258,23 +258,23 @@ function Install-WingetAutoUpdate{
#Run Winget ?
Start-WingetAutoUpdate
}
catch{
catch {
Write-host "WAU Installation failed! Run me with admin rights" -ForegroundColor Red
Start-sleep 1
return $False
}
}
function Uninstall-WingetAutoUpdate{
function Uninstall-WingetAutoUpdate {
Write-Host "`nUninstalling WAU..." -ForegroundColor Yellow
try{
try {
#Get registry install location
$InstallLocation = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocation
#Check if installed location exists and delete
if (Test-Path ($InstallLocation)){
if (Test-Path ($InstallLocation)) {
Remove-Item $InstallLocation -Force -Recurse
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
@ -288,46 +288,46 @@ function Uninstall-WingetAutoUpdate{
Write-host "$InstallLocation not found! Uninstallation failed!" -ForegroundColor Red
}
}
catch{
catch {
Write-host "Uninstallation failed! Run as admin ?" -ForegroundColor Red
Start-sleep 1
}
}
function Start-WingetAutoUpdate{
function Start-WingetAutoUpdate {
#If -DoNotUpdate is true, skip.
if (!($DoNotUpdate)){
#If -Silent, run Winget-AutoUpdate now
if ($Silent){
if (!($DoNotUpdate)) {
#If -Silent, run Winget-AutoUpdate now
if ($Silent) {
$RunWinget = 1
}
#Ask for WingetAutoUpdate
else {
$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
}
#Ask for WingetAutoUpdate
else{
$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
}
else {
$RunWinget = 0
}
if ($RunWinget -eq 1){
try{
}
if ($RunWinget -eq 1) {
try {
Write-host "`nRunning Winget-AutoUpdate..." -ForegroundColor Yellow
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Start-ScheduledTask -ErrorAction SilentlyContinue
while ((Get-ScheduledTask -TaskName "Winget-AutoUpdate").State -ne 'Ready') {
while ((Get-ScheduledTask -TaskName "Winget-AutoUpdate").State -ne 'Ready') {
Start-Sleep 1
}
}
catch{
catch {
Write-host "Failed to run Winget-AutoUpdate..." -ForegroundColor Red
}
}
}
else{
else {
Write-host "Skip running Winget-AutoUpdate"
}
}
@ -348,7 +348,7 @@ Write-Host "`t Winget-AutoUpdate $WAUVersion`n" -ForegroundColor
Write-Host "`t https://github.com/Romanitho/Winget-AutoUpdate`n" -ForegroundColor Magenta
Write-Host "`t________________________________________________________`n`n"
if (!$Uninstall){
if (!$Uninstall) {
Write-host "Installing WAU to $WingetUpdatePath\"
Install-Prerequisites
Install-WinGet

View File

@ -11,13 +11,13 @@ Write-Host "`t Winget-AutoUpdate`n" -ForegroundColor Cyan
Write-Host "`t https://github.com/Romanitho/Winget-AutoUpdate`n" -ForegroundColor Magenta
Write-Host "`t________________________________________________________`n`n"
try{
try {
Write-host "Uninstalling WAU..." -ForegroundColor Yellow
#Get registry install location
$InstallLocation = Get-ItemPropertyValue -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate\" -Name InstallLocation
#Check if installed location exists and delete
if (Test-Path ($InstallLocation)){
if (Test-Path ($InstallLocation)) {
Remove-Item "$InstallLocation\*" -Force -Recurse -Exclude "*.log"
Get-ScheduledTask -TaskName "Winget-AutoUpdate" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
Get-ScheduledTask -TaskName "Winget-AutoUpdate-Notify" -ErrorAction SilentlyContinue | Unregister-ScheduledTask -Confirm:$False
@ -33,7 +33,7 @@ try{
Write-host "$InstallLocation not found! Uninstallation failed!" -ForegroundColor Red
}
}
catch{
catch {
Write-host "`nUninstallation failed! Run as admin ?" -ForegroundColor Red
}

View File

@ -1,21 +1,19 @@
#Function to configure prefered scope option as Machine
function Add-ScopeMachine ($SettingsPath) {
if (Test-Path $SettingsPath){
$ConfigFile = Get-Content -Path $SettingsPath | Where-Object {$_ -notmatch '//'} | ConvertFrom-Json
if (Test-Path $SettingsPath) {
$ConfigFile = Get-Content -Path $SettingsPath | Where-Object { $_ -notmatch '//' } | ConvertFrom-Json
}
if (!$ConfigFile){
if (!$ConfigFile) {
$ConfigFile = @{}
}
if ($ConfigFile.installBehavior.preferences.scope){
if ($ConfigFile.installBehavior.preferences.scope) {
$ConfigFile.installBehavior.preferences.scope = "Machine"
}
else {
Add-Member -InputObject $ConfigFile -MemberType NoteProperty -Name 'installBehavior' -Value $(
New-Object PSObject -Property $(@{preferences = $(
New-Object PSObject -Property $(@{scope = "Machine"}))
})
) -Force
$Scope = New-Object PSObject -Property $(@{scope = "Machine" })
$Preference = New-Object PSObject -Property $(@{preferences = $Scope })
Add-Member -InputObject $ConfigFile -MemberType NoteProperty -Name 'installBehavior' -Value $Preference -Force
}
$ConfigFile | ConvertTo-Json | Out-File $SettingsPath -Encoding utf8 -Force

View File

@ -1,8 +1,8 @@
#Function to get Black List apps
function Get-ExcludedApps{
function Get-ExcludedApps {
if (Test-Path "$WorkingDir\excluded_apps.txt"){
if (Test-Path "$WorkingDir\excluded_apps.txt") {
return Get-Content -Path "$WorkingDir\excluded_apps.txt"

View File

@ -1,8 +1,8 @@
#Function to get White List apps
function Get-IncludedApps{
function Get-IncludedApps {
if (Test-Path "$WorkingDir\included_apps.txt"){
if (Test-Path "$WorkingDir\included_apps.txt") {
return Get-Content -Path "$WorkingDir\included_apps.txt"

View File

@ -9,12 +9,12 @@ Function Get-NotifLocale {
$TestOSLocalPath = "$WorkingDir\locale\$($OSLocale.Name).xml"
#Set OS Local if file exists
if(Test-Path $TestOSLocalPath){
if (Test-Path $TestOSLocalPath) {
$LocaleDisplayName = $OSLocale.DisplayName
$LocaleFile = $TestOSLocalPath
}
#Set English if file doesn't exist
else{
else {
$LocaleDisplayName = "English"
$LocaleFile = "$WorkingDir\locale\en.xml"
}

View File

@ -19,6 +19,6 @@ function Get-WAUAvailableVersion {
}
return ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v","")
return ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "")
}

View File

@ -4,25 +4,25 @@ Function Get-WingetCmd {
#Get WinGet Path (if admin context)
$ResolveWingetPath = Resolve-Path "C:\Program Files\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe"
if ($ResolveWingetPath){
if ($ResolveWingetPath) {
#If multiple version, pick last one
$WingetPath = $ResolveWingetPath[-1].Path
}
#Get Winget Location in User context
$WingetCmd = Get-Command winget.exe -ErrorAction SilentlyContinue
if ($WingetCmd){
if ($WingetCmd) {
$Script:Winget = $WingetCmd.Source
}
#Get Winget Location in System context (WinGet < 1.17)
elseif (Test-Path "$WingetPath\AppInstallerCLI.exe"){
elseif (Test-Path "$WingetPath\AppInstallerCLI.exe") {
$Script:Winget = "$WingetPath\AppInstallerCLI.exe"
}
#Get Winget Location in System context (WinGet > 1.17)
elseif (Test-Path "$WingetPath\winget.exe"){
elseif (Test-Path "$WingetPath\winget.exe") {
$Script:Winget = "$WingetPath\winget.exe"
}
else{
else {
Write-Log "Winget not installed or detected !" "Red"
return $false
}

View File

@ -13,16 +13,16 @@ function Get-WingetOutdatedApps {
$upgradeResult = & $Winget upgrade | Out-String
#Start Convertion of winget format to an array. Check if "-----" exists
if (!($upgradeResult -match "-----")){
if (!($upgradeResult -match "-----")) {
return
}
#Split winget output to lines
$lines = $upgradeResult.Split([Environment]::NewLine) | Where-Object {$_}
$lines = $upgradeResult.Split([Environment]::NewLine) | Where-Object { $_ }
# Find the line that starts with "------"
$fl = 0
while (-not $lines[$fl].StartsWith("-----")){
while (-not $lines[$fl].StartsWith("-----")) {
$fl++
}
@ -40,9 +40,9 @@ function Get-WingetOutdatedApps {
# Now cycle in real package and split accordingly
$upgradeList = @()
For ($i = $fl + 2; $i -le $lines.Length; $i++){
For ($i = $fl + 2; $i -le $lines.Length; $i++) {
$line = $lines[$i]
if ($line.Length -gt ($sourceStart+5) -and -not $line.Contains("--include-unknown")){
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()

View File

@ -7,7 +7,7 @@ function Invoke-PostUpdateActions {
#Reset Winget Sources
$ResolveWingetPath = Resolve-Path "$env:programfiles\WindowsApps\Microsoft.DesktopAppInstaller_*_x64__8wekyb3d8bbwe\winget.exe"
if ($ResolveWingetPath){
if ($ResolveWingetPath) {
#If multiple version, pick last one
$WingetPath = $ResolveWingetPath[-1].Path
& $WingetPath source reset --force
@ -52,10 +52,10 @@ function Invoke-PostUpdateActions {
$WAUConfigPath = "$WorkingDir\config\config.xml"
if (test-path $WAUConfigPath) {
[xml]$Config = Get-Content $WAUConfigPath -Encoding UTF8 -ErrorAction SilentlyContinue
if ($Config.app.WAUautoupdate -eq "False") {New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value 1 -Force}
if ($Config.app.NotificationLevel) {New-ItemProperty $regPath -Name WAU_NotificationLevel -Value $Config.app.NotificationLevel -Force}
if ($Config.app.UseWAUWhiteList -eq "True") {New-ItemProperty $regPath -Name WAU_UseWhiteList -Value 1 -PropertyType DWord -Force}
if ($Config.app.WAUprerelease -eq "True") {New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 1 -PropertyType DWord -Force}
if ($Config.app.WAUautoupdate -eq "False") { New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value 1 -Force }
if ($Config.app.NotificationLevel) { New-ItemProperty $regPath -Name WAU_NotificationLevel -Value $Config.app.NotificationLevel -Force }
if ($Config.app.UseWAUWhiteList -eq "True") { New-ItemProperty $regPath -Name WAU_UseWhiteList -Value 1 -PropertyType DWord -Force }
if ($Config.app.WAUprerelease -eq "True") { New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 1 -PropertyType DWord -Force }
#Remove file once converted
Remove-Item $WAUConfigPath -Force -Confirm:$false
@ -70,7 +70,7 @@ function Invoke-PostUpdateActions {
"$WorkingDir\functions\Get-WAUCurrentVersion.ps1",
"$WorkingDir\functions\Get-WAUUpdateStatus.ps1"
)
foreach ($FileName in $FileNames){
foreach ($FileName in $FileNames) {
if (Test-Path $FileName) {
Remove-Item $FileName -Force -Confirm:$false

View File

@ -10,11 +10,11 @@ function Start-Init {
$Log | Write-host
#Logs initialisation if admin
try{
try {
$LogPath = "$WorkingDir\logs"
if (!(Test-Path $LogPath)){
if (!(Test-Path $LogPath)) {
New-Item -ItemType Directory -Force -Path $LogPath
}
@ -24,11 +24,11 @@ function Start-Init {
}
#Logs initialisation if non-admin
catch{
catch {
$LogPath = "$env:USERPROFILE\Winget-AutoUpdate\logs"
if (!(Test-Path $LogPath)){
if (!(Test-Path $LogPath)) {
New-Item -ItemType Directory -Force -Path $LogPath
}

View File

@ -1,6 +1,6 @@
#Function to send notifications to user
function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
function Start-NotifTask ($Title, $Message, $MessageType, $Balise) {
if (($WAUConfig.WAU_NotificationLevel -eq "Full") -or ($WAUConfig.WAU_NotificationLevel -eq "SuccessOnly" -and $MessageType -eq "Success")) {
@ -22,11 +22,11 @@ function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
$currentPrincipal = [bool](([System.Security.Principal.WindowsIdentity]::GetCurrent()).groups -match "S-1-5-4")
#if not "Interactive" user, run as system
if ($currentPrincipal -eq $false){
if ($currentPrincipal -eq $false) {
#Save XML to File
$ToastTemplateLocation = "$env:ProgramData\Winget-AutoUpdate\config\"
if (!(Test-Path $ToastTemplateLocation)){
if (!(Test-Path $ToastTemplateLocation)) {
New-Item -ItemType Directory -Force -Path $ToastTemplateLocation
}
$ToastTemplate.Save("$ToastTemplateLocation\notif.xml")
@ -36,7 +36,7 @@ function Start-NotifTask ($Title,$Message,$MessageType,$Balise) {
}
#else, run as connected user
else{
else {
#Load Assemblies
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null

View File

@ -1,22 +1,22 @@
#Function to check if modification exists in 'mods' directory
function Test-Mods ($app){
function Test-Mods ($app) {
#Takes care of a null situation
$ModsInstall = $null
$ModsUpgrade = $null
$Mods = "$WorkingDir\mods"
if (Test-Path "$Mods\$app-*"){
if (Test-Path "$Mods\$app-install.ps1"){
if (Test-Path "$Mods\$app-*") {
if (Test-Path "$Mods\$app-install.ps1") {
$ModsInstall = "$Mods\$app-install.ps1"
$ModsUpgrade = "$Mods\$app-install.ps1"
}
if (Test-Path "$Mods\$app-upgrade.ps1"){
if (Test-Path "$Mods\$app-upgrade.ps1") {
$ModsUpgrade = "$Mods\$app-upgrade.ps1"
}
}
return $ModsInstall,$ModsUpgrade
return $ModsInstall, $ModsUpgrade
}

View File

@ -7,23 +7,23 @@ function Test-Network {
#Test connectivity during 30 min then timeout
Write-Log "Checking internet connection..." "Yellow"
While ($timeout -lt 1800){
While ($timeout -lt 1800) {
$TestNetwork = Test-NetConnection 8.8.8.8 -Port 443 -InformationLevel Quiet
if ($TestNetwork){
if ($TestNetwork) {
Write-Log "Connected !" "Green"
return $true
}
else{
else {
Start-Sleep 10
$timeout += 10
#Send Warning Notif if no connection for 5 min
if ($timeout -eq 300){
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

View File

@ -21,7 +21,7 @@ Function Update-App ($app) {
$FailedToUpgrade = $false
#Check if mods exist
$ModsInstall, $ModsUpgrade = Test-Mods $($app.Id)
foreach ($CheckApp in $CheckOutdated){
foreach ($CheckApp in $CheckOutdated) {
if ($($CheckApp.Id) -eq $($app.Id)) {
#If app failed to upgrade, run Install command
@ -29,12 +29,12 @@ Function Update-App ($app) {
#Check if application installed properly
$CheckOutdated2 = Get-WingetOutdatedApps
foreach ($CheckApp2 in $CheckOutdated2){
foreach ($CheckApp2 in $CheckOutdated2) {
if ($($CheckApp2.Id) -eq $($app.Id)) {
$FailedToUpgrade = $true
}
else {
if ($ModsInstall){
if ($ModsInstall) {
Write-Log "Modifications for $($app.Id) after install are being applied..." "Yellow"
& "$ModsInstall"
}
@ -42,7 +42,7 @@ Function Update-App ($app) {
}
}
else {
if ($ModsUpgrade){
if ($ModsUpgrade) {
Write-Log "Modifications for $($app.Id) after upgrade are being applied..." "Yellow"
& "$ModsUpgrade"
}
@ -52,7 +52,7 @@ Function Update-App ($app) {
Write-Log "########## WINGET UPGRADE PROCESS FINISHED FOR APPLICATION ID '$($App.Id)' ##########" "Gray"
#Notify installation
if ($FailedToUpgrade -eq $false){
if ($FailedToUpgrade -eq $false) {
#Send success updated app notification
Write-Log "$($app.Name) updated to $($app.AvailableVersion) !" "Green"

View File

@ -10,7 +10,7 @@ function Update-WAU {
Start-NotifTask $Title $Message $MessageType $Balise
#Run WAU update
try{
try {
#Force to create a zip file
$ZipFile = "$WorkingDir\WAU_update.zip"
@ -29,7 +29,7 @@ function Update-WAU {
#Update scritps
Write-Log "Updating WAU" "Yellow"
$TempPath = (Resolve-Path "$location\*\Winget-AutoUpdate\")[0].Path
if ($TempPath){
if ($TempPath) {
Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Exclude "icons" -Recurse -Force
}
@ -62,7 +62,7 @@ function Update-WAU {
}
catch{
catch {
#Send Error Notif
$Title = $NotifLocale.local.outputs.output[4].title -f "Winget-AutoUpdate"

View File

@ -2,7 +2,9 @@
#get xml notif config
[xml]$NotifConf = Get-Content "$env:ProgramData\Winget-AutoUpdate\config\notif.xml" -Encoding UTF8 -ErrorAction SilentlyContinue
if (!($NotifConf)) {break}
if (!($NotifConf)) {
break
}
#Load Assemblies
[Windows.UI.Notifications.ToastNotificationManager, Windows.UI.Notifications, ContentType = WindowsRuntime] | Out-Null

View File

@ -3,7 +3,7 @@
#Get Working Dir
$Script:WorkingDir = $PSScriptRoot
#Get Functions
Get-ChildItem "$WorkingDir\functions" | ForEach-Object {. $_.FullName}
Get-ChildItem "$WorkingDir\functions" | ForEach-Object { . $_.FullName }
<# MAIN #>
@ -15,7 +15,7 @@ Start-Init
$Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
#Run post update actions if necessary
if (!($WAUConfig.WAU_PostUpdateActions -eq 0)){
if (!($WAUConfig.WAU_PostUpdateActions -eq 0)) {
Invoke-PostUpdateActions
}
@ -29,42 +29,42 @@ if ([System.Security.Principal.WindowsIdentity]::GetCurrent().IsSystem) {
Get-NotifLocale
#Check network connectivity
if (Test-Network){
if (Test-Network) {
#Check if Winget is installed and get Winget cmd
$TestWinget = Get-WingetCmd
if ($TestWinget){
if ($TestWinget) {
#Get Current Version
$WAUCurrentVersion = $WAUConfig.DisplayVersion
Write-Log "WAU current version: $WAUCurrentVersion"
#Check if WAU update feature is enabled or not
$WAUDisableAutoUpdate = $WAUConfig.WAU_DisableAutoUpdate
#If yes then check WAU update
if ($WAUDisableAutoUpdate -eq 1){
if ($WAUDisableAutoUpdate -eq 1) {
Write-Log "WAU AutoUpdate is Disabled." "Grey"
}
else{
else {
Write-Log "WAU AutoUpdate is Enabled." "Green"
#Get Available Version
$WAUAvailableVersion = Get-WAUAvailableVersion
#Compare
if ([version]$WAUAvailableVersion -gt [version]$WAUCurrentVersion){
if ([version]$WAUAvailableVersion -gt [version]$WAUCurrentVersion) {
#If new version is available, update it
Write-Log "WAU Available version: $WAUAvailableVersion" "Yellow"
Update-WAU
}
else{
else {
Write-Log "WAU is up to date." "Green"
}
}
#Get White or Black list
if ($WAUConfig.WAU_UseWhiteList -eq 1){
if ($WAUConfig.WAU_UseWhiteList -eq 1) {
Write-Log "WAU uses White List config"
$toUpdate = Get-IncludedApps
$UseWhiteList = $true
}
else{
else {
Write-Log "WAU uses Black List config"
$toSkip = Get-ExcludedApps
}
@ -73,7 +73,7 @@ if (Test-Network){
$outdated = Get-WingetOutdatedApps
#Log list of app to update
foreach ($app in $outdated){
foreach ($app in $outdated) {
#List available updates
$Log = "-> Available update : $($app.Name). Current version : $($app.Version). Available version : $($app.AvailableVersion)."
$Log | Write-host
@ -84,44 +84,44 @@ if (Test-Network){
$Script:InstallOK = 0
#If White List
if ($UseWhiteList){
if ($UseWhiteList) {
#For each app, notify and update
foreach ($app in $outdated){
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown"){
foreach ($app in $outdated) {
if (($toUpdate -contains $app.Id) -and $($app.Version) -ne "Unknown") {
Update-App $app
}
#if current app version is unknown
elseif($($app.Version) -eq "Unknown"){
elseif ($($app.Version) -eq "Unknown") {
Write-Log "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
}
#if app is in "excluded list"
else{
else {
Write-Log "$($app.Name) : Skipped upgrade because it is not in the included app list" "Gray"
}
}
}
#If Black List or default
else{
else {
#For each app, notify and update
foreach ($app in $outdated){
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown"){
foreach ($app in $outdated) {
if (-not ($toSkip -contains $app.Id) -and $($app.Version) -ne "Unknown") {
Update-App $app
}
#if current app version is unknown
elseif($($app.Version) -eq "Unknown"){
elseif ($($app.Version) -eq "Unknown") {
Write-Log "$($app.Name) : Skipped upgrade because current version is 'Unknown'" "Gray"
}
#if app is in "excluded list"
else{
else {
Write-Log "$($app.Name) : Skipped upgrade because it is in the excluded app list" "Gray"
}
}
}
if ($InstallOK -gt 0){
if ($InstallOK -gt 0) {
Write-Log "$InstallOK apps updated ! No more update." "Green"
}
if ($InstallOK -eq 0){
if ($InstallOK -eq 0) {
Write-Log "No new update." "Green"
}
}