main
cs 207 lines 7.29 KB
Raw
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 WixToolset.Core.Burn
4 {
5 using System;
6 using System.Diagnostics;
7 using System.Xml;
8 using WixToolset.Data;
9 using WixToolset.Data.Symbols;
10
11 internal class LegacySearchFacade : BaseSearchFacade
12 {
13 public LegacySearchFacade(WixSearchSymbol searchSymbol, IntermediateSymbol searchSpecificSymbol)
14 {
15 this.SearchSymbol = searchSymbol;
16 this.SearchSpecificSymbol = searchSpecificSymbol;
17 }
18
19 public IntermediateSymbol SearchSpecificSymbol { get; }
20
21 /// <summary>
22 /// Generates Burn manifest and ParameterInfo-style markup a search.
23 /// </summary>
24 /// <param name="writer"></param>
25 public override void WriteXml(XmlTextWriter writer)
26 {
27 switch (this.SearchSpecificSymbol)
28 {
29 case WixComponentSearchSymbol symbol:
30 this.WriteComponentSearchXml(writer, symbol);
31 break;
32 case WixFileSearchSymbol symbol:
33 this.WriteFileSearchXml(writer, symbol);
34 break;
35 case WixProductSearchSymbol symbol:
36 this.WriteProductSearchXml(writer, symbol);
37 break;
38 case WixRegistrySearchSymbol symbol:
39 this.WriteRegistrySearchXml(writer, symbol);
40 break;
41 default:
42 throw new NotImplementedException();
43 }
44 }
45
46 private void WriteComponentSearchXml(XmlTextWriter writer, WixComponentSearchSymbol searchSymbol)
47 {
48 writer.WriteStartElement("MsiComponentSearch");
49
50 base.WriteXml(writer);
51
52 writer.WriteAttributeString("ComponentId", searchSymbol.Guid);
53
54 if (!String.IsNullOrEmpty(searchSymbol.ProductCode))
55 {
56 writer.WriteAttributeString("ProductCode", searchSymbol.ProductCode);
57 }
58
59 switch (searchSymbol.Type)
60 {
61 case WixComponentSearchType.KeyPath:
62 writer.WriteAttributeString("Type", "keyPath");
63 break;
64 case WixComponentSearchType.State:
65 writer.WriteAttributeString("Type", "state");
66 break;
67 case WixComponentSearchType.WantDirectory:
68 writer.WriteAttributeString("Type", "directory");
69 break;
70 default:
71 throw new NotImplementedException();
72 }
73
74 writer.WriteEndElement();
75 }
76
77 private void WriteFileSearchXml(XmlTextWriter writer, WixFileSearchSymbol searchSymbol)
78 {
79 writer.WriteStartElement(!searchSymbol.IsDirectory ? "FileSearch" : "DirectorySearch");
80
81 base.WriteXml(writer);
82
83 writer.WriteAttributeString("Path", searchSymbol.Path);
84
85 switch (searchSymbol.Type)
86 {
87 case WixFileSearchType.Exists:
88 writer.WriteAttributeString("Type", "exists");
89 break;
90 case WixFileSearchType.Version:
91 Debug.Assert(!searchSymbol.IsDirectory, "Version search type is invalid for DirectorySearch");
92 writer.WriteAttributeString("Type", "version");
93 break;
94 case WixFileSearchType.Path:
95 writer.WriteAttributeString("Type", "path");
96 break;
97 default:
98 throw new NotImplementedException();
99 }
100
101 if (searchSymbol.DisableFileRedirection)
102 {
103 writer.WriteAttributeString("DisableFileRedirection", "yes");
104 }
105
106 writer.WriteEndElement();
107 }
108
109 private void WriteProductSearchXml(XmlTextWriter writer, WixProductSearchSymbol symbol)
110 {
111 writer.WriteStartElement("MsiProductSearch");
112
113 base.WriteXml(writer);
114
115 if (symbol.IsUpgradeCode)
116 {
117 writer.WriteAttributeString("UpgradeCode", symbol.Guid);
118 }
119 else
120 {
121 writer.WriteAttributeString("ProductCode", symbol.Guid);
122 }
123
124 switch (symbol.Type)
125 {
126 case WixProductSearchType.Version:
127 writer.WriteAttributeString("Type", "version");
128 break;
129 case WixProductSearchType.Language:
130 writer.WriteAttributeString("Type", "language");
131 break;
132 case WixProductSearchType.State:
133 writer.WriteAttributeString("Type", "state");
134 break;
135 case WixProductSearchType.Assignment:
136 writer.WriteAttributeString("Type", "assignment");
137 break;
138 default:
139 throw new NotImplementedException();
140 }
141
142 writer.WriteEndElement();
143 }
144
145 private void WriteRegistrySearchXml(XmlTextWriter writer, WixRegistrySearchSymbol symbol)
146 {
147 writer.WriteStartElement("RegistrySearch");
148
149 base.WriteXml(writer);
150
151 switch (symbol.Root)
152 {
153 case RegistryRootType.ClassesRoot:
154 writer.WriteAttributeString("Root", "HKCR");
155 break;
156 case RegistryRootType.CurrentUser:
157 writer.WriteAttributeString("Root", "HKCU");
158 break;
159 case RegistryRootType.LocalMachine:
160 writer.WriteAttributeString("Root", "HKLM");
161 break;
162 case RegistryRootType.Users:
163 writer.WriteAttributeString("Root", "HKU");
164 break;
165 default:
166 throw new NotImplementedException();
167 }
168
169 writer.WriteAttributeString("Key", symbol.Key);
170
171 if (!String.IsNullOrEmpty(symbol.Value))
172 {
173 writer.WriteAttributeString("Value", symbol.Value);
174 }
175
176 if (symbol.Win64)
177 {
178 writer.WriteAttributeString("Win64", "yes");
179 }
180
181 switch (symbol.Type)
182 {
183 case WixRegistrySearchType.Exists:
184 writer.WriteAttributeString("Type", "exists");
185 break;
186 case WixRegistrySearchType.Value:
187 writer.WriteAttributeString("Type", "value");
188
189 if (symbol.ExpandEnvironmentVariables)
190 {
191 writer.WriteAttributeString("ExpandEnvironment", "yes");
192 }
193
194 // We *always* say this is VariableType="string".
195 // If we end up needing to be more specific,
196 // we will have to actually implement the "Format" attribute.
197 writer.WriteAttributeString("VariableType", "string");
198
199 break;
200 default:
201 throw new NotImplementedException();
202 }
203
204 writer.WriteEndElement();
205 }
206 }
207 }