aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Compiler_Bundle.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/Compiler_Bundle.cs')
-rw-r--r--src/WixToolset.Core/Compiler_Bundle.cs244
1 files changed, 244 insertions, 0 deletions
diff --git a/src/WixToolset.Core/Compiler_Bundle.cs b/src/WixToolset.Core/Compiler_Bundle.cs
index 31896a42..5154a72f 100644
--- a/src/WixToolset.Core/Compiler_Bundle.cs
+++ b/src/WixToolset.Core/Compiler_Bundle.cs
@@ -7,6 +7,7 @@ namespace WixToolset.Core
7 using System.Diagnostics; 7 using System.Diagnostics;
8 using System.Globalization; 8 using System.Globalization;
9 using System.IO; 9 using System.IO;
10 using System.Linq;
10 using System.Xml.Linq; 11 using System.Xml.Linq;
11 using WixToolset.Data; 12 using WixToolset.Data;
12 using WixToolset.Data.Burn; 13 using WixToolset.Data.Burn;
@@ -276,6 +277,9 @@ namespace WixToolset.Core
276 case "BootstrapperApplicationRef": 277 case "BootstrapperApplicationRef":
277 this.ParseBootstrapperApplicationRefElement(child); 278 this.ParseBootstrapperApplicationRefElement(child);
278 break; 279 break;
280 case "BundleCustomData":
281 this.ParseBundleCustomDataElement(child);
282 break;
279 case "BundleExtension": 283 case "BundleExtension":
280 this.ParseBundleExtensionElement(child); 284 this.ParseBundleExtensionElement(child);
281 break; 285 break;
@@ -767,6 +771,246 @@ namespace WixToolset.Core
767 } 771 }
768 } 772 }
769 773
774
775
776 /// <summary>
777 /// Parses a BundleCustomData element.
778 /// </summary>
779 /// <param name="node">Element to parse.</param>
780 private void ParseBundleCustomDataElement(XElement node)
781 {
782 var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);
783 string customDataId = null;
784 WixBundleCustomDataType? customDataType = null;
785 string extensionId = null;
786 var attributeDefinitions = new List<WixBundleCustomDataAttributeTuple>();
787
788 foreach (var attrib in node.Attributes())
789 {
790 if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || CompilerCore.WixNamespace == attrib.Name.Namespace)
791 {
792 switch (attrib.Name.LocalName)
793 {
794 case "Id":
795 customDataId = this.Core.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
796 break;
797 case "Type":
798 var typeValue = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
799 switch (typeValue)
800 {
801 case "bootstrapperApplication":
802 customDataType = WixBundleCustomDataType.BootstrapperApplication;
803 break;
804 case "bundleExtension":
805 customDataType = WixBundleCustomDataType.BundleExtension;
806 break;
807 default:
808 this.Core.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, node.Name.LocalName, "Type", typeValue, "bootstrapperApplication", "bundleExtension"));
809 customDataType = WixBundleCustomDataType.Unknown; // set a value to prevent expected attribute error below.
810 break;
811 }
812 break;
813 case "ExtensionId":
814 extensionId = this.Core.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
815 this.Core.CreateSimpleReference(sourceLineNumbers, TupleDefinitions.WixBundleExtension, extensionId);
816 break;
817 default:
818 this.Core.UnexpectedAttribute(node, attrib);
819 break;
820 }
821 }
822 else
823 {
824 this.Core.ParseExtensionAttribute(node, attrib);
825 }
826 }
827
828 if (null == customDataId)
829 {
830 this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id"));
831 }
832
833 var hasExtensionId = null != extensionId;
834 if (hasExtensionId && !customDataType.HasValue)
835 {
836 customDataType = WixBundleCustomDataType.BundleExtension;
837 }
838
839 if (!customDataType.HasValue)
840 {
841 this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Type"));
842 }
843 else if (hasExtensionId)
844 {
845 if (customDataType.Value == WixBundleCustomDataType.BootstrapperApplication)
846 {
847 this.Core.Write(ErrorMessages.IllegalAttributeWithOtherAttribute(sourceLineNumbers, node.Name.LocalName, "ExtensonId", "Type", "bootstrapperApplication"));
848 }
849 }
850 else if (customDataType.Value == WixBundleCustomDataType.BundleExtension)
851 {
852 this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "ExtensionId", "Type", "bundleExtension"));
853 }
854
855 foreach (var child in node.Elements())
856 {
857 if (CompilerCore.WixNamespace == child.Name.Namespace)
858 {
859 var childSourceLineNumbers = Preprocessor.GetSourceLineNumbers(child);
860 switch (child.Name.LocalName)
861 {
862 case "BundleAttributeDefinition":
863 var attributeDefinition = this.ParseBundleAttributeDefinitionElement(child, childSourceLineNumbers, customDataId);
864 if (attributeDefinition != null)
865 {
866 attributeDefinitions.Add(attributeDefinition);
867 }
868 break;
869 case "BundleElement":
870 this.ParseBundleElementElement(child, childSourceLineNumbers, customDataId);
871 break;
872 default:
873 this.Core.UnexpectedElement(node, child);
874 break;
875 }
876 }
877 else
878 {
879 this.Core.ParseExtensionElement(node, child);
880 }
881 }
882
883 if (attributeDefinitions.Count > 0)
884 {
885 if (!this.Core.EncounteredError)
886 {
887 var attributeNames = String.Join(new string(WixBundleCustomDataTuple.AttributeNamesSeparator, 1), attributeDefinitions.Select(c => c.Name));
888
889 this.Core.AddTuple(new WixBundleCustomDataTuple(sourceLineNumbers, new Identifier(AccessModifier.Public, customDataId))
890 {
891 AttributeNames = attributeNames,
892 Type = customDataType.Value,
893 BundleExtensionRef = extensionId,
894 });
895 }
896 }
897 }
898
899 /// <summary>
900 /// Parses a BundleAttributeDefinition element.
901 /// </summary>
902 /// <param name="node">Element to parse.</param>
903 /// <param name="sourceLineNumbers">Element's SourceLineNumbers.</param>
904 /// <param name="customDataId">BundleCustomData Id.</param>
905 private WixBundleCustomDataAttributeTuple ParseBundleAttributeDefinitionElement(XElement node, SourceLineNumber sourceLineNumbers, string customDataId)
906 {
907 string attributeName = null;
908
909 foreach (var attrib in node.Attributes())
910 {
911 switch (attrib.Name.LocalName)
912 {
913 case "Id":
914 attributeName = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
915 break;
916 default:
917 this.Core.UnexpectedAttribute(node, attrib);
918 break;
919 }
920 }
921
922 if (null == attributeName)
923 {
924 this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id"));
925 }
926
927 this.Core.ParseForExtensionElements(node);
928
929 if (this.Core.EncounteredError)
930 {
931 return null;
932 }
933
934 var customDataAttribute = this.Core.AddTuple(new WixBundleCustomDataAttributeTuple(sourceLineNumbers, new Identifier(AccessModifier.Private, customDataId, attributeName))
935 {
936 CustomDataRef = customDataId,
937 Name = attributeName,
938 });
939 return customDataAttribute;
940 }
941
942 /// <summary>
943 /// Parses a BundleElement element.
944 /// </summary>
945 /// <param name="node">Element to parse.</param>
946 /// <param name="sourceLineNumbers">Element's SourceLineNumbers.</param>
947 /// <param name="customDataId">BundleCustomData Id.</param>
948 private void ParseBundleElementElement(XElement node, SourceLineNumber sourceLineNumbers, string customDataId)
949 {
950 var elementId = Guid.NewGuid().ToString("N").ToUpperInvariant();
951
952 foreach (var attrib in node.Attributes())
953 {
954 this.Core.ParseExtensionAttribute(node, attrib);
955 }
956
957 foreach (var child in node.Elements())
958 {
959 var childSourceLineNumbers = Preprocessor.GetSourceLineNumbers(child);
960 switch (child.Name.LocalName)
961 {
962 case "BundleAttribute":
963 string attributeName = null;
964 string value = null;
965 foreach (var attrib in child.Attributes())
966 {
967 switch (attrib.Name.LocalName)
968 {
969 case "Id":
970 attributeName = this.Core.GetAttributeValue(childSourceLineNumbers, attrib);
971 break;
972 case "Value":
973 value = this.Core.GetAttributeValue(childSourceLineNumbers, attrib);
974 break;
975 default:
976 this.Core.ParseExtensionAttribute(child, attrib);
977 break;
978 }
979 }
980
981 if (null == attributeName)
982 {
983 this.Core.Write(ErrorMessages.ExpectedAttribute(childSourceLineNumbers, child.Name.LocalName, "Id"));
984 }
985
986 if (String.IsNullOrEmpty(value))
987 {
988 value = Common.GetInnerText(child);
989 }
990
991 if (!this.Core.EncounteredError)
992 {
993 this.Core.AddTuple(new WixBundleCustomDataCellTuple(childSourceLineNumbers, new Identifier(AccessModifier.Private, customDataId, elementId, attributeName))
994 {
995 ElementId = elementId,
996 AttributeRef = attributeName,
997 CustomDataRef = customDataId,
998 Value = value,
999 });
1000 }
1001 break;
1002 default:
1003 this.Core.UnexpectedElement(node, child);
1004 break;
1005 }
1006 }
1007
1008 if (!this.Core.EncounteredError)
1009 {
1010 this.Core.CreateSimpleReference(sourceLineNumbers, TupleDefinitions.WixBundleCustomData, customDataId);
1011 }
1012 }
1013
770 /// <summary> 1014 /// <summary>
771 /// Parse the BundleExtension element. 1015 /// Parse the BundleExtension element.
772 /// </summary> 1016 /// </summary>