From dcfc3e2e369958d58dc070e3dbb8992e147b7a05 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sat, 19 Jan 2019 12:11:35 -0600 Subject: Import code from old v4 repo --- src/wixext/PSCompiler.cs | 290 +++++++++++++++++++++++++++++++++++++++ src/wixext/PSExtensionData.cs | 34 +++++ src/wixext/WixPSExtension.csproj | 43 ++++++ src/wixext/messages.xml | 20 +++ src/wixext/ps.xsd | 191 ++++++++++++++++++++++++++ src/wixlib/PSExtension.wixproj | 19 +++ src/wixlib/PSExtension.wxs | 12 ++ 7 files changed, 609 insertions(+) create mode 100644 src/wixext/PSCompiler.cs create mode 100644 src/wixext/PSExtensionData.cs create mode 100644 src/wixext/WixPSExtension.csproj create mode 100644 src/wixext/messages.xml create mode 100644 src/wixext/ps.xsd create mode 100644 src/wixlib/PSExtension.wixproj create mode 100644 src/wixlib/PSExtension.wxs (limited to 'src') diff --git a/src/wixext/PSCompiler.cs b/src/wixext/PSCompiler.cs new file mode 100644 index 00000000..61eb287c --- /dev/null +++ b/src/wixext/PSCompiler.cs @@ -0,0 +1,290 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Extensions +{ + using System; + using System.Collections.Generic; + using System.Globalization; + using System.Xml.Linq; + using WixToolset.Data; + using WixToolset.Data.Rows; + using WixToolset.Extensibility; + + /// + /// The compiler for the WiX Toolset Internet Information Services Extension. + /// + public sealed class PSCompiler : CompilerExtension + { + private const string KeyFormat = @"SOFTWARE\Microsoft\PowerShell\{0}\PowerShellSnapIns\{1}"; + private const string VarPrefix = "PSVersionMajor"; + + /// + /// Instantiate a new PSCompiler. + /// + public PSCompiler() + { + this.Namespace = "http://wixtoolset.org/schemas/v4/wxs/powershell"; + } + + /// + /// Processes an element for the Compiler. + /// + /// Source line number for the parent element. + /// Parent element of element to process. + /// Element to process. + /// Extra information about the context in which this element is being parsed. + public override void ParseElement(XElement parentElement, XElement element, IDictionary context) + { + switch (parentElement.Name.LocalName) + { + case "File": + string fileId = context["FileId"]; + string componentId = context["ComponentId"]; + + switch (element.Name.LocalName) + { + case "FormatsFile": + this.ParseExtensionsFile(element, "Formats", fileId, componentId); + break; + + case "SnapIn": + this.ParseSnapInElement(element, fileId, componentId); + break; + + case "TypesFile": + this.ParseExtensionsFile(element, "Types", fileId, componentId); + break; + + default: + this.Core.UnexpectedElement(parentElement, element); + break; + } + break; + + default: + this.Core.UnexpectedElement(parentElement, element); + break; + } + } + + /// + /// Parses a SnapIn element. + /// + /// Element to parse. + /// Identifier for parent file. + /// Identifier for parent component. + private void ParseSnapInElement(XElement node, string fileId, string componentId) + { + SourceLineNumber sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); + string id = null; + string assemblyName = null; + string customSnapInType = null; + string description = null; + string descriptionIndirect = null; + Version requiredPowerShellVersion = CompilerConstants.IllegalVersion; + string vendor = null; + string vendorIndirect = null; + string version = null; + + foreach (XAttribute attrib in node.Attributes()) + { + if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || this.Namespace == attrib.Name.Namespace) + { + switch (attrib.Name.LocalName) + { + case "Id": + id = this.Core.GetAttributeIdentifierValue(sourceLineNumbers, attrib); + break; + + case "CustomSnapInType": + customSnapInType = 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": + string ver = this.Core.GetAttributeVersionValue(sourceLineNumbers, attrib); + requiredPowerShellVersion = new Version(ver); + 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(node, attrib); + break; + } + } + else + { + this.Core.ParseExtensionAttribute(node, attrib); + } + } + + if (null == id) + { + this.Core.OnMessage(WixErrors.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id")); + } + + // Default to require PowerShell 1.0. + if (CompilerConstants.IllegalVersion == requiredPowerShellVersion) + { + requiredPowerShellVersion = new Version(1, 0); + } + + // If the snap-in version isn't explicitly specified, get it + // from the assembly version at bind time. + if (null == version) + { + version = String.Format("!(bind.assemblyVersion.{0})", fileId); + } + + foreach (XElement child in node.Elements()) + { + if (this.Namespace == child.Name.Namespace) + { + switch (child.Name.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.ParseExtensionElement(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. PowerShell v2 still uses 1. + int major = (2 == requiredPowerShellVersion.Major) ? 1 : requiredPowerShellVersion.Major; + + WixVariableRow wixVariableRow = (WixVariableRow)this.Core.CreateRow(sourceLineNumbers, "WixVariable"); + wixVariableRow.Id = String.Format(CultureInfo.InvariantCulture, "{0}_{1}", VarPrefix, id); + wixVariableRow.Value = major.ToString(CultureInfo.InvariantCulture); + 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); + + // set the assembly name automatically when binding. + // processorArchitecture is not handled correctly by PowerShell v1.0 + // so format the assembly name explicitly. + assemblyName = String.Format(CultureInfo.InvariantCulture, "!(bind.assemblyName.{0}), Version=!(bind.assemblyVersion.{0}), Culture=!(bind.assemblyCulture.{0}), PublicKeyToken=!(bind.assemblyPublicKeyToken.{0})", fileId); + this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "AssemblyName", assemblyName, componentId, false); + + if (null != customSnapInType) + { + this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "CustomPSSnapInType", customSnapInType, 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); + + this.Core.CreateRegistryRow(sourceLineNumbers, registryRoot, registryKey, "PowerShellVersion", requiredPowerShellVersion.ToString(2), componentId, false); + + 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, componentId, false); + } + } + + /// + /// Parses a FormatsFile and TypesFile element. + /// + /// Element to parse. + /// Registry value name. + /// Idendifier for parent file or snap-in. + /// Identifier for parent component. + 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); + } + } +} diff --git a/src/wixext/PSExtensionData.cs b/src/wixext/PSExtensionData.cs new file mode 100644 index 00000000..578bda91 --- /dev/null +++ b/src/wixext/PSExtensionData.cs @@ -0,0 +1,34 @@ +// Copyright (c) .NET Foundation and contributors. All rights reserved. Licensed under the Microsoft Reciprocal License. See LICENSE.TXT file in the project root for full license information. + +namespace WixToolset.Extensions +{ + using System; + using System.Reflection; + using WixToolset.Data; + using WixToolset.Extensibility; + + /// + /// The WiX Toolset PowerShell Extension. + /// + public sealed class PSExtensionData : ExtensionData + { + /// + /// Gets the library associated with this extension. + /// + /// The table definitions to use while loading the library. + /// The loaded library. + public override Library GetLibrary(TableDefinitionCollection tableDefinitions) + { + return PSExtensionData.GetExtensionLibrary(tableDefinitions); + } + + /// + /// Internal mechanism to access the extension's library. + /// + /// Extension's library. + internal static Library GetExtensionLibrary(TableDefinitionCollection tableDefinitions) + { + return ExtensionData.LoadLibraryHelper(Assembly.GetExecutingAssembly(), "WixToolset.Extensions.Data.ps.wixlib", tableDefinitions); + } + } +} diff --git a/src/wixext/WixPSExtension.csproj b/src/wixext/WixPSExtension.csproj new file mode 100644 index 00000000..f9349ef1 --- /dev/null +++ b/src/wixext/WixPSExtension.csproj @@ -0,0 +1,43 @@ + + + + + + + {6F1482DF-1598-4D88-BDAA-B9D0E0242139} + WixPSExtension + Library + WixToolset.Extensions + + + + + + + $(RootNamespace).Data.Messages.resources + + + $(RootNamespace).Xsd.ps.xsd + PreserveNewest + + + WixToolset.Data.Serialize + WixToolset.Extensions.Serialize.PS + + + Data\ps.wixlib + + + + + + + + + + false + + + + + diff --git a/src/wixext/messages.xml b/src/wixext/messages.xml new file mode 100644 index 00000000..ef715640 --- /dev/null +++ b/src/wixext/messages.xml @@ -0,0 +1,20 @@ + + + + + + + + Either the {0}/@FileId attribute must be specified if nested under a SnapIn element, or the {0}/@SnapIn attribute must be specified if nested under under a File element. + + + + + + + The SnapIn/@AssemblyName attribute is deprecated. It is assigned automatically. + + + + + diff --git a/src/wixext/ps.xsd b/src/wixext/ps.xsd new file mode 100644 index 00000000..0c4c2bef --- /dev/null +++ b/src/wixext/ps.xsd @@ -0,0 +1,191 @@ + + + + + + + + The source code schema for the WiX Toolset PowerShell Extension. + + + + + + + Identifies the parent File as a formats XML file for the referenced PowerShell snap-in. + + + + + A formats XML file that defines output formats for objects on the pipeline. + + + + + + + + Reference to the formats File ID. This is required when nested under the SnapIn element. + + + + + + + Reference to the PowerShell snap-in ID for which this formats file is associated. This is required when nested under the File element. + + + + + + + + + Identifies the parent File as a types XML file for the referenced PowerShell snap-in. + + + + + A types XML file used by the extensible type system. + + + + + + + + Reference to the types File ID. This is required when nested under the SnapIn element. + + + + + + + Reference to the PowerShell snap-in ID for which this types file is associated. This is required when nested under the File element. + + + + + + + + + Identifies the parent File as a PowerShell snap-in to be registered on the system. + + + + + PowerShell snap-ins + allow developers to extend the functionality of of the PowerShell engine. + Add this element to identify the parent File as a PowerShell snap-in that will + get registered on the system. + + + + + + + + + + + + The identifier for this PowerShell snap-in. + + + + + + + The fully-qualified name of the assembly. + + + + + + + + + + The full type name of a class that is used to register a list of cmdlets and providers. + + + + + + + A brief description of the snap-in. + + + + + + + An embedded resource that contains a brief description of the snap-in. + This resource must be embedded in the current snap-in assembly. + + + + + + + The required version of PowerShell that must be installed and is associated with the + snap-in registration. The default value is "1.0". + + + + + + + The name of the snap-in vendor. + + + + + + + An embedded resource that contains the name of the snap-in vendor. + This resource must be embedded in the current snap-in assembly. + + + + + + + The version of the snapin. If not specified, this is taken from the assembly name. + + + + + + + + + + Values should be in the format ResourceName,StringName, where ResourceName + is the name of the embedded resource in your assembly sans the ".resources" extension, and StringName + is the name of the string resource in the embedded resource. + + + Example: UtilityMshSnapInResources,Description + + + + + + + + + Values of this type will look like: "x", "x.x", "x.x.x", or "x.x.x.x" where x is an integer from 0 to 65534. + + + + + + + diff --git a/src/wixlib/PSExtension.wixproj b/src/wixlib/PSExtension.wixproj new file mode 100644 index 00000000..da2b6463 --- /dev/null +++ b/src/wixlib/PSExtension.wixproj @@ -0,0 +1,19 @@ + + + + + + + {9d4ccdfc-840c-4d4e-a9b0-3d6015480645} + ps + Library + true + true + + + + + + + + diff --git a/src/wixlib/PSExtension.wxs b/src/wixlib/PSExtension.wxs new file mode 100644 index 00000000..a1f16ee6 --- /dev/null +++ b/src/wixlib/PSExtension.wxs @@ -0,0 +1,12 @@ + + + + + + + + + + + + -- cgit v1.2.3-55-g6feb