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.cs81
1 files changed, 50 insertions, 31 deletions
diff --git a/src/WixToolset.Core/Resolver.cs b/src/WixToolset.Core/Resolver.cs
index 92c2a9c9..f4cb2fd6 100644
--- a/src/WixToolset.Core/Resolver.cs
+++ b/src/WixToolset.Core/Resolver.cs
@@ -4,6 +4,7 @@ namespace WixToolset.Core
4{ 4{
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.Globalization;
7 using System.Linq; 8 using System.Linq;
8 using WixToolset.Core.Bind; 9 using WixToolset.Core.Bind;
9 using WixToolset.Data; 10 using WixToolset.Data;
@@ -22,26 +23,12 @@ namespace WixToolset.Core
22 this.ServiceProvider = serviceProvider; 23 this.ServiceProvider = serviceProvider;
23 24
24 this.Messaging = serviceProvider.GetService<IMessaging>(); 25 this.Messaging = serviceProvider.GetService<IMessaging>();
25
26 this.VariableResolver = serviceProvider.GetService<IVariableResolver>();
27 } 26 }
28 27
29 private IServiceProvider ServiceProvider { get; } 28 private IServiceProvider ServiceProvider { get; }
30 29
31 private IMessaging Messaging { get; } 30 private IMessaging Messaging { get; }
32 31
33 private IVariableResolver VariableResolver { get; set; }
34
35 public IEnumerable<IBindPath> BindPaths { get; set; }
36
37 public string IntermediateFolder { get; set; }
38
39 public Intermediate IntermediateRepresentation { get; set; }
40
41 public IEnumerable<Localization> Localizations { get; set; }
42
43 public IEnumerable<string> FilterCultures { get; set; }
44
45 public IResolveResult Resolve(IResolveContext context) 32 public IResolveResult Resolve(IResolveContext context)
46 { 33 {
47 foreach (var extension in context.Extensions) 34 foreach (var extension in context.Extensions)
@@ -52,11 +39,26 @@ namespace WixToolset.Core
52 ResolveResult resolveResult = null; 39 ResolveResult resolveResult = null;
53 try 40 try
54 { 41 {
55 var codepage = this.PopulateVariableResolver(context); 42 var filteredLocalizations = FilterLocalizations(context);
43
44 var variableResolver = this.CreateVariableResolver(context, filteredLocalizations);
45
46 this.LocalizeUI(variableResolver, context.IntermediateRepresentation);
47
48 resolveResult = this.DoResolve(context, variableResolver);
49
50 var primaryLocalization = filteredLocalizations.FirstOrDefault();
51
52 if (primaryLocalization != null)
53 {
54 this.TryGetCultureInfo(primaryLocalization.Culture, out var cultureInfo);
56 55
57 this.LocalizeUI(context); 56 resolveResult.Codepage = primaryLocalization.Codepage ?? cultureInfo?.TextInfo.ANSICodePage;
58 57
59 resolveResult = this.DoResolve(context, codepage); 58 resolveResult.SummaryInformationCodepage = primaryLocalization.SummaryInformationCodepage ?? primaryLocalization.Codepage ?? cultureInfo?.TextInfo.ANSICodePage;
59
60 resolveResult.PackageLcid = cultureInfo?.LCID;
61 }
60 } 62 }
61 finally 63 finally
62 { 64 {
@@ -69,7 +71,7 @@ namespace WixToolset.Core
69 return resolveResult; 71 return resolveResult;
70 } 72 }
71 73
72 private ResolveResult DoResolve(IResolveContext context, int? codepage) 74 private ResolveResult DoResolve(IResolveContext context, IVariableResolver variableResolver)
73 { 75 {
74 var buildingPatch = context.IntermediateRepresentation.Sections.Any(s => s.Type == SectionType.Patch); 76 var buildingPatch = context.IntermediateRepresentation.Sections.Any(s => s.Type == SectionType.Patch);
75 77
@@ -80,7 +82,7 @@ namespace WixToolset.Core
80 var command = new ResolveFieldsCommand(); 82 var command = new ResolveFieldsCommand();
81 command.Messaging = this.Messaging; 83 command.Messaging = this.Messaging;
82 command.BuildingPatch = buildingPatch; 84 command.BuildingPatch = buildingPatch;
83 command.VariableResolver = this.VariableResolver; 85 command.VariableResolver = variableResolver;
84 command.BindPaths = context.BindPaths; 86 command.BindPaths = context.BindPaths;
85 command.Extensions = context.Extensions; 87 command.Extensions = context.Extensions;
86 command.FilesWithEmbeddedFiles = filesWithEmbeddedFiles; 88 command.FilesWithEmbeddedFiles = filesWithEmbeddedFiles;
@@ -118,7 +120,6 @@ namespace WixToolset.Core
118 120
119 return new ResolveResult 121 return new ResolveResult
120 { 122 {
121 Codepage = codepage.HasValue ? codepage.Value : -1,
122 ExpectedEmbeddedFiles = expectedEmbeddedFiles, 123 ExpectedEmbeddedFiles = expectedEmbeddedFiles,
123 DelayedFields = delayedFields, 124 DelayedFields = delayedFields,
124 IntermediateRepresentation = context.IntermediateRepresentation 125 IntermediateRepresentation = context.IntermediateRepresentation
@@ -128,13 +129,13 @@ namespace WixToolset.Core
128 /// <summary> 129 /// <summary>
129 /// Localize dialogs and controls. 130 /// Localize dialogs and controls.
130 /// </summary> 131 /// </summary>
131 private void LocalizeUI(IResolveContext context) 132 private void LocalizeUI(IVariableResolver variableResolver, Intermediate intermediate)
132 { 133 {
133 foreach (var section in context.IntermediateRepresentation.Sections) 134 foreach (var section in intermediate.Sections)
134 { 135 {
135 foreach (var symbol in section.Symbols.OfType<DialogSymbol>()) 136 foreach (var symbol in section.Symbols.OfType<DialogSymbol>())
136 { 137 {
137 if (this.VariableResolver.TryGetLocalizedControl(symbol.Id.Id, null, out var localizedControl)) 138 if (variableResolver.TryGetLocalizedControl(symbol.Id.Id, null, out var localizedControl))
138 { 139 {
139 if (CompilerConstants.IntegerNotSet != localizedControl.X) 140 if (CompilerConstants.IntegerNotSet != localizedControl.X)
140 { 141 {
@@ -169,7 +170,7 @@ namespace WixToolset.Core
169 170
170 foreach (var symbol in section.Symbols.OfType<ControlSymbol>()) 171 foreach (var symbol in section.Symbols.OfType<ControlSymbol>())
171 { 172 {
172 if (this.VariableResolver.TryGetLocalizedControl(symbol.DialogRef, symbol.Control, out var localizedControl)) 173 if (variableResolver.TryGetLocalizedControl(symbol.DialogRef, symbol.Control, out var localizedControl))
173 { 174 {
174 if (CompilerConstants.IntegerNotSet != localizedControl.X) 175 if (CompilerConstants.IntegerNotSet != localizedControl.X)
175 { 176 {
@@ -204,24 +205,42 @@ namespace WixToolset.Core
204 } 205 }
205 } 206 }
206 207
207 private int? PopulateVariableResolver(IResolveContext context) 208 private IVariableResolver CreateVariableResolver(IResolveContext context, IEnumerable<Localization> filteredLocalizations)
208 { 209 {
209 var localizations = FilterLocalizations(context); 210 var variableResolver = this.ServiceProvider.GetService<IVariableResolver>();
210 var codepage = localizations.FirstOrDefault()?.Codepage;
211 211
212 foreach (var localization in localizations) 212 foreach (var localization in filteredLocalizations)
213 { 213 {
214 this.VariableResolver.AddLocalization(localization); 214 variableResolver.AddLocalization(localization);
215 } 215 }
216 216
217 // Gather all the wix variables. 217 // Gather all the wix variables.
218 var wixVariableSymbols = context.IntermediateRepresentation.Sections.SelectMany(s => s.Symbols).OfType<WixVariableSymbol>(); 218 var wixVariableSymbols = context.IntermediateRepresentation.Sections.SelectMany(s => s.Symbols).OfType<WixVariableSymbol>();
219 foreach (var symbol in wixVariableSymbols) 219 foreach (var symbol in wixVariableSymbols)
220 { 220 {
221 this.VariableResolver.AddVariable(symbol.SourceLineNumbers, symbol.Id.Id, symbol.Value, symbol.Overridable); 221 variableResolver.AddVariable(symbol.SourceLineNumbers, symbol.Id.Id, symbol.Value, symbol.Overridable);
222 }
223
224 return variableResolver;
225 }
226
227 private bool TryGetCultureInfo(string culture, out CultureInfo cultureInfo)
228 {
229 cultureInfo = null;
230
231 if (!String.IsNullOrEmpty(culture))
232 {
233 try
234 {
235 cultureInfo = new CultureInfo(culture, useUserOverride: false);
236 }
237 catch
238 {
239 this.Messaging.Write("");
240 }
222 } 241 }
223 242
224 return codepage; 243 return cultureInfo != null;
225 } 244 }
226 245
227 private static IEnumerable<Localization> FilterLocalizations(IResolveContext context) 246 private static IEnumerable<Localization> FilterLocalizations(IResolveContext context)