Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions dotnet/src/Devolutions.Pinget.Core.Tests/CoreTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2203,6 +2203,16 @@ public void RegistryEntryMatchesInstalledPackage_UsesLocalIdentityInsteadOfCorre
Assert.False(InstallerDispatch.RegistryEntryMatchesInstalledPackage("ShareX.ShareX", "ShareX.ShareX", null, installed));
}

[Theory]
[InlineData(null, false)]
[InlineData(0, false)]
[InlineData(1, true)]
public void IsMsiArpEntry_RequiresWindowsInstallerDword(int? windowsInstaller, bool expected)
{
// A GUID-shaped Burn/EXE key must not be treated as an MSI ProductCode.
Assert.Equal(expected, InstallerDispatch.IsMsiArpEntry(windowsInstaller));
}

[Fact]
public void CorrelateInstalledPackage_TiebreaksOnUnnormalizedNamePrefix()
{
Expand Down
13 changes: 11 additions & 2 deletions dotnet/src/Devolutions.Pinget.Core/InstallerDispatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ private static bool TryUninstallArp(ListMatch installed, UninstallRequest reques
if (!RegistryEntryMatchesInstalledPackage(subkeyName, displayName, productCode, installed))
continue;

if (TryRunMsiUninstall(installed, subkeyName, productCode, request, out exitCode))
if (IsMsiArpEntry(subkey.GetValue("WindowsInstaller")) &&
TryRunMsiUninstall(installed, subkeyName, productCode, request, out exitCode))
return true;

var quietUninstallCmd = subkey.GetValue("QuietUninstallString") as string;
Expand Down Expand Up @@ -1013,7 +1014,15 @@ internal static string BuildMsixUninstallScript(string? packageFullName, IReadOn
"$targets | Remove-AppxPackage";
}

private static bool TryRunMsiUninstall(ListMatch installed, string subkeyName, string? productCode, UninstallRequest request, out int exitCode)
internal static bool IsMsiArpEntry(object? windowsInstaller)
=> windowsInstaller is int value && value == 1;

private static bool TryRunMsiUninstall(
ListMatch installed,
string subkeyName,
string? productCode,
UninstallRequest request,
out int exitCode)
{
exitCode = 0;
var uninstallCode = installed.ProductCodes
Expand Down
18 changes: 16 additions & 2 deletions rust/crates/pinget-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9944,8 +9944,9 @@ fn try_uninstall_arp(installed: &ListMatch, request: &UninstallRequest) -> Resul
continue;
}

if let Some(exit_code) =
try_run_msi_uninstall(installed, &subkey_name, product_code.as_deref(), request)?
if is_msi_arp_entry(read_reg_dword(&subkey, "WindowsInstaller"))
&& let Some(exit_code) =
try_run_msi_uninstall(installed, &subkey_name, product_code.as_deref(), request)?
{
return Ok(Some(exit_code));
}
Expand Down Expand Up @@ -10195,6 +10196,11 @@ fn build_msix_uninstall_script(package_full_name: Option<&str>, package_family_n
)
}

#[cfg(any(windows, test))]
fn is_msi_arp_entry(windows_installer: Option<u32>) -> bool {
windows_installer == Some(1)
}

#[cfg(windows)]
fn try_run_msi_uninstall(
installed: &ListMatch,
Expand Down Expand Up @@ -15272,6 +15278,14 @@ Installers:
));
}

#[test]
fn msi_arp_dispatch_requires_windows_installer_dword() {
// A GUID-shaped Burn/EXE key must not be treated as an MSI ProductCode.
assert!(!is_msi_arp_entry(None));
assert!(!is_msi_arp_entry(Some(0)));
assert!(is_msi_arp_entry(Some(1)));
}

#[test]
#[cfg(windows)]
fn build_uninstall_command_only_appends_silent_flag_when_needed() {
Expand Down
Loading