From b52ec9345e00cad4470895fb6b115261361903bd Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Tue, 17 Sep 2024 11:48:52 +0200 Subject: [PATCH 01/12] Removing '-wait' when switching to msi --- Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 index 2bc0d11..ee41962 100644 --- a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 @@ -98,7 +98,7 @@ function Update-WAU { #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" -Wait + Start-Process msiexec.exe -ArgumentList "/i $MsiFile /qn /L*v ""$WorkingDir\logs\WAU-Installer.log"" RUN_WAU=YES" #Send success Notif Write-ToLog "WAU Update completed. Rerunning WAU..." "Green" From 015ac3731b71ae7d04ba7a7c836497b662a08a2b Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Tue, 17 Sep 2024 12:07:28 +0200 Subject: [PATCH 02/12] Set Repo as Variable --- Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 | 3 +++ .../functions/Get-WAUAvailableVersion.ps1 | 12 ++++++------ .../functions/Invoke-PostUpdateActions.ps1 | 2 +- Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 | 6 +++--- 4 files changed, 13 insertions(+), 10 deletions(-) diff --git a/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 index 8208061..4ad1785 100644 --- a/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -13,6 +13,9 @@ $null = cmd /c '' [Console]::OutputEncoding = [System.Text.Encoding]::UTF8 $Script:ProgressPreference = 'SilentlyContinue' +#Set GitHub Repo +$Script:GitHub_Repo = "Winget-AutoUpdate" + #Log initialization $LogFile = "$WorkingDir\logs\updates.log" diff --git a/Sources/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 b/Sources/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 index 24b289e..b3e0e03 100644 --- a/Sources/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 @@ -10,12 +10,12 @@ function Get-WAUAvailableVersion { try { #Get latest pre-release info - $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/releases' + $WAUurl = "https://api.github.com/repos/Romanitho/$GitHub_Repo/releases" $WAUAvailableVersion = ((Invoke-WebRequest $WAUurl -UseBasicParsing | ConvertFrom-Json)[0].tag_name).Replace("v", "") } catch { - $url = "https://github.com/Romanitho/Winget-AutoUpdate/releases" - $link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/Winget-AutoUpdate/releases/tag/v*")[0] + $url = "https://github.com/Romanitho/$GitHub_Repo/releases" + $link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/$GitHub_Repo/releases/tag/v*")[0] $WAUAvailableVersion = $link.Trim().Split("v")[-1] } @@ -24,12 +24,12 @@ function Get-WAUAvailableVersion { try { #Get latest stable info - $WAUurl = 'https://api.github.com/repos/Romanitho/Winget-AutoUpdate/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", "") } catch { - $url = "https://github.com/Romanitho/Winget-AutoUpdate/releases/latest" - $link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/Winget-AutoUpdate/releases/tag/v*")[0] + $url = "https://github.com/Romanitho/$GitHub_Repo/releases/latest" + $link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/$GitHub_Repo/releases/tag/v*")[0] $WAUAvailableVersion = $link.Trim().Split("v")[-1] } diff --git a/Sources/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Sources/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 index 00eb446..744d7ce 100644 --- a/Sources/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 @@ -156,7 +156,7 @@ function Invoke-PostUpdateActions { #Add 1 to counter file try { - Invoke-RestMethod -Uri "https://github.com/Romanitho/Winget-AutoUpdate/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 { Write-ToLog "-> Not able to report installation." "Yellow" diff --git a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 index ee41962..437d44c 100644 --- a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 @@ -2,7 +2,7 @@ function Update-WAU { - $OnClickAction = "https://github.com/Romanitho/Winget-AutoUpdate/releases" + $OnClickAction = "https://github.com/Romanitho/$GitHub_Repo/releases" $Button1Text = $NotifLocale.local.outputs.output[10].message #Send available update notification @@ -21,7 +21,7 @@ function Update-WAU { #Download the zip Write-ToLog "Downloading the GitHub Repository Zip version $WAUAvailableVersion" "Cyan" - Invoke-RestMethod -Uri "https://github.com/Romanitho/Winget-AutoUpdate/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 Write-ToLog "Unzipping the WAU Update package" "Cyan" @@ -74,7 +74,7 @@ function Update-WAU { #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/Winget-AutoUpdate/releases/download/v$($WAUAvailableVersion)/WAU.msi" -OutFile $MsiFile + 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" From a64eda4ac7ba51043062964d51c0c7ad3fd21145 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Tue, 17 Sep 2024 23:22:59 +0200 Subject: [PATCH 03/12] Improve MSI update from v1 --- .../functions/Update-WAU.ps1 | 23 +++++++++++++------ 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 index 437d44c..68d10a5 100644 --- a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 @@ -96,17 +96,26 @@ function Update-WAU { } } + #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" - #Send success Notif - Write-ToLog "WAU Update completed. Rerunning WAU..." "Green" - $Title = $NotifLocale.local.outputs.output[3].title -f "Winget-AutoUpdate" - $Message = $NotifLocale.local.outputs.output[3].message -f $WAUAvailableVersion - $MessageType = "success" - Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text - Exit 0 } From 3cc8d7950e5e8bc99f4cb7c81f7939d69c437ebf Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Tue, 17 Sep 2024 23:31:05 +0200 Subject: [PATCH 04/12] key not needed --- Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 index 68d10a5..bdd01a1 100644 --- a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 @@ -89,7 +89,7 @@ function Update-WAU { $properties = Get-ItemProperty -Path $sourcePath foreach ($property in $properties.PSObject.Properties) { #Check if the value name starts with "WAU_" - if ($property.Name -like "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." From a9feed326d4f7560f0cb67c846c250711c5e119e Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Tue, 17 Sep 2024 22:36:40 +0000 Subject: [PATCH 05/12] Changed version to 1.21.5 --- Sources/Winget-AutoUpdate/Version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Winget-AutoUpdate/Version.txt b/Sources/Winget-AutoUpdate/Version.txt index 3d8ac63..d6a49eb 100644 --- a/Sources/Winget-AutoUpdate/Version.txt +++ b/Sources/Winget-AutoUpdate/Version.txt @@ -1 +1 @@ -1.21.4 \ No newline at end of file +1.21.5 \ No newline at end of file From 3d29e2c3d77d05cb981e69ac5828a562c5861ed1 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Wed, 18 Sep 2024 12:55:43 +0200 Subject: [PATCH 06/12] Keep Install Dir on update --- Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 | 2 +- Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 b/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 index 4ad1785..6f279f3 100644 --- a/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 +++ b/Sources/Winget-AutoUpdate/Winget-Upgrade.ps1 @@ -153,7 +153,7 @@ if (Test-Network) { #Get Available Version $Script:WAUAvailableVersion = Get-WAUAvailableVersion #Compare - if ([version]$WAUAvailableVersion -gt [version]$WAUCurrentVersion) { + if ([version]$WAUAvailableVersion.replace("-n", "") -gt [version]$WAUCurrentVersion.replace("-n", "")) { #If new version is available, update it Write-ToLog "WAU Available version: $WAUAvailableVersion" "Yellow" Update-WAU diff --git a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 index bdd01a1..7d95077 100644 --- a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 @@ -114,7 +114,7 @@ function Update-WAU { #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" + Start-Process msiexec.exe -ArgumentList "/i $MsiFile /qn /L*v ""$WorkingDir\logs\WAU-Installer.log"" RUN_WAU=YES INSTALLDIR=""$WorkingDir""" Exit 0 } From 1704cce673b09ef2937a240a98148256de3cf979 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Wed, 18 Sep 2024 15:55:43 +0200 Subject: [PATCH 07/12] Try MSI first --- .../functions/Get-WAUAvailableVersion.ps1 | 12 +- .../functions/Invoke-PostUpdateActions.ps1 | 2 +- .../functions/Update-WAU.ps1 | 181 +++++++++--------- 3 files changed, 100 insertions(+), 95 deletions(-) diff --git a/Sources/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 b/Sources/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 index b3e0e03..b07eac7 100644 --- a/Sources/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Get-WAUAvailableVersion.ps1 @@ -10,12 +10,12 @@ function Get-WAUAvailableVersion { try { #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", "") } catch { - $url = "https://github.com/Romanitho/$GitHub_Repo/releases" - $link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/$GitHub_Repo/releases/tag/v*")[0] + $url = "https://github.com/Romanitho/$($GitHub_Repo)/releases" + $link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/$($GitHub_Repo)/releases/tag/v*")[0] $WAUAvailableVersion = $link.Trim().Split("v")[-1] } @@ -24,12 +24,12 @@ function Get-WAUAvailableVersion { try { #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", "") } catch { - $url = "https://github.com/Romanitho/$GitHub_Repo/releases/latest" - $link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/$GitHub_Repo/releases/tag/v*")[0] + $url = "https://github.com/Romanitho/$($GitHub_Repo)/releases/latest" + $link = ((Invoke-WebRequest $url -UseBasicParsing).Links.href -match "/$($GitHub_Repo)/releases/tag/v*")[0] $WAUAvailableVersion = $link.Trim().Split("v")[-1] } diff --git a/Sources/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Sources/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 index 744d7ce..a363308 100644 --- a/Sources/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 @@ -156,7 +156,7 @@ function Invoke-PostUpdateActions { #Add 1 to counter file 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 { Write-ToLog "-> Not able to report installation." "Yellow" diff --git a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 index 7d95077..d1521e7 100644 --- a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 @@ -2,7 +2,7 @@ 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 #Send available update notification @@ -12,111 +12,114 @@ function Update-WAU { Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text #Run WAU update + + #Try WAU.msi (v2) if available try { - #Try WAU.zip (v1) + #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 - #Force to create a zip file - $ZipFile = "$WorkingDir\WAU_update.zip" - New-Item $ZipFile -ItemType File -Force | Out-Null + #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." + } + } - #Download the zip - 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 + #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" + } + } - #Extract Zip File - Write-ToLog "Unzipping the WAU Update package" "Cyan" - $location = "$WorkingDir\WAU_update" - Expand-Archive -Path $ZipFile -DestinationPath $location -Force - Get-ChildItem -Path $location -Recurse | Unblock-File + #Uninstall WAU v1 + Write-ToLog "Uninstalling WAU v1" + Start-Process powershell -ArgumentList "-WindowStyle Hidden -ExecutionPolicy Bypass -Command `"$WorkingDir\WAU-Uninstall.ps1`"" -Wait - #Update scritps + #Update WAU and run Write-ToLog "Updating WAU..." "Yellow" - $TempPath = (Resolve-Path "$location\Winget-AutoUpdate\")[0].Path - $ServiceUI = Test-Path "$WorkingDir\ServiceUI.exe" - if ($TempPath -and $ServiceUI) { - #Do not copy ServiceUI if already existing, causing error if in use. - Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Exclude ("icons", "ServiceUI.exe") -Recurse -Force - } - elseif ($TempPath) { - Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Exclude "icons" -Recurse -Force - } - - #Remove update zip file and update temp folder - Write-ToLog "Done. Cleaning temp files..." "Cyan" - Remove-Item -Path $ZipFile -Force -ErrorAction SilentlyContinue - Remove-Item -Path $location -Recurse -Force -ErrorAction SilentlyContinue - - #Set new version to registry - New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "DisplayVersion" -Value $WAUAvailableVersion -Force | Out-Null - - #Set Post Update actions to 1 - New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "WAU_PostUpdateActions" -Value 1 -Force | Out-Null - - #Send success Notif - Write-ToLog "WAU Update completed." "Green" - $Title = $NotifLocale.local.outputs.output[3].title -f "Winget-AutoUpdate" - $Message = $NotifLocale.local.outputs.output[3].message -f $WAUAvailableVersion - $MessageType = "success" - Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text - - #Rerun with newer version - Write-ToLog "Re-run WAU" - Start-Process powershell -ArgumentList "-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade.ps1`"" - - exit + Start-Process msiexec.exe -ArgumentList "/i $MsiFile /qn /L*v ""$WorkingDir\logs\WAU-Installer.log"" RUN_WAU=YES INSTALLDIR=""$WorkingDir""" + Exit 0 } 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 + #Try WAU.zip (v1) - #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." - } - } + Write-ToLog "No MSI found yet." - #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" - } - } + #Force to create a zip file + $ZipFile = "$WorkingDir\WAU_update.zip" + New-Item $ZipFile -ItemType File -Force | Out-Null - #Uninstall WAU v1 - Write-ToLog "Uninstalling WAU v1" - Start-Process powershell -ArgumentList "-WindowStyle Hidden -ExecutionPolicy Bypass -Command `"$WorkingDir\WAU-Uninstall.ps1`"" -Wait + #Download the zip + 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 - #Update WAU and run + #Extract Zip File + Write-ToLog "Unzipping the WAU Update package" "Cyan" + $location = "$WorkingDir\WAU_update" + Expand-Archive -Path $ZipFile -DestinationPath $location -Force + Get-ChildItem -Path $location -Recurse | Unblock-File + + #Update scritps 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""" + $TempPath = (Resolve-Path "$location\Winget-AutoUpdate\")[0].Path + $ServiceUI = Test-Path "$WorkingDir\ServiceUI.exe" + if ($TempPath -and $ServiceUI) { + #Do not copy ServiceUI if already existing, causing error if in use. + Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Exclude ("icons", "ServiceUI.exe") -Recurse -Force + } + elseif ($TempPath) { + Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Exclude "icons" -Recurse -Force + } + + #Remove update zip file and update temp folder + Write-ToLog "Done. Cleaning temp files..." "Cyan" + Remove-Item -Path $ZipFile -Force -ErrorAction SilentlyContinue + Remove-Item -Path $location -Recurse -Force -ErrorAction SilentlyContinue + + #Set new version to registry + New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "DisplayVersion" -Value $WAUAvailableVersion -Force | Out-Null + + #Set Post Update actions to 1 + New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "WAU_PostUpdateActions" -Value 1 -Force | Out-Null + + #Send success Notif + Write-ToLog "WAU Update completed." "Green" + $Title = $NotifLocale.local.outputs.output[3].title -f "Winget-AutoUpdate" + $Message = $NotifLocale.local.outputs.output[3].message -f $WAUAvailableVersion + $MessageType = "success" + Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text + + #Rerun with newer version + Write-ToLog "Re-run WAU" + Start-Process powershell -ArgumentList "-NoProfile -WindowStyle Hidden -ExecutionPolicy Bypass -Command `"$WorkingDir\winget-upgrade.ps1`"" + + exit - Exit 0 } catch { @@ -128,6 +131,8 @@ function Update-WAU { Start-NotifTask -Title $Title -Message $Message -MessageType $MessageType -Button1Action $OnClickAction -Button1Text $Button1Text Write-ToLog "WAU Update failed" "Red" + Remove-Item -Path $ZipFile -Force -ErrorAction SilentlyContinue + } } From b67345ee8987e664fee5318a0ee83062d9b5a962 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 18 Sep 2024 23:18:24 +0000 Subject: [PATCH 08/12] Changed version to 1.21.6 --- Sources/Winget-AutoUpdate/Version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Winget-AutoUpdate/Version.txt b/Sources/Winget-AutoUpdate/Version.txt index d6a49eb..6e83421 100644 --- a/Sources/Winget-AutoUpdate/Version.txt +++ b/Sources/Winget-AutoUpdate/Version.txt @@ -1 +1 @@ -1.21.5 \ No newline at end of file +1.21.6 \ No newline at end of file From 2795d4ee58277c81c6a5af9471d488645e7b4cf8 Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Thu, 19 Sep 2024 10:18:33 +0200 Subject: [PATCH 09/12] [MSI Prerequisite] Do not clean current config on update to MSI version --- Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 index d1521e7..86e870d 100644 --- a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 @@ -54,7 +54,7 @@ function Update-WAU { #Uninstall WAU v1 Write-ToLog "Uninstalling WAU v1" - Start-Process powershell -ArgumentList "-WindowStyle Hidden -ExecutionPolicy Bypass -Command `"$WorkingDir\WAU-Uninstall.ps1`"" -Wait + Start-Process powershell -ArgumentList "-WindowStyle Hidden -ExecutionPolicy Bypass -Command `"$WorkingDir\WAU-Uninstall.ps1`" -NoClean" -Wait #Update WAU and run Write-ToLog "Updating WAU..." "Yellow" From a2bc01d298a4d6a4b79291286f9b90f9b23f72d5 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 19 Sep 2024 10:08:31 +0000 Subject: [PATCH 10/12] Changed version to 1.21.7 --- Sources/Winget-AutoUpdate/Version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Winget-AutoUpdate/Version.txt b/Sources/Winget-AutoUpdate/Version.txt index 6e83421..915ddf3 100644 --- a/Sources/Winget-AutoUpdate/Version.txt +++ b/Sources/Winget-AutoUpdate/Version.txt @@ -1 +1 @@ -1.21.6 \ No newline at end of file +1.21.7 \ No newline at end of file From 6264a259af5e21ce93399031b8c8df9b0a5202ba Mon Sep 17 00:00:00 2001 From: Romain <96626929+Romanitho@users.noreply.github.com> Date: Thu, 19 Sep 2024 14:19:18 +0200 Subject: [PATCH 11/12] Update Update-WAU.ps1 --- Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 index 86e870d..e39dfc9 100644 --- a/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 +++ b/Sources/Winget-AutoUpdate/functions/Update-WAU.ps1 @@ -96,13 +96,16 @@ function Update-WAU { Copy-Item -Path "$TempPath\*" -Destination "$WorkingDir\" -Exclude "icons" -Recurse -Force } + #Get installed version + $InstalledVersion = Get-Content "$TempPath\Version.txt" + #Remove update zip file and update temp folder Write-ToLog "Done. Cleaning temp files..." "Cyan" Remove-Item -Path $ZipFile -Force -ErrorAction SilentlyContinue Remove-Item -Path $location -Recurse -Force -ErrorAction SilentlyContinue #Set new version to registry - New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "DisplayVersion" -Value $WAUAvailableVersion -Force | Out-Null + New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "DisplayVersion" -Value $InstalledVersion -Force | Out-Null #Set Post Update actions to 1 New-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "WAU_PostUpdateActions" -Value 1 -Force | Out-Null From 8e7004b30b8fde9b8fcb960e829d35c8b4711b86 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Thu, 19 Sep 2024 12:43:39 +0000 Subject: [PATCH 12/12] Changed version to 1.21.8 --- Sources/Winget-AutoUpdate/Version.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Sources/Winget-AutoUpdate/Version.txt b/Sources/Winget-AutoUpdate/Version.txt index 915ddf3..5c9a6fe 100644 --- a/Sources/Winget-AutoUpdate/Version.txt +++ b/Sources/Winget-AutoUpdate/Version.txt @@ -1 +1 @@ -1.21.7 \ No newline at end of file +1.21.8 \ No newline at end of file