2023-03-31 15:56:07 +00:00
|
|
|
#Function to update WAU
|
2022-03-14 13:55:02 +00:00
|
|
|
|
2022-03-26 21:27:11 +00:00
|
|
|
function Update-WAU {
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-07-05 14:48:23 +00:00
|
|
|
$OnClickAction = "https://github.com/Romanitho/Winget-AutoUpdate/releases"
|
2022-10-26 22:49:10 +00:00
|
|
|
$Button1Text = $NotifLocale.local.outputs.output[10].message
|
2022-07-05 14:48:23 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
#Send available update notification
|
|
|
|
$Title = $NotifLocale.local.outputs.output[2].title -f "Winget-AutoUpdate"
|
2022-03-26 21:27:11 +00:00
|
|
|
$Message = $NotifLocale.local.outputs.output[2].message -f $WAUCurrentVersion, $WAUAvailableVersion
|
2022-03-14 13:55:02 +00:00
|
|
|
$MessageType = "info"
|
2022-10-26 22:49:10 +00:00
|
|
|
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
|
2022-03-14 13:55:02 +00:00
|
|
|
|
|
|
|
#Run WAU update
|
2022-06-10 08:26:41 +00:00
|
|
|
try {
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-10-26 22:49:10 +00:00
|
|
|
#Force to create a zip file
|
2022-03-14 13:55:02 +00:00
|
|
|
$ZipFile = "$WorkingDir\WAU_update.zip"
|
|
|
|
New-Item $ZipFile -ItemType File -Force | Out-Null
|
|
|
|
|
2022-10-26 22:49:10 +00:00
|
|
|
#Download the zip
|
2022-03-27 10:20:33 +00:00
|
|
|
Write-Log "Downloading the GitHub Repository version $WAUAvailableVersion" "Cyan"
|
2022-03-26 21:27:11 +00:00
|
|
|
Invoke-RestMethod -Uri "https://github.com/Romanitho/Winget-AutoUpdate/archive/refs/tags/v$($WAUAvailableVersion).zip/" -OutFile $ZipFile
|
2022-03-14 13:55:02 +00:00
|
|
|
|
|
|
|
#Extract Zip File
|
2022-03-27 10:20:33 +00:00
|
|
|
Write-Log "Unzipping the WAU GitHub Repository" "Cyan"
|
2022-03-14 13:55:02 +00:00
|
|
|
$location = "$WorkingDir\WAU_update"
|
|
|
|
Expand-Archive -Path $ZipFile -DestinationPath $location -Force
|
|
|
|
Get-ChildItem -Path $location -Recurse | Unblock-File
|
2022-10-26 22:49:10 +00:00
|
|
|
|
2022-04-13 16:50:06 +00:00
|
|
|
#Update scritps
|
2022-03-27 10:20:33 +00:00
|
|
|
Write-Log "Updating WAU" "Yellow"
|
2022-03-22 17:19:30 +00:00
|
|
|
$TempPath = (Resolve-Path "$location\*\Winget-AutoUpdate\")[0].Path
|
2022-06-10 08:26:41 +00:00
|
|
|
if ($TempPath) {
|
2022-03-26 15:02:00 +00:00
|
|
|
Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Exclude "icons" -Recurse -Force
|
|
|
|
}
|
2022-10-26 22:49:10 +00:00
|
|
|
|
2022-03-27 10:20:33 +00:00
|
|
|
#Remove update zip file and update temp folder
|
|
|
|
Write-Log "Done. Cleaning temp files" "Cyan"
|
2022-03-14 13:55:02 +00:00
|
|
|
Remove-Item -Path $ZipFile -Force -ErrorAction SilentlyContinue
|
|
|
|
Remove-Item -Path $location -Recurse -Force -ErrorAction SilentlyContinue
|
|
|
|
|
2022-05-22 13:27:45 +00:00
|
|
|
#Set new version to registry
|
2022-05-22 22:41:21 +00:00
|
|
|
$WAUConfig | New-ItemProperty -Name DisplayVersion -Value $WAUAvailableVersion -Force
|
|
|
|
$WAUConfig | New-ItemProperty -Name VersionMajor -Value ([version]$WAUAvailableVersion).Major -Force
|
|
|
|
$WAUConfig | New-ItemProperty -Name VersionMinor -Value ([version]$WAUAvailableVersion).Minor -Force
|
|
|
|
|
|
|
|
#Set Post Update actions to 1
|
|
|
|
$WAUConfig | New-ItemProperty -Name WAU_PostUpdateActions -Value 1 -Force
|
2022-03-14 13:55:02 +00:00
|
|
|
|
|
|
|
#Send success Notif
|
2022-03-27 10:20:33 +00:00
|
|
|
Write-Log "WAU Update completed." "Green"
|
2022-03-14 13:55:02 +00:00
|
|
|
$Title = $NotifLocale.local.outputs.output[3].title -f "Winget-AutoUpdate"
|
2022-03-26 21:27:11 +00:00
|
|
|
$Message = $NotifLocale.local.outputs.output[3].message -f $WAUAvailableVersion
|
2022-03-14 13:55:02 +00:00
|
|
|
$MessageType = "success"
|
2022-10-26 22:49:10 +00:00
|
|
|
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
|
2022-03-14 13:55:02 +00:00
|
|
|
|
|
|
|
#Rerun with newer version
|
2022-04-13 16:50:06 +00:00
|
|
|
Write-Log "Re-run WAU"
|
2022-05-22 22:41:21 +00:00
|
|
|
Start-Process powershell -ArgumentList "-NoProfile -ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade.ps1`""
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
exit
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
}
|
2022-04-13 16:50:06 +00:00
|
|
|
|
2022-06-10 08:26:41 +00:00
|
|
|
catch {
|
2022-10-26 22:49:10 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
#Send Error Notif
|
|
|
|
$Title = $NotifLocale.local.outputs.output[4].title -f "Winget-AutoUpdate"
|
|
|
|
$Message = $NotifLocale.local.outputs.output[4].message
|
|
|
|
$MessageType = "error"
|
2022-10-26 22:49:10 +00:00
|
|
|
Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text
|
2022-03-27 10:20:33 +00:00
|
|
|
Write-Log "WAU Update failed" "Red"
|
2022-10-26 22:49:10 +00:00
|
|
|
|
2022-03-14 13:55:02 +00:00
|
|
|
}
|
2022-04-13 16:50:06 +00:00
|
|
|
|
|
|
|
}
|