diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index c92dcfe..84bc570 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -213,26 +213,33 @@ function Install-WingetAutoUpdate{ $task = New-ScheduledTask -Action $taskAction -Principal $taskUserPrincipal -Settings $taskSettings Register-ScheduledTask -TaskName 'Winget-AutoUpdate-Notify' -InputObject $task -Force | Out-Null - # Install config file - [xml]$ConfigXML = @" - - - $(!($DisableWAUAutoUpdate)) - False - $UseWhiteList - $NotificationLevel - -"@ - $ConfigXML.Save("$WingetUpdatePath\config\config.xml") + # Configure Reg Key + $regPath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" + New-Item $regPath -Force + New-ItemProperty $regPath -Name DisplayName -Value "Winget-AutoUpdate (WAU)" -Force + New-ItemProperty $regPath -Name DisplayVersion -Value 1.10.0 -Force + New-ItemProperty $regPath -Name InstallLocation -Value $WingetUpdatePath -Force + New-ItemProperty $regPath -Name UninstallString -Value "$WingetUpdatePath\Uninstall.bat" -Force + New-ItemProperty $regPath -Name QuietUninstallString -Value "$WingetUpdatePath\Uninstall.bat" -Force + New-ItemProperty $regPath -Name NoModify -Value 1 -Force + New-ItemProperty $regPath -Name NoRepair -Value 1 -Force + New-ItemProperty $regPath -Name VersionMajor -Value 1 -Force + New-ItemProperty $regPath -Name VersionMinor -Value 10 -Force + New-ItemProperty $regPath -Name Publisher -Value "Romanitho" -Force + New-ItemProperty $regPath -Name URLInfoAbout -Value "https://github.com/Romanitho/Winget-AutoUpdate" -Force + if ($DisableWAUAutoUpdate) {New-ItemProperty $regPath -Name WAU_DisableAutoUpdate -Value 1 -Force} + New-ItemProperty $regPath -Name WAU_UpdatePrerelease -Value 0 -PropertyType DWord -Force + if ($UseWhiteList) {New-ItemProperty $regPath -Name WAU_UseWhiteList -Value 1 -PropertyType DWord -Force} + New-ItemProperty $regPath -Name WAU_NotificationLevel -Value $NotificationLevel -Force - Write-host "`n WAU Installation succeeded!" -ForegroundColor Green + Write-host "`nWAU Installation succeeded!" -ForegroundColor Green Start-sleep 1 #Run Winget ? Start-WingetAutoUpdate } catch{ - Write-host "`n WAU Installation failed! Run me with admin rights" -ForegroundColor Red + Write-host "`nWAU Installation failed! Run me with admin rights" -ForegroundColor Red Start-sleep 1 return $False } diff --git a/Winget-AutoUpdate/config/about.xml b/Winget-AutoUpdate/config/about.xml deleted file mode 100644 index 03dec77..0000000 --- a/Winget-AutoUpdate/config/about.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - Winget-AutoUpdate (WAU) - 1.10.0 - Romanitho - https://github.com/Romanitho/Winget-AutoUpdate - diff --git a/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 b/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 index 22e78b7..1fcead4 100644 --- a/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 +++ b/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 @@ -3,7 +3,7 @@ function Get-WAUAvailableVersion { #Get Github latest version - if ($true -eq $WAUprerelease) { + if ($WAUConfig.WAU_UpdatePrerelease -eq 1) { #Get latest pre-release info $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases' @@ -16,6 +16,6 @@ function Get-WAUAvailableVersion { } - $Script:WAUAvailableVersion = ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v","") + return ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v","") } \ No newline at end of file diff --git a/Winget-AutoUpdate/functions/Get-WAUConfig.ps1 b/Winget-AutoUpdate/functions/Get-WAUConfig.ps1 deleted file mode 100644 index 4e82ce5..0000000 --- a/Winget-AutoUpdate/functions/Get-WAUConfig.ps1 +++ /dev/null @@ -1,25 +0,0 @@ -#Function to get WAU Configs - -function Get-WAUConfig{ - - #Get config file - [xml]$WAUConfig = Get-Content "$WorkingDir\config\config.xml" -Encoding UTF8 -ErrorAction SilentlyContinue - - #Check if WAU is configured for Black or White List - if ($true -eq [System.Convert]::ToBoolean($WAUConfig.app.UseWAUWhiteList)){ - $Script:UseWhiteList = $true - } - else{ - $Script:UseWhiteList = $false - } - - #Get Notification Level - if ($WAUConfig.app.NotificationLevel){ - $Script:NotificationLevel = $WAUConfig.app.NotificationLevel - } - else{ - #Default: Full - $Script:NotificationLevel = "Full" - } - -} diff --git a/Winget-AutoUpdate/functions/Get-WAUCurrentVersion.ps1 b/Winget-AutoUpdate/functions/Get-WAUCurrentVersion.ps1 deleted file mode 100644 index 6888f6e..0000000 --- a/Winget-AutoUpdate/functions/Get-WAUCurrentVersion.ps1 +++ /dev/null @@ -1,9 +0,0 @@ -#Function to get current WAU installed version - -function Get-WAUCurrentVersion{ - - #Get current installed version - [xml]$About = Get-Content "$WorkingDir\config\about.xml" -Encoding UTF8 -ErrorAction SilentlyContinue - $Script:WAUCurrentVersion = $About.app.version - -} \ No newline at end of file diff --git a/Winget-AutoUpdate/functions/Get-WAUUpdateStatus.ps1 b/Winget-AutoUpdate/functions/Get-WAUUpdateStatus.ps1 deleted file mode 100644 index 985c719..0000000 --- a/Winget-AutoUpdate/functions/Get-WAUUpdateStatus.ps1 +++ /dev/null @@ -1,29 +0,0 @@ -#Function to get WAU Update configurations - -function Get-WAUUpdateStatus{ - - [xml]$UpdateStatus = Get-Content "$WorkingDir\config\config.xml" -Encoding UTF8 -ErrorAction SilentlyContinue - - #Check if AutoUpdate is enabled - if ($true -eq [System.Convert]::ToBoolean($UpdateStatus.app.WAUautoupdate)){ - - Write-Log "WAU AutoUpdate is Enabled. Current version : $WAUCurrentVersion" "Green" - $Script:WAUautoupdate = $true - - #Check if pre-release versions are enabled - if ($true -eq [System.Convert]::ToBoolean($UpdateStatus.app.WAUprerelease)){ - Write-Log "WAU AutoUpdate Pre-release versions is Enabled" "Cyan" - $Script:WAUprerelease = $true - } - else{ - $Script:WAUprerelease = $false - } - - } - else{ - - Write-Log "WAU AutoUpdate is Disabled. Current version : $WAUCurrentVersion" "Grey" - $Script:WAUautoupdate = $false - - } -} \ No newline at end of file diff --git a/Winget-AutoUpdate/functions/Start-NotifTask.ps1 b/Winget-AutoUpdate/functions/Start-NotifTask.ps1 index 4b68c8c..db68276 100644 --- a/Winget-AutoUpdate/functions/Start-NotifTask.ps1 +++ b/Winget-AutoUpdate/functions/Start-NotifTask.ps1 @@ -2,7 +2,7 @@ function Start-NotifTask ($Title,$Message,$MessageType,$Balise) { - if (($NotificationLevel -eq "Full") -or ($NotificationLevel -eq "SuccessOnly" -and $MessageType -eq "Success")) { + if (($WAUConfig.WAU_NotificationLevel -eq "Full") -or ($WAUConfig.WAU_NotificationLevel -eq "SuccessOnly" -and $MessageType -eq "Success")) { #Add XML variables [xml]$ToastTemplate = @" @@ -25,11 +25,11 @@ function Start-NotifTask ($Title,$Message,$MessageType,$Balise) { if ($currentPrincipal -eq $false){ #Save XML to File - $ToastTemplateLocation = "$env:ProgramData\Winget-AutoUpdate\" + $ToastTemplateLocation = "$env:ProgramData\Winget-AutoUpdate\config\" 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 diff --git a/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Winget-AutoUpdate/functions/Update-WAU.ps1 index c46c9d2..9e41b52 100644 --- a/Winget-AutoUpdate/functions/Update-WAU.ps1 +++ b/Winget-AutoUpdate/functions/Update-WAU.ps1 @@ -38,10 +38,10 @@ function Update-WAU { Remove-Item -Path $ZipFile -Force -ErrorAction SilentlyContinue Remove-Item -Path $location -Recurse -Force -ErrorAction SilentlyContinue - #Set new version to 'about.xml' - [xml]$XMLconf = Get-content "$WorkingDir\config\about.xml" -Encoding UTF8 -ErrorAction SilentlyContinue - $XMLconf.app.version = $WAUAvailableVersion - $XMLconf.Save("$WorkingDir\config\about.xml") + #Set new version to registry + $WAUConfig | New-ItemProperty $regPath -Name DisplayVersion -Value $WAUAvailableVersion -Force + $WAUConfig | New-ItemProperty $regPath -Name VersionMajor -Value ([version]$WAUAvailableVersion).Major -Force + $WAUConfig | New-ItemProperty $regPath -Name VersionMinor -Value ([version]$WAUAvailableVersion).Minor -Force #Send success Notif Write-Log "WAU Update completed." "Green" diff --git a/Winget-AutoUpdate/winget-upgrade.ps1 b/Winget-AutoUpdate/winget-upgrade.ps1 index 065b9c0..756b2cd 100644 --- a/Winget-AutoUpdate/winget-upgrade.ps1 +++ b/Winget-AutoUpdate/winget-upgrade.ps1 @@ -18,7 +18,7 @@ if ([System.Security.Principal.WindowsIdentity]::GetCurrent().IsSystem) { } #Get WAU Configurations -Get-WAUConfig +$Script:WAUConfig = Get-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" #Get Notif Locale function Get-NotifLocale @@ -30,13 +30,18 @@ if (Test-Network){ if ($TestWinget){ #Get Current Version - Get-WAUCurrentVersion - #Check if WAU update feature is enabled - Get-WAUUpdateStatus + $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 ($true -eq $WAUautoupdate){ + if ($WAUDisableAutoUpdate -eq 1){ + Write-Log "WAU AutoUpdate is Disabled." "Grey" + } + else{ + Write-Log "WAU AutoUpdate is Enabled." "Green" #Get Available Version - Get-WAUAvailableVersion + $WAUAvailableVersion = Get-WAUAvailableVersion #Compare if ([version]$WAUAvailableVersion -gt [version]$WAUCurrentVersion){ #If new version is available, update it @@ -49,9 +54,10 @@ if (Test-Network){ } #Get White or Black list - if ($UseWhiteList){ + if ($WAUConfig.WAU_UseWhiteList -eq 1){ Write-Log "WAU uses White List config" $toUpdate = Get-IncludedApps + $UseWhiteList = $true } else{ Write-Log "WAU uses Black List config" @@ -89,7 +95,7 @@ if (Test-Network){ } } } - #If Black List + #If Black List or default else{ #For each app, notify and update foreach ($app in $outdated){ diff --git a/install.bat b/install.bat index fe26091..6fcd9a2 100644 --- a/install.bat +++ b/install.bat @@ -1,2 +1,2 @@ @echo off -powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-noprofile -executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -UpdatesAtLogon'" -Verb RunAs +powershell -Command "Get-ChildItem -Path '%~dp0' -Recurse | Unblock-File; Start-Process powershell.exe -Argument '-noprofile -executionpolicy bypass -file """%~dp0Winget-AutoUpdate-Install.ps1"" -UpdatesAtLogon'" -Verb RunAs \ No newline at end of file