| 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 : GenericArpRegistration |
| 9 | { |
| 10 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_ADDON_CODE = "BundleAddonCode"; |
| 11 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH = "BundleCachePath"; |
| 12 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_DETECT_CODE = "BundleDetectCode"; |
| 13 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_PATCH_CODE = "BundlePatchCode"; |
| 14 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY = "BundleProviderKey"; |
| 15 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_RESUME_COMMAND_LINE = "BundleResumeCommandLine"; |
| 16 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_TAG = "BundleTag"; |
| 17 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE = "BundleUpgradeCode"; |
| 18 | public const string BURN_REGISTRATION_REGISTRY_BUNDLE_VERSION = "BundleVersion"; |
| 19 | public const string BURN_REGISTRATION_REGISTRY_ENGINE_VERSION = "EngineVersion"; |
| 20 | |
| 21 | public string[] AddonCodes { get; set; } |
| 22 | |
| 23 | public string BundleVersion { get; set; } |
| 24 | |
| 25 | public string CachePath { get; set; } |
| 26 | |
| 27 | public string[] DetectCodes { get; set; } |
| 28 | |
| 29 | public string EngineVersion { get; set; } |
| 30 | |
| 31 | public string[] PatchCodes { get; set; } |
| 32 | |
| 33 | public string ProviderKey { get; set; } |
| 34 | |
| 35 | public string Tag { get; set; } |
| 36 | |
| 37 | public string[] UpgradeCodes { get; set; } |
| 38 | |
| 39 | public static bool TryGetPerMachineBundleRegistrationById(string id, bool x64, out BundleRegistration registration) |
| 40 | { |
| 41 | return TryGetRegistrationById(id, x64, false, out registration); |
| 42 | } |
| 43 | |
| 44 | public static bool TryGetPerUserBundleRegistrationById(string id, out BundleRegistration registration) |
| 45 | { |
| 46 | return TryGetRegistrationById(id, true, true, out registration); |
| 47 | } |
| 48 | |
| 49 | private static bool TryGetRegistrationById(string id, bool x64, bool perUser, out BundleRegistration registration) |
| 50 | { |
| 51 | registration = GetGenericArpRegistration(id, x64, perUser, key => GetBundleRegistration(key)); |
| 52 | return registration != null; |
| 53 | } |
| 54 | |
| 55 | private static BundleRegistration GetBundleRegistration(RegistryKey idKey) |
| 56 | { |
| 57 | var registration = new BundleRegistration(); |
| 58 | |
| 59 | registration.AddonCodes = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_ADDON_CODE) as string[]; |
| 60 | registration.CachePath = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_CACHE_PATH) as string; |
| 61 | registration.DetectCodes = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_DETECT_CODE) as string[]; |
| 62 | registration.PatchCodes = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_PATCH_CODE) as string[]; |
| 63 | registration.ProviderKey = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_PROVIDER_KEY) as string; |
| 64 | registration.Tag = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_TAG) as string; |
| 65 | registration.UpgradeCodes = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_UPGRADE_CODE) as string[]; |
| 66 | registration.BundleVersion = idKey.GetValue(BURN_REGISTRATION_REGISTRY_BUNDLE_VERSION) as string; |
| 67 | registration.EngineVersion = idKey.GetValue(BURN_REGISTRATION_REGISTRY_ENGINE_VERSION) as string; |
| 68 | |
| 69 | return registration; |
| 70 | } |
| 71 | |
| 72 | public static bool TryGetDependencyProviderValue(string providerId, string name, out string value) |
| 73 | { |
| 74 | value = null; |
| 75 | |
| 76 | string key = String.Format(@"Installer\Dependencies\{0}", providerId); |
| 77 | using (RegistryKey providerKey = Registry.ClassesRoot.OpenSubKey(key)) |
| 78 | { |
| 79 | if (null == providerKey) |
| 80 | { |
| 81 | return false; |
| 82 | } |
| 83 | |
| 84 | value = providerKey.GetValue(name) as string; |
| 85 | return value != null; |
| 86 | } |
| 87 | } |
| 88 | |
| 89 | public static bool DependencyDependentExists(string providerId, string dependentId) |
| 90 | { |
| 91 | string key = String.Format(@"Installer\Dependencies\{0}\Dependents\{1}", providerId, dependentId); |
| 92 | using (RegistryKey dependentKey = Registry.ClassesRoot.OpenSubKey(key)) |
| 93 | { |
| 94 | return null != dependentKey; |
| 95 | } |
| 96 | } |
| 97 | } |
| 98 | } |