diff --git a/TASKS.md b/TASKS.md index 8d224ae..2741600 100644 --- a/TASKS.md +++ b/TASKS.md @@ -133,3 +133,4 @@ open until it is run on disposable machines with the required account setups. - [x] Report CLI exceptions concisely on stderr without throwing from the error handler; preserve exit code 2 and JSON errors. - [x] Accept signed registry DWORD/QWORD exports and validate the complete MPC-HC declaration with mocked registry writes. - [x] Color terminal item statuses while preserving plain redirected output and supporting NO_COLOR. +- [x] Preserve existing registry keys during MPC-HC apply and document registry-only storage and capture filtering. diff --git a/docs/desktop-app-configs.md b/docs/desktop-app-configs.md index 924c724..b729132 100644 --- a/docs/desktop-app-configs.md +++ b/docs/desktop-app-configs.md @@ -23,6 +23,18 @@ MPC-HC normally stores preferences below `HKCU\Software\MPC-HC\MPC-HC`. Config Central applies only values listed in `configs/mpc-hc/settings.json`; it does not delete other values or registry keys. +This adapter supports **registry mode only**. MPC-HC also supports an INI file +next to its executable (`mpc-hc.ini` or `mpc-hc64.ini`). Check the player's +settings-storage option before capture or apply: an old registry key can remain +even when the active player uses INI storage. A successful registry write does +not prove the player reads that registry key. +See [MPC-HC's storage implementation](https://github.com/clsid2/mpc-hc/blob/develop/src/mpc-hc/mplayerc.cpp). + +Capture is deliberately filtered, not a complete player backup: monitor/device +selection and other machine-specific or private values are excluded. Apply only +updates declared values for the current Windows user. Close MPC-HC before +capture or deployment, then reopen it afterward. + On the machine whose settings should be the baseline, close MPC-HC and run: ```powershell diff --git a/src/Adapters.psm1 b/src/Adapters.psm1 index ebf9f64..2219475 100644 --- a/src/Adapters.psm1 +++ b/src/Adapters.psm1 @@ -194,7 +194,7 @@ function Set-RegistryDeclaration { param([string]$Root, $Declaration) foreach ($entry in $Declaration.values) { $path = if ([string]::IsNullOrWhiteSpace([string]$entry.path)) { $Root } else { Join-Path $Root $entry.path } - [void](New-Item -Path $path -Force) + if (-not (Test-Path -LiteralPath $path)) { [void](New-Item -Path $path -ErrorAction Stop) } $value = switch ($entry.type) { 'DWord' { if ($entry.value -lt 0) { [int32]$entry.value } else { [uint32]$entry.value } } 'QWord' { if ($entry.value -lt 0) { [int64]$entry.value } else { [uint64]$entry.value } } diff --git a/tests/Adapters.Tests.ps1 b/tests/Adapters.Tests.ps1 index 1ed5b89..91c71a2 100644 --- a/tests/Adapters.Tests.ps1 +++ b/tests/Adapters.Tests.ps1 @@ -89,3 +89,35 @@ Describe 'Registry integer deployment' { } } } + +Describe 'Registry key preservation' { + It 'preserves existing values while applying multiple values to the same key' { + InModuleScope Adapters { + $script:stored = @{ Existing = 'keep' } + Mock Test-Path { $true } + Mock New-Item { throw 'Existing key must not be recreated' } + Mock New-ItemProperty { $script:stored[$Name] = $Value } + $declaration = [pscustomobject]@{ values = @( + [pscustomobject]@{ path = ''; name = 'First'; type = 'DWord'; value = 1 }, + [pscustomobject]@{ path = ''; name = 'Second'; type = 'DWord'; value = 2 } + ) } + Set-RegistryDeclaration -Root 'TestRoot' -Declaration $declaration + $script:stored.Existing | Should -Be 'keep' + $script:stored.First | Should -Be 1 + $script:stored.Second | Should -Be 2 + Should -Invoke New-Item -Times 0 + } + } + It 'creates a missing key without forcing replacement' { + InModuleScope Adapters { + Mock Test-Path { $false } + Mock New-Item {} + Mock New-ItemProperty {} + $declaration = [pscustomobject]@{ values = @( + [pscustomobject]@{ path = ''; name = 'First'; type = 'DWord'; value = 1 } + ) } + Set-RegistryDeclaration -Root 'TestRoot' -Declaration $declaration + Should -Invoke New-Item -Times 1 -ParameterFilter { -not $Force } + } + } +}