/// <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); }
/// <summary> /// Parses a SnapIn element. /// </summary> /// <param name="node">Element to parse.</param> /// <param name="fileId">Identifier for parent file.</param> /// <param name="componentId">Identifier for parent component.</param> private void ParseSnapInElement(XmlNode node, string fileId, string componentId) { SourceLineNumberCollection sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); string id = null; string assemblyName = null; string description = null; string descriptionIndirect = null; Version requiredPowerShellVersion = CompilerCore.IllegalVersion; string vendor = null; string vendorIndirect = null; Version version = CompilerCore.IllegalVersion; foreach (XmlAttribute attrib in node.Attributes) { if (0 == attrib.NamespaceURI.Length || attrib.NamespaceURI == this.schema.TargetNamespace) { switch (attrib.LocalName) { case "Id": id = this.Core.GetAttributeIdentifierValue(sourceLineNumbers, attrib); break; case "AssemblyName": assemblyName = this.Core.GetAttributeValue(sourceLineNumbers, attrib); break; case "Description": description = this.Core.GetAttributeValue(sourceLineNumbers, attrib); break; case "DescriptionIndirect": descriptionIndirect = this.Core.GetAttributeValue(sourceLineNumbers, attrib); break; case "RequiredPowerShellVersion": requiredPowerShellVersion = this.Core.GetAttributeVersionValue(sourceLineNumbers, attrib); break; case "Vendor": vendor = this.Core.GetAttributeValue(sourceLineNumbers, attrib); break; case "VendorIndirect": vendorIndirect = this.Core.GetAttributeValue(sourceLineNumbers, attrib); break; case "Version": version = this.Core.GetAttributeVersionValue(sourceLineNumbers, attrib); break; default: this.Core.UnexpectedAttribute(sourceLineNumbers, attrib); break; } } else { this.Core.UnsupportedExtensionAttribute(sourceLineNumbers, attrib); } } if (null == id) { this.Core.OnMessage(WixErrors.ExpectedAttribute(sourceLineNumbers, node.Name, "Id")); } // Default to require PowerShell 1.0. if (CompilerCore.IllegalVersion == requiredPowerShellVersion) { requiredPowerShellVersion = new Version(1, 0); } // Get the snapin version. if (CompilerCore.IllegalVersion == version && null != assemblyName) { Match m = this.VersionRegex.Match(assemblyName); if (m.Success) { version = new Version(m.Groups["Version"].Value); } } if (CompilerCore.IllegalVersion == version) { this.Core.OnMessage(PSErrors.IllegalSnapInVersion(sourceLineNumbers, id)); } foreach (XmlNode child in node.ChildNodes) { if (XmlNodeType.Element == child.NodeType) { if (child.NamespaceURI == this.schema.TargetNamespace) { switch (child.LocalName) { case "FormatsFile": this.ParseExtensionsFile(child, "Formats", id, componentId); break; case "TypesFile": this.ParseExtensionsFile(child, "Types", id, componentId); break; default: this.Core.UnexpectedElement(node, child); break; } } else { this.Core.UnsupportedExtensionElement(node, child); } } } // Get the major part of the required PowerShell version which is // needed for the registry key, and put that into a WiX variable // for use in Formats and Types files. string major = requiredPowerShellVersion.Major.ToString(); WixVariableRow wixVariableRow = (WixVariableRow)this.Core.CreateRow(sourceLineNumbers, "WixVariable"); wixVariableRow.Id = string.Format(CultureInfo.InvariantCulture, "{0}_{1}", VarPrefix, id); wixVariableRow.Value = major; wixVariableRow.Overridable = false; int registryRoot = 2; // HKLM string registryKey = string.Format(CultureInfo.InvariantCulture, KeyFormat, major, id); this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "ApplicationBase", string.Format(CultureInfo.InvariantCulture, "[${0}]", componentId), componentId, false); if (null != assemblyName) { this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "AssemblyName", assemblyName, componentId, false); } if (null != description) { this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "Description", description, componentId, false); } if (null != descriptionIndirect) { this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "DescriptionIndirect", descriptionIndirect, componentId, false); } this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "ModuleName", string.Format(CultureInfo.InvariantCulture, "[#{0}]", fileId), componentId, false); // Create PowerShellVersion row and import appropriate AppSearch. string requiredVersion = requiredPowerShellVersion.ToString(2); this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "PowerShellVersion", requiredVersion, componentId, false); this.Core.CreateWixSimpleReferenceRow(sourceLineNumbers, "Property", string.Concat("POWERSHELL", requiredVersion)); if (null != vendor) { this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "Vendor", vendor, componentId, false); } if (null != vendorIndirect) { this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "VendorIndirect", vendorIndirect, componentId, false); } if (null != version) { this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "Version", version.ToString(), componentId, false); } }