diff --git a/Scripts/Get.ps1 b/Scripts/Get.ps1 index a3cba0d..206bdb1 100644 --- a/Scripts/Get.ps1 +++ b/Scripts/Get.ps1 @@ -127,11 +127,29 @@ catch { Exit } -# Remove old script folder if it exists, except for CustomAppsList and LastUsedSettings.json files +Write-Output "" +Write-Output "> Cleaning up old Win11Debloat folder..." + +# Remove old script folder if it exists, but keep config and log files if (Test-Path "$env:TEMP/Win11Debloat") { - Write-Output "" - Write-Output "> Cleaning up old Win11Debloat folder..." - Get-ChildItem -Path "$env:TEMP/Win11Debloat" -Exclude CustomAppsList,LastUsedSettings.json,Win11Debloat.log,Logs | Remove-Item -Recurse -Force + Get-ChildItem -Path "$env:TEMP/Win11Debloat" -Exclude CustomAppsList,LastUsedSettings.json,Win11Debloat.log,Config,Logs | Remove-Item -Recurse -Force +} + +$configDir = "$env:TEMP/Win11Debloat/Config" +$backupDir = "$env:TEMP/Win11Debloat/ConfigOld" + +# Temporarily move existing config files if they exist to prevent them from being overwritten by the new script files, will be moved back after the new script is unpacked +if (Test-Path "$configDir") { + New-Item -ItemType Directory -Path "$backupDir" -Force | Out-Null + + $filesToKeep = @( + 'CustomAppsList', + 'LastUsedSettings.json' + ) + + Get-ChildItem -Path "$configDir" -Recurse | Where-Object { $_.Name -in $filesToKeep } | Move-Item -Destination "$backupDir" + + Remove-Item "$configDir" -Recurse -Force } Write-Output "" @@ -146,6 +164,16 @@ Remove-Item "$env:TEMP/win11debloat.zip" # Move files Get-ChildItem -Path "$env:TEMP/Win11Debloat/Raphire-Win11Debloat-*" -Recurse | Move-Item -Destination "$env:TEMP/Win11Debloat" +# Add existing config files back to Config folder +if (Test-Path "$backupDir") { + if (-not (Test-Path "$configDir")) { + New-Item -ItemType Directory -Path "$configDir" -Force | Out-Null + } + + Get-ChildItem -Path "$backupDir" -Recurse | Move-Item -Destination "$configDir" + Remove-Item "$backupDir" -Recurse -Force +} + # Make list of arguments to pass on to the script $arguments = $($PSBoundParameters.GetEnumerator() | ForEach-Object { if ($_.Value -eq $true) { @@ -187,7 +215,7 @@ if (Test-Path "$env:TEMP/Win11Debloat") { Write-Output "> Cleaning up..." # Cleanup, remove Win11Debloat directory - Get-ChildItem -Path "$env:TEMP/Win11Debloat" -Exclude CustomAppsList,LastUsedSettings.json,Win11Debloat.log,Logs | Remove-Item -Recurse -Force + Get-ChildItem -Path "$env:TEMP/Win11Debloat" -Exclude CustomAppsList,LastUsedSettings.json,Win11Debloat.log,Config,Logs | Remove-Item -Recurse -Force } Write-Output ""