/// <summary> /// Parse a localization string. /// </summary> /// <param name="node">Element to parse.</param> private void ParseString(XmlNode node) { string id = null; bool overridable = false; SourceLineNumberCollection sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); foreach (XmlAttribute attrib in node.Attributes) { if (0 == attrib.NamespaceURI.Length || attrib.NamespaceURI == Localization.XmlNamespaceUri) { switch (attrib.LocalName) { case "Id": id = Common.GetAttributeIdentifierValue(sourceLineNumbers, attrib, null); break; case "Overridable": overridable = Common.IsYes(sourceLineNumbers, "String", attrib.Name, attrib.Value); break; case "Localizable": ; // do nothing break; default: throw new WixException(WixErrors.UnexpectedAttribute(sourceLineNumbers, attrib.OwnerElement.Name, attrib.Name)); } } else { throw new WixException(WixErrors.UnsupportedExtensionAttribute(sourceLineNumbers, attrib.OwnerElement.Name, attrib.Name)); } } string value = node.InnerText; if (null == id) { throw new WixException(WixErrors.ExpectedAttribute(sourceLineNumbers, "String", "Id")); } 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)); } }
/// <summary> /// Parse a localized control. /// </summary> /// <param name="node">Element to parse.</param> /// <param name="localization">The localization being parsed.</param> private void ParseUI(XmlNode node) { string dialog = null; string control = null; int x = CompilerCore.IntegerNotSet; int y = CompilerCore.IntegerNotSet; int width = CompilerCore.IntegerNotSet; int height = CompilerCore.IntegerNotSet; int attribs = 0; string text = null; SourceLineNumberCollection sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); foreach (XmlAttribute attrib in node.Attributes) { if (0 == attrib.NamespaceURI.Length || attrib.NamespaceURI == Localization.XmlNamespaceUri) { switch (attrib.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: throw new WixException(WixErrors.UnexpectedAttribute(sourceLineNumbers, attrib.OwnerElement.Name, attrib.Name)); } } else { throw new WixException(WixErrors.UnsupportedExtensionAttribute(sourceLineNumbers, attrib.OwnerElement.Name, attrib.Name)); } } text = node.InnerText; if (String.IsNullOrEmpty(control) && 0 < attribs) { if (MsiInterop.MsidbControlAttributesRTLRO == (attribs & MsiInterop.MsidbControlAttributesRTLRO)) { throw new WixException(WixErrors.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name, "RightToLeft", "Control")); } else if (MsiInterop.MsidbControlAttributesRightAligned == (attribs & MsiInterop.MsidbControlAttributesRightAligned)) { throw new WixException(WixErrors.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name, "RightAligned", "Control")); } else if (MsiInterop.MsidbControlAttributesLeftScroll == (attribs & MsiInterop.MsidbControlAttributesLeftScroll)) { throw new WixException(WixErrors.IllegalAttributeWithoutOtherAttributes(sourceLineNumbers, node.Name, "LeftScroll", "Control")); } } if (String.IsNullOrEmpty(control) && String.IsNullOrEmpty(dialog)) { throw new WixException(WixErrors.ExpectedAttributesWithOtherAttribute(sourceLineNumbers, node.Name, "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)); }