diff options
Diffstat (limited to '')
| -rw-r--r-- | src/test/burn/WixTestTools/GenericArpRegistration.cs | 143 |
1 files changed, 143 insertions, 0 deletions
diff --git a/src/test/burn/WixTestTools/GenericArpRegistration.cs b/src/test/burn/WixTestTools/GenericArpRegistration.cs new file mode 100644 index 00000000..d87c4feb --- /dev/null +++ b/src/test/burn/WixTestTools/GenericArpRegistration.cs | |||
| @@ -0,0 +1,143 @@ | |||
| 1 | // Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. | ||
| 2 | |||
| 3 | namespace WixTestTools | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using Microsoft.Win32; | ||
| 7 | |||
| 8 | public class GenericArpRegistration | ||
| 9 | { | ||
| 10 | public const string UNINSTALL_KEY = "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; | ||
| 11 | public const string UNINSTALL_KEY_WOW6432NODE = "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; | ||
| 12 | |||
| 13 | public const string REGISTRY_ARP_INSTALLED = "Installed"; | ||
| 14 | public const string REGISTRY_ARP_DISPLAY_ICON = "DisplayIcon"; | ||
| 15 | public const string REGISTRY_ARP_DISPLAY_NAME = "DisplayName"; | ||
| 16 | public const string REGISTRY_ARP_DISPLAY_VERSION = "DisplayVersion"; | ||
| 17 | public const string REGISTRY_ARP_ESTIMATED_SIZE = "EstimatedSize"; | ||
| 18 | public const string REGISTRY_ARP_PUBLISHER = "Publisher"; | ||
| 19 | public const string REGISTRY_ARP_HELP_LINK = "HelpLink"; | ||
| 20 | public const string REGISTRY_ARP_HELP_TELEPHONE = "HelpTelephone"; | ||
| 21 | public const string REGISTRY_ARP_URL_INFO_ABOUT = "URLInfoAbout"; | ||
| 22 | public const string REGISTRY_ARP_URL_UPDATE_INFO = "URLUpdateInfo"; | ||
| 23 | public const string REGISTRY_ARP_COMMENTS = "Comments"; | ||
| 24 | public const string REGISTRY_ARP_CONTACT = "Contact"; | ||
| 25 | public const string REGISTRY_ARP_NO_MODIFY = "NoModify"; | ||
| 26 | public const string REGISTRY_ARP_MODIFY_PATH = "ModifyPath"; | ||
| 27 | public const string REGISTRY_ARP_NO_ELEVATE_ON_MODIFY = "NoElevateOnModify"; | ||
| 28 | public const string REGISTRY_ARP_NO_REMOVE = "NoRemove"; | ||
| 29 | public const string REGISTRY_ARP_SYSTEM_COMPONENT = "SystemComponent"; | ||
| 30 | public const string REGISTRY_ARP_QUIET_UNINSTALL_STRING = "QuietUninstallString"; | ||
| 31 | public const string REGISTRY_ARP_UNINSTALL_STRING = "UninstallString"; | ||
| 32 | public const string REGISTRY_ARP_VERSION_MAJOR = "VersionMajor"; | ||
| 33 | public const string REGISTRY_ARP_VERSION_MINOR = "VersionMinor"; | ||
| 34 | |||
| 35 | public RegistryKey BaseKey { get; set; } | ||
| 36 | |||
| 37 | public string KeyPath { get; set; } | ||
| 38 | |||
| 39 | public string DisplayName { get; set; } | ||
| 40 | |||
| 41 | public string DisplayVersion { get; set; } | ||
| 42 | |||
| 43 | public int? EstimatedSize { get; set; } | ||
| 44 | |||
| 45 | public int? Installed { get; set; } | ||
| 46 | |||
| 47 | public string ModifyPath { get; set; } | ||
| 48 | |||
| 49 | public string Publisher { get; set; } | ||
| 50 | |||
| 51 | public int? SystemComponent { get; set; } | ||
| 52 | |||
| 53 | public string QuietUninstallString { get; set; } | ||
| 54 | |||
| 55 | public string QuietUninstallCommand { get; set; } | ||
| 56 | |||
| 57 | public string QuietUninstallCommandArguments { get; set; } | ||
| 58 | |||
| 59 | public string UninstallCommand { get; set; } | ||
| 60 | |||
| 61 | public string UninstallCommandArguments { get; set; } | ||
| 62 | |||
| 63 | public string UninstallString { get; set; } | ||
| 64 | |||
| 65 | public string UrlInfoAbout { get; set; } | ||
| 66 | |||
| 67 | public string UrlUpdateInfo { get; set; } | ||
| 68 | |||
| 69 | public static bool TryGetPerMachineRegistrationById(string id, bool x64, out GenericArpRegistration registration) | ||
| 70 | { | ||
| 71 | return TryGetRegistrationById(id, x64, false, out registration); | ||
| 72 | } | ||
| 73 | |||
| 74 | public static bool TryGetPerUserRegistrationById(string id, out GenericArpRegistration registration) | ||
| 75 | { | ||
| 76 | return TryGetRegistrationById(id, true, true, out registration); | ||
| 77 | } | ||
| 78 | |||
| 79 | private static bool TryGetRegistrationById(string id, bool x64, bool perUser, out GenericArpRegistration registration) | ||
| 80 | { | ||
| 81 | registration = GetGenericArpRegistration(id, x64, perUser, key => new GenericArpRegistration()); | ||
| 82 | return registration != null; | ||
| 83 | } | ||
| 84 | |||
| 85 | protected static T GetGenericArpRegistration<T>(string id, bool x64, bool perUser, Func<RegistryKey, T> fnCreate) | ||
| 86 | where T : GenericArpRegistration | ||
| 87 | { | ||
| 88 | var baseKey = perUser ? Registry.CurrentUser : Registry.LocalMachine; | ||
| 89 | var baseKeyPath = x64 ? UNINSTALL_KEY : UNINSTALL_KEY_WOW6432NODE; | ||
| 90 | var registrationKeyPath = $"{baseKeyPath}\\{id}"; | ||
| 91 | using var idKey = baseKey.OpenSubKey(registrationKeyPath); | ||
| 92 | |||
| 93 | if (idKey == null) | ||
| 94 | { | ||
| 95 | return null; | ||
| 96 | } | ||
| 97 | |||
| 98 | var registration = fnCreate(idKey); | ||
| 99 | |||
| 100 | registration.BaseKey = baseKey; | ||
| 101 | registration.KeyPath = registrationKeyPath; | ||
| 102 | |||
| 103 | registration.DisplayName = idKey.GetValue(REGISTRY_ARP_DISPLAY_NAME) as string; | ||
| 104 | registration.DisplayVersion = idKey.GetValue(REGISTRY_ARP_DISPLAY_VERSION) as string; | ||
| 105 | registration.EstimatedSize = idKey.GetValue(REGISTRY_ARP_ESTIMATED_SIZE) as int?; | ||
| 106 | registration.Installed = idKey.GetValue(REGISTRY_ARP_INSTALLED) as int?; | ||
| 107 | registration.ModifyPath = idKey.GetValue(REGISTRY_ARP_MODIFY_PATH) as string; | ||
| 108 | registration.Publisher = idKey.GetValue(REGISTRY_ARP_PUBLISHER) as string; | ||
| 109 | registration.SystemComponent = idKey.GetValue(REGISTRY_ARP_SYSTEM_COMPONENT) as int?; | ||
| 110 | registration.UrlInfoAbout = idKey.GetValue(REGISTRY_ARP_URL_INFO_ABOUT) as string; | ||
| 111 | registration.UrlUpdateInfo = idKey.GetValue(REGISTRY_ARP_URL_UPDATE_INFO) as string; | ||
| 112 | |||
| 113 | registration.QuietUninstallString = idKey.GetValue(REGISTRY_ARP_QUIET_UNINSTALL_STRING) as string; | ||
| 114 | if (!String.IsNullOrEmpty(registration.QuietUninstallString)) | ||
| 115 | { | ||
| 116 | var closeQuote = registration.QuietUninstallString.IndexOf("\"", 1); | ||
| 117 | if (closeQuote > 0) | ||
| 118 | { | ||
| 119 | registration.QuietUninstallCommand = registration.QuietUninstallString.Substring(1, closeQuote - 1).Trim(); | ||
| 120 | registration.QuietUninstallCommandArguments = registration.QuietUninstallString.Substring(closeQuote + 1).Trim(); | ||
| 121 | } | ||
| 122 | } | ||
| 123 | |||
| 124 | registration.UninstallString = idKey.GetValue(REGISTRY_ARP_UNINSTALL_STRING) as string; | ||
| 125 | if (!String.IsNullOrEmpty(registration.UninstallString)) | ||
| 126 | { | ||
| 127 | var closeQuote = registration.UninstallString.IndexOf("\"", 1); | ||
| 128 | if (closeQuote > 0) | ||
| 129 | { | ||
| 130 | registration.UninstallCommand = registration.UninstallString.Substring(1, closeQuote - 1).Trim(); | ||
| 131 | registration.UninstallCommandArguments = registration.UninstallString.Substring(closeQuote + 1).Trim(); | ||
| 132 | } | ||
| 133 | } | ||
| 134 | |||
| 135 | return registration; | ||
| 136 | } | ||
| 137 | |||
| 138 | public void Delete() | ||
| 139 | { | ||
| 140 | this.BaseKey.DeleteSubKeyTree(this.KeyPath); | ||
| 141 | } | ||
| 142 | } | ||
| 143 | } | ||
