diff --git a/Scripts/Get-Dev.ps1 b/Scripts/Get-Dev.ps1 index c067eb0..5e2942a 100644 --- a/Scripts/Get-Dev.ps1 +++ b/Scripts/Get-Dev.ps1 @@ -131,8 +131,29 @@ catch { Exit } -# Remove old script folder if it exists +# Migrate old user data from previous runs to AppData before cleanup if (Test-Path $tempWorkPath) { + $appDataPath = Join-Path $env:LOCALAPPDATA 'Win11Debloat' + if (-not (Test-Path $appDataPath)) { New-Item -ItemType Directory -Path $appDataPath -Force | Out-Null } + + $oldBackupsDir = Join-Path $tempWorkPath 'Backups' + $oldLogsDir = Join-Path $tempWorkPath 'Logs' + $oldSettingsFile = Join-Path $tempWorkPath 'Config\LastUsedSettings.json' + + if ((Test-Path $oldBackupsDir) -and (Get-ChildItem -Path $oldBackupsDir -ErrorAction SilentlyContinue)) { + $newBackupsDir = Join-Path $appDataPath 'Backups' + if (-not (Test-Path $newBackupsDir)) { New-Item -ItemType Directory -Path $newBackupsDir -Force | Out-Null } + Get-ChildItem -Path $oldBackupsDir | Move-Item -Destination $newBackupsDir -Force -ErrorAction SilentlyContinue + } + if ((Test-Path $oldLogsDir) -and (Get-ChildItem -Path $oldLogsDir -ErrorAction SilentlyContinue)) { + $newLogsDir = Join-Path $appDataPath 'Logs' + if (-not (Test-Path $newLogsDir)) { New-Item -ItemType Directory -Path $newLogsDir -Force | Out-Null } + Get-ChildItem -Path $oldLogsDir | Move-Item -Destination $newLogsDir -Force -ErrorAction SilentlyContinue + } + if (Test-Path $oldSettingsFile) { + Move-Item -Path $oldSettingsFile -Destination $appDataPath -Force -ErrorAction SilentlyContinue + } + Write-Output "" Write-Output "> Cleaning up old Win11Debloat folder..." diff --git a/Scripts/Get.ps1 b/Scripts/Get.ps1 index bdf1783..00de7b3 100644 --- a/Scripts/Get.ps1 +++ b/Scripts/Get.ps1 @@ -132,8 +132,29 @@ catch { Exit } -# Remove old script folder if it exists +# Migrate old user data from previous runs to AppData before cleanup if (Test-Path $tempWorkPath) { + $appDataPath = Join-Path $env:LOCALAPPDATA 'Win11Debloat' + if (-not (Test-Path $appDataPath)) { New-Item -ItemType Directory -Path $appDataPath -Force | Out-Null } + + $oldBackupsDir = Join-Path $tempWorkPath 'Backups' + $oldLogsDir = Join-Path $tempWorkPath 'Logs' + $oldSettingsFile = Join-Path $tempWorkPath 'Config\LastUsedSettings.json' + + if ((Test-Path $oldBackupsDir) -and (Get-ChildItem -Path $oldBackupsDir -ErrorAction SilentlyContinue)) { + $newBackupsDir = Join-Path $appDataPath 'Backups' + if (-not (Test-Path $newBackupsDir)) { New-Item -ItemType Directory -Path $newBackupsDir -Force | Out-Null } + Get-ChildItem -Path $oldBackupsDir | Move-Item -Destination $newBackupsDir -Force -ErrorAction SilentlyContinue + } + if ((Test-Path $oldLogsDir) -and (Get-ChildItem -Path $oldLogsDir -ErrorAction SilentlyContinue)) { + $newLogsDir = Join-Path $appDataPath 'Logs' + if (-not (Test-Path $newLogsDir)) { New-Item -ItemType Directory -Path $newLogsDir -Force | Out-Null } + Get-ChildItem -Path $oldLogsDir | Move-Item -Destination $newLogsDir -Force -ErrorAction SilentlyContinue + } + if (Test-Path $oldSettingsFile) { + Move-Item -Path $oldSettingsFile -Destination $appDataPath -Force -ErrorAction SilentlyContinue + } + Write-Output "" Write-Output "> Cleaning up old Win11Debloat folder..."