Files
YouTubeDL/tests/test-native-registration.ps1
T
DepressedCat 5f2aad00f4
Check extension and helper / check (push) Canceled after 0s
Publish YouTubeDL 1.4.5 and website on Gitea
2026-10-10 23:53:17 +03:00

23 lines
1.1 KiB
PowerShell

param(
[Parameter(Mandatory=$true)][string]$Name,
[Parameter(Mandatory=$true)][string]$ManifestPath,
[switch]$Remove
)
$ErrorActionPreference = 'Stop'
if ($Name -notmatch '^com\.youtubedl\.test_[a-f0-9]{16}$') { throw 'Only isolated test hosts are allowed.' }
$taskManifest = [IO.Path]::GetFullPath($ManifestPath)
$taskKey = "Registry::HKEY_CURRENT_USER\Software\Microsoft\Edge\NativeMessagingHosts\$Name"
if (Test-Path -LiteralPath $taskKey) {
$taskRegistered = (Get-Item -LiteralPath $taskKey).GetValue('')
if ($taskRegistered -and $taskRegistered -ne $taskManifest) { throw 'Test registration belongs to another path.' }
}
if ($Remove) {
if (Test-Path -LiteralPath $taskKey) { Remove-Item -LiteralPath $taskKey }
} else {
$taskData = Get-Content -LiteralPath $taskManifest -Raw | ConvertFrom-Json
if ($taskData.name -ne $Name) { throw 'Wrong test host manifest.' }
New-Item -Path $taskKey -Force | Out-Null
Set-Item -LiteralPath $taskKey -Value $taskManifest
if ((Get-Item -LiteralPath $taskKey).GetValue('') -ne $taskManifest) { throw 'Test registration was not written.' }
}