Ensure folders exist

This commit is contained in:
Jeffrey
2026-06-23 01:21:40 +02:00
parent 5bd8c9957b
commit 0a8999f635
2 changed files with 10 additions and 5 deletions

View File

@@ -228,7 +228,9 @@ function RestoreStartMenuFromBackup {
$userName = GetStartMenuUserNameFromPath -StartMenuBinFile $StartMenuBinFile $userName = GetStartMenuUserNameFromPath -StartMenuBinFile $StartMenuBinFile
$backupTimestamp = (Get-Date).ToString('yyyyMMdd_HHmmss') $backupTimestamp = (Get-Date).ToString('yyyyMMdd_HHmmss')
$startMenuBackupsDir = Join-Path $script:AppDataPath 'Backups' $startMenuBackupsDir = Join-Path $script:AppDataPath 'Backups'
$backupBinFile = if ([string]::IsNullOrWhiteSpace($BackupFilePath)) { if (-not (Test-Path $startMenuBackupsDir)) { New-Item -ItemType Directory -Path $startMenuBackupsDir -Force | Out-Null }
$resolvedBackupPath = if ([string]::IsNullOrWhiteSpace($BackupFilePath)) {
Join-Path $startMenuBackupsDir "Win11Debloat-Start2BinBackup-$userName-$backupTimestamp.bak" Join-Path $startMenuBackupsDir "Win11Debloat-Start2BinBackup-$userName-$backupTimestamp.bak"
} }
else { else {
@@ -237,7 +239,7 @@ function RestoreStartMenuFromBackup {
$currentBinBackup = Join-Path $startMenuBackupsDir "Win11Debloat-Start2BinRestore-$userName-$backupTimestamp.bak" $currentBinBackup = Join-Path $startMenuBackupsDir "Win11Debloat-Start2BinRestore-$userName-$backupTimestamp.bak"
if ($script:Params.ContainsKey("WhatIf")) { if ($script:Params.ContainsKey("WhatIf")) {
Write-Host "[WhatIf] Restore start menu for user $userName from backup $BackupFilePath" -ForegroundColor Cyan Write-Host "[WhatIf] Restore start menu for user $userName from backup $resolvedBackupPath" -ForegroundColor Cyan
return [PSCustomObject]@{ return [PSCustomObject]@{
UserName = $userName UserName = $userName
Result = $true Result = $true
@@ -245,11 +247,11 @@ function RestoreStartMenuFromBackup {
} }
} }
if (-not (Test-Path -LiteralPath $BackupFilePath)) { if (-not (Test-Path -LiteralPath $resolvedBackupPath)) {
return [PSCustomObject]@{ return [PSCustomObject]@{
UserName = $userName UserName = $userName
Result = $false Result = $false
Message = "Start menu backup file not found: $BackupFilePath" Message = "Start menu backup file not found: $resolvedBackupPath"
} }
} }
@@ -258,7 +260,7 @@ function RestoreStartMenuFromBackup {
Move-Item -Path $StartMenuBinFile -Destination $currentBinBackup -Force Move-Item -Path $StartMenuBinFile -Destination $currentBinBackup -Force
} }
Copy-Item -Path $BackupFilePath -Destination $StartMenuBinFile -Force Copy-Item -Path $resolvedBackupPath -Destination $StartMenuBinFile -Force
return [PSCustomObject]@{ return [PSCustomObject]@{
UserName = $userName UserName = $userName
Result = $true Result = $true

View File

@@ -212,6 +212,9 @@ Write-Host ""
Write-Host "" Write-Host ""
# Log script output to 'Win11Debloat.log' at the specified path # Log script output to 'Win11Debloat.log' at the specified path
$logDir = if ($LogPath) { $LogPath } else { Split-Path $script:DefaultLogPath -Parent }
if (-not (Test-Path $logDir)) { New-Item -ItemType Directory -Path $logDir -Force | Out-Null }
if ($LogPath -and (Test-Path $LogPath)) { if ($LogPath -and (Test-Path $LogPath)) {
Start-Transcript -Path (Join-Path $LogPath 'Win11Debloat.log') -Append -IncludeInvocationHeader -Force | Out-Null Start-Transcript -Path (Join-Path $LogPath 'Win11Debloat.log') -Append -IncludeInvocationHeader -Force | Out-Null
} }