From dbde9e7104b907bbbaea17e21247d8cafc8b3a4c Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sat, 14 Oct 2017 16:12:07 -0700 Subject: Massive refactoring to introduce the concept of IBackend --- .../Bind/ConfigurationCallback.cs | 91 ++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/WixToolset.Core.WindowsInstaller/Bind/ConfigurationCallback.cs (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/ConfigurationCallback.cs') diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/ConfigurationCallback.cs b/src/WixToolset.Core.WindowsInstaller/Bind/ConfigurationCallback.cs new file mode 100644 index 00000000..d4d3799f --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/Bind/ConfigurationCallback.cs @@ -0,0 +1,91 @@ +// 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.WindowsInstaller.Databases +{ + using System; + using System.Collections; + using System.Globalization; + using WixToolset.MergeMod; + + /// + /// Callback object for configurable merge modules. + /// + internal sealed class ConfigurationCallback : IMsmConfigureModule + { + private const int SOk = 0x0; + private const int SFalse = 0x1; + private Hashtable configurationData; + + /// + /// Creates a ConfigurationCallback object. + /// + /// String to break up into name/value pairs. + public ConfigurationCallback(string configData) + { + if (String.IsNullOrEmpty(configData)) + { + throw new ArgumentNullException("configData"); + } + + string[] pairs = configData.Split(','); + this.configurationData = new Hashtable(pairs.Length); + for (int i = 0; i < pairs.Length; ++i) + { + string[] nameVal = pairs[i].Split('='); + string name = nameVal[0]; + string value = nameVal[1]; + + name = name.Replace("%2C", ","); + name = name.Replace("%3D", "="); + name = name.Replace("%25", "%"); + + value = value.Replace("%2C", ","); + value = value.Replace("%3D", "="); + value = value.Replace("%25", "%"); + + this.configurationData[name] = value; + } + } + + /// + /// Returns text data based on name. + /// + /// Name of value to return. + /// Out param to put configuration data into. + /// S_OK if value provided, S_FALSE if not. + public int ProvideTextData(string name, out string configData) + { + if (this.configurationData.Contains(name)) + { + configData = (string)this.configurationData[name]; + return SOk; + } + else + { + configData = null; + return SFalse; + } + } + + /// + /// Returns integer data based on name. + /// + /// Name of value to return. + /// Out param to put configuration data into. + /// S_OK if value provided, S_FALSE if not. + public int ProvideIntegerData(string name, out int configData) + { + if (this.configurationData.Contains(name)) + { + string val = (string)this.configurationData[name]; + configData = Convert.ToInt32(val, CultureInfo.InvariantCulture); + return SOk; + } + else + { + configData = 0; + return SFalse; + } + } + } +} -- cgit v1.2.3-55-g6feb