From 457c144720964a7f50b1d184e6b19faa930e970e Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Wed, 17 Jun 2020 12:10:28 -0700 Subject: Introduce Value attribute on MultiString/MultiStringValue elements --- src/WixToolset.Core/Compiler_2.cs | 43 +++++++- .../MsiQueryFixture.cs | 65 ------------ .../RegistryFixture.cs | 114 +++++++++++++++++++++ .../TestData/Registry/RegistryValueMultiString.wxs | 15 +++ .../WixToolsetTest.CoreIntegration.csproj | 1 + 5 files changed, 168 insertions(+), 70 deletions(-) create mode 100644 src/test/WixToolsetTest.CoreIntegration/RegistryFixture.cs create mode 100644 src/test/WixToolsetTest.CoreIntegration/TestData/Registry/RegistryValueMultiString.wxs diff --git a/src/WixToolset.Core/Compiler_2.cs b/src/WixToolset.Core/Compiler_2.cs index 9e2ddb5b..84961f9b 100644 --- a/src/WixToolset.Core/Compiler_2.cs +++ b/src/WixToolset.Core/Compiler_2.cs @@ -1964,18 +1964,15 @@ namespace WixToolset.Core { switch (child.Name.LocalName) { + case "MultiString": case "MultiStringValue": if (RegistryValueType.MultiString != valueType && null != value) { this.Core.Write(ErrorMessages.RegistryMultipleValuesWithoutMultiString(sourceLineNumbers, node.Name.LocalName, "Value", child.Name.LocalName, "Type")); } - else if (null == value) - { - value = Common.GetInnerText(child); - } else { - value = String.Concat(value, "[~]", Common.GetInnerText(child)); + value = this.ParseRegistryMultiStringElement(child, value); } break; case "Permission": @@ -2069,6 +2066,42 @@ namespace WixToolset.Core return keyPath; } + private string ParseRegistryMultiStringElement(XElement node, string value) + { + var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); + string multiStringValue = null; + + foreach (var attrib in node.Attributes()) + { + if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || CompilerCore.WixNamespace == attrib.Name.Namespace) + { + switch (attrib.Name.LocalName) + { + case "Value": + multiStringValue = this.Core.GetAttributeValue(sourceLineNumbers, attrib); + break; + default: + this.Core.UnexpectedAttribute(node, attrib); + break; + } + } + } + + if (multiStringValue == null) + { + multiStringValue = Common.GetInnerText(node); + } + + if (multiStringValue == null) + { + this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Value")); + } + + this.Core.ParseForExtensionElements(node); + + return (null == value) ? multiStringValue : String.Concat(value, "[~]", multiStringValue); + } + /// /// Parses a RemoveRegistryKey element. /// diff --git a/src/test/WixToolsetTest.CoreIntegration/MsiQueryFixture.cs b/src/test/WixToolsetTest.CoreIntegration/MsiQueryFixture.cs index 70d6612e..c78b0c29 100644 --- a/src/test/WixToolsetTest.CoreIntegration/MsiQueryFixture.cs +++ b/src/test/WixToolsetTest.CoreIntegration/MsiQueryFixture.cs @@ -804,71 +804,6 @@ namespace WixToolsetTest.CoreIntegration } } - [Fact] - public void PopulatesRegistryTableFromRegistryValue() - { - var folder = TestData.Get(@"TestData"); - - using (var fs = new DisposableFileSystem()) - { - var baseFolder = fs.GetFolder(); - var intermediateFolder = Path.Combine(baseFolder, "obj"); - var msiPath = Path.Combine(baseFolder, @"bin\test.msi"); - - var result = WixRunner.Execute(new[] - { - "build", - Path.Combine(folder, "Registry", "RegistryValue.wxs"), - Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"), - "-bindpath", Path.Combine(folder, "SingleFile", "data"), - "-intermediateFolder", intermediateFolder, - "-o", msiPath - }); - - result.AssertSuccess(); - - Assert.True(File.Exists(msiPath)); - var results = Query.QueryDatabase(msiPath, new[] { "Registry" }); - Assert.Equal(new[] - { - "Registry:reg04OIwIchl.9ZTjisTT6NzGSsQSM\t2\tPath\\To\\AnotherKey\tSecret\t#x\tMiscComponent", - "Registry:regEblTuusqFNSUQNy88zaP_UA5kIY\t2\tPath\\To\\Key\t\t1.0.1234.123\tMiscComponent", - }, results); - } - } - - [Fact] - public void PopulatesRegistryTableFromRemoveRegistryKey() - { - var folder = TestData.Get(@"TestData"); - - using (var fs = new DisposableFileSystem()) - { - var baseFolder = fs.GetFolder(); - var intermediateFolder = Path.Combine(baseFolder, "obj"); - var msiPath = Path.Combine(baseFolder, @"bin\test.msi"); - - var result = WixRunner.Execute(new[] - { - "build", - Path.Combine(folder, "Registry", "RemoveRegistryKey.wxs"), - Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"), - "-bindpath", Path.Combine(folder, "SingleFile", "data"), - "-intermediateFolder", intermediateFolder, - "-o", msiPath - }); - - result.AssertSuccess(); - - Assert.True(File.Exists(msiPath)); - var results = Query.QueryDatabase(msiPath, new[] { "Registry" }); - Assert.Equal(new[] - { - "Registry:RemoveAKeyName\t2\tAKeyName\t-\t\tRemoveRegistryKeyComp", - }, results); - } - } - [Fact] public void PopulatesReserveCostTable() { diff --git a/src/test/WixToolsetTest.CoreIntegration/RegistryFixture.cs b/src/test/WixToolsetTest.CoreIntegration/RegistryFixture.cs new file mode 100644 index 00000000..2a1e2a49 --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/RegistryFixture.cs @@ -0,0 +1,114 @@ +// 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 WixToolsetTest.CoreIntegration +{ + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Text; + using WixBuildTools.TestSupport; + using WixToolset.Core.TestPackage; + using WixToolset.Data; + using Xunit; + + public class RegistryFixture + { + [Fact] + public void PopulatesRegistryTableFromRegistryValue() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var msiPath = Path.Combine(baseFolder, @"bin\test.msi"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "Registry", "RegistryValue.wxs"), + Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"), + "-bindpath", Path.Combine(folder, "SingleFile", "data"), + "-intermediateFolder", intermediateFolder, + "-o", msiPath + }); + + result.AssertSuccess(); + + Assert.True(File.Exists(msiPath)); + var results = Query.QueryDatabase(msiPath, new[] { "Registry" }); + Assert.Equal(new[] + { + "Registry:reg04OIwIchl.9ZTjisTT6NzGSsQSM\t2\tPath\\To\\AnotherKey\tSecret\t#x\tMiscComponent", + "Registry:regEblTuusqFNSUQNy88zaP_UA5kIY\t2\tPath\\To\\Key\t\t1.0.1234.123\tMiscComponent", + }, results); + } + } + + [Fact] + public void PopulatesRegistryTableFromRegistryValueMultiString() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var msiPath = Path.Combine(baseFolder, @"bin\test.msi"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "Registry", "RegistryValueMultiString.wxs"), + Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"), + "-bindpath", Path.Combine(folder, "SingleFile", "data"), + "-intermediateFolder", intermediateFolder, + "-o", msiPath + }); + + result.AssertSuccess(); + + var results = Query.QueryDatabase(msiPath, new[] { "Registry" }); + Assert.Equal(new[] + { + "Registry:regitq_Wx9LfvJuNSc2un6gIHAzr4A\t2\tPath\\To\\AnotherKey\tSecret\t#x\tMultiStringComponent", + "Registry:regmeTJMpOD41igfxhTcUVZ7kNG1Mo\t2\tPath\\To\\Key\t\ta[~]b[~]c\tMultiStringComponent", + }, results); + } + } + + [Fact] + public void PopulatesRegistryTableFromRemoveRegistryKey() + { + var folder = TestData.Get(@"TestData"); + + using (var fs = new DisposableFileSystem()) + { + var baseFolder = fs.GetFolder(); + var intermediateFolder = Path.Combine(baseFolder, "obj"); + var msiPath = Path.Combine(baseFolder, @"bin\test.msi"); + + var result = WixRunner.Execute(new[] + { + "build", + Path.Combine(folder, "Registry", "RemoveRegistryKey.wxs"), + Path.Combine(folder, "ProductWithComponentGroupRef", "Product.wxs"), + "-bindpath", Path.Combine(folder, "SingleFile", "data"), + "-intermediateFolder", intermediateFolder, + "-o", msiPath + }); + + result.AssertSuccess(); + + Assert.True(File.Exists(msiPath)); + var results = Query.QueryDatabase(msiPath, new[] { "Registry" }); + Assert.Equal(new[] + { + "Registry:RemoveAKeyName\t2\tAKeyName\t-\t\tRemoveRegistryKeyComp", + }, results); + } + } + } +} diff --git a/src/test/WixToolsetTest.CoreIntegration/TestData/Registry/RegistryValueMultiString.wxs b/src/test/WixToolsetTest.CoreIntegration/TestData/Registry/RegistryValueMultiString.wxs new file mode 100644 index 00000000..d5c680ee --- /dev/null +++ b/src/test/WixToolsetTest.CoreIntegration/TestData/Registry/RegistryValueMultiString.wxs @@ -0,0 +1,15 @@ + + + + + + + + + + + + + + + diff --git a/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj b/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj index 7ede6655..c86a691f 100644 --- a/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj +++ b/src/test/WixToolsetTest.CoreIntegration/WixToolsetTest.CoreIntegration.csproj @@ -74,6 +74,7 @@ + -- cgit v1.2.3-55-g6feb