From 2ddd18bdd4cec631657597c416943bd49ab259aa Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Mon, 19 Oct 2026 15:51:25 +0200 Subject: [PATCH] Explain how to initialize missing MPC-HC settings --- TASKS.md | 1 + docs/desktop-app-configs.md | 5 +++++ src/Adapters.psm1 | 7 ++++++- src/Configs.psm1 | 5 ++++- tests/Adapters.Tests.ps1 | 16 ++++++++++++++++ tests/Configs.Tests.ps1 | 11 +++++++++++ tools/Export-MpcHcSettings.ps1 | 2 +- 7 files changed, 44 insertions(+), 3 deletions(-) diff --git a/TASKS.md b/TASKS.md index f1cc49a..6bdd9f5 100644 --- a/TASKS.md +++ b/TASKS.md @@ -142,3 +142,4 @@ open until it is run on disposable machines with the required account setups. - [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. - [x] Hide Ontime clock seconds and slow background blink to a three-second fade with a steady reduced-motion fallback. +- [x] Explain first-launch/registry-mode steps for missing MPC-HC capture settings and key-creation failures without suppressing the underlying error. diff --git a/docs/desktop-app-configs.md b/docs/desktop-app-configs.md index ddcbfb3..667b9bc 100644 --- a/docs/desktop-app-configs.md +++ b/docs/desktop-app-configs.md @@ -28,6 +28,11 @@ 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). +Apply attempts to create missing registry keys automatically. If Windows rejects +key creation, launch MPC-HC once, save settings in Windows registry mode, close +it, and retry; the error also retains the Windows diagnostic. Capture cannot +export settings that do not exist and gives the same first-launch guidance. + 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 diff --git a/src/Adapters.psm1 b/src/Adapters.psm1 index e9b6698..6c96ef2 100644 --- a/src/Adapters.psm1 +++ b/src/Adapters.psm1 @@ -198,7 +198,12 @@ function Set-RegistryDeclaration { } 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) } + if (-not (Test-Path -LiteralPath $path)) { + try { [void](New-Item -Path $path -ErrorAction Stop) } + catch { + throw "Could not create MPC-HC settings key '$path'. Launch MPC-HC once, save its settings in Windows registry mode, then close both MPC-HC versions and retry. Check permissions if it still fails. Windows reported: $($_.Exception.Message)" + } + } $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/src/Configs.psm1 b/src/Configs.psm1 index 9222bef..0cb0a36 100644 --- a/src/Configs.psm1 +++ b/src/Configs.psm1 @@ -145,7 +145,10 @@ function Export-ConfigCapture { foreach ($config in $selectedConfigs) { $location = $locations | Where-Object name -eq $config.name | Select-Object -First 1 if (-not $location.targetExists) { - $operations.Add([pscustomobject]@{ kind = 'config'; name = $config.name; status = 'Missing'; message = "Computer source is absent: $($location.target)" }) + $missingMessage = if ($config.name -eq 'mpc-hc-settings' -and $config.mode -eq 'registry') { + 'MPC-HC has no registry settings to capture. Launch MPC-HC, save its settings in Windows registry mode, close both MPC-HC versions, then rerun cc capture.' + } else { "Computer source is absent: $($location.target)" } + $operations.Add([pscustomobject]@{ kind = 'config'; name = $config.name; status = 'Missing'; message = $missingMessage }) continue } if ($config.mode -eq 'copy') { diff --git a/tests/Adapters.Tests.ps1 b/tests/Adapters.Tests.ps1 index 38fdd03..d3585dd 100644 --- a/tests/Adapters.Tests.ps1 +++ b/tests/Adapters.Tests.ps1 @@ -138,3 +138,19 @@ Describe 'MPC-HC running player protection' { } } } + +Describe 'Missing MPC-HC settings guidance' { + It 'explains first launch and retains the key-creation error' { + InModuleScope Adapters { + Mock Get-Process { $null } + Mock Test-Path { $false } + Mock New-Item { throw 'Access denied' } + Mock New-ItemProperty {} + $declaration = [pscustomobject]@{ values = @( + [pscustomobject]@{ path = ''; name = 'Volume'; type = 'DWord'; value = 80 } + ) } + { Set-RegistryDeclaration -Root 'TestRoot' -Declaration $declaration } | Should -Throw '*Launch MPC-HC once*Access denied*' + Should -Invoke New-ItemProperty -Times 0 + } + } +} diff --git a/tests/Configs.Tests.ps1 b/tests/Configs.Tests.ps1 index 8c92f3e..781bd38 100644 --- a/tests/Configs.Tests.ps1 +++ b/tests/Configs.Tests.ps1 @@ -120,6 +120,17 @@ Describe 'Configuration deployment' { $result.message | Should -Be 'Registry access denied' } + It 'explains how to initialize missing MPC-HC settings for capture' { + Mock Get-RepositoryRevision { 'abc123' } -ModuleName Configs + Mock Get-ConfigLocations { + [pscustomobject]@{ name = 'mpc-hc-settings'; targetExists = $false; target = 'HKCU:\Software\MPC-HC\MPC-HC' } + } -ModuleName Configs + $config = [pscustomobject]@{ name = 'mpc-hc-settings'; mode = 'registry' } + $result = Export-ConfigCapture -Configs @($config) -RepositoryRoot $repo -Settings $settings -Machine test -OutputPath (Join-Path $caseRoot 'missing-capture') + $result.operations[0].status | Should -Be 'Missing' + $result.operations[0].message | Should -Match 'Launch MPC-HC.*close both MPC-HC versions' + } + It 'refuses unsafe automatic restoration of registry and hosts backups' { $registryState = @{ configs = @{ 'mpc-hc-settings' = @{ mode = 'registry'; target = 'HKCU:\Software\MPC-HC\MPC-HC' } } } { Restore-ConfigBackup -Name mpc-hc-settings -Paths $paths -State $registryState } | Should -Throw '*not supported for registry*' diff --git a/tools/Export-MpcHcSettings.ps1 b/tools/Export-MpcHcSettings.ps1 index aad87fb..47bdcda 100644 --- a/tools/Export-MpcHcSettings.ps1 +++ b/tools/Export-MpcHcSettings.ps1 @@ -33,7 +33,7 @@ Set-StrictMode -Version Latest $ErrorActionPreference = 'Stop' $rootPath = 'HKCU:\Software\MPC-HC\MPC-HC' -if (-not (Test-Path -LiteralPath $rootPath)) { throw "MPC-HC registry settings were not found at '$rootPath'. Start MPC-HC and save its settings first." } +if (-not (Test-Path -LiteralPath $rootPath)) { throw "MPC-HC registry settings were not found at '$rootPath'. Launch MPC-HC, save its settings in Windows registry mode, close both MPC-HC versions, then retry capture." } function Test-PrivateMpcHcSetting { param([string]$RelativePath, [string]$Name, $Value)