aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Resolver.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/Resolver.cs')
-rw-r--r--src/WixToolset.Core/Resolver.cs234
1 files changed, 234 insertions, 0 deletions
diff --git a/src/WixToolset.Core/Resolver.cs b/src/WixToolset.Core/Resolver.cs
new file mode 100644
index 00000000..b0d3a189
--- /dev/null
+++ b/src/WixToolset.Core/Resolver.cs
@@ -0,0 +1,234 @@
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 WixToolset.Core
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Linq;
8 using WixToolset.Core.Bind;
9 using WixToolset.Data;
10 using WixToolset.Data.Tuples;
11 using WixToolset.Extensibility;
12 using WixToolset.Extensibility.Services;
13
14 /// <summary>
15 /// Resolver for the WiX toolset.
16 /// </summary>
17 public sealed class Resolver
18 {
19 public Resolver(IServiceProvider serviceProvider, IEnumerable<BindPath> bindPaths, Intermediate intermediateRepresentation, string intermediateFolder, IEnumerable<Localization> localizations)
20 {
21 this.ServiceProvider = serviceProvider;
22 this.BindPaths = bindPaths;
23 this.IntermediateRepresentation = intermediateRepresentation;
24 this.IntermediateFolder = intermediateFolder;
25 this.Localizations = localizations;
26
27 this.Messaging = this.ServiceProvider.GetService<IMessaging>();
28 }
29
30 private IServiceProvider ServiceProvider { get; }
31
32 private IEnumerable<BindPath> BindPaths { get; }
33
34 private Intermediate IntermediateRepresentation { get; }
35
36 private string IntermediateFolder { get; }
37
38 private IEnumerable<Localization> Localizations { get; }
39
40 private IMessaging Messaging { get; }
41
42 public ResolveResult Execute()
43 {
44 var localizer = new Localizer(this.Messaging, this.Localizations);
45
46 var variableResolver = new WixVariableResolver(this.Messaging, localizer);
47
48 var context = this.ServiceProvider.GetService<IResolveContext>();
49 context.Messaging = this.Messaging;
50 context.BindPaths = this.BindPaths;
51 context.Extensions = this.ServiceProvider.GetService<IExtensionManager>().Create<IResolverExtension>();
52 context.IntermediateFolder = this.IntermediateFolder;
53 context.IntermediateRepresentation = this.IntermediateRepresentation;
54 context.WixVariableResolver = this.PopulateVariableResolver(variableResolver);
55
56 // Preresolve.
57 //
58 foreach (IResolverExtension extension in context.Extensions)
59 {
60 extension.PreResolve(context);
61 }
62
63 // Resolve.
64 //
65 this.LocalizeUI(context);
66
67 var resolveResult = this.Resolve(localizer.Codepage, context);
68
69 if (resolveResult != null)
70 {
71 // Postresolve.
72 //
73 foreach (IResolverExtension extension in context.Extensions)
74 {
75 extension.PostResolve(resolveResult);
76 }
77 }
78
79 return resolveResult;
80 }
81
82 private ResolveResult Resolve(int codepage, IResolveContext context)
83 {
84 var buildingPatch = context.IntermediateRepresentation.Sections.Any(s => s.Type == SectionType.Patch);
85
86 var filesWithEmbeddedFiles = new ExtractEmbeddedFiles();
87
88 IEnumerable<DelayedField> delayedFields;
89 {
90 var command = new ResolveFieldsCommand();
91 command.Messaging = context.Messaging;
92 command.BuildingPatch = buildingPatch;
93 command.BindVariableResolver = context.WixVariableResolver;
94 command.BindPaths = context.BindPaths;
95 command.Extensions = context.Extensions;
96 command.FilesWithEmbeddedFiles = filesWithEmbeddedFiles;
97 command.IntermediateFolder = context.IntermediateFolder;
98 command.Intermediate = context.IntermediateRepresentation;
99 command.SupportDelayedResolution = true;
100 command.Execute();
101
102 delayedFields = command.DelayedFields;
103 }
104
105#if REVISIT_FOR_PATCHING
106 if (context.IntermediateRepresentation.SubStorages != null)
107 {
108 foreach (SubStorage transform in context.IntermediateRepresentation.SubStorages)
109 {
110 var command = new ResolveFieldsCommand();
111 command.BuildingPatch = buildingPatch;
112 command.BindVariableResolver = context.WixVariableResolver;
113 command.BindPaths = context.BindPaths;
114 command.Extensions = context.Extensions;
115 command.FilesWithEmbeddedFiles = filesWithEmbeddedFiles;
116 command.IntermediateFolder = context.IntermediateFolder;
117 command.Intermediate = context.IntermediateRepresentation;
118 command.SupportDelayedResolution = false;
119 command.Execute();
120 }
121 }
122#endif
123
124 var expectedEmbeddedFiles = filesWithEmbeddedFiles.GetExpectedEmbeddedFiles();
125
126 return new ResolveResult
127 {
128 Codepage = codepage,
129 ExpectedEmbeddedFiles = expectedEmbeddedFiles,
130 DelayedFields = delayedFields,
131 IntermediateRepresentation = context.IntermediateRepresentation
132 };
133 }
134
135 /// <summary>
136 /// Localize dialogs and controls.
137 /// </summary>
138 private void LocalizeUI(IResolveContext context)
139 {
140 foreach (var section in context.IntermediateRepresentation.Sections)
141 {
142 foreach (var row in section.Tuples.OfType<DialogTuple>())
143 {
144 string dialog = row.Dialog;
145
146 if (context.WixVariableResolver.TryGetLocalizedControl(dialog, null, out LocalizedControl localizedControl))
147 {
148 if (CompilerConstants.IntegerNotSet != localizedControl.X)
149 {
150 row.HCentering = localizedControl.X;
151 }
152
153 if (CompilerConstants.IntegerNotSet != localizedControl.Y)
154 {
155 row.VCentering = localizedControl.Y;
156 }
157
158 if (CompilerConstants.IntegerNotSet != localizedControl.Width)
159 {
160 row.Width = localizedControl.Width;
161 }
162
163 if (CompilerConstants.IntegerNotSet != localizedControl.Height)
164 {
165 row.Height = localizedControl.Height;
166 }
167
168 row.Attributes = row.Attributes | localizedControl.Attributes;
169
170 if (!String.IsNullOrEmpty(localizedControl.Text))
171 {
172 row.Title = localizedControl.Text;
173 }
174 }
175 }
176
177 foreach (var row in section.Tuples.OfType<ControlTuple>())
178 {
179 string dialog = row.Dialog_;
180 string control = row.Control;
181
182 if (context.WixVariableResolver.TryGetLocalizedControl(dialog, control, out LocalizedControl localizedControl))
183 {
184 if (CompilerConstants.IntegerNotSet != localizedControl.X)
185 {
186 row.X = localizedControl.X;
187 }
188
189 if (CompilerConstants.IntegerNotSet != localizedControl.Y)
190 {
191 row.Y = localizedControl.Y;
192 }
193
194 if (CompilerConstants.IntegerNotSet != localizedControl.Width)
195 {
196 row.Width = localizedControl.Width;
197 }
198
199 if (CompilerConstants.IntegerNotSet != localizedControl.Height)
200 {
201 row.Height = localizedControl.Height;
202 }
203
204 row.Attributes = row.Attributes | localizedControl.Attributes;
205
206 if (!String.IsNullOrEmpty(localizedControl.Text))
207 {
208 row.Text = localizedControl.Text;
209 }
210 }
211 }
212 }
213 }
214
215 private WixVariableResolver PopulateVariableResolver(WixVariableResolver resolver)
216 {
217 // Gather all the wix variables.
218 var wixVariableTuples = this.IntermediateRepresentation.Sections.SelectMany(s => s.Tuples).OfType<WixVariableTuple>();
219 foreach (var tuple in wixVariableTuples)
220 {
221 try
222 {
223 resolver.AddVariable(tuple.WixVariable, tuple.Value, tuple.Overridable);
224 }
225 catch (ArgumentException)
226 {
227 this.Messaging.Write(ErrorMessages.WixVariableCollision(tuple.SourceLineNumbers, tuple.WixVariable));
228 }
229 }
230
231 return resolver;
232 }
233 }
234}