From c125b77f86341e71be93dbfb810fbd6b7e8202f6 Mon Sep 17 00:00:00 2001 From: romanitho <96626929+Romanitho@users.noreply.github.com> Date: Tue, 31 Oct 2023 16:30:10 +0100 Subject: [PATCH] Better reinstall --- Winget-AutoUpdate-Install.ps1 | 16 +++++++++------- .../functions/Invoke-PostUpdateActions.ps1 | 14 +++++--------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/Winget-AutoUpdate-Install.ps1 b/Winget-AutoUpdate-Install.ps1 index 40295f5..283b084 100644 --- a/Winget-AutoUpdate-Install.ps1 +++ b/Winget-AutoUpdate-Install.ps1 @@ -193,20 +193,22 @@ function Install-WingetAutoUpdate { Write-ToLog "Installing WAU..." "Yellow" try { - #Copy files to location (and clean old install) + #Copy files to location if (!(Test-Path $WAUinstallPath)) { New-Item -ItemType Directory -Force -Path $WAUinstallPath | Out-Null + Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WAUinstallPath -Recurse -Force -ErrorAction SilentlyContinue } - elseif (!$NoClean) { - Remove-Item -Path "$WAUinstallPath\*" -Exclude *.log -Recurse -Force + elseif ($NoClean) { + #Keep critical files + Get-ChildItem -Path $WAUinstallPath -Exclude *.txt, mods, logs, icons | Remove-Item -Recurse -Force + Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WAUinstallPath -Exclude icons -Recurse -Force -ErrorAction SilentlyContinue #Exclude icons if personalized } else { - #Keep critical files - Get-ChildItem -Path $WAUinstallPath -Exclude *.txt, mods, logs | Remove-Item -Recurse -Force + #Keep logs only + Get-ChildItem -Path $WAUinstallPath -Exclude *.logs | Remove-Item -Recurse -Force + Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WAUinstallPath -Recurse -Force -ErrorAction SilentlyContinue } - Copy-Item -Path "$PSScriptRoot\Winget-AutoUpdate\*" -Destination $WAUinstallPath -Recurse -Force -ErrorAction SilentlyContinue - #White List or Black List apps if ($UseWhiteList) { if (!$NoClean) { diff --git a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 index ecbc3ab..79ebeec 100644 --- a/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 +++ b/Winget-AutoUpdate/functions/Invoke-PostUpdateActions.ps1 @@ -137,15 +137,11 @@ function Invoke-PostUpdateActions { } #Remove old registry key - $RegistryKeys = @( - "VersionMajor", - "VersionMinor" - ) - foreach ($RegistryKey in $RegistryKeys) { - if (Get-ItemProperty -Path $regPath -Name $RegistryKey -ErrorAction SilentlyContinue) { - Remove-ItemProperty -Path $regPath -Name $RegistryKey - } - } + Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "VersionMajor" -ErrorAction SilentlyContinue + Remove-ItemProperty -Path "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\Winget-AutoUpdate" -Name "VersionMinor" -ErrorAction SilentlyContinue + Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "VersionMajor" -ErrorAction SilentlyContinue + Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "VersionMinor" -ErrorAction SilentlyContinue + Remove-ItemProperty -Path "HKLM:\SOFTWARE\Policies\Romanitho\Winget-AutoUpdate" -Name "DisplayVersion" -ErrorAction SilentlyContinue #Activate WAU in user context if previously configured (as "Winget-AutoUpdate-UserContext" at root) $UserContextTask = Get-ScheduledTask -TaskName 'Winget-AutoUpdate-UserContext' -TaskPath '\' -ErrorAction SilentlyContinue