Exclude private MPC-HC export values
This commit is contained in:
parent
9efbf7cd30
commit
dd2bb7a4b7
|
|
@ -0,0 +1,25 @@
|
|||
BeforeAll {
|
||||
$script:exporterPath = "$PSScriptRoot/../tools/Export-MpcHcSettings.ps1"
|
||||
$tokens = $null
|
||||
$errors = $null
|
||||
$ast = [System.Management.Automation.Language.Parser]::ParseFile($exporterPath, [ref]$tokens, [ref]$errors)
|
||||
if ($errors.Count -gt 0) { throw "MPC-HC exporter does not parse: $($errors[0].Message)" }
|
||||
$functionAst = $ast.Find({
|
||||
param($node)
|
||||
$node -is [System.Management.Automation.Language.FunctionDefinitionAst] -and $node.Name -eq 'Test-PrivateMpcHcSetting'
|
||||
}, $true)
|
||||
. ([scriptblock]::Create($functionAst.Extent.Text))
|
||||
}
|
||||
|
||||
Describe 'MPC-HC export filtering' {
|
||||
It 'excludes history, device identities, paths, and URLs' {
|
||||
Test-PrivateMpcHcSetting -RelativePath 'PlaylistHistory\item' -Name Position -Value 42 | Should -BeTrue
|
||||
Test-PrivateMpcHcSetting -RelativePath Settings -Name AudioDevice -Value speakers | Should -BeTrue
|
||||
Test-PrivateMpcHcSetting -RelativePath Settings -Name Logo -Value 'C:\Users\Alice\logo.png' | Should -BeTrue
|
||||
Test-PrivateMpcHcSetting -RelativePath Settings -Name Server -Value 'https://example.test' | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'keeps ordinary portable playback settings' {
|
||||
Test-PrivateMpcHcSetting -RelativePath Settings -Name Volume -Value 80 | Should -BeFalse
|
||||
}
|
||||
}
|
||||
|
|
@ -10,20 +10,25 @@ $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." }
|
||||
|
||||
function Test-PrivateMpcHcSetting {
|
||||
param([string]$RelativePath, [string]$Name, $Value)
|
||||
if ($RelativePath -match '(?i)(^|\\)(MediaHistory|PlaylistHistory|Recent File List|Favorites)(\\|$)') { return $true }
|
||||
if ($Name -match '(?i)(path|directory|folder|filename|recent|url|device|monitor|history|guid|uuid|^last)') { return $true }
|
||||
$text = if ($Value -is [Array]) { @($Value) -join ' ' } else { [string]$Value }
|
||||
return $text -match '(?i)([a-z]:[\\/]|https?://|@device:|^\\\\)'
|
||||
}
|
||||
|
||||
$root = Get-Item -LiteralPath $rootPath
|
||||
$excludedSubkeys = '(?i)(^|\\)(MediaHistory|Recent File List|Favorites)(\\|$)'
|
||||
$excludedValues = '(?i)(path|directory|folder|filename|lastopen|lastused|recent|url)'
|
||||
$values = [Collections.Generic.List[object]]::new()
|
||||
|
||||
foreach ($key in @($root) + @(Get-ChildItem -LiteralPath $rootPath -Recurse)) {
|
||||
$relativePath = $key.Name.Substring($root.Name.Length).TrimStart('\')
|
||||
if (-not $IncludePrivateValues -and $relativePath -match $excludedSubkeys) { continue }
|
||||
foreach ($name in $key.GetValueNames()) {
|
||||
if ([string]::IsNullOrWhiteSpace($name)) { continue }
|
||||
if (-not $IncludePrivateValues -and $name -match $excludedValues) { continue }
|
||||
$kind = [string]$key.GetValueKind($name)
|
||||
if ($kind -notin @('String', 'ExpandString', 'DWord', 'QWord', 'MultiString', 'Binary')) { continue }
|
||||
$raw = $key.GetValue($name, $null, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
|
||||
if (-not $IncludePrivateValues -and (Test-PrivateMpcHcSetting -RelativePath $relativePath -Name $name -Value $raw)) { continue }
|
||||
$value = switch ($kind) {
|
||||
'Binary' { @([byte[]]$raw) }
|
||||
'MultiString' { @([string[]]$raw) }
|
||||
|
|
|
|||
Loading…
Reference in New Issue