From c9c3ab2776252d3131fea561bd3f3fac8c045f5e Mon Sep 17 00:00:00 2001 From: Bob Arnson Date: Wed, 29 Jan 2020 15:04:53 -0500 Subject: Clean up variable resolution during Resolve. --- src/WixToolset.Core/CommandLine/BuildCommand.cs | 1 - src/WixToolset.Core/Resolver.cs | 30 ++++++++++++++----------- src/WixToolset.Core/VariableResolver.cs | 8 ------- 3 files changed, 17 insertions(+), 22 deletions(-) (limited to 'src/WixToolset.Core') diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index 023a3c1e..0868a3b6 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs @@ -284,7 +284,6 @@ namespace WixToolset.Core.CommandLine context.IntermediateFolder = intermediateFolder; context.IntermediateRepresentation = output; context.Localizations = localizations; - context.VariableResolver = this.ServiceProvider.GetService(); var resolver = this.ServiceProvider.GetService(); resolveResult = resolver.Resolve(context); diff --git a/src/WixToolset.Core/Resolver.cs b/src/WixToolset.Core/Resolver.cs index d2a81477..cbae3742 100644 --- a/src/WixToolset.Core/Resolver.cs +++ b/src/WixToolset.Core/Resolver.cs @@ -22,12 +22,16 @@ namespace WixToolset.Core this.ServiceProvider = serviceProvider; this.Messaging = serviceProvider.GetService(); + + this.VariableResolver = serviceProvider.GetService(); } private IServiceProvider ServiceProvider { get; } private IMessaging Messaging { get; } + private IVariableResolver VariableResolver { get; set; } + public IEnumerable BindPaths { get; set; } public string IntermediateFolder { get; set; } @@ -40,7 +44,6 @@ namespace WixToolset.Core public IResolveResult Resolve(IResolveContext context) { - foreach (var extension in context.Extensions) { extension.PreResolve(context); @@ -49,11 +52,11 @@ namespace WixToolset.Core ResolveResult resolveResult = null; try { - PopulateVariableResolver(context); + var codepage = this.PopulateVariableResolver(context); this.LocalizeUI(context); - resolveResult = this.DoResolve(context); + resolveResult = this.DoResolve(context, codepage); } finally { @@ -66,7 +69,7 @@ namespace WixToolset.Core return resolveResult; } - private ResolveResult DoResolve(IResolveContext context) + private ResolveResult DoResolve(IResolveContext context, int? codepage) { var buildingPatch = context.IntermediateRepresentation.Sections.Any(s => s.Type == SectionType.Patch); @@ -77,7 +80,7 @@ namespace WixToolset.Core var command = new ResolveFieldsCommand(); command.Messaging = this.Messaging; command.BuildingPatch = buildingPatch; - command.VariableResolver = context.VariableResolver; + command.VariableResolver = this.VariableResolver; command.BindPaths = context.BindPaths; command.Extensions = context.Extensions; command.FilesWithEmbeddedFiles = filesWithEmbeddedFiles; @@ -112,7 +115,7 @@ namespace WixToolset.Core return new ResolveResult { - Codepage = context.VariableResolver.Codepage, + Codepage = codepage.HasValue ? codepage.Value : -1, ExpectedEmbeddedFiles = expectedEmbeddedFiles, DelayedFields = delayedFields, IntermediateRepresentation = context.IntermediateRepresentation @@ -128,7 +131,7 @@ namespace WixToolset.Core { foreach (var tuple in section.Tuples.OfType()) { - if (context.VariableResolver.TryGetLocalizedControl(tuple.Id.Id, null, out var localizedControl)) + if (this.VariableResolver.TryGetLocalizedControl(tuple.Id.Id, null, out var localizedControl)) { if (CompilerConstants.IntegerNotSet != localizedControl.X) { @@ -163,7 +166,7 @@ namespace WixToolset.Core foreach (var tuple in section.Tuples.OfType()) { - if (context.VariableResolver.TryGetLocalizedControl(tuple.DialogRef, tuple.Control, out var localizedControl)) + if (this.VariableResolver.TryGetLocalizedControl(tuple.DialogRef, tuple.Control, out var localizedControl)) { if (CompilerConstants.IntegerNotSet != localizedControl.X) { @@ -198,23 +201,24 @@ namespace WixToolset.Core } } - private static void PopulateVariableResolver(IResolveContext context) + private int? PopulateVariableResolver(IResolveContext context) { - var creator = context.ServiceProvider.GetService(); - var localizations = FilterLocalizations(context); + var codepage = localizations.FirstOrDefault()?.Codepage; foreach (var localization in localizations) { - context.VariableResolver.AddLocalization(localization); + this.VariableResolver.AddLocalization(localization); } // Gather all the wix variables. var wixVariableTuples = context.IntermediateRepresentation.Sections.SelectMany(s => s.Tuples).OfType(); foreach (var tuple in wixVariableTuples) { - context.VariableResolver.AddVariable(tuple.SourceLineNumbers, tuple.Id.Id, tuple.Value, tuple.Overridable); + this.VariableResolver.AddVariable(tuple.SourceLineNumbers, tuple.Id.Id, tuple.Value, tuple.Overridable); } + + return codepage; } private static IEnumerable FilterLocalizations(IResolveContext context) diff --git a/src/WixToolset.Core/VariableResolver.cs b/src/WixToolset.Core/VariableResolver.cs index c2a54a12..189fb883 100644 --- a/src/WixToolset.Core/VariableResolver.cs +++ b/src/WixToolset.Core/VariableResolver.cs @@ -29,24 +29,16 @@ namespace WixToolset.Core this.locVariables = new Dictionary(); this.wixVariables = new Dictionary(); this.localizedControls = new Dictionary(); - this.Codepage = -1; } private IServiceProvider ServiceProvider { get; } private IMessaging Messaging { get; } - public int Codepage { get; private set; } - public int VariableCount => this.wixVariables.Count; public void AddLocalization(Localization localization) { - if (-1 == this.Codepage) - { - this.Codepage = localization.Codepage; - } - foreach (var variable in localization.Variables) { if (!TryAddWixVariable(this.locVariables, variable)) -- cgit v1.2.3-55-g6feb