main
cs 90 lines 3.1 KB
Raw
1 // 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.
2
3 namespace WixToolset.Core.Native.Msm
4 {
5 using System;
6 using System.Collections;
7 using System.Globalization;
8
9 /// <summary>
10 /// Callback object for configurable merge modules.
11 /// </summary>
12 public sealed class ConfigurationCallback : IMsmConfigureModule
13 {
14 private const int SOk = 0x0;
15 private const int SFalse = 0x1;
16 private readonly Hashtable configurationData;
17
18 /// <summary>
19 /// Creates a ConfigurationCallback object.
20 /// </summary>
21 /// <param name="configData">String to break up into name/value pairs.</param>
22 public ConfigurationCallback(string configData)
23 {
24 if (String.IsNullOrEmpty(configData))
25 {
26 throw new ArgumentNullException(nameof(configData));
27 }
28
29 var pairs = configData.Split(',');
30 this.configurationData = new Hashtable(pairs.Length);
31 for (var i = 0; i < pairs.Length; ++i)
32 {
33 var nameVal = pairs[i].Split('=');
34 var name = nameVal[0];
35 var value = nameVal[1];
36
37 name = name.Replace("%2C", ",");
38 name = name.Replace("%3D", "=");
39 name = name.Replace("%25", "%");
40
41 value = value.Replace("%2C", ",");
42 value = value.Replace("%3D", "=");
43 value = value.Replace("%25", "%");
44
45 this.configurationData[name] = value;
46 }
47 }
48
49 /// <summary>
50 /// Returns text data based on name.
51 /// </summary>
52 /// <param name="name">Name of value to return.</param>
53 /// <param name="configData">Out param to put configuration data into.</param>
54 /// <returns>S_OK if value provided, S_FALSE if not.</returns>
55 public int ProvideTextData(string name, out string configData)
56 {
57 if (this.configurationData.Contains(name))
58 {
59 configData = (string)this.configurationData[name];
60 return SOk;
61 }
62 else
63 {
64 configData = null;
65 return SFalse;
66 }
67 }
68
69 /// <summary>
70 /// Returns integer data based on name.
71 /// </summary>
72 /// <param name="name">Name of value to return.</param>
73 /// <param name="configData">Out param to put configuration data into.</param>
74 /// <returns>S_OK if value provided, S_FALSE if not.</returns>
75 public int ProvideIntegerData(string name, out int configData)
76 {
77 if (this.configurationData.Contains(name))
78 {
79 var val = (string)this.configurationData[name];
80 configData = Convert.ToInt32(val, CultureInfo.InvariantCulture);
81 return SOk;
82 }
83 else
84 {
85 configData = 0;
86 return SFalse;
87 }
88 }
89 }
90 }