diff options
Diffstat (limited to 'src/WixTestTools/BundleRegistration.cs')
| -rw-r--r-- | src/WixTestTools/BundleRegistration.cs | 145 |
1 files changed, 145 insertions, 0 deletions
diff --git a/src/WixTestTools/BundleRegistration.cs b/src/WixTestTools/BundleRegistration.cs new file mode 100644 index 00000000..d473dcdd --- /dev/null +++ b/src/WixTestTools/BundleRegistration.cs | |||
| @@ -0,0 +1,145 @@ | |||
| 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 BundleRegistration | ||
| 9 | { | ||
| 10 | public const string BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY = "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\Uninstall"; | ||
| 11 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH = "BundleCachePath"; | ||
| 12 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_ADDON_CODE = "BundleAddonCode"; | ||
| 13 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_DETECT_CODE = "BundleDetectCode"; | ||
| 14 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_PATCH_CODE = "BundlePatchCode"; | ||
| 15 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE = "BundleUpgradeCode"; | ||
| 16 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_DISPLAY_NAME = "DisplayName"; | ||
| 17 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_VERSION = "BundleVersion"; | ||
| 18 | public const string BURN_REGISTRATION_REGISTRY_ENGINE_VERSION = "EngineVersion"; | ||
| 19 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY = "BundleProviderKey"; | ||
| 20 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_TAG = "BundleTag"; | ||
| 21 | public const string REGISTRY_REBOOT_PENDING_FORMAT = "{0}.RebootRequired"; | ||
| 22 | public const string REGISTRY_BUNDLE_INSTALLED = "Installed"; | ||
| 23 | public const string REGISTRY_BUNDLE_DISPLAY_ICON = "DisplayIcon"; | ||
| 24 | public const string REGISTRY_BUNDLE_DISPLAY_VERSION = "DisplayVersion"; | ||
| 25 | public const string REGISTRY_BUNDLE_ESTIMATED_SIZE = "EstimatedSize"; | ||
| 26 | public const string REGISTRY_BUNDLE_PUBLISHER = "Publisher"; | ||
| 27 | public const string REGISTRY_BUNDLE_HELP_LINK = "HelpLink"; | ||
| 28 | public const string REGISTRY_BUNDLE_HELP_TELEPHONE = "HelpTelephone"; | ||
| 29 | public const string REGISTRY_BUNDLE_URL_INFO_ABOUT = "URLInfoAbout"; | ||
| 30 | public const string REGISTRY_BUNDLE_URL_UPDATE_INFO = "URLUpdateInfo"; | ||
| 31 | public const string REGISTRY_BUNDLE_PARENT_DISPLAY_NAME = "ParentDisplayName"; | ||
| 32 | public const string REGISTRY_BUNDLE_PARENT_KEY_NAME = "ParentKeyName"; | ||
| 33 | public const string REGISTRY_BUNDLE_COMMENTS = "Comments"; | ||
| 34 | public const string REGISTRY_BUNDLE_CONTACT = "Contact"; | ||
| 35 | public const string REGISTRY_BUNDLE_NO_MODIFY = "NoModify"; | ||
| 36 | public const string REGISTRY_BUNDLE_MODIFY_PATH = "ModifyPath"; | ||
| 37 | public const string REGISTRY_BUNDLE_NO_ELEVATE_ON_MODIFY = "NoElevateOnModify"; | ||
| 38 | public const string REGISTRY_BUNDLE_NO_REMOVE = "NoRemove"; | ||
| 39 | public const string REGISTRY_BUNDLE_SYSTEM_COMPONENT = "SystemComponent"; | ||
| 40 | public const string REGISTRY_BUNDLE_QUIET_UNINSTALL_STRING = "QuietUninstallString"; | ||
| 41 | public const string REGISTRY_BUNDLE_UNINSTALL_STRING = "UninstallString"; | ||
| 42 | public const string REGISTRY_BUNDLE_RESUME_COMMAND_LINE = "BundleResumeCommandLine"; | ||
| 43 | public const string REGISTRY_BUNDLE_VERSION_MAJOR = "VersionMajor"; | ||
| 44 | public const string REGISTRY_BUNDLE_VERSION_MINOR = "VersionMinor"; | ||
| 45 | |||
| 46 | public string[] AddonCodes { get; set; } | ||
| 47 | |||
| 48 | public string CachePath { get; set; } | ||
| 49 | |||
| 50 | public string DisplayName { get; set; } | ||
| 51 | |||
| 52 | public string[] DetectCodes { get; set; } | ||
| 53 | |||
| 54 | public string EngineVersion { get; set; } | ||
| 55 | |||
| 56 | public int? EstimatedSize { get; set; } | ||
| 57 | |||
| 58 | public int? Installed { get; set; } | ||
| 59 | |||
| 60 | public string ModifyPath { get; set; } | ||
| 61 | |||
| 62 | public string[] PatchCodes { get; set; } | ||
| 63 | |||
| 64 | public string ProviderKey { get; set; } | ||
| 65 | |||
| 66 | public string Publisher { get; set; } | ||
| 67 | |||
| 68 | public string QuietUninstallString { get; set; } | ||
| 69 | |||
| 70 | public string QuietUninstallCommand { get; set; } | ||
| 71 | |||
| 72 | public string QuietUninstallCommandArguments { get; set; } | ||
| 73 | |||
| 74 | public string Tag { get; set; } | ||
| 75 | |||
| 76 | public string UninstallCommand { get; set; } | ||
| 77 | |||
| 78 | public string UninstallCommandArguments { get; set; } | ||
| 79 | |||
| 80 | public string UninstallString { get; set; } | ||
| 81 | |||
| 82 | public string[] UpgradeCodes { get; set; } | ||
| 83 | |||
| 84 | public string UrlInfoAbout { get; set; } | ||
| 85 | |||
| 86 | public string UrlUpdateInfo { get; set; } | ||
| 87 | |||
| 88 | public string Version { get; set; } | ||
| 89 | |||
| 90 | public static bool TryGetPerMachineBundleRegistrationById(string bundleId, out BundleRegistration registration) | ||
| 91 | { | ||
| 92 | var registrationKeyPath = $"{BURN_REGISTRATION_REGISTRY_UNINSTALL_KEY}\\{bundleId}"; | ||
| 93 | using var registrationKey = Registry.LocalMachine.OpenSubKey(registrationKeyPath); | ||
| 94 | var success = registrationKey != null; | ||
| 95 | registration = success ? GetBundleRegistration(registrationKey) : null; | ||
| 96 | return success; | ||
| 97 | } | ||
| 98 | |||
| 99 | private static BundleRegistration GetBundleRegistration(RegistryKey idKey) | ||
| 100 | { | ||
| 101 | var registration = new BundleRegistration(); | ||
| 102 | |||
| 103 | registration.AddonCodes = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_ADDON_CODE) as string[]; | ||
| 104 | registration.CachePath = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH) as string; | ||
| 105 | registration.DetectCodes = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_DETECT_CODE) as string[]; | ||
| 106 | registration.PatchCodes = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_PATCH_CODE) as string[]; | ||
| 107 | registration.ProviderKey = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY) as string; | ||
| 108 | registration.Tag = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_TAG) as string; | ||
| 109 | registration.UpgradeCodes = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE) as string[]; | ||
| 110 | registration.Version = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_VERSION) as string; | ||
| 111 | registration.DisplayName = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_DISPLAY_NAME) as string; | ||
| 112 | registration.EngineVersion = idKey.GetValue(BURN_REGISTRATION_REGISTRY_ENGINE_VERSION) as string; | ||
| 113 | registration.EstimatedSize = idKey.GetValue(REGISTRY_BUNDLE_ESTIMATED_SIZE) as int?; | ||
| 114 | registration.Installed = idKey.GetValue(REGISTRY_BUNDLE_INSTALLED) as int?; | ||
| 115 | registration.ModifyPath = idKey.GetValue(REGISTRY_BUNDLE_MODIFY_PATH) as string; | ||
| 116 | registration.Publisher = idKey.GetValue(REGISTRY_BUNDLE_PUBLISHER) as string; | ||
| 117 | registration.UrlInfoAbout = idKey.GetValue(REGISTRY_BUNDLE_URL_INFO_ABOUT) as string; | ||
| 118 | registration.UrlUpdateInfo = idKey.GetValue(REGISTRY_BUNDLE_URL_UPDATE_INFO) as string; | ||
| 119 | |||
| 120 | registration.QuietUninstallString = idKey.GetValue(REGISTRY_BUNDLE_QUIET_UNINSTALL_STRING) as string; | ||
| 121 | if (!String.IsNullOrEmpty(registration.QuietUninstallString)) | ||
| 122 | { | ||
| 123 | var closeQuote = registration.QuietUninstallString.IndexOf("\"", 1); | ||
| 124 | if (closeQuote > 0) | ||
| 125 | { | ||
| 126 | registration.QuietUninstallCommand = registration.QuietUninstallString.Substring(1, closeQuote - 1).Trim(); | ||
| 127 | registration.QuietUninstallCommandArguments = registration.QuietUninstallString.Substring(closeQuote + 1).Trim(); | ||
| 128 | } | ||
| 129 | } | ||
| 130 | |||
| 131 | registration.UninstallString = idKey.GetValue(REGISTRY_BUNDLE_UNINSTALL_STRING) as string; | ||
| 132 | if (!String.IsNullOrEmpty(registration.UninstallString)) | ||
| 133 | { | ||
| 134 | var closeQuote = registration.UninstallString.IndexOf("\"", 1); | ||
| 135 | if (closeQuote > 0) | ||
| 136 | { | ||
| 137 | registration.UninstallCommand = registration.UninstallString.Substring(1, closeQuote - 1).Trim(); | ||
| 138 | registration.UninstallCommandArguments = registration.UninstallString.Substring(closeQuote + 1).Trim(); | ||
| 139 | } | ||
| 140 | } | ||
| 141 | |||
| 142 | return registration; | ||
| 143 | } | ||
| 144 | } | ||
| 145 | } | ||
