From 52005c7e6917f9866dd0b0de6993def16a72ed4b Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 1 Aug 2018 03:02:34 -0700 Subject: Major reduction in public surface area of WixToolset.Core --- src/WixToolset.Core/CommandLine/BuildCommand.cs | 5 +- .../CommandLine/CommandLineResponseFile.cs | 132 --------------------- 2 files changed, 3 insertions(+), 134 deletions(-) delete mode 100644 src/WixToolset.Core/CommandLine/CommandLineResponseFile.cs (limited to 'src/WixToolset.Core/CommandLine') diff --git a/src/WixToolset.Core/CommandLine/BuildCommand.cs b/src/WixToolset.Core/CommandLine/BuildCommand.cs index 822c4a9a..5c089b5f 100644 --- a/src/WixToolset.Core/CommandLine/BuildCommand.cs +++ b/src/WixToolset.Core/CommandLine/BuildCommand.cs @@ -317,6 +317,8 @@ namespace WixToolset.Core.CommandLine private IEnumerable LoadLocalizationFiles() { + var localizer = new Localizer(this.ServiceProvider); + foreach (var loc in this.LocFiles) { var preprocessor = new Preprocessor(this.ServiceProvider); @@ -331,8 +333,7 @@ namespace WixToolset.Core.CommandLine continue; } - var localization = Localizer.ParseLocalizationFile(this.Messaging, document); - + var localization = localizer.ParseLocalizationFile(document); yield return localization; } } diff --git a/src/WixToolset.Core/CommandLine/CommandLineResponseFile.cs b/src/WixToolset.Core/CommandLine/CommandLineResponseFile.cs deleted file mode 100644 index 6922b246..00000000 --- a/src/WixToolset.Core/CommandLine/CommandLineResponseFile.cs +++ /dev/null @@ -1,132 +0,0 @@ -// 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.Core.CommandLine -{ - using System; - using System.Collections; - using System.Collections.Generic; - using System.IO; - using System.Text; - using System.Text.RegularExpressions; - - /// - /// Common utilities for Wix command-line processing. - /// - public static class CommandLineResponseFile - { - /// - /// Parses a response file. - /// - /// The file to parse. - /// The array of arguments. - public static string[] Parse(string responseFile) - { - string arguments; - - using (StreamReader reader = new StreamReader(responseFile)) - { - arguments = reader.ReadToEnd(); - } - - return CommandLineResponseFile.ParseArgumentsToArray(arguments); - } - - /// - /// Parses an argument string into an argument array based on whitespace and quoting. - /// - /// Argument string. - /// Argument array. - public static string[] ParseArgumentsToArray(string arguments) - { - // Scan and parse the arguments string, dividing up the arguments based on whitespace. - // Unescaped quotes cause whitespace to be ignored, while the quotes themselves are removed. - // Quotes may begin and end inside arguments; they don't necessarily just surround whole arguments. - // Escaped quotes and escaped backslashes also need to be unescaped by this process. - - // Collects the final list of arguments to be returned. - List argsList = new List(); - - // True if we are inside an unescaped quote, meaning whitespace should be ignored. - bool insideQuote = false; - - // Index of the start of the current argument substring; either the start of the argument - // or the start of a quoted or unquoted sequence within it. - int partStart = 0; - - // The current argument string being built; when completed it will be added to the list. - StringBuilder arg = new StringBuilder(); - - for (int i = 0; i <= arguments.Length; i++) - { - if (i == arguments.Length || (Char.IsWhiteSpace(arguments[i]) && !insideQuote)) - { - // Reached a whitespace separator or the end of the string. - - // Finish building the current argument. - arg.Append(arguments.Substring(partStart, i - partStart)); - - // Skip over the whitespace character. - partStart = i + 1; - - // Add the argument to the list if it's not empty. - if (arg.Length > 0) - { - argsList.Add(CommandLineResponseFile.ExpandEnvVars(arg.ToString())); - arg.Length = 0; - } - } - else if (i > partStart && arguments[i - 1] == '\\') - { - // Check the character following an unprocessed backslash. - // Unescape quotes, and backslashes followed by a quote. - if (arguments[i] == '"' || (arguments[i] == '\\' && arguments.Length > i + 1 && arguments[i + 1] == '"')) - { - // Unescape the quote or backslash by skipping the preceeding backslash. - arg.Append(arguments.Substring(partStart, i - 1 - partStart)); - arg.Append(arguments[i]); - partStart = i + 1; - } - } - else if (arguments[i] == '"') - { - // Add the quoted or unquoted section to the argument string. - arg.Append(arguments.Substring(partStart, i - partStart)); - - // And skip over the quote character. - partStart = i + 1; - - insideQuote = !insideQuote; - } - } - - return argsList.ToArray(); - } - - static private string ExpandEnvVars(string arguments) - { - IDictionary id = Environment.GetEnvironmentVariables(); - - Regex regex = new Regex("(?<=\\%)(?:[\\w\\.]+)(?=\\%)"); - MatchCollection matches = regex.Matches(arguments); - - string value = String.Empty; - for (int i = 0; i <= (matches.Count - 1); i++) - { - try - { - string key = matches[i].Value; - regex = new Regex(String.Concat("(?i)(?:\\%)(?:" , key , ")(?:\\%)")); - value = id[key].ToString(); - arguments = regex.Replace(arguments, value); - } - catch (NullReferenceException) - { - // Collapse unresolved environment variables. - arguments = regex.Replace(arguments, value); - } - } - - return arguments; - } - } -} -- cgit v1.2.3-55-g6feb