fix(desktop): normalize uninstall targets and report registry read failures

This commit is contained in:
winewill committed 2026-11-18 16:12:40 +08:00
1 parent 2a840de9d0
commit b2f8b99d21
3 files changed
+40 -16

No files matched your search

+2 -14
View File
@@ -144,17 +144,6 @@ FunctionEnd
!define /ifndef DSH_COMMAND_OWNER_KEY "Software\DeepSeekHarness\Command"
!define /ifndef DSH_PROTOCOL_KEY "Software\Classes\dsh"
!define /ifndef DSH_COMMAND_MUTEX "default"
!macro unRemoveOwnedUninstallEntry KEY
ReadRegStr $0 SHELL_CONTEXT "${KEY}" UninstallString
${If} $0 == '"$INSTDIR\${UNINSTALL_FILENAME}" /currentuser'
ClearErrors
DeleteRegKey SHELL_CONTEXT "${KEY}"
${If} ${Errors}
System::Call '$PLUGINSDIR\window-frame.dll::UninstallNote(p $UnSession, w "[unverified] Delete uninstall entry: ${KEY}") ?c'
${EndIf}
${EndIf}
!macroend
Function un.CleanRegistration
${If} ${isUpdated}
Return
@@ -173,11 +162,10 @@ Function un.CleanRegistration
Delete "$PLUGINSDIR\unowned-path"
StrCpy $UnRegistrationArguments ""
${If} $UnDirectoryOnly == 1
!insertmacro unRemoveOwnedUninstallEntry "${UNINSTALL_REGISTRY_KEY}"
StrCpy $UnRegistrationArguments '-DesktopLink "$oldDesktopLink" -StartMenuLink "$oldStartMenuLink" -UninstallKey "${UNINSTALL_REGISTRY_KEY}" -UninstallerName "${UNINSTALL_FILENAME}"'
!ifdef UNINSTALL_REGISTRY_KEY_2
!insertmacro unRemoveOwnedUninstallEntry "${UNINSTALL_REGISTRY_KEY_2}"
StrCpy $UnRegistrationArguments '$UnRegistrationArguments -LegacyUninstallKey "${UNINSTALL_REGISTRY_KEY_2}"'
!endif
StrCpy $UnRegistrationArguments '-DesktopLink "$oldDesktopLink" -StartMenuLink "$oldStartMenuLink"'
${EndIf}
Call un.RunRegistrationCleanup
IfFileExists "$PLUGINSDIR\unowned-path" 0 +2
@@ -9,7 +9,10 @@ param([Parameter(Mandatory)][string]$Directory,
[switch]$UnownedOnly,
[string]$UnownedMarker,
[string]$DesktopLink,
[string]$StartMenuLink)
[string]$StartMenuLink,
[string]$UninstallKey,
[string]$LegacyUninstallKey,
[string]$UninstallerName)
$ErrorActionPreference = 'Stop'
. (Join-Path $PSScriptRoot 'command-path.ps1')
$failures = [Collections.Generic.List[string]]::new()
@@ -46,6 +49,26 @@ if (-not $UnownedOnly) { try {
} catch {
$failures.Add("[unverified] Remove protocol registration`r`nHKCU\$ProtocolKey`r`nCode: $($_.Exception.HResult)`r`nReason: $($_.Exception.Message)")
} }
foreach ($uninstallEntry in @($UninstallKey, $LegacyUninstallKey)) {
if (-not $uninstallEntry) { continue }
try {
$key = [Microsoft.Win32.Registry]::CurrentUser.OpenSubKey($uninstallEntry)
try { $registered = if ($key) { $key.GetValue('UninstallString') } else { $null } }
finally { if ($key) { $key.Dispose() } }
if ($null -eq $registered) { continue }
if ($registered -isnot [string]) { throw 'UninstallString is not a string' }
# Only the command emitted by the per-user installer is eligible for removal.
if ($registered -match '^\s*"([^"]+)"\s+/currentuser\s*$') {
$target = [IO.Path]::GetFullPath($Matches[1])
$expected = [IO.Path]::GetFullPath((Join-Path $Directory $UninstallerName))
if ($target -eq $expected) {
[Microsoft.Win32.Registry]::CurrentUser.DeleteSubKeyTree($uninstallEntry, $false)
}
}
} catch {
$failures.Add("[unverified] Inspect or remove uninstall entry`r`nHKCU\$uninstallEntry [UninstallString]`r`nCode: $($_.Exception.HResult)`r`nReason: $($_.Exception.Message)")
}
}
foreach ($link in @($DesktopLink, $StartMenuLink)) {
if (-not $link) { continue }
try {
+14 -1
View File
@@ -75,8 +75,15 @@ try {
$foreign = $mode -eq 'missing-location-foreign'
if ($missingLocation) { Remove-ItemProperty -LiteralPath ('HKCU:\Software\' + $RegistryKey) -Name InstallLocation }
$arpKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\' + $RegistryKey
if ($mode -eq 'missing-location') {
$originalCommand = (Get-ItemProperty $arpKey).UninstallString
$alternateCommand = $originalCommand.Replace($installPath + '\', $installPath + '\.\')
Set-ItemProperty $arpKey UninstallString $alternateCommand
}
$desktopLink = Join-Path ([Environment]::GetFolderPath('DesktopDirectory')) ($ProductName + '.lnk')
$startLink = Join-Path ([Environment]::GetFolderPath('Programs')) ($ProductName + '.lnk')
if ($missingLocation) {
if (-not (Test-Path -LiteralPath $startLink) -or (New-Object -ComObject WScript.Shell).CreateShortcut($startLink).TargetPath -ne (Join-Path $installPath ($ProductName + '.exe'))) { throw 'Missing A Start menu fixture' }
$shortcut = (New-Object -ComObject WScript.Shell).CreateShortcut($desktopLink)
$shortcut.TargetPath = Join-Path $installPath ($ProductName + '.exe')
$shortcut.Save()
@@ -218,7 +225,7 @@ try {
if ($mode -notin @('registration-error', 'save-report') -and ($path.Contains($commandDirectory) -ne $pathRetained -or -not $path.Contains('C:\Windows'))) { throw "PATH cleanup failed: $mode" }
if ($mode -eq 'owned-retained' -and $path -ne ($commandDirectory + ';C:\Windows')) { throw 'Owned cleanup removed a pre-existing manual PATH entry' }
if ((Test-Path -LiteralPath ('HKCU:\' + $protocolKey)) -ne ($foreign -or $mode -eq 'upgrade')) { throw "Protocol cleanup failed: $mode" }
if ($missingLocation -and ((Test-Path -LiteralPath $desktopLink) -or (Test-Path -LiteralPath $arpKey))) { throw 'Missing location left an A shortcut or uninstall entry' }
if ($missingLocation -and ((Test-Path -LiteralPath $desktopLink) -or (Test-Path -LiteralPath $startLink) -or (Test-Path -LiteralPath $arpKey))) { throw 'Missing location left an A shortcut or uninstall entry' }
Write-Output "passed: $mode"
}
# Real replacement publishes B after the old A uninstaller has been retained.
@@ -303,6 +310,12 @@ try {
if ($registeredExe -ne (Join-Path $newPath ('Uninstall ' + $ProductName + '.exe'))) { throw 'B uninstall entry targets another installation' }
$process = Start-Process $registeredExe -ArgumentList ($registeredArgs + ' /S') -PassThru -WindowStyle Hidden
Wait-Exit
foreach ($key in @($arpKey, ('HKCU:\Software\' + $RegistryKey), ('HKCU:\' + $protocolKey))) {
if (Test-Path -LiteralPath $key) { throw "B uninstall retained registration: $key" }
}
foreach ($link in $replacementLinks.Keys) {
if (Test-Path -LiteralPath $link) { throw "B uninstall retained shortcut: $link" }
}
Write-Output 'passed: installation takeover'
} finally {
if ($held) { $held.Dispose() }