Merge pull request #674 from Romanitho/msi-prerequisites

[MSI Prerequisites] Registry migration before msi upgrade
pull/678/head
Romain 2024-09-01 14:18:20 +02:00 committed by GitHub
commit 0a761706a3
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 2 deletions

View File

@ -76,7 +76,25 @@ function Update-WAU {
$MsiFile = "$env:temp\WAU.msi"
Invoke-RestMethod -Uri "https://github.com/Romanitho/Winget-AutoUpdate/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_*") {
#Copy the value to the destination key
Set-ItemProperty -Path $destinationPath -Name $property.Name -Value $property.Value
Write-ToLog "$($property.Name) saved."
}
}
#Update WAU and run
Write-ToLog "Updating WAU..." "Yellow"
@ -104,4 +122,4 @@ function Update-WAU {
}
}
}
}