Пример #1
0
        /// <summary>
        /// Parse a localization string into a WixVariableRow.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        private static void ParseString(XElement node, IDictionary <string, WixVariableRow> variables, TableDefinitionCollection tableDefinitions)
        {
            string           id                = null;
            bool             overridable       = false;
            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 "Id":
                        id = Common.GetAttributeIdentifierValue(sourceLineNumbers, attrib);
                        break;

                    case "Overridable":
                        overridable = YesNoType.Yes == Common.GetAttributeYesNoValue(sourceLineNumbers, attrib);
                        break;

                    case "Localizable":
                        ;     // do nothing
                        break;

                    default:
                        Messaging.Instance.OnMessage(WixErrors.UnexpectedAttribute(sourceLineNumbers, attrib.Parent.Name.ToString(), attrib.Name.ToString()));
                        break;
                    }
                }
                else
                {
                    Messaging.Instance.OnMessage(WixErrors.UnsupportedExtensionAttribute(sourceLineNumbers, attrib.Parent.Name.ToString(), attrib.Name.ToString()));
                }
            }

            string value = Common.GetInnerText(node);

            if (null == id)
            {
                Messaging.Instance.OnMessage(WixErrors.ExpectedAttribute(sourceLineNumbers, "String", "Id"));
            }
            else if (0 == id.Length)
            {
                Messaging.Instance.OnMessage(WixErrors.IllegalIdentifier(sourceLineNumbers, "String", "Id", 0));
            }

            if (!Messaging.Instance.EncounteredError)
            {
                WixVariableRow wixVariableRow = new WixVariableRow(sourceLineNumbers, tableDefinitions["WixVariable"]);
                wixVariableRow.Id          = id;
                wixVariableRow.Overridable = overridable;
                wixVariableRow.Value       = value;

                Localizer.AddWixVariable(variables, wixVariableRow);
            }
        }
Пример #2
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(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(sourceLineNumbers, attrib);
                        break;

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

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

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

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

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

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

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

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

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

            text = Common.GetInnerText(node);

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

            if (String.IsNullOrEmpty(control) && String.IsNullOrEmpty(dialog))
            {
                Messaging.Instance.OnMessage(WixErrors.ExpectedAttributesWithOtherAttribute(sourceLineNumbers, node.Name.ToString(), "Dialog", "Control"));
            }

            if (!Messaging.Instance.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.Instance.OnMessage(WixErrors.DuplicatedUiLocalization(sourceLineNumbers, localizedControl.Dialog));
                    }
                    else
                    {
                        Messaging.Instance.OnMessage(WixErrors.DuplicatedUiLocalization(sourceLineNumbers, localizedControl.Dialog, localizedControl.Control));
                    }
                }
                else
                {
                    localizedControls.Add(key, localizedControl);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// Parse a localized control.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        /// <param name="localization">The localization being parsed.</param>
        private void ParseUI(XElement node)
        {
            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 = Preprocessor.GetSourceLineNumbers(node);

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

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

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

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

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

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

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

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

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

                    default:
                        Common.UnexpectedAttribute(sourceLineNumbers, attrib, Localization.OnMessage);
                        break;
                    }
                }
                else
                {
                    Common.UnsupportedExtensionAttribute(sourceLineNumbers, attrib, Localization.OnMessage);
                }
            }

            text = Common.GetInnerText(node);

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

            if (String.IsNullOrEmpty(control) && String.IsNullOrEmpty(dialog))
            {
                throw new WixException(WixErrors.ExpectedAttributesWithOtherAttribute(sourceLineNumbers, node.Name.ToString(), "Dialog", "Control"));
            }

            string key = LocalizedControl.GetKey(dialog, control);

            if (this.localizedControls.ContainsKey(key))
            {
                if (String.IsNullOrEmpty(control))
                {
                    throw new WixException(WixErrors.DuplicatedUiLocalization(sourceLineNumbers, dialog));
                }
                else
                {
                    throw new WixException(WixErrors.DuplicatedUiLocalization(sourceLineNumbers, dialog, control));
                }
            }

            this.localizedControls.Add(key, new LocalizedControl(x, y, width, height, attribs, text));
        }
Пример #4
0
        /// <summary>
        /// Parse a localization string.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        private void ParseString(XElement node)
        {
            string           id                = null;
            bool             overridable       = false;
            SourceLineNumber sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);

            foreach (XAttribute attrib in node.Attributes())
            {
                if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || Localization.WxlNamespace == attrib.Name.Namespace)
                {
                    switch (attrib.Name.LocalName)
                    {
                    case "Id":
                        id = Common.GetAttributeIdentifierValue(sourceLineNumbers, attrib, null);
                        break;

                    case "Overridable":
                        overridable = YesNoType.Yes == Common.GetAttributeYesNoValue(sourceLineNumbers, attrib, null);
                        break;

                    case "Localizable":
                        ;     // do nothing
                        break;

                    default:
                        throw new WixException(WixErrors.UnexpectedAttribute(sourceLineNumbers, attrib.Parent.Name.ToString(), attrib.Name.ToString()));
                    }
                }
                else
                {
                    throw new WixException(WixErrors.UnsupportedExtensionAttribute(sourceLineNumbers, attrib.Parent.Name.ToString(), attrib.Name.ToString()));
                }
            }

            string value = Common.GetInnerText(node);

            if (null == id)
            {
                throw new WixException(WixErrors.ExpectedAttribute(sourceLineNumbers, "String", "Id"));
            }
            else if (0 == id.Length)
            {
                throw new WixException(WixErrors.IllegalIdentifier(sourceLineNumbers, "String", "Id", 0));
            }

            WixVariableRow wixVariableRow = new WixVariableRow(sourceLineNumbers, this.tableDefinitions["WixVariable"]);

            wixVariableRow.Id          = id;
            wixVariableRow.Overridable = overridable;
            wixVariableRow.Value       = value;

            WixVariableRow existingWixVariableRow = (WixVariableRow)this.variables[id];

            if (null == existingWixVariableRow || (existingWixVariableRow.Overridable && !overridable))
            {
                this.variables.Add(id, wixVariableRow);
            }
            else if (!overridable)
            {
                throw new WixException(WixErrors.DuplicateLocalizationIdentifier(sourceLineNumbers, id));
            }
        }