commit
d3597e774b
|
@ -10,12 +10,12 @@ function Get-WAUAvailableVersion {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
#Get latest pre-release info
|
#Get latest pre-release info
|
||||||
$WAUurl = "https://api.github.com/repos/Romanitho/$GitHub_Repo/releases"
|
$WAUurl = "https://api.github.com/repos/Romanitho/$($GitHub_Repo)/releases"
|
||||||
$WAUAvailableVersion = ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "")
|
$WAUAvailableVersion = ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "")
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
$url = "https://github.com/Romanitho/$GitHub_Repo/releases"
|
$url = "https://github.com/Romanitho/$($GitHub_Repo)/releases"
|
||||||
$link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/$GitHub_Repo/releases/tag/v*")[0]
|
$link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/$($GitHub_Repo)/releases/tag/v*")[0]
|
||||||
$WAUAvailableVersion = $link.Trim().Split("v")[-1]
|
$WAUAvailableVersion = $link.Trim().Split("v")[-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,12 +24,12 @@ function Get-WAUAvailableVersion {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
#Get latest stable info
|
#Get latest stable info
|
||||||
$WAUurl = "https://api.github.com/repos/Romanitho/$GitHub_Repo/releases/latest"
|
$WAUurl = "https://api.github.com/repos/Romanitho/$($GitHub_Repo)/releases/latest"
|
||||||
$WAUAvailableVersion = ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "")
|
$WAUAvailableVersion = ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "")
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
$url = "https://github.com/Romanitho/$GitHub_Repo/releases/latest"
|
$url = "https://github.com/Romanitho/$($GitHub_Repo)/releases/latest"
|
||||||
$link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/$GitHub_Repo/releases/tag/v*")[0]
|
$link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/$($GitHub_Repo)/releases/tag/v*")[0]
|
||||||
$WAUAvailableVersion = $link.Trim().Split("v")[-1]
|
$WAUAvailableVersion = $link.Trim().Split("v")[-1]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -156,7 +156,7 @@ function Invoke-PostUpdateActions {
|
||||||
|
|
||||||
#Add 1 to counter file
|
#Add 1 to counter file
|
||||||
try {
|
try {
|
||||||
Invoke-RestMethod -Uri "https://github.com/Romanitho/$GitHub_Repo/releases/download/v$($WAUConfig.DisplayVersion)/WAU_InstallCounter" | Out-Null
|
Invoke-RestMethod -Uri "https://github.com/Romanitho/$($GitHub_Repo)/releases/download/v$($WAUConfig.DisplayVersion)/WAU_InstallCounter" | Out-Null
|
||||||
}
|
}
|
||||||
catch {
|
catch {
|
||||||
Write-ToLog "-> Not able to report installation." "Yellow"
|
Write-ToLog "-> Not able to report installation." "Yellow"
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
function Update-WAU {
|
function Update-WAU {
|
||||||
|
|
||||||
$OnClickAction = "https://github.com/Romanitho/$GitHub_Repo/releases"
|
$OnClickAction = "https://github.com/Romanitho/$($GitHub_Repo)/releases"
|
||||||
$Button1Text = $NotifLocale.local.outputs.output[10].message
|
$Button1Text = $NotifLocale.local.outputs.output[10].message
|
||||||
|
|
||||||
#Send available update notification
|
#Send available update notification
|
||||||
|
@ -12,16 +12,71 @@ function Update-WAU {
|
||||||
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
|
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
|
||||||
|
|
||||||
#Run WAU update
|
#Run WAU update
|
||||||
|
|
||||||
|
#Try WAU.msi (v2) if available
|
||||||
|
try {
|
||||||
|
#Download the msi
|
||||||
|
Write-ToLog "Downloading the GitHub Repository MSI version $WAUAvailableVersion" "Cyan"
|
||||||
|
$MsiFile = "$env:temp\WAU.msi"
|
||||||
|
Invoke-RestMethod -Uri "https://github.com/Romanitho/$($GitHub_Repo)/releases/download/v$($WAUAvailableVersion)/WAU.msi" -OutFile $MsiFile
|
||||||
|
|
||||||
|
#Migrate registry to save current WAU settings
|
||||||
|
Write-ToLog "Saving current config before updating with MSI"
|
||||||
|
$sourcePath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
|
||||||
|
$destinationPath = "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate"
|
||||||
|
#Create the destination key if it doesn't exist
|
||||||
|
if (-not (Test-Path -Path $destinationPath)) {
|
||||||
|
New-Item -Path $destinationPath -ItemType Directory -Force
|
||||||
|
Write-ToLog "New registry key created."
|
||||||
|
}
|
||||||
|
#Retrieve the properties of the source key
|
||||||
|
$properties = Get-ItemProperty -Path $sourcePath
|
||||||
|
foreach ($property in $properties.PSObject.Properties) {
|
||||||
|
#Check if the value name starts with "WAU_"
|
||||||
|
if ($property.Name -like "WAU_*" -and $property.Name -notlike "WAU_PostUpdateActions*") {
|
||||||
|
#Copy the value to the destination key
|
||||||
|
Set-ItemProperty -Path $destinationPath -Name $property.Name -Value $property.Value
|
||||||
|
Write-ToLog "$($property.Name) saved."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Stop ServiceUI
|
||||||
|
$ServiceUI = Get-Process -ProcessName serviceui -ErrorAction SilentlyContinue
|
||||||
|
if ($ServiceUI) {
|
||||||
|
try {
|
||||||
|
Write-ToLog "Stopping ServiceUI"
|
||||||
|
$ServiceUI | Stop-Process
|
||||||
|
}
|
||||||
|
catch {
|
||||||
|
Write-ToLog "Failed to stop ServiceUI"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#Uninstall WAU v1
|
||||||
|
Write-ToLog "Uninstalling WAU v1"
|
||||||
|
Start-Process powershell -ArgumentList "-WindowStyle Hidden -ExecutionPolicy Bypass -Command `"$WorkingDir\WAU-Uninstall.ps1`"" -Wait
|
||||||
|
|
||||||
|
#Update WAU and run
|
||||||
|
Write-ToLog "Updating WAU..." "Yellow"
|
||||||
|
Start-Process msiexec.exe -ArgumentList "/i $MsiFile /qn /L*v ""$WorkingDir\logs\WAU-Installer.log"" RUN_WAU=YES INSTALLDIR=""$WorkingDir"""
|
||||||
|
|
||||||
|
Exit 0
|
||||||
|
}
|
||||||
|
|
||||||
|
catch {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
#Try WAU.zip (v1)
|
#Try WAU.zip (v1)
|
||||||
|
|
||||||
|
Write-ToLog "No MSI found yet."
|
||||||
|
|
||||||
#Force to create a zip file
|
#Force to create a zip file
|
||||||
$ZipFile = "$WorkingDir\WAU_update.zip"
|
$ZipFile = "$WorkingDir\WAU_update.zip"
|
||||||
New-Item $ZipFile -ItemType File -Force | Out-Null
|
New-Item $ZipFile -ItemType File -Force | Out-Null
|
||||||
|
|
||||||
#Download the zip
|
#Download the zip
|
||||||
Write-ToLog "Downloading the GitHub Repository Zip version $WAUAvailableVersion" "Cyan"
|
Write-ToLog "Downloading the GitHub Repository Zip version $WAUAvailableVersion" "Cyan"
|
||||||
Invoke-RestMethod -Uri "https://github.com/Romanitho/$GitHub_Repo/releases/download/v$($WAUAvailableVersion)/WAU.zip" -OutFile $ZipFile
|
Invoke-RestMethod -Uri "https://github.com/Romanitho/$($GitHub_Repo)/releases/download/v$($WAUAvailableVersion)/WAU.zip" -OutFile $ZipFile
|
||||||
|
|
||||||
#Extract Zip File
|
#Extract Zip File
|
||||||
Write-ToLog "Unzipping the WAU Update package" "Cyan"
|
Write-ToLog "Unzipping the WAU Update package" "Cyan"
|
||||||
|
@ -67,58 +122,6 @@ function Update-WAU {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
catch {
|
|
||||||
|
|
||||||
#Try WAU.msi (v2)
|
|
||||||
try {
|
|
||||||
#Download the msi
|
|
||||||
Write-ToLog "Downloading the GitHub Repository MSI version $WAUAvailableVersion" "Cyan"
|
|
||||||
$MsiFile = "$env:temp\WAU.msi"
|
|
||||||
Invoke-RestMethod -Uri "https://github.com/Romanitho/$GitHub_Repo/releases/download/v$($WAUAvailableVersion)/WAU.msi" -OutFile $MsiFile
|
|
||||||
|
|
||||||
#Migrate registry to save current WAU settings
|
|
||||||
Write-ToLog "Saving current config before updating with MSI"
|
|
||||||
$sourcePath = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate"
|
|
||||||
$destinationPath = "HKLM:\SOFTWARE\Romanitho\Winget-AutoUpdate"
|
|
||||||
#Create the destination key if it doesn't exist
|
|
||||||
if (-not (Test-Path -Path $destinationPath)) {
|
|
||||||
New-Item -Path $destinationPath -ItemType Directory -Force
|
|
||||||
Write-ToLog "New registry key created."
|
|
||||||
}
|
|
||||||
#Retrieve the properties of the source key
|
|
||||||
$properties = Get-ItemProperty -Path $sourcePath
|
|
||||||
foreach ($property in $properties.PSObject.Properties) {
|
|
||||||
#Check if the value name starts with "WAU_"
|
|
||||||
if ($property.Name -like "WAU_*" -and $property.Name -notlike "WAU_PostUpdateActions*") {
|
|
||||||
#Copy the value to the destination key
|
|
||||||
Set-ItemProperty -Path $destinationPath -Name $property.Name -Value $property.Value
|
|
||||||
Write-ToLog "$($property.Name) saved."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#Stop ServiceUI
|
|
||||||
$ServiceUI = Get-Process -ProcessName serviceui -ErrorAction SilentlyContinue
|
|
||||||
if ($ServiceUI) {
|
|
||||||
try {
|
|
||||||
Write-ToLog "Stopping ServiceUI"
|
|
||||||
$ServiceUI | Stop-Process
|
|
||||||
}
|
|
||||||
catch {
|
|
||||||
Write-ToLog "Failed to stop ServiceUI"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
#Uninstall WAU v1
|
|
||||||
Write-ToLog "Uninstalling WAU v1"
|
|
||||||
Start-Process powershell -ArgumentList "-WindowStyle Hidden -ExecutionPolicy Bypass -Command `"$WorkingDir\WAU-Uninstall.ps1`"" -Wait
|
|
||||||
|
|
||||||
#Update WAU and run
|
|
||||||
Write-ToLog "Updating WAU..." "Yellow"
|
|
||||||
Start-Process msiexec.exe -ArgumentList "/i $MsiFile /qn /L*v ""$WorkingDir\logs\WAU-Installer.log"" RUN_WAU=YES INSTALLDIR=""$WorkingDir"""
|
|
||||||
|
|
||||||
Exit 0
|
|
||||||
}
|
|
||||||
|
|
||||||
catch {
|
catch {
|
||||||
|
|
||||||
#Send Error Notif
|
#Send Error Notif
|
||||||
|
@ -128,6 +131,8 @@ function Update-WAU {
|
||||||
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
|
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
|
||||||
Write-ToLog "WAU Update failed" "Red"
|
Write-ToLog "WAU Update failed" "Red"
|
||||||
|
|
||||||
|
Remove-Item -Path $ZipFile -Force -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue