Example #1
0
        /// <summary>
        /// Parse a localized control.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        /// <param name="localizedControls">Dictionary of localized controls.</param>
        private static void ParseUI(IMessaging messaging, XElement node, IDictionary <string, LocalizedControl> localizedControls)
        {
            string           dialog            = null;
            string           control           = null;
            int              x                 = CompilerConstants.IntegerNotSet;
            int              y                 = CompilerConstants.IntegerNotSet;
            int              width             = CompilerConstants.IntegerNotSet;
            int              height            = CompilerConstants.IntegerNotSet;
            int              attribs           = 0;
            string           text              = null;
            SourceLineNumber sourceLineNumbers = SourceLineNumber.CreateFromXObject(node);

            foreach (XAttribute attrib in node.Attributes())
            {
                if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || Localizer.WxlNamespace == attrib.Name.Namespace)
                {
                    switch (attrib.Name.LocalName)
                    {
                    case "Dialog":
                        dialog = Common.GetAttributeIdentifierValue(messaging, sourceLineNumbers, attrib);
                        break;

                    case "Control":
                        control = Common.GetAttributeIdentifierValue(messaging, sourceLineNumbers, attrib);
                        break;

                    case "X":
                        x = Common.GetAttributeIntegerValue(messaging, sourceLineNumbers, attrib, 0, short.MaxValue);
                        break;

                    case "Y":
                        y = Common.GetAttributeIntegerValue(messaging, sourceLineNumbers, attrib, 0, short.MaxValue);
                        break;

                    case "Width":
                        width = Common.GetAttributeIntegerValue(messaging, sourceLineNumbers, attrib, 0, short.MaxValue);
                        break;

                    case "Height":
                        height = Common.GetAttributeIntegerValue(messaging, sourceLineNumbers, attrib, 0, short.MaxValue);
                        break;

                    case "RightToLeft":
                        if (YesNoType.Yes == Common.GetAttributeYesNoValue(messaging, sourceLineNumbers, attrib))
                        {
                            attribs |= MsiInterop.MsidbControlAttributesRTLRO;
                        }
                        break;

                    case "RightAligned":
                        if (YesNoType.Yes == Common.GetAttributeYesNoValue(messaging, sourceLineNumbers, attrib))
                        {
                            attribs |= MsiInterop.MsidbControlAttributesRightAligned;
                        }
                        break;

                    case "LeftScroll":
                        if (YesNoType.Yes == Common.GetAttributeYesNoValue(messaging, sourceLineNumbers, attrib))
                        {
                            attribs |= MsiInterop.MsidbControlAttributesLeftScroll;
                        }
                        break;

                    default:
                        Common.UnexpectedAttribute(messaging, sourceLineNumbers, attrib);
                        break;
                    }
                }
                else
                {
                    Common.UnexpectedAttribute(messaging, sourceLineNumbers, attrib);
                }
            }

            text = Common.GetInnerText(node);

            if (String.IsNullOrEmpty(control) && 0 < attribs)
            {
                if (MsiInterop.MsidbControlAttributesRTLRO == (attribs & MsiInterop.MsidbControlAttributesRTLRO))
                {
                    messaging.Write(ErrorMessages.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.ToString(), "RightToLeft", "Control"));
                }
                else if (MsiInterop.MsidbControlAttributesRightAligned == (attribs & MsiInterop.MsidbControlAttributesRightAligned))
                {
                    messaging.Write(ErrorMessages.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.ToString(), "RightAligned", "Control"));
                }
                else if (MsiInterop.MsidbControlAttributesLeftScroll == (attribs & MsiInterop.MsidbControlAttributesLeftScroll))
                {
                    messaging.Write(ErrorMessages.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.ToString(), "LeftScroll", "Control"));
                }
            }

            if (String.IsNullOrEmpty(control) && String.IsNullOrEmpty(dialog))
            {
                messaging.Write(ErrorMessages.ExpectedAttributesWithOtherAttribute(sourceLineNumbers, node.Name.ToString(), "Dialog", "Control"));
            }

            if (!messaging.EncounteredError)
            {
                LocalizedControl localizedControl = new LocalizedControl(dialog, control, x, y, width, height, attribs, text);
                string           key = localizedControl.GetKey();
                if (localizedControls.ContainsKey(key))
                {
                    if (String.IsNullOrEmpty(localizedControl.Control))
                    {
                        messaging.Write(ErrorMessages.DuplicatedUiLocalization(sourceLineNumbers, localizedControl.Dialog));
                    }
                    else
                    {
                        messaging.Write(ErrorMessages.DuplicatedUiLocalization(sourceLineNumbers, localizedControl.Dialog, localizedControl.Control));
                    }
                }
                else
                {
                    localizedControls.Add(key, localizedControl);
                }
            }
        }
Example #2
0
        /// <summary>
        /// Parses the WixLocalization element.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        private static Localization ParseWixLocalizationElement(IMessaging messaging, XElement node)
        {
            int              codepage          = -1;
            string           culture           = null;
            SourceLineNumber sourceLineNumbers = SourceLineNumber.CreateFromXObject(node);

            foreach (XAttribute attrib in node.Attributes())
            {
                if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || Localizer.WxlNamespace == attrib.Name.Namespace)
                {
                    switch (attrib.Name.LocalName)
                    {
                    case "Codepage":
                        codepage = Common.GetValidCodePage(attrib.Value, true, false, sourceLineNumbers);
                        break;

                    case "Culture":
                        culture = attrib.Value;
                        break;

                    case "Language":
                        // do nothing; @Language is used for locutil which can't convert Culture to lcid
                        break;

                    default:
                        Common.UnexpectedAttribute(messaging, sourceLineNumbers, attrib);
                        break;
                    }
                }
                else
                {
                    Common.UnexpectedAttribute(messaging, sourceLineNumbers, attrib);
                }
            }

            Dictionary <string, BindVariable>     variables         = new Dictionary <string, BindVariable>();
            Dictionary <string, LocalizedControl> localizedControls = new Dictionary <string, LocalizedControl>();

            foreach (XElement child in node.Elements())
            {
                if (Localizer.WxlNamespace == child.Name.Namespace)
                {
                    switch (child.Name.LocalName)
                    {
                    case "String":
                        Localizer.ParseString(messaging, child, variables);
                        break;

                    case "UI":
                        Localizer.ParseUI(messaging, child, localizedControls);
                        break;

                    default:
                        messaging.Write(ErrorMessages.UnexpectedElement(sourceLineNumbers, node.Name.ToString(), child.Name.ToString()));
                        break;
                    }
                }
                else
                {
                    messaging.Write(ErrorMessages.UnsupportedExtensionElement(sourceLineNumbers, node.Name.ToString(), child.Name.ToString()));
                }
            }

            return(messaging.EncounteredError ? null : new Localization(codepage, culture, variables, localizedControls));
        }
Example #3
0
        /// <summary>
        /// Parse a localized control.
        /// </summary>
        /// <param name="messaging"></param>
        /// <param name="node">Element to parse.</param>
        /// <param name="localizedControls">Dictionary of localized controls.</param>
        private static void ParseUI(IMessaging messaging, XElement node, IDictionary <string, LocalizedControl> localizedControls)
        {
            string dialog            = null;
            string control           = null;
            var    x                 = CompilerConstants.IntegerNotSet;
            var    y                 = CompilerConstants.IntegerNotSet;
            var    width             = CompilerConstants.IntegerNotSet;
            var    height            = CompilerConstants.IntegerNotSet;
            var    sourceLineNumbers = SourceLineNumber.CreateFromXObject(node);
            var    rightToLeft       = false;
            var    rightAligned      = false;
            var    leftScroll        = false;

            foreach (var attrib in node.Attributes())
            {
                if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || LocalizationParser.WxlNamespace == attrib.Name.Namespace)
                {
                    switch (attrib.Name.LocalName)
                    {
                    case "Dialog":
                        dialog = Common.GetAttributeIdentifierValue(messaging, sourceLineNumbers, attrib);
                        break;

                    case "Control":
                        control = Common.GetAttributeIdentifierValue(messaging, sourceLineNumbers, attrib);
                        break;

                    case "X":
                        x = Common.GetAttributeIntegerValue(messaging, sourceLineNumbers, attrib, 0, Int16.MaxValue);
                        break;

                    case "Y":
                        y = Common.GetAttributeIntegerValue(messaging, sourceLineNumbers, attrib, 0, Int16.MaxValue);
                        break;

                    case "Width":
                        width = Common.GetAttributeIntegerValue(messaging, sourceLineNumbers, attrib, 0, Int16.MaxValue);
                        break;

                    case "Height":
                        height = Common.GetAttributeIntegerValue(messaging, sourceLineNumbers, attrib, 0, Int16.MaxValue);
                        break;

                    case "RightToLeft":
                        rightToLeft = YesNoType.Yes == Common.GetAttributeYesNoValue(messaging, sourceLineNumbers, attrib);
                        break;

                    case "RightAligned":
                        rightAligned = YesNoType.Yes == Common.GetAttributeYesNoValue(messaging, sourceLineNumbers, attrib);
                        break;

                    case "LeftScroll":
                        leftScroll = YesNoType.Yes == Common.GetAttributeYesNoValue(messaging, sourceLineNumbers, attrib);
                        break;

                    default:
                        Common.UnexpectedAttribute(messaging, sourceLineNumbers, attrib);
                        break;
                    }
                }
                else
                {
                    Common.UnexpectedAttribute(messaging, sourceLineNumbers, attrib);
                }
            }

            var text = Common.GetInnerText(node);

            if (String.IsNullOrEmpty(control) && (rightToLeft || rightAligned || leftScroll))
            {
                if (rightToLeft)
                {
                    messaging.Write(ErrorMessages.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.ToString(), "RightToLeft", "Control"));
                }

                if (rightAligned)
                {
                    messaging.Write(ErrorMessages.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.ToString(), "RightAligned", "Control"));
                }

                if (leftScroll)
                {
                    messaging.Write(ErrorMessages.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name.ToString(), "LeftScroll", "Control"));
                }
            }

            if (String.IsNullOrEmpty(control) && String.IsNullOrEmpty(dialog))
            {
                messaging.Write(ErrorMessages.ExpectedAttributesWithOtherAttribute(sourceLineNumbers, node.Name.ToString(), "Dialog", "Control"));
            }

            if (!messaging.EncounteredError)
            {
                var localizedControl = new LocalizedControl(dialog, control, x, y, width, height, rightToLeft, rightAligned, leftScroll, text);
                var key = localizedControl.GetKey();
                if (localizedControls.ContainsKey(key))
                {
                    if (String.IsNullOrEmpty(localizedControl.Control))
                    {
                        messaging.Write(ErrorMessages.DuplicatedUiLocalization(sourceLineNumbers, localizedControl.Dialog));
                    }
                    else
                    {
                        messaging.Write(ErrorMessages.DuplicatedUiLocalization(sourceLineNumbers, localizedControl.Dialog, localizedControl.Control));
                    }
                }
                else
                {
                    localizedControls.Add(key, localizedControl);
                }
            }
        }