From 6ee43de5154de3d664062fc68bc15239e847a091 Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 19 Oct 2026 15:47:34 +0200 Subject: [PATCH] Protect shared MPC-HC settings from running x86 and x64 players --- TASKS.md | 1 + docs/desktop-app-configs.md | 11 +++++++++++ src/Adapters.psm1 | 4 ++++ tests/Adapters.Tests.ps1 | 17 +++++++++++++++++ 4 files changed, 33 insertions(+) diff --git a/TASKS.md b/TASKS.md index d2c6bc5..419468d 100644 --- a/TASKS.md +++ b/TASKS.md @@ -140,3 +140,4 @@ open until it is run on disposable machines with the required account setups. - [x] Record the cross-script output and error-handling convention in AGENTS.md and the advanced guide. - [x] Simplify the Ontime event timer: hide event cards, enlarge countdown and bottom message equally, and blink the background red; checked in a local Firefox fixture. - [x] Reduce Ontime countdown/message sizing by 30%, enlarge the clock, and bottom-align fullscreen messages; preview both layouts in Firefox. +- [x] Verify the shared MPC-HC x86/x64 registry target and block apply while either player is running to prevent settings being overwritten on exit. diff --git a/docs/desktop-app-configs.md b/docs/desktop-app-configs.md index 941f0de..465b667 100644 --- a/docs/desktop-app-configs.md +++ b/docs/desktop-app-configs.md @@ -22,6 +22,17 @@ preferences. 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. +The standard x86 and x64 builds use this same settings key for the same Windows +user: applying once configures both. This HKCU location is shared across registry +views; do not add a speculative Wow6432Node or "MPC-HC x64" target. +See [MPC-HC's settings store](https://github.com/clsid2/mpc-hc/blob/develop/src/mpc-hc/Profile.cpp) +and [Windows registry sharing rules](https://learn.microsoft.com/en-us/windows/win32/winprog64/shared-registry-keys). + +Close **both** `mpc-hc.exe` and `mpc-hc64.exe` before applying. The adapter refuses +writes while either process is running, to prevent an open player from saving +stale settings over the new values. If the two players still differ, check each +one's settings-storage option and Windows account: separate INI files are not +managed by this registry adapter. 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 diff --git a/src/Adapters.psm1 b/src/Adapters.psm1 index 2219475..e9b6698 100644 --- a/src/Adapters.psm1 +++ b/src/Adapters.psm1 @@ -192,6 +192,10 @@ function Get-AdapterPlan { function Set-RegistryDeclaration { param([string]$Root, $Declaration) + # Standard x86 and x64 MPC-HC share this HKCU settings store. + if (Get-Process -Name 'mpc-hc', 'mpc-hc64' -ErrorAction SilentlyContinue) { + throw 'Close both MPC-HC and MPC-HC x64 before applying settings, then rerun the update.' + } foreach ($entry in $Declaration.values) { $path = if ([string]::IsNullOrWhiteSpace([string]$entry.path)) { $Root } else { Join-Path $Root $entry.path } if (-not (Test-Path -LiteralPath $path)) { [void](New-Item -Path $path -ErrorAction Stop) } diff --git a/tests/Adapters.Tests.ps1 b/tests/Adapters.Tests.ps1 index 91c71a2..38fdd03 100644 --- a/tests/Adapters.Tests.ps1 +++ b/tests/Adapters.Tests.ps1 @@ -121,3 +121,20 @@ Describe 'Registry key preservation' { } } } + +Describe 'MPC-HC running player protection' { + It 'refuses registry writes when either player is running' { + InModuleScope Adapters { + Mock Get-Process { [pscustomobject]@{ ProcessName = 'mpc-hc64' } } + Mock New-Item {} + Mock New-ItemProperty {} + $declaration = [pscustomobject]@{ values = @( + [pscustomobject]@{ path = ''; name = 'Volume'; type = 'DWord'; value = 80 } + ) } + { Set-RegistryDeclaration -Root 'TestRoot' -Declaration $declaration } | Should -Throw '*Close both MPC-HC and MPC-HC x64*' + Should -Invoke Get-Process -Times 1 -ParameterFilter { $Name -contains 'mpc-hc' -and $Name -contains 'mpc-hc64' } + Should -Invoke New-Item -Times 0 + Should -Invoke New-ItemProperty -Times 0 + } + } +}