Skip to content

Commit

Permalink
MP1-5185: DeployTool: Fix incorrect uninstall registry key deleting
Browse files Browse the repository at this point in the history
  • Loading branch information
epbk committed Jan 14, 2024
1 parent de3b580 commit afa0e54
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Tools/MediaPortal.DeployTool/Sections/UpgradeDlg.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public override void UpdateUI()
string MpBuild = "0";
string MpDisplayVer = string.Empty;

RegistryKey key = Utils.GetUninstallKey("MediaPortal", false);
RegistryKey key = Utils.GetUninstallKey("MediaPortal", false, false);
if (key != null)
{
MpBuild = key.GetValue("VersionBuild").ToString();
Expand All @@ -96,7 +96,7 @@ public override void UpdateUI()
string Tv3Build = "0";
string Tv3DisplayVer = string.Empty;

key = Utils.GetUninstallKey("MediaPortal TV Server", false);
key = Utils.GetUninstallKey("MediaPortal TV Server", false, false);
if (key != null)
{
Tv3Build = key.GetValue("VersionBuild").ToString();
Expand Down
28 changes: 17 additions & 11 deletions Tools/MediaPortal.DeployTool/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -395,21 +395,21 @@ public static void UninstallMSI(string clsid)
CheckUninstallString(clsid, true);
}

public static RegistryKey GetUninstallKey(string clsid, bool bIncludeWow6432 = true)
public static RegistryKey GetUninstallKey(string clsid, bool writable, bool bIncludeWow6432)
{
return LMOpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + clsid, bIncludeWow6432: bIncludeWow6432);
return LMOpenSubKey("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + clsid, writable, bIncludeWow6432);
}

public static string CheckUninstallString(string clsid, string section, bool bIncludeWow6432 = true)
{
RegistryKey key = GetUninstallKey(clsid, bIncludeWow6432);
RegistryKey key = GetUninstallKey(clsid, false, bIncludeWow6432);
if (key != null)
{
string strSection = key.GetValue(section).ToString();
if (!string.IsNullOrEmpty(strSection))
object value = key.GetValue(section, string.Empty);
if (value is string && !string.IsNullOrEmpty((string)value))
{
key.Close();
return strSection;
return (string)value;
}
key.Close();
}
Expand All @@ -429,11 +429,17 @@ public static string CheckUninstallString(string clsid, bool delete, bool bInclu

if (delete)
{
RegistryKey key = GetUninstallKey(clsid, bIncludeWow6432);
if (key != null)
// SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\
RegistryKey keyUninstall = GetUninstallKey(null, true, bIncludeWow6432);
if (keyUninstall != null)
{
key.DeleteSubKeyTree("SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall\\" + clsid);
key.Close();
RegistryKey keyCLSID = keyUninstall.OpenSubKey(clsid);
if (keyCLSID != null)
{
keyUninstall.DeleteSubKeyTree(clsid);
keyCLSID.Close();
}
keyUninstall.Close();
}
}
return null;
Expand All @@ -446,7 +452,7 @@ public static CheckResult CheckNSISUninstallString(string RegistryPath, string M
state = CheckState.NOT_INSTALLED
};

RegistryKey key = GetUninstallKey(RegistryPath, false);
RegistryKey key = GetUninstallKey(RegistryPath, false, false);
if (key != null)
{
int _IsInstalled = (int)key.GetValue(MementoSection, 0);
Expand Down

0 comments on commit afa0e54

Please sign in to comment.