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