diff options
Diffstat (limited to 'src/WixToolset.Core/Compiler_Bundle.cs')
| -rw-r--r-- | src/WixToolset.Core/Compiler_Bundle.cs | 142 |
1 files changed, 110 insertions, 32 deletions
diff --git a/src/WixToolset.Core/Compiler_Bundle.cs b/src/WixToolset.Core/Compiler_Bundle.cs index a840e448..5d7072d0 100644 --- a/src/WixToolset.Core/Compiler_Bundle.cs +++ b/src/WixToolset.Core/Compiler_Bundle.cs | |||
| @@ -323,6 +323,12 @@ namespace WixToolset.Core | |||
| 323 | case "RelatedBundle": | 323 | case "RelatedBundle": |
| 324 | this.ParseRelatedBundleElement(child); | 324 | this.ParseRelatedBundleElement(child); |
| 325 | break; | 325 | break; |
| 326 | case "SetVariable": | ||
| 327 | this.ParseSetVariableElement(child); | ||
| 328 | break; | ||
| 329 | case "SetVariableRef": | ||
| 330 | this.ParseSimpleRefElement(child, "WixSetVariable"); | ||
| 331 | break; | ||
| 326 | case "Update": | 332 | case "Update": |
| 327 | this.ParseUpdateElement(child); | 333 | this.ParseUpdateElement(child); |
| 328 | break; | 334 | break; |
| @@ -2705,6 +2711,78 @@ namespace WixToolset.Core | |||
| 2705 | } | 2711 | } |
| 2706 | 2712 | ||
| 2707 | /// <summary> | 2713 | /// <summary> |
| 2714 | /// Parse SetVariable element | ||
| 2715 | /// </summary> | ||
| 2716 | /// <param name="node">Element to parse</param> | ||
| 2717 | private void ParseSetVariableElement(XElement node) | ||
| 2718 | { | ||
| 2719 | var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); | ||
| 2720 | Identifier id = null; | ||
| 2721 | string variable = null; | ||
| 2722 | string condition = null; | ||
| 2723 | string after = null; | ||
| 2724 | string value = null; | ||
| 2725 | string type = null; | ||
| 2726 | |||
| 2727 | foreach (var attrib in node.Attributes()) | ||
| 2728 | { | ||
| 2729 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || CompilerCore.WixNamespace == attrib.Name.Namespace) | ||
| 2730 | { | ||
| 2731 | switch (attrib.Name.LocalName) | ||
| 2732 | { | ||
| 2733 | case "Id": | ||
| 2734 | id = this.Core.GetAttributeIdentifier(sourceLineNumbers, attrib); | ||
| 2735 | break; | ||
| 2736 | case "Variable": | ||
| 2737 | variable = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | ||
| 2738 | break; | ||
| 2739 | case "Condition": | ||
| 2740 | condition = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | ||
| 2741 | break; | ||
| 2742 | case "After": | ||
| 2743 | after = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | ||
| 2744 | break; | ||
| 2745 | case "Value": | ||
| 2746 | value = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | ||
| 2747 | break; | ||
| 2748 | case "Type": | ||
| 2749 | type = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | ||
| 2750 | break; | ||
| 2751 | |||
| 2752 | default: | ||
| 2753 | this.Core.UnexpectedAttribute(node, attrib); | ||
| 2754 | break; | ||
| 2755 | } | ||
| 2756 | } | ||
| 2757 | else | ||
| 2758 | { | ||
| 2759 | this.Core.ParseExtensionAttribute(node, attrib, null); | ||
| 2760 | } | ||
| 2761 | } | ||
| 2762 | |||
| 2763 | type = this.ValidateVariableTypeWithValue(sourceLineNumbers, type, value); | ||
| 2764 | |||
| 2765 | this.Core.ParseForExtensionElements(node); | ||
| 2766 | |||
| 2767 | if (id == null) | ||
| 2768 | { | ||
| 2769 | id = this.Core.CreateIdentifier("sbv", variable, condition, after, value, type); | ||
| 2770 | } | ||
| 2771 | |||
| 2772 | this.Core.CreateWixSearchTuple(sourceLineNumbers, node.Name.LocalName, id, variable, condition, after); | ||
| 2773 | |||
| 2774 | if (!this.Messaging.EncounteredError) | ||
| 2775 | { | ||
| 2776 | var tuple = new WixSetVariableTuple(sourceLineNumbers, id) | ||
| 2777 | { | ||
| 2778 | Value = value, | ||
| 2779 | Type = type, | ||
| 2780 | }; | ||
| 2781 | this.Core.AddTuple(tuple); | ||
| 2782 | } | ||
| 2783 | } | ||
| 2784 | |||
| 2785 | /// <summary> | ||
| 2708 | /// Parse Variable element | 2786 | /// Parse Variable element |
| 2709 | /// </summary> | 2787 | /// </summary> |
| 2710 | /// <param name="node">Element to parse</param> | 2788 | /// <param name="node">Element to parse</param> |
| @@ -2764,64 +2842,64 @@ namespace WixToolset.Core | |||
| 2764 | this.Core.Write(ErrorMessages.ReservedNamespaceViolation(sourceLineNumbers, node.Name.LocalName, "Name", "Wix")); | 2842 | this.Core.Write(ErrorMessages.ReservedNamespaceViolation(sourceLineNumbers, node.Name.LocalName, "Name", "Wix")); |
| 2765 | } | 2843 | } |
| 2766 | 2844 | ||
| 2767 | if (null == type && null != value) | 2845 | type = this.ValidateVariableTypeWithValue(sourceLineNumbers, type, value); |
| 2846 | |||
| 2847 | this.Core.ParseForExtensionElements(node); | ||
| 2848 | |||
| 2849 | if (!this.Core.EncounteredError) | ||
| 2850 | { | ||
| 2851 | var tuple = new WixBundleVariableTuple(sourceLineNumbers, new Identifier(AccessModifier.Private, name)) | ||
| 2852 | { | ||
| 2853 | Value = value, | ||
| 2854 | Type = type, | ||
| 2855 | Hidden = hidden, | ||
| 2856 | Persisted = persisted | ||
| 2857 | }; | ||
| 2858 | |||
| 2859 | this.Core.AddTuple(tuple); | ||
| 2860 | } | ||
| 2861 | } | ||
| 2862 | |||
| 2863 | private string ValidateVariableTypeWithValue(SourceLineNumber sourceLineNumbers, string type, string value) | ||
| 2864 | { | ||
| 2865 | var newType = type; | ||
| 2866 | if (newType == null && value != null) | ||
| 2768 | { | 2867 | { |
| 2769 | // Infer the type from the current value... | 2868 | // Infer the type from the current value... |
| 2770 | if (value.StartsWith("v", StringComparison.OrdinalIgnoreCase)) | 2869 | if (value.StartsWith("v", StringComparison.OrdinalIgnoreCase)) |
| 2771 | { | 2870 | { |
| 2772 | // Version constructor does not support simple "v#" syntax so check to see if the value is | 2871 | // Version constructor does not support simple "v#" syntax so check to see if the value is |
| 2773 | // non-negative real quick. | 2872 | // non-negative real quick. |
| 2774 | if (Int32.TryParse(value.Substring(1), NumberStyles.None, CultureInfo.InvariantCulture.NumberFormat, out var number)) | 2873 | if (Int32.TryParse(value.Substring(1), NumberStyles.None, CultureInfo.InvariantCulture.NumberFormat, out var _)) |
| 2775 | { | 2874 | { |
| 2776 | type = "version"; | 2875 | newType = "version"; |
| 2777 | } | 2876 | } |
| 2778 | else | 2877 | else if (Version.TryParse(value.Substring(1), out var _)) |
| 2779 | { | 2878 | { |
| 2780 | // Sadly, Version doesn't have a TryParse() method until .NET 4, so we have to try/catch to see if it parses. | 2879 | newType = "version"; |
| 2781 | try | ||
| 2782 | { | ||
| 2783 | var version = new Version(value.Substring(1)); | ||
| 2784 | type = "version"; | ||
| 2785 | } | ||
| 2786 | catch (Exception) | ||
| 2787 | { | ||
| 2788 | } | ||
| 2789 | } | 2880 | } |
| 2790 | } | 2881 | } |
| 2791 | 2882 | ||
| 2792 | // Not a version, check for numeric. | 2883 | // Not a version, check for numeric. |
| 2793 | if (null == type) | 2884 | if (newType == null) |
| 2794 | { | 2885 | { |
| 2795 | if (Int64.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture.NumberFormat, out var number)) | 2886 | if (Int64.TryParse(value, NumberStyles.Integer, CultureInfo.InvariantCulture.NumberFormat, out var _)) |
| 2796 | { | 2887 | { |
| 2797 | type = "numeric"; | 2888 | newType = "numeric"; |
| 2798 | } | 2889 | } |
| 2799 | else | 2890 | else |
| 2800 | { | 2891 | { |
| 2801 | type = "string"; | 2892 | newType = "string"; |
| 2802 | } | 2893 | } |
| 2803 | } | 2894 | } |
| 2804 | } | 2895 | } |
| 2805 | 2896 | ||
| 2806 | if (null == value && null != type) | 2897 | if (value == null && newType != null) |
| 2807 | { | 2898 | { |
| 2808 | this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, "Variable", "Value", "Type")); | 2899 | this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, "Variable", "Value", "Type")); |
| 2809 | } | 2900 | } |
| 2810 | 2901 | ||
| 2811 | this.Core.ParseForExtensionElements(node); | 2902 | return newType; |
| 2812 | |||
| 2813 | if (!this.Core.EncounteredError) | ||
| 2814 | { | ||
| 2815 | var tuple = new WixBundleVariableTuple(sourceLineNumbers, new Identifier(AccessModifier.Private, name)) | ||
| 2816 | { | ||
| 2817 | Value = value, | ||
| 2818 | Type = type, | ||
| 2819 | Hidden = hidden, | ||
| 2820 | Persisted = persisted | ||
| 2821 | }; | ||
| 2822 | |||
| 2823 | this.Core.AddTuple(tuple); | ||
| 2824 | } | ||
| 2825 | } | 2903 | } |
| 2826 | 2904 | ||
| 2827 | private class RemotePayload | 2905 | private class RemotePayload |
