Ejemplo n.º 1
0
        /// <summary>
        /// Parses a FormatsFile and TypesFile element.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        /// <param name="valueName">Registry value name.</param>
        /// <param name="id">Idendifier for parent file or snap-in.</param>
        /// <param name="componentId">Identifier for parent component.</param>
        private void ParseExtensionsFile(XmlNode node, string valueName, string id, string componentId)
        {
            SourceLineNumberCollection sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);
            string fileId = null;
            string snapIn = null;

            foreach (XmlAttribute attrib in node.Attributes)
            {
                if (0 == attrib.NamespaceURI.Length || attrib.NamespaceURI == this.schema.TargetNamespace)
                {
                    switch (attrib.LocalName)
                    {
                    case "FileId":
                        fileId = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
                        snapIn = id;
                        break;

                    case "SnapIn":
                        fileId = id;
                        snapIn = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
                        break;

                    default:
                        this.Core.UnexpectedAttribute(sourceLineNumbers, attrib);
                        break;
                    }
                }
                else
                {
                    this.Core.UnsupportedExtensionAttribute(sourceLineNumbers, attrib);
                }
            }

            if (null == fileId && null == snapIn)
            {
                this.Core.OnMessage(PSErrors.NeitherIdSpecified(sourceLineNumbers, valueName));
            }

            foreach (XmlNode child in node.ChildNodes)
            {
                if (XmlNodeType.Element == child.NodeType)
                {
                    if (child.NamespaceURI == this.schema.TargetNamespace)
                    {
                        this.Core.UnexpectedElement(node, child);
                    }
                    else
                    {
                        this.Core.UnsupportedExtensionElement(node, child);
                    }
                }
            }

            int    registryRoot = 2; // HKLM
            string registryKey  = string.Format(CultureInfo.InvariantCulture, KeyFormat, string.Format(CultureInfo.InvariantCulture, "!(wix.{0}_{1})", VarPrefix, snapIn), snapIn);

            this.Core.CreateWixSimpleReferenceRow(sourceLineNumbers, "File", fileId);
            this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, valueName, string.Format(CultureInfo.InvariantCulture, "[~][#{0}]", fileId), componentId, false);
        }
        /// <summary>
        /// Parses a FormatsFile and TypesFile element.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        /// <param name="valueName">Registry value name.</param>
        /// <param name="id">Idendifier for parent file or snap-in.</param>
        /// <param name="componentId">Identifier for parent component.</param>
        private void ParseExtensionsFile(XElement node, string valueName, string id, string componentId)
        {
            SourceLineNumber sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);
            string           fileId            = null;
            string           snapIn            = null;

            foreach (XAttribute attrib in node.Attributes())
            {
                if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace)
                {
                    switch (attrib.Name.LocalName)
                    {
                    case "FileId":
                        fileId = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
                        snapIn = id;
                        break;

                    case "SnapIn":
                        fileId = id;
                        snapIn = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
                        break;

                    default:
                        this.Core.UnexpectedAttribute(node, attrib);
                        break;
                    }
                }
                else
                {
                    this.Core.ParseExtensionAttribute(node, attrib);
                }
            }

            if (null == fileId && null == snapIn)
            {
                this.Core.OnMessage(PSErrors.NeitherIdSpecified(sourceLineNumbers, valueName));
            }

            this.Core.ParseForExtensionElements(node);

            int    registryRoot = 2; // HKLM
            string registryKey  = String.Format(CultureInfo.InvariantCulture, KeyFormat, String.Format(CultureInfo.InvariantCulture, "!(wix.{0}_{1})", VarPrefix, snapIn), snapIn);

            this.Core.CreateSimpleReference(sourceLineNumbers, "File", fileId);
            this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, valueName, String.Format(CultureInfo.InvariantCulture, "[~][#{0}]", fileId), componentId, false);
        }