From 110f09dac221ade3c679c3ceda1160429c6a128a Mon Sep 17 00:00:00 2001 From: Dandaedre Date: Sat, 21 Nov 2026 12:53:51 +0100 Subject: [PATCH] Remove legacy PDF Presenter registration --- README.md | 7 ++--- TASKS.md | 1 + docs/advanced_commands.md | 3 ++- docs/manifest-contract.md | 3 +++ profiles/desktop-apps.json | 6 ++++- schemas/profile.schema.json | 22 ++++++++++++++++ src/Manifest.psm1 | 14 +++++++++- src/PortablePackages.psm1 | 45 +++++++++++++++++++++++++++++++- tests/PortableManifest.Tests.ps1 | 9 ++++++- tests/PortablePackages.Tests.ps1 | 33 +++++++++++++++++++++++ tests/Schema.Tests.ps1 | 8 +++++- 11 files changed, 142 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index b00daf1..21e4b46 100644 --- a/README.md +++ b/README.md @@ -105,9 +105,10 @@ user confirmation and Config Central preserves that choice across updates. The first Deckstride update installs and verifies [Deckstride 0.1.96](https://proxy.dandaedre.com/gitea/idle-org/Deckstride/releases/tag/v0.1.96) before removing the managed PDF Presenter files, Start menu shortcut and old -handler registration. The desktop policy declares Pympress absent, so Config -Central uninstalls it by its exact WinGet ID when found and treats an already -removed copy as unchanged. +handler registration. Cleanup also removes PDF Presenter's obsolete Default Apps +and **Open with** registry entries. The desktop policy declares Pympress absent, +so Config Central uninstalls it by its exact WinGet ID when found and treats an +already removed copy as unchanged. Like `cc sync`, `update-software` refuses to fetch while the checkout contains uncommitted or untracked files. It does not reset or overwrite those edits. diff --git a/TASKS.md b/TASKS.md index bd4fbae..197c82d 100644 --- a/TASKS.md +++ b/TASKS.md @@ -166,6 +166,7 @@ open until it is run on disposable machines with the required account setups. - [x] Give PDF Presenter associations a dedicated branded PDF document icon that remains stable across portable updates (169 Linux Pester tests pass; 5 Windows-only skips). - [x] Support explicit portable rename migrations that activate the successor before removing the verified old installation and handler registration, preserve local edits, and retry cleanup (189 Linux Pester tests pass; 5 Windows-only skips). - [x] Replace the PDF Presenter declaration with verified Deckstride 0.1.96 from `idle-org/Deckstride`; keep the one-time Windows `.pdf` default selection in the Windows acceptance task (192 Linux Pester tests pass; 5 Windows-only skips). +- [x] Remove PDF Presenter's legacy self-registered Default Apps and Open With entries during the Deckstride migration. ## PowerShell prerequisite reliability diff --git a/docs/advanced_commands.md b/docs/advanced_commands.md index 33b5ba1..3370c25 100644 --- a/docs/advanced_commands.md +++ b/docs/advanced_commands.md @@ -408,7 +408,8 @@ rewriting the user's default-app preference. Deckstride's declaration includes a `replaces` entry for `idle-org/pdf-presenter`. On the first successful update, Config Central activates Deckstride before removing PDF Presenter's managed files, shortcut and -old `.pdf` registration. If the old installation was locally modified or cannot +old `.pdf` registration, including PDF Presenter's own obsolete Default Apps and +Open With ProgID entries. If the old installation was locally modified or cannot be removed, Deckstride stays installed and cleanup is retried later. Select Deckstride once in Windows Default Apps because Windows does not allow software to transfer the protected `.pdf` default choice to a renamed handler. diff --git a/docs/manifest-contract.md b/docs/manifest-contract.md index b90e312..a54f1d8 100644 --- a/docs/manifest-contract.md +++ b/docs/manifest-contract.md @@ -125,6 +125,9 @@ in the package root instead of pointing Explorer at a versioned executable icon. A renamed portable package may declare `replaces` with the old lowercase `source` and `id`, plus any old `fileAssociations` that must be unregistered. +When the predecessor registered itself separately, `legacyRegistration` names +its Registered Applications value and ProgIDs so Config Central can also remove +those obsolete Default Apps and Open With entries. This is an explicit removal request. Config Central activates and verifies the new package first, then removes the old managed root, Start menu shortcut, Default Apps registration and listed ProgIDs. Missing or locally modified files diff --git a/profiles/desktop-apps.json b/profiles/desktop-apps.json index 895e133..c552c6c 100644 --- a/profiles/desktop-apps.json +++ b/profiles/desktop-apps.json @@ -26,7 +26,11 @@ { "source": "idle-org", "id": "pdf-presenter", - "fileAssociations": [".pdf"] + "fileAssociations": [".pdf"], + "legacyRegistration": { + "registeredApplication": "PDF Presenter", + "progIds": ["PDFPresenter.Document"] + } } ] }, diff --git a/schemas/profile.schema.json b/schemas/profile.schema.json index f3d2879..80fe965 100644 --- a/schemas/profile.schema.json +++ b/schemas/profile.schema.json @@ -167,6 +167,28 @@ "type": "string", "pattern": "^\\.[a-z0-9]{1,16}$" } + }, + "legacyRegistration": { + "type": "object", + "additionalProperties": false, + "required": ["registeredApplication", "progIds"], + "properties": { + "registeredApplication": { + "type": "string", + "minLength": 1, + "maxLength": 64, + "pattern": "^[^\\x00-\\x1f\\\\/]+$" + }, + "progIds": { + "type": "array", + "minItems": 1, + "uniqueItems": true, + "items": { + "type": "string", + "pattern": "^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$" + } + } + } } } } diff --git a/src/Manifest.psm1 b/src/Manifest.psm1 index 605520b..b5a2661 100644 --- a/src/Manifest.psm1 +++ b/src/Manifest.psm1 @@ -84,7 +84,7 @@ function Assert-PortableDeclaration { if ($replacementProperty.Value -isnot [Array] -or $replacementProperty.Value.Count -eq 0) { throw 'Portable replaces must be a non-empty array.' } $seenReplacements = [Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase) foreach ($replacement in @($replacementProperty.Value)) { - Assert-AllowedProperties $replacement @('source', 'id', 'fileAssociations') 'portable replacement' + Assert-AllowedProperties $replacement @('source', 'id', 'fileAssociations', 'legacyRegistration') 'portable replacement' $replacementSource = [string](Get-OptionalProperty $replacement 'source') $replacementId = [string](Get-OptionalProperty $replacement 'id') if ($replacementSource -cnotmatch '^[a-z0-9][a-z0-9-]{0,63}$' -or $replacementId -cnotmatch '^[a-z0-9][a-z0-9-]{0,63}$') { throw 'Portable replacement source and id must be lowercase slugs.' } @@ -98,6 +98,18 @@ function Assert-PortableDeclaration { foreach ($extension in @($replacementAssociations)) { if ($extension -cnotmatch '^\.[a-z0-9]{1,16}$' -or -not $seenExtensions.Add($extension)) { throw "Invalid or duplicate portable replacement file association '$extension'." } } + $legacyRegistration = $replacement.PSObject.Properties['legacyRegistration'] + if ($null -ne $legacyRegistration) { + Assert-AllowedProperties $legacyRegistration.Value @('registeredApplication', 'progIds') 'portable replacement legacyRegistration' + $registeredApplication = [string](Get-OptionalProperty $legacyRegistration.Value 'registeredApplication') + if ([string]::IsNullOrWhiteSpace($registeredApplication) -or $registeredApplication.Length -gt 64 -or $registeredApplication -match '[\x00-\x1f\\/]') { throw 'Portable replacement registeredApplication is unsafe.' } + $progIdProperty = $legacyRegistration.Value.PSObject.Properties['progIds'] + if ($null -eq $progIdProperty -or $progIdProperty.Value -isnot [Array] -or $progIdProperty.Value.Count -eq 0) { throw 'Portable replacement legacyRegistration progIds must be a non-empty array.' } + $seenProgIds = [Collections.Generic.HashSet[string]]::new([StringComparer]::OrdinalIgnoreCase) + foreach ($progId in @($progIdProperty.Value)) { + if ($progId -cnotmatch '^[A-Za-z0-9][A-Za-z0-9._-]{0,127}$' -or -not $seenProgIds.Add($progId)) { throw "Invalid or duplicate portable replacement ProgID '$progId'." } + } + } } } diff --git a/src/PortablePackages.psm1 b/src/PortablePackages.psm1 index bd3219a..4f36686 100644 --- a/src/PortablePackages.psm1 +++ b/src/PortablePackages.psm1 @@ -114,6 +114,14 @@ function Remove-PortableRegistryTree { [Microsoft.Win32.Registry]::CurrentUser.DeleteSubKeyTree($Path, $false) } +function Test-PortableRegistryTree { + param([Parameter(Mandatory)][string]$Path) + $key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($Path, $false) + if ($null -eq $key) { return $false } + $key.Dispose() + return $true +} + function Test-PortableFileAssociations { param($Package, [Parameter(Mandatory)][string]$Executable, [string]$Icon) $specs = @(Get-PortableAssociationSpec -Package $Package -Executable $Executable -Icon $Icon) @@ -159,6 +167,40 @@ function Remove-PortableFileAssociations { Remove-PortableRegistryTree -Path "Software\Classes\$progId" } Remove-PortableRegistryTree -Path $capabilitiesPath + if ($Replacement.PSObject.Properties['legacyRegistration']) { + Remove-PortableLegacyRegistration -Replacement $Replacement + } +} + +function Remove-PortableLegacyRegistration { + param($Replacement) + $legacy = $Replacement.legacyRegistration + $registeredApplication = [string]$legacy.registeredApplication + $extensions = if ($Replacement.PSObject.Properties['fileAssociations']) { @($Replacement.fileAssociations) } else { @() } + Remove-PortableRegistryValue -Path 'Software\RegisteredApplications' -Name $registeredApplication + foreach ($progId in @($legacy.progIds)) { + foreach ($extension in $extensions) { + Remove-PortableRegistryValue -Path "Software\Classes\$($extension.ToLowerInvariant())\OpenWithProgids" -Name $progId + } + Remove-PortableRegistryTree -Path "Software\Classes\$progId" + } + Remove-PortableRegistryTree -Path "Software\$registeredApplication\Capabilities" +} + +function Test-PortableLegacyRegistrationPresent { + param($Replacement) + if (-not $Replacement.PSObject.Properties['legacyRegistration']) { return $false } + $legacy = $Replacement.legacyRegistration + if ($null -ne (Get-PortableRegistryValue -Path 'Software\RegisteredApplications' -Name ([string]$legacy.registeredApplication))) { return $true } + if (Test-PortableRegistryTree -Path "Software\$($legacy.registeredApplication)\Capabilities") { return $true } + $extensions = if ($Replacement.PSObject.Properties['fileAssociations']) { @($Replacement.fileAssociations) } else { @() } + foreach ($progId in @($legacy.progIds)) { + if (Test-PortableRegistryTree -Path "Software\Classes\$progId") { return $true } + foreach ($extension in $extensions) { + if ($null -ne (Get-PortableRegistryValue -Path "Software\Classes\$($extension.ToLowerInvariant())\OpenWithProgids" -Name $progId)) { return $true } + } + } + return $false } function Test-PortableReplacementPresent { @@ -167,7 +209,8 @@ function Test-PortableReplacementPresent { if ((Test-Path -LiteralPath $paths.Root) -or ($paths.Shortcut -and (Test-Path -LiteralPath $paths.Shortcut))) { return $true } if (-not $IsWindows) { return $false } $registeredName = "ConfigCentral.$($Replacement.source).$($Replacement.id)" - return $null -ne (Get-PortableRegistryValue -Path 'Software\RegisteredApplications' -Name $registeredName) + return $null -ne (Get-PortableRegistryValue -Path 'Software\RegisteredApplications' -Name $registeredName) -or + (Test-PortableLegacyRegistrationPresent -Replacement $Replacement) } function Assert-PortableManagedReplacement { diff --git a/tests/PortableManifest.Tests.ps1 b/tests/PortableManifest.Tests.ps1 index 9a5a1a3..a3a255b 100644 --- a/tests/PortableManifest.Tests.ps1 +++ b/tests/PortableManifest.Tests.ps1 @@ -58,7 +58,10 @@ Describe 'Portable declarations' { It 'accepts and preserves an explicit portable replacement declaration' { $item | Add-Member -NotePropertyName replaces -NotePropertyValue ([object[]]@( - [pscustomobject]@{ source = 'idle-org'; id = 'pdf-presenter'; fileAssociations = [object[]]@('.pdf') } + [pscustomobject]@{ + source = 'idle-org'; id = 'pdf-presenter'; fileAssociations = [object[]]@('.pdf') + legacyRegistration = [pscustomobject]@{ registeredApplication = 'PDF Presenter'; progIds = [object[]]@('PDFPresenter.Document') } + } )) Assert-ItemList @($item) package test $items = [ordered]@{} @@ -67,6 +70,8 @@ Describe 'Portable declarations' { $replacement.source | Should -Be 'idle-org' $replacement.id | Should -Be 'pdf-presenter' $replacement.fileAssociations | Should -Be @('.pdf') + $replacement.legacyRegistration.registeredApplication | Should -Be 'PDF Presenter' + $replacement.legacyRegistration.progIds | Should -Be @('PDFPresenter.Document') } It 'accepts explicit WinGet absence and rejects it for portable packages' { @@ -85,6 +90,8 @@ Describe 'Portable declarations' { @{ Replacements = @([pscustomobject]@{ source = 'gitea'; id = 'presenter' }) } @{ Replacements = @([pscustomobject]@{ source = 'old'; id = 'app' }, [pscustomobject]@{ source = 'OLD'; id = 'app' }) } @{ Replacements = @([pscustomobject]@{ source = 'old'; id = 'app'; fileAssociations = @('pdf') }) } + @{ Replacements = @([pscustomobject]@{ source = 'old'; id = 'app'; legacyRegistration = [pscustomobject]@{ registeredApplication = 'Old/App'; progIds = @('Old.App') } }) } + @{ Replacements = @([pscustomobject]@{ source = 'old'; id = 'app'; legacyRegistration = [pscustomobject]@{ registeredApplication = 'Old App'; progIds = @('bad progid') } }) } @{ Replacements = @([pscustomobject]@{ source = 'old'; id = 'app'; unknown = 'value' }) } ) { $item | Add-Member replaces $Replacements diff --git a/tests/PortablePackages.Tests.ps1 b/tests/PortablePackages.Tests.ps1 index 2f12505..467e36f 100644 --- a/tests/PortablePackages.Tests.ps1 +++ b/tests/PortablePackages.Tests.ps1 @@ -321,6 +321,39 @@ Describe 'Portable file association registration' { $Path -like '*\DefaultIcon' -and $Name -eq '' -and $Value -eq ($icon + ',0') } } + It 'removes a predecessor application own PDF registration' { + $replacement = [pscustomobject]@{ + source = 'idle-org'; id = 'pdf-presenter'; fileAssociations = @('.pdf') + legacyRegistration = [pscustomobject]@{ registeredApplication = 'PDF Presenter'; progIds = @('PDFPresenter.Document') } + } + Mock Remove-PortableRegistryValue {} + Mock Remove-PortableRegistryTree {} + Remove-PortableLegacyRegistration -Replacement $replacement + Should -Invoke Remove-PortableRegistryValue -Times 1 -Exactly -ParameterFilter { + $Path -eq 'Software\RegisteredApplications' -and $Name -eq 'PDF Presenter' + } + Should -Invoke Remove-PortableRegistryValue -Times 1 -Exactly -ParameterFilter { + $Path -eq 'Software\Classes\.pdf\OpenWithProgids' -and $Name -eq 'PDFPresenter.Document' + } + Should -Invoke Remove-PortableRegistryTree -Times 1 -Exactly -ParameterFilter { + $Path -eq 'Software\Classes\PDFPresenter.Document' + } + Should -Invoke Remove-PortableRegistryTree -Times 1 -Exactly -ParameterFilter { + $Path -eq 'Software\PDF Presenter\Capabilities' + } + } + It 'detects a predecessor registration after managed files are gone' { + $replacement = [pscustomobject]@{ + source = 'idle-org'; id = 'pdf-presenter'; fileAssociations = @('.pdf') + legacyRegistration = [pscustomobject]@{ registeredApplication = 'PDF Presenter'; progIds = @('PDFPresenter.Document') } + } + Mock Get-PortableRegistryValue { + if ($Path -eq 'Software\Classes\.pdf\OpenWithProgids' -and $Name -eq 'PDFPresenter.Document') { return '' } + return $null + } + Mock Test-PortableRegistryTree { $false } + Test-PortableLegacyRegistrationPresent -Replacement $replacement | Should -BeTrue + } } } diff --git a/tests/Schema.Tests.ps1 b/tests/Schema.Tests.ps1 index 48a3f58..eb5509f 100644 --- a/tests/Schema.Tests.ps1 +++ b/tests/Schema.Tests.ps1 @@ -35,13 +35,19 @@ Describe 'Published manifest schemas' { $package = [ordered]@{ id = 'deckstride'; provider = 'portable'; source = 'idle-org'; version = '1.0'; update = 'pinned' url = 'https://example.org/deckstride.zip'; executable = 'deckstride.exe'; sha256 = 'a' * 64 - replaces = @([ordered]@{ source = 'idle-org'; id = 'pdf-presenter'; fileAssociations = @('.pdf') }) + replaces = @([ordered]@{ + source = 'idle-org'; id = 'pdf-presenter'; fileAssociations = @('.pdf') + legacyRegistration = [ordered]@{ registeredApplication = 'PDF Presenter'; progIds = @('PDFPresenter.Document') } + }) } $profile = [ordered]@{ schemaVersion = 1; name = 'test'; packages = @($package) } $profile | ConvertTo-Json -Depth 8 | Test-Json -SchemaFile $schema | Should -BeTrue $package.replaces[0].fileAssociations = @('pdf') $profile | ConvertTo-Json -Depth 8 | Test-Json -SchemaFile $schema -ErrorAction SilentlyContinue | Should -BeFalse $package.replaces[0].fileAssociations = @('.pdf') + $package.replaces[0].legacyRegistration.progIds = @('bad progid') + $profile | ConvertTo-Json -Depth 8 | Test-Json -SchemaFile $schema -ErrorAction SilentlyContinue | Should -BeFalse + $package.replaces[0].legacyRegistration.progIds = @('PDFPresenter.Document') $package.replaces[0].unknown = 'value' $profile | ConvertTo-Json -Depth 8 | Test-Json -SchemaFile $schema -ErrorAction SilentlyContinue | Should -BeFalse }