diff --git a/Config/DefaultSettings.json b/Config/DefaultSettings.json index e3cf0b4..e697a2e 100644 --- a/Config/DefaultSettings.json +++ b/Config/DefaultSettings.json @@ -57,10 +57,6 @@ "Name": "ShowKnownFileExt", "Value": true }, - { - "Name": "DisableDragTray", - "Value": true - }, { "Name": "Hide3dObjects", "Value": true diff --git a/Config/Features.json b/Config/Features.json index 6e0346c..9e36f0c 100644 --- a/Config/Features.json +++ b/Config/Features.json @@ -832,19 +832,6 @@ "MinVersion": null, "MaxVersion": null }, - { - "FeatureId": "DisableDragTray", - "Label": "Disable 'Drag Tray' for sharing & moving files", - "ToolTip": "The Drag Tray is a new feature for sharing & moving files in Windows 11, it appears at the top of the screen when dragging files.", - "Category": "System", - "RegistryKey": "Disable_Share_Drag_Tray.reg", - "ApplyText": "Disabling Drag Tray", - "UndoLabel": "Enable 'Drag Tray' for sharing & moving files", - "ApplyUndoText": "Enabling Drag Tray", - "RegistryUndoKey": "Enable_Share_Drag_Tray.reg", - "MinVersion": 26200, - "MaxVersion": null - }, { "FeatureId": "RevertContextMenu", "Label": "Use classic Windows 10 context menu style", diff --git a/Config/Languages/en-US/Features.json b/Config/Languages/en-US/Features.json index e4aea48..21b3cbf 100644 --- a/Config/Languages/en-US/Features.json +++ b/Config/Languages/en-US/Features.json @@ -230,13 +230,6 @@ "UndoLabel": "Disable dark theme for system and apps", "ApplyUndoText": "Disabling dark mode for system and apps" }, - "DisableDragTray": { - "Label": "Disable 'Drag Tray' for sharing & moving files", - "ToolTip": "The Drag Tray is a new feature for sharing & moving files in Windows 11, it appears at the top of the screen when dragging files.", - "ApplyText": "Disabling Drag Tray", - "UndoLabel": "Enable 'Drag Tray' for sharing & moving files", - "ApplyUndoText": "Enabling Drag Tray" - }, "RevertContextMenu": { "Label": "Use classic Windows 10 context menu style", "ToolTip": "This will restore the classic Windows 10 style context menu, which is normally hidden behind the 'Show more options' entry in the new Windows 11 context menu.", diff --git a/Config/Languages/it-IT/Features.json b/Config/Languages/it-IT/Features.json index f04d112..e425375 100644 --- a/Config/Languages/it-IT/Features.json +++ b/Config/Languages/it-IT/Features.json @@ -230,13 +230,6 @@ "UndoLabel": "Disabilita il tema scuro per sistema e app", "ApplyUndoText": "Disabilitazione della modalità scura per sistema e app" }, - "DisableDragTray": { - "Label": "Disabilita 'Drag Tray' per condividere e spostare file", - "ToolTip": "Drag Tray è una nuova funzionalità di Windows 11 per condividere e spostare file; viene visualizzata nella parte superiore dello schermo quando trascini dei file.", - "ApplyText": "Disabilitazione di Drag Tray", - "UndoLabel": "Abilita 'Drag Tray' per condividere e spostare file", - "ApplyUndoText": "Abilitazione di Drag Tray" - }, "RevertContextMenu": { "Label": "Usa lo stile del menu contestuale classico di Windows 10", "ToolTip": "Ripristina il menu contestuale nello stile classico di Windows 10, normalmente nascosto dietro la voce 'Mostra altre opzioni' del nuovo menu contestuale di Windows 11.", diff --git a/Config/Languages/ja-JP/Features.json b/Config/Languages/ja-JP/Features.json index 39c9473..82eef3f 100644 --- a/Config/Languages/ja-JP/Features.json +++ b/Config/Languages/ja-JP/Features.json @@ -230,13 +230,6 @@ "UndoLabel": "システムとアプリでダーク テーマを無効にする", "ApplyUndoText": "システムとアプリのダーク モードを無効にしています" }, - "DisableDragTray": { - "Label": "ファイルの共有と移動用の「Drag Tray」を無効にする", - "ToolTip": "Drag Tray は Windows 11 でファイルを共有および移動するための新機能であり、ファイルをドラッグしたときに画面上部に表示されます。", - "ApplyText": "Drag Tray を無効にしています", - "UndoLabel": "ファイルの共有と移動用の「Drag Tray」を有効にする", - "ApplyUndoText": "Drag Tray を有効にしています" - }, "RevertContextMenu": { "Label": "従来の Windows 10 スタイルのコンテキスト メニューを使用する", "ToolTip": "新しい Windows 11 のコンテキスト メニューでは通常「その他のオプションを表示」項目の奥に隠されている、従来の Windows 10 スタイルのコンテキスト メニューを復元します。", diff --git a/Config/Languages/nl-NL/Features.json b/Config/Languages/nl-NL/Features.json index 942b3a6..0b9f709 100644 --- a/Config/Languages/nl-NL/Features.json +++ b/Config/Languages/nl-NL/Features.json @@ -230,13 +230,6 @@ "UndoLabel": "Donker thema voor Windows en apps uitschakelen", "ApplyUndoText": "Donker thema voor Windows en apps uitschakelen" }, - "DisableDragTray": { - "Label": "'Drag Tray' voor het delen van bestanden uitschakelen", - "ToolTip": "Drag Tray is een nieuwe functie voor het delen en verplaatsen van bestanden in Windows 11. Deze verschijnt bovenaan het scherm wanneer je bestanden sleept.", - "ApplyText": "Drag Tray uitschakelen", - "UndoLabel": "'Drag Tray' voor het delen van bestanden inschakelen", - "ApplyUndoText": "Drag Tray inschakelen" - }, "RevertContextMenu": { "Label": "Het klassieke contextmenu van Windows 10 gebruiken", "ToolTip": "Herstelt het klassieke Windows 10-contextmenu, dat normaal achter 'Meer opties weergeven' in het nieuwe Windows 11-contextmenu verborgen zit.", diff --git a/Config/Languages/pt-BR/Features.json b/Config/Languages/pt-BR/Features.json index 35bd792..4009cc6 100644 --- a/Config/Languages/pt-BR/Features.json +++ b/Config/Languages/pt-BR/Features.json @@ -230,13 +230,6 @@ "UndoLabel": "Desabilitar tema escuro para o sistema e apps", "ApplyUndoText": "Desabilitando modo escuro para o sistema e apps" }, - "DisableDragTray": { - "Label": "Desabilitar 'Drag Tray' para compartilhar e mover arquivos", - "ToolTip": "O Drag Tray é uma nova funcionalidade para compartilhar e mover arquivos no Windows 11, aparece no topo da tela ao arrastar arquivos.", - "ApplyText": "Desabilitando Drag Tray", - "UndoLabel": "Habilitar 'Drag Tray' para compartilhar e mover arquivos", - "ApplyUndoText": "Habilitando Drag Tray" - }, "RevertContextMenu": { "Label": "Usar estilo clássico de menu de contexto do Windows 10", "ToolTip": "Isto restaurará o estilo clássico do menu de contexto do Windows 10, que normalmente fica oculto atrás da entrada 'Mostrar mais opções' no novo menu de contexto do Windows 11.", diff --git a/Config/Languages/zh-CN/Features.json b/Config/Languages/zh-CN/Features.json index df53e2a..3573645 100644 --- a/Config/Languages/zh-CN/Features.json +++ b/Config/Languages/zh-CN/Features.json @@ -230,13 +230,6 @@ "UndoLabel": "禁用系统和应用的深色主题", "ApplyUndoText": "正在禁用系统和应用的深色模式" }, - "DisableDragTray": { - "Label": "禁用用于共享和移动文件的拖放托盘", - "ToolTip": "拖放托盘是 Windows 11 用于共享和移动文件的新功能,会在拖动文件时出现在屏幕顶部。", - "ApplyText": "正在禁用拖放托盘", - "UndoLabel": "启用用于共享和移动文件的拖放托盘", - "ApplyUndoText": "正在启用拖放托盘" - }, "RevertContextMenu": { "Label": "使用经典 Windows 10 右键菜单样式", "ToolTip": "恢复经典 Windows 10 风格的右键菜单。在 Windows 11 中,通常需要点击“显示更多选项”才能打开此菜单。", diff --git a/README.md b/README.md index 29a87f7..a36579a 100755 --- a/README.md +++ b/README.md @@ -98,7 +98,6 @@ Below is an overview of the key features and functionality offered by Win11Deblo #### System -- Disable the Drag Tray for sharing & moving files. - Restore the old Windows 10 style context menu. - Turn off Enhance Pointer Precision (mouse acceleration). - Disable the Sticky Keys keyboard shortcut. diff --git a/Regfiles/Disable_Share_Drag_Tray.reg b/Regfiles/Disable_Share_Drag_Tray.reg deleted file mode 100644 index 5669f76..0000000 Binary files a/Regfiles/Disable_Share_Drag_Tray.reg and /dev/null differ diff --git a/Regfiles/Sysprep/Disable_Share_Drag_Tray.reg b/Regfiles/Sysprep/Disable_Share_Drag_Tray.reg deleted file mode 100644 index 3faa70a..0000000 Binary files a/Regfiles/Sysprep/Disable_Share_Drag_Tray.reg and /dev/null differ diff --git a/Regfiles/Undo/Enable_Share_Drag_Tray.reg b/Regfiles/Undo/Enable_Share_Drag_Tray.reg deleted file mode 100644 index 1295836..0000000 Binary files a/Regfiles/Undo/Enable_Share_Drag_Tray.reg and /dev/null differ diff --git a/Scripts/Features/Registry-BackupValidation.ps1 b/Scripts/Features/Registry-BackupValidation.ps1 index 8d862ea..9bcf518 100644 --- a/Scripts/Features/Registry-BackupValidation.ps1 +++ b/Scripts/Features/Registry-BackupValidation.ps1 @@ -344,12 +344,12 @@ function Test-RegistryExecutableValueDataAllowed { <# .SYNOPSIS - Converts legacy absent value-only keys into scoped missing-value snapshots. + Filters unknown backup entries and converts legacy absent value-only keys. .DESCRIPTION - Uses only trusted feature plans. Empty absent-key snapshots at exact value-only - paths are converted in memory; authorized tree deletions and invalid snapshots - remain unchanged for subsequent validation. The input snapshots are not modified. + Uses trusted feature plans to warn and discard unknown values and keys, then + converts legacy absent keys into scoped missing-value snapshots. Retained data + still undergoes normal validation. The input snapshots are not modified. #> function ConvertTo-CompatibleRegistryKeySnapshots { param( @@ -362,9 +362,48 @@ function ConvertTo-CompatibleRegistryKeySnapshots { foreach ($snapshot in $RegistryKeys) { $normalizedPath = Get-NormalizedRegistryPathKey -Path $snapshot.Path - $plan = if ($normalizedPath) { $PlanMap[$normalizedPath] } else { $null } + # Invalid paths remain blocking validation errors. + if (-not $normalizedPath -or $snapshot.Path.IndexOf([char]0) -ge 0) { + $snapshot + continue + } + + $planMatch = Find-RegistryAllowListPlanMatch -NormalizedPath $normalizedPath -PlanMap $PlanMap + $values = @( + foreach ($value in @($snapshot.Values)) { + $valueName = Get-NormalizedRegistryValueName -ValueName $value.Name + if ($null -ne $planMatch -and + ($valueName.IndexOf([char]0) -ge 0 -or + (Test-RegistryValueAllowedByPlan -PlanMatch $planMatch -ValueName $valueName))) { + $value + } + else { + $reference = Get-RegistryValueReferenceForError -SnapshotPath $snapshot.Path -ValueName $valueName + Write-Warning "Skipping unknown backup registry value '$reference'." + } + } + ) + + if ($null -eq $planMatch) { + if (@($snapshot.Values).Count -eq 0) { + Write-Warning "Skipping unknown backup registry key '$($snapshot.Path)'." + } + # Discard the entire unknown subtree, including any deletion request. + $null = @(ConvertTo-CompatibleRegistryKeySnapshots -RegistryKeys @($snapshot.SubKeys) -PlanMap @{}) + continue + } + + $subKeys = @(ConvertTo-CompatibleRegistryKeySnapshots -RegistryKeys @($snapshot.SubKeys) -PlanMap $PlanMap) + # An emptied snapshot must not become a key-creation or legacy deletion request. + if ($values.Count -eq 0 -and $subKeys.Count -eq 0 -and + (@($snapshot.Values).Count -gt 0 -or @($snapshot.SubKeys).Count -gt 0)) { + continue + } + + # Legacy conversion requires an exact plan; inherited subtree permissions do not qualify. + $plan = $PlanMap[$normalizedPath] $convertAbsentKey = $snapshot.Exists -is [bool] -and -not $snapshot.Exists -and - @($snapshot.Values).Count -eq 0 -and @($snapshot.SubKeys).Count -eq 0 -and + $values.Count -eq 0 -and $subKeys.Count -eq 0 -and $null -ne $plan -and -not $plan.CaptureAllValues -and -not $plan.IncludeSubKeys -and $plan.ValueNames.Count -gt 0 -and -not (Test-RegistryKeyDeletionAllowed -NormalizedPath $normalizedPath -PlanMap $PlanMap) @@ -374,8 +413,8 @@ function ConvertTo-CompatibleRegistryKeySnapshots { # RemoveEmptyKey is derived here and is deliberately not read by normalization. $removeEmptyKey = $originallyAbsent -and ($snapshot.Exists -or $convertAbsentKey) -and $null -ne $plan -and -not $plan.CaptureAllValues -and -not $plan.IncludeSubKeys -and - @($snapshot.SubKeys).Count -eq 0 -and - @($snapshot.Values | Where-Object { [bool]$_.Exists }).Count -eq 0 + $subKeys.Count -eq 0 -and + @($values | Where-Object { [bool]$_.Exists }).Count -eq 0 [PSCustomObject]@{ Path = $snapshot.Path @@ -387,9 +426,9 @@ function ConvertTo-CompatibleRegistryKeySnapshots { foreach ($valueName in @($plan.ValueNames | Sort-Object)) { [PSCustomObject]@{ Name = $valueName; Exists = $false; Kind = $null; Data = $null } } - } else { $snapshot.Values } + } else { $values } ) - SubKeys = @(ConvertTo-CompatibleRegistryKeySnapshots -RegistryKeys @($snapshot.SubKeys) -PlanMap $PlanMap) + SubKeys = $subKeys } } } @@ -400,8 +439,7 @@ function ConvertTo-CompatibleRegistryKeySnapshots { registry-backed apply or undo key relevant to the requested direction. .DESCRIPTION - Appends a translated error to the caller-supplied Errors list for any feature ID that - isn't in the current catalog, rather than failing the whole validation outright. + Warns and skips feature IDs that are no longer in the current catalog. #> function Get-SelectedRegistryFeaturesForBackupValidation { param( @@ -424,7 +462,7 @@ function Get-SelectedRegistryFeaturesForBackupValidation { $selectedRegistryFeatures = New-Object System.Collections.Generic.List[object] foreach ($featureId in @($SelectedFeatureIds)) { if (-not $script:Features.ContainsKey($featureId)) { - $Errors.Add((Get-Translation -Key 'BackupFeatureNotInCatalog' -FormatArgs @($featureId))) + Write-Warning "Skipping unknown backup feature '$featureId'." continue } diff --git a/Scripts/Get.ps1 b/Scripts/Get.ps1 index 716093b..72a8dd3 100644 --- a/Scripts/Get.ps1 +++ b/Scripts/Get.ps1 @@ -81,7 +81,6 @@ param ( [switch]$ClearStartAllUsers, [string]$ReplaceStartAllUsers, [switch]$RevertContextMenu, - [switch]$DisableDragTray, [switch]$DisableMouseAcceleration, [switch]$DisableStickyKeys, [switch]$DisableWindowSnapping, diff --git a/Tests/Registry-BackupDeletion.Tests.ps1 b/Tests/Registry-BackupDeletion.Tests.ps1 index 58b9afe..9b98de3 100644 --- a/Tests/Registry-BackupDeletion.Tests.ps1 +++ b/Tests/Registry-BackupDeletion.Tests.ps1 @@ -19,6 +19,7 @@ BeforeAll { Describe 'Registry backup deletion permissions' { BeforeEach { $script:Params = @{} + Mock Write-Warning {} $script:RegfilesPath = Join-Path $PSScriptRoot '..\Regfiles' $script:Features = @{} foreach ($feature in $script:FeatureCatalog.Features) { @@ -26,6 +27,116 @@ Describe 'Registry backup deletion permissions' { } } + It 'skips retired Drag Tray data in an existing backup (undo: , absent key: )' -ForEach @( + @{ Undo = $false; Absent = $false } + @{ Undo = $true; Absent = $false } + @{ Undo = $false; Absent = $true } + ) { + $backup = [PSCustomObject]@{ + Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile' + SelectedFeatures = @(if (-not $Undo) { 'DisableDragTray' }) + SelectedUndoFeatures = @(if ($Undo) { 'DisableDragTray' }) + RegistryKeys = @([PSCustomObject]@{ + Path = 'HKEY_USERS\Default\Software\Microsoft\Windows\CurrentVersion\CDP' + Exists = -not $Absent + Values = @(if (-not $Absent) { [PSCustomObject]@{ Name = 'DragTrayEnabled'; Exists = $true; Kind = 'DWord'; Data = 1 } }) + SubKeys = @() + }) + } + + $normalized = ConvertTo-NormalizedRegistryBackup -Backup $backup + + $normalized.RegistryKeys | Should -BeNullOrEmpty + # Restore normalizes a second time, so skipping must be idempotent. + (ConvertTo-NormalizedRegistryBackup -Backup $normalized).RegistryKeys | Should -BeNullOrEmpty + } + + It 'warns for each unknown value beside a retired value' { + $snapshot = [PSCustomObject]@{ + Path = 'HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\CDP' + Exists = $true + Values = @( + [PSCustomObject]@{ Name = 'DragTrayEnabled'; Exists = $true; Kind = 'DWord'; Data = 1 } + [PSCustomObject]@{ Name = 'OtherValue'; Exists = $true; Kind = 'DWord'; Data = 1 } + ) + SubKeys = @() + } + + $normalized = @(ConvertTo-CompatibleRegistryKeySnapshots -RegistryKeys @($snapshot) -PlanMap @{}) + + $normalized | Should -BeNullOrEmpty + Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*DragTrayEnabled*' } + Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*OtherValue*' } + } + + It 'ignores additional unknown features without retirement definitions' { + $backup = [PSCustomObject]@{ + Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile' + SelectedFeatures = @('RetiredOne'); SelectedUndoFeatures = @('RetiredTwo') + RegistryKeys = @([PSCustomObject]@{ + Path = 'HKEY_USERS\Default\Software\Retired'; Exists = $true; SubKeys = @() + Values = @('First', 'Second', 'Third' | ForEach-Object { + [PSCustomObject]@{ Name = $_; Exists = $true; Kind = 'DWord'; Data = 1 } + }) + }) + } + + (ConvertTo-NormalizedRegistryBackup -Backup $backup).RegistryKeys | Should -BeNullOrEmpty + Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like "*feature 'RetiredOne'*" } + Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like "*feature 'RetiredTwo'*" } + Should -Invoke Write-Warning -Times 3 -Exactly -ParameterFilter { $Message -like '*registry value*' } + } + + It 'preserves known values while dropping unknown values and child keys' { + $path = 'HKEY_USERS\Default\Control Panel\Desktop' + $backup = [PSCustomObject]@{ + Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile' + SelectedFeatures = @('DisableAnimations', 'UnknownFeature') + RegistryKeys = @([PSCustomObject]@{ + Path = $path; Exists = $true + Values = @( + [PSCustomObject]@{ Name = 'UserPreferencesMask'; Exists = $true; Kind = 'Binary'; Data = @(144, 18, 7, 128, 16, 0, 0, 0) } + [PSCustomObject]@{ Name = 'OldSetting'; Exists = $true; Kind = 'Invalid'; Data = 'ignored' } + ) + SubKeys = @([PSCustomObject]@{ + Path = "$path\OldChild"; Exists = $true; SubKeys = @() + Values = @([PSCustomObject]@{ Name = ''; Exists = $true; Kind = 'String'; Data = 'ignored' }) + }) + }) + } + + $normalized = ConvertTo-NormalizedRegistryBackup -Backup $backup + $normalized.RegistryKeys | Should -HaveCount 1 + $normalized.RegistryKeys[0].Values | Should -HaveCount 1 + $normalized.RegistryKeys[0].Values[0].Name | Should -Be 'UserPreferencesMask' + $normalized.RegistryKeys[0].SubKeys | Should -BeNullOrEmpty + Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*OldSetting*' } + Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*OldChild*(Default)*' } + + $backup.RegistryKeys[0].Values[0].Data = @(256) + Mock Write-Error {} + { ConvertTo-NormalizedRegistryBackup -Backup $backup } | Should -Throw '*Validation failed*' + } + + It 'drops an emptied known key without creating or deleting it (exists: )' -ForEach @( + @{ Exists = $true } + @{ Exists = $false } + ) { + $backup = [PSCustomObject]@{ + Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile' + SelectedFeatures = @('DisableAnimations') + RegistryKeys = @([PSCustomObject]@{ + Path = 'HKEY_USERS\Default\Control Panel\Desktop'; Exists = $Exists; SubKeys = @() + Values = @([PSCustomObject]@{ Name = 'OldSetting'; Exists = $false }) + }) + } + + $normalized = ConvertTo-NormalizedRegistryBackup -Backup $backup + $normalized.RegistryKeys | Should -BeNullOrEmpty + (ConvertTo-NormalizedRegistryBackup -Backup $normalized).RegistryKeys | Should -BeNullOrEmpty + Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*OldSetting*' } + } + It 'rejects deletion of a key that only changes values under' -ForEach @( @{ FeatureId = 'DisableAnimations'; Path = 'HKEY_USERS\Default\Control Panel\Desktop' } @{ FeatureId = 'DisableLocationServices'; Path = 'HKEY_LOCAL_MACHINE\SOFTWARE\Policies\Microsoft\Windows\LocationAndSensors' } @@ -207,8 +318,8 @@ Describe 'Executable registry backup values' { $desktop = [PSCustomObject]@{ Path = 'HKEY_USERS\Default\Control Panel\Desktop'; Exists = $true; Values = @(); SubKeys = @() } $backup = [PSCustomObject]@{ Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile'; SelectedFeatures = @('DisableAnimations') - RegistryKeys = @($desktop, [PSCustomObject]@{ - Path = 'HKEY_USERS\Default\SOFTWARE\Microsoft\Windows\CurrentVersion\RunOnce'; Exists = $true; Values = @(); SubKeys = @($desktop) + RegistryKeys = @([PSCustomObject]@{ + Path = $desktop.Path; Exists = $true; Values = @(); SubKeys = @($desktop) }) } @@ -311,14 +422,16 @@ Describe 'Legacy absent-key backup compatibility' { (Get-Content -LiteralPath $filePath -Raw) | Should -Be $originalContent } - It 'rejects an unknown absent-key path instead of converting it' { + It 'ignores an unknown absent-key path instead of converting or deleting it' { + Mock Write-Warning {} $backup = [PSCustomObject]@{ Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile' SelectedFeatures = @('DisableAnimations') RegistryKeys = @([PSCustomObject]@{ Path = 'HKEY_USERS\Default\Software\NotAllowedHere'; Exists = $false; Values = @(); SubKeys = @() }) } - { ConvertTo-NormalizedRegistryBackup -Backup $backup } | Should -Throw '*unexpected registry path*' + (ConvertTo-NormalizedRegistryBackup -Backup $backup).RegistryKeys | Should -BeNullOrEmpty + Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*NotAllowedHere*' } } It 'imports a legacy value-only backup for using the correct profile paths' -ForEach @( @@ -384,7 +497,8 @@ Describe 'Legacy absent-key backup compatibility' { Should -Invoke Get-RegistryBackupCapturePlans -Times 1 -Exactly } - It 'rejects an absent value-only key containing subkeys' { + It 'skips an unknown child and its emptied absent parent without requesting deletion' { + Mock Write-Warning {} $path = 'HKEY_USERS\Default\Control Panel\Desktop' $backup = [PSCustomObject]@{ Version = '1.0'; BackupType = 'RegistryState'; Target = 'DefaultUserProfile' @@ -395,8 +509,11 @@ Describe 'Legacy absent-key backup compatibility' { }) } - { ConvertTo-NormalizedRegistryBackup -Backup $backup } | Should -Throw '*Validation failed*' - Should -Invoke Write-Error -Times 1 -Exactly -ParameterFilter { $Message -like '*unauthorized registry key deletion*' } + $normalized = ConvertTo-NormalizedRegistryBackup -Backup $backup + + $normalized.RegistryKeys | Should -BeNullOrEmpty + Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -eq "Skipping unknown backup registry key '$path\Child'." } + Should -Invoke Write-Error -Times 0 -Exactly } } @@ -602,17 +719,35 @@ Describe 'Executable registry restore confirmation' { Should -Invoke Invoke-WithLoadedRestoreHive -Times 0 -Exactly } - It 'does not permit overriding ' -ForEach @( + It 'skips with a warning and never restores it or asks for confirmation' -ForEach @( @{ Case = 'an unauthorized path' } @{ Case = 'an unauthorized value name' } + ) { + Mock Write-Warning {} + $backup = New-ExecutableTestBackup + if ($Case -eq 'an unauthorized path') { + $backup.RegistryKeys[0].Path = 'HKEY_LOCAL_MACHINE\Software\Unrelated' + } + else { + $backup.RegistryKeys[0].Values[0].Name = 'Unrelated' + } + + $result = Restore-RegistryBackupState -Backup $backup -ConfirmUntrustedValues { throw 'Confirmation must not be reached' } + + $result.Result | Should -BeTrue + Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like 'Skipping unknown backup registry value *Unrelated*' } + Should -Invoke Write-Error -Times 0 -Exactly + Should -Invoke Restore-RegistryKeySnapshot -Times 0 -Exactly + Should -Invoke Invoke-WithLoadedRestoreHive -Times 1 -Exactly -ParameterFilter { @($ArgumentObject.RegistryKeys).Count -eq 0 } + } + + It 'does not permit overriding ' -ForEach @( @{ Case = 'an unauthorized tree deletion' } @{ Case = 'an invalid kind' } @{ Case = 'a misplaced child' } ) { $backup = New-ExecutableTestBackup switch ($Case) { - 'an unauthorized path' { $backup.RegistryKeys[0].Path = 'HKEY_LOCAL_MACHINE\Software\Unrelated' } - 'an unauthorized value name' { $backup.RegistryKeys[0].Values[0].Name = 'Unrelated' } 'an unauthorized tree deletion' { $backup.RegistryKeys[0].Exists = $false } 'an invalid kind' { $backup.RegistryKeys[0].Values[0].Kind = '99' } 'a misplaced child' { $backup.RegistryKeys[0].SubKeys = (New-ExecutableTestBackup -Path 'HKEY_CLASSES_ROOT\ms-gamebarservices\shell\open\command').RegistryKeys } diff --git a/Tests/Registry-BackupFeatureValidation.Tests.ps1 b/Tests/Registry-BackupFeatureValidation.Tests.ps1 index f5a3e0a..f2190a2 100644 --- a/Tests/Registry-BackupFeatureValidation.Tests.ps1 +++ b/Tests/Registry-BackupFeatureValidation.Tests.ps1 @@ -49,10 +49,12 @@ Describe 'Test-RegistryBackupMatchesSelectedFeatures' { $script:CapturePlanCalls | Should -Be @($true) } - It 'reports unknown selected features without deriving capture plans' { + It 'warns and skips unknown selected features without deriving capture plans' { + Mock Write-Warning {} $errors = @(Test-RegistryBackupMatchesSelectedFeatures -SelectedFeatureIds @('UnknownFeature') -SelectedUndoFeatureIds @() -Target 'CurrentUser' -RegistryKeys @()) - $errors | Should -Contain "Selected feature 'UnknownFeature' was not found in the current feature catalog." + $errors | Should -BeNullOrEmpty + Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*UnknownFeature*' } $script:CapturePlanCalls | Should -BeNullOrEmpty } diff --git a/Tests/Registry-BackupValidation.Tests.ps1 b/Tests/Registry-BackupValidation.Tests.ps1 index 58133b9..f2ca823 100644 --- a/Tests/Registry-BackupValidation.Tests.ps1 +++ b/Tests/Registry-BackupValidation.Tests.ps1 @@ -79,13 +79,15 @@ Describe 'Get-SelectedRegistryFeaturesForBackupValidation' { $valueNames.Contains('mode') | Should -BeTrue } - It 'selects registry-backed apply features and reports unknown IDs' { + It 'selects registry-backed apply features and warns for unknown IDs' { + Mock Write-Warning {} $errors = New-Object System.Collections.Generic.List[string] $result = @(Get-SelectedRegistryFeaturesForBackupValidation -SelectedFeatureIds @('ApplyFeature', 'CustomFeature', 'MissingFeature') -IsUndoFeature:$false -Errors $errors) $result.Id | Should -Be 'ApplyFeature' - $errors | Should -Contain "Selected feature 'MissingFeature' was not found in the current feature catalog." + $errors | Should -BeNullOrEmpty + Should -Invoke Write-Warning -Times 1 -Exactly -ParameterFilter { $Message -like '*MissingFeature*' } } It 'uses undo registry keys and falls back to apply keys when needed' { diff --git a/Tests/Restore-RegistryBackup.Tests.ps1 b/Tests/Restore-RegistryBackup.Tests.ps1 index 541f12b..168520a 100644 --- a/Tests/Restore-RegistryBackup.Tests.ps1 +++ b/Tests/Restore-RegistryBackup.Tests.ps1 @@ -27,6 +27,7 @@ Describe 'Import-RegistryBackup' { It 'parses and normalizes registry snapshots from a real backup structure' { Mock Test-UserNameMatch { $true } Mock Get-RegistryBackupValidationPlanMap { @{} } + Mock ConvertTo-CompatibleRegistryKeySnapshots { param($RegistryKeys) $RegistryKeys } Mock Test-RegistryBackupAgainstAllowList { @() } $result = Import-RegistryBackup -FilePath (Join-Path $script:JsonFixturePath 'RegistryBackup.RealStructure.json') @@ -61,6 +62,7 @@ Describe 'ConvertTo-NormalizedRegistryBackup' { BeforeEach { $script:Features = @{ Example = [PSCustomObject]@{ FeatureId = 'Example'; RegistryKey = 'Example.reg' } } Mock Get-RegistryBackupValidationPlanMap { @{} } + Mock ConvertTo-CompatibleRegistryKeySnapshots { param($RegistryKeys) $RegistryKeys } Mock Test-RegistryBackupAgainstAllowList { @() } Mock Write-Error {} } @@ -122,6 +124,7 @@ Describe 'Restore-RegistryBackupState' { Mock Test-UserNameMatch { $true } Mock Write-Error {} Mock Get-RegistryBackupValidationPlanMap { @{} } + Mock ConvertTo-CompatibleRegistryKeySnapshots { param($RegistryKeys) $RegistryKeys } Mock Test-RegistryBackupAgainstAllowList { @() } $script:backup = [PSCustomObject]@{ Version = '1.0'; BackupType = 'RegistryState'; Target = 'CurrentUser:Tester'; SelectedFeatures = @('Example') diff --git a/Win11Debloat.ps1 b/Win11Debloat.ps1 index 2145737..3571d18 100644 --- a/Win11Debloat.ps1 +++ b/Win11Debloat.ps1 @@ -79,7 +79,6 @@ param ( [switch]$ClearStartAllUsers, [string]$ReplaceStartAllUsers, [switch]$RevertContextMenu, - [switch]$DisableDragTray, [switch]$DisableMouseAcceleration, [switch]$DisableStickyKeys, [switch]$DisableWindowSnapping,