aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/WixRegistrySearchInfo.cs
blob: e8d7ce9b489f76722134da45a6f1f8b72cfc041f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
// 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.

namespace WixToolset
{
    using System;
    using System.Xml;
    using WixToolset.Data;

    /// <summary>
    /// Utility class for all WixRegistrySearches.
    /// </summary>
    internal class WixRegistrySearchInfo : WixSearchInfo
    {
        public WixRegistrySearchInfo(Row row)
            : this((string)row[0], (int)row[1], (string)row[2], (string)row[3], (int)row[4])
        {
        }

        public WixRegistrySearchInfo(string id, int root, string key, string value, int attributes)
            : base(id)
        {
            this.Root = root;
            this.Key = key;
            this.Value = value;
            this.Attributes = (WixRegistrySearchAttributes)attributes;
        }

        public int Root { get; private set; }
        public string Key { get; private set; }
        public string Value { get; private set; }
        public WixRegistrySearchAttributes Attributes { get; private set; }

        /// <summary>
        /// Generates Burn manifest and ParameterInfo-style markup for a registry search.
        /// </summary>
        /// <param name="writer"></param>
        public override void WriteXml(XmlTextWriter writer)
        {
            writer.WriteStartElement("RegistrySearch");
            this.WriteWixSearchAttributes(writer);

            switch (this.Root)
            {
                case Core.Native.MsiInterop.MsidbRegistryRootClassesRoot:
                    writer.WriteAttributeString("Root", "HKCR");
                    break;
                case Core.Native.MsiInterop.MsidbRegistryRootCurrentUser:
                    writer.WriteAttributeString("Root", "HKCU");
                    break;
                case Core.Native.MsiInterop.MsidbRegistryRootLocalMachine:
                    writer.WriteAttributeString("Root", "HKLM");
                    break;
                case Core.Native.MsiInterop.MsidbRegistryRootUsers:
                    writer.WriteAttributeString("Root", "HKU");
                    break;
            }

            writer.WriteAttributeString("Key", this.Key);

            if (!String.IsNullOrEmpty(this.Value))
            {
                writer.WriteAttributeString("Value", this.Value);
            }

            bool existenceOnly = 0 != (this.Attributes & WixRegistrySearchAttributes.WantExists);

            writer.WriteAttributeString("Type", existenceOnly ? "exists" : "value");

            if (0 != (this.Attributes & WixRegistrySearchAttributes.Win64))
            {
                writer.WriteAttributeString("Win64", "yes");
            }

            if (!existenceOnly)
            {
                if (0 != (this.Attributes & WixRegistrySearchAttributes.ExpandEnvironmentVariables))
                {
                    writer.WriteAttributeString("ExpandEnvironment", "yes");
                }

                // We *always* say this is VariableType="string". If we end up
                // needing to be more specific, we will have to expand the "Format"
                // attribute to allow "number" and "version".

                writer.WriteAttributeString("VariableType", "string");
            }

            writer.WriteEndElement();
        }
    }

}