aboutsummaryrefslogtreecommitdiff
path: root/src/test/burn/WixTestTools/BundleUpdateRegistration.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/burn/WixTestTools/BundleUpdateRegistration.cs')
-rw-r--r--src/test/burn/WixTestTools/BundleUpdateRegistration.cs57
1 files changed, 57 insertions, 0 deletions
diff --git a/src/test/burn/WixTestTools/BundleUpdateRegistration.cs b/src/test/burn/WixTestTools/BundleUpdateRegistration.cs
new file mode 100644
index 00000000..2ce68122
--- /dev/null
+++ b/src/test/burn/WixTestTools/BundleUpdateRegistration.cs
@@ -0,0 +1,57 @@
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
3namespace WixTestTools
4{
5 using System;
6 using Microsoft.Win32;
7
8 public class BundleUpdateRegistration
9 {
10 public const string BURN_UPDATE_REGISTRATION_REGISTRY_BUNDLE_PACKAGE_NAME = "PackageName";
11 public const string BURN_UPDATE_REGISTRATION_REGISTRY_BUNDLE_PACKAGE_VERSION = "PackageVersion";
12 public const string BURN_UPDATE_REGISTRATION_REGISTRY_BUNDLE_PUBLISHER = "Publisher";
13 public const string BURN_UPDATE_REGISTRATION_REGISTRY_BUNDLE_PUBLISHING_GROUP = "PublishingGroup";
14
15 public string PackageName { get; set; }
16
17 public string PackageVersion { get; set; }
18
19 public string Publisher { get; set; }
20
21 public string PublishingGroup { get; set; }
22
23 public static bool TryGetPerMachineBundleUpdateRegistration(string manufacturer, string productFamily, string name, bool x64, out BundleUpdateRegistration registration)
24 {
25 return TryGetUpdateRegistration(manufacturer, productFamily, name, x64, perUser: false, out registration);
26 }
27
28 public static bool TryGetPerUserBundleUpdateRegistration(string manufacturer, string productFamily, string name, out BundleUpdateRegistration registration)
29 {
30 return TryGetUpdateRegistration(manufacturer, productFamily, name, x64: true, perUser: true, out registration);
31 }
32
33 private static bool TryGetUpdateRegistration(string manufacturer, string productFamily, string name, bool x64, bool perUser, out BundleUpdateRegistration registration)
34 {
35 var baseKey = perUser ? Registry.CurrentUser : Registry.LocalMachine;
36 var baseKeyPath = x64 ? @$"SOFTWARE\{manufacturer}\Updates\{productFamily}\{name}"
37 : @$"SOFTWARE\WOW6432Node\{manufacturer}\Updates\{productFamily}\{name}";
38 using var idKey = baseKey.OpenSubKey(baseKeyPath);
39
40 if (idKey == null)
41 {
42 registration = null;
43 return false;
44 }
45
46 registration = new BundleUpdateRegistration()
47 {
48 PackageName = idKey.GetValue(BURN_UPDATE_REGISTRATION_REGISTRY_BUNDLE_PACKAGE_NAME) as string,
49 PackageVersion = idKey.GetValue(BURN_UPDATE_REGISTRATION_REGISTRY_BUNDLE_PACKAGE_VERSION) as string,
50 Publisher = idKey.GetValue(BURN_UPDATE_REGISTRATION_REGISTRY_BUNDLE_PUBLISHER) as string,
51 PublishingGroup = idKey.GetValue(BURN_UPDATE_REGISTRATION_REGISTRY_BUNDLE_PUBLISHING_GROUP) as string,
52 };
53
54 return true;
55 }
56 }
57}