From dc9f4c329e6f55ce7595970463e0caf148096f4b Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Thu, 21 Dec 2017 13:42:52 -0800 Subject: Support wixout and extract Resolve and Layout from Binder --- .../Bind/BindDatabaseCommand.cs | 98 ++----------------- .../Bind/BindTransformCommand.cs | 2 +- .../Bind/CalculateComponentGuids.cs | 3 +- .../Bind/CopyTransformDataCommand.cs | 2 +- .../Bind/GenerateDatabaseCommand.cs | 2 +- .../Bind/PathResolver.cs | 105 +++++++++++++++++++++ .../Bind/ProcessUncompressedFilesCommand.cs | 11 +-- .../Bind/ResolvedDirectory.cs | 31 ++++++ src/WixToolset.Core.WindowsInstaller/MsiBackend.cs | 8 +- src/WixToolset.Core.WindowsInstaller/MsmBackend.cs | 8 +- src/WixToolset.Core.WindowsInstaller/MspBackend.cs | 2 +- src/WixToolset.Core.WindowsInstaller/MstBackend.cs | 1 - .../Unbind/UnbindTranformCommand.cs | 2 +- src/WixToolset.Core.WindowsInstaller/Validator.cs | 2 +- .../WindowsInstallerBackendFactory.cs | 1 - 15 files changed, 164 insertions(+), 114 deletions(-) create mode 100644 src/WixToolset.Core.WindowsInstaller/Bind/PathResolver.cs create mode 100644 src/WixToolset.Core.WindowsInstaller/Bind/ResolvedDirectory.cs (limited to 'src/WixToolset.Core.WindowsInstaller') diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs index 410e462a..2f161305 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs @@ -22,31 +22,27 @@ namespace WixToolset.Core.WindowsInstaller.Bind // As outlined in RFC 4122, this is our namespace for generating name-based (version 3) UUIDs. internal static readonly Guid WixComponentGuidNamespace = new Guid("{3064E5C6-FB63-4FE9-AC49-E446A792EFA5}"); - public BindDatabaseCommand(IBindContext context, IEnumerable backendExtension, Validator validator) + public BindDatabaseCommand(WixToolset.Extensibility.IBindContext context, IEnumerable backendExtension, Validator validator) { this.TableDefinitions = WindowsInstallerStandardInternal.GetTableDefinitions(); - this.BindPaths = context.BindPaths; this.CabbingThreadCount = context.CabbingThreadCount; this.CabCachePath = context.CabCachePath; this.Codepage = context.Codepage; this.DefaultCompressionLevel = context.DefaultCompressionLevel; this.DelayedFields = context.DelayedFields; this.ExpectedEmbeddedFiles = context.ExpectedEmbeddedFiles; - this.Extensions = context.Extensions; + this.FileSystemExtensions = context.FileSystemExtensions; this.Intermediate = context.IntermediateRepresentation; this.Messaging = context.Messaging; this.OutputPath = context.OutputPath; this.PdbFile = context.OutputPdbPath; this.IntermediateFolder = context.IntermediateFolder; this.Validator = validator; - this.WixVariableResolver = context.WixVariableResolver; - + this.BackendExtensions = backendExtension; } - private IEnumerable BindPaths { get; } - private int Codepage { get; } private int CabbingThreadCount { get; } @@ -59,12 +55,12 @@ namespace WixToolset.Core.WindowsInstaller.Bind public IEnumerable ExpectedEmbeddedFiles { get; } + public IEnumerable FileSystemExtensions { get; } + public bool DeltaBinaryPatch { get; set; } private IEnumerable BackendExtensions { get; } - private IEnumerable Extensions { get; } - private string PdbFile { get; } private Intermediate Intermediate { get; } @@ -83,7 +79,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind private Validator Validator { get; } - private IBindVariableResolver WixVariableResolver { get; } public IEnumerable FileTransfers { get; private set; } @@ -100,8 +95,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind // If there are any fields to resolve later, create the cache to populate during bind. var variableCache = this.DelayedFields.Any() ? new Dictionary(StringComparer.InvariantCultureIgnoreCase) : null; - this.LocalizeUI(section); - // Process the summary information table before the other tables. bool compressed; bool longNames; @@ -534,85 +527,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind intermediate.Save(Path.ChangeExtension(this.OutputPath, "wir")); } - /// - /// Localize dialogs and controls. - /// - /// The tables to localize. - private void LocalizeUI(IntermediateSection section) - { - foreach (var row in section.Tuples.OfType()) - { - string dialog = row.Dialog; - - if (this.WixVariableResolver.TryGetLocalizedControl(dialog, null, out LocalizedControl localizedControl)) - { - if (CompilerConstants.IntegerNotSet != localizedControl.X) - { - row.HCentering = localizedControl.X; - } - - if (CompilerConstants.IntegerNotSet != localizedControl.Y) - { - row.VCentering = localizedControl.Y; - } - - if (CompilerConstants.IntegerNotSet != localizedControl.Width) - { - row.Width = localizedControl.Width; - } - - if (CompilerConstants.IntegerNotSet != localizedControl.Height) - { - row.Height = localizedControl.Height; - } - - row.Attributes = row.Attributes | localizedControl.Attributes; - - if (!String.IsNullOrEmpty(localizedControl.Text)) - { - row.Title = localizedControl.Text; - } - } - } - - - foreach (var row in section.Tuples.OfType()) - { - string dialog = row.Dialog_; - string control = row.Control; - - if (this.WixVariableResolver.TryGetLocalizedControl(dialog, control, out LocalizedControl localizedControl)) - { - if (CompilerConstants.IntegerNotSet != localizedControl.X) - { - row.X = localizedControl.X; - } - - if (CompilerConstants.IntegerNotSet != localizedControl.Y) - { - row.Y = localizedControl.Y; - } - - if (CompilerConstants.IntegerNotSet != localizedControl.Width) - { - row.Width = localizedControl.Width; - } - - if (CompilerConstants.IntegerNotSet != localizedControl.Height) - { - row.Height = localizedControl.Height; - } - - row.Attributes = row.Attributes | localizedControl.Attributes; - - if (!String.IsNullOrEmpty(localizedControl.Text)) - { - row.Text = localizedControl.Text; - } - } - } - } - #if TODO_FINISH_PATCH /// /// Copy file data between transform substorages and the patch output object @@ -984,7 +898,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind private void GenerateDatabase(Output output, string databaseFile, bool keepAddedColumns, bool useSubdirectory) { var command = new GenerateDatabaseCommand(); - command.Extensions = this.Extensions; + command.Extensions = this.FileSystemExtensions; command.Output = output; command.OutputPath = databaseFile; command.KeepAddedColumns = keepAddedColumns; diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindTransformCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindTransformCommand.cs index 800ebac0..8cb0e0de 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindTransformCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindTransformCommand.cs @@ -15,7 +15,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind internal class BindTransformCommand { - public IEnumerable Extensions { private get; set; } + public IEnumerable Extensions { private get; set; } public TableDefinitionCollection TableDefinitions { private get; set; } diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs index 056f92a7..76747728 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs @@ -6,7 +6,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System.Collections.Generic; using System.IO; using System.Linq; - using WixToolset.Bind; using WixToolset.Core.Native; using WixToolset.Data; using WixToolset.Data.Tuples; @@ -135,7 +134,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind if (fileRow.File == componentRow.KeyPath) { // calculate the key file's canonical target path - string directoryPath = Binder.GetDirectoryPath(targetPathsByDirectoryId, componentIdGenSeeds, componentRow.Directory_, true); + string directoryPath = PathResolver.GetDirectoryPath(targetPathsByDirectoryId, componentIdGenSeeds, componentRow.Directory_, true); string fileName = Common.GetName(fileRow.LongFileName, false, true).ToLowerInvariant(); path = Path.Combine(directoryPath, fileName); diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs index 13408312..6ff03941 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CopyTransformDataCommand.cs @@ -18,7 +18,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind { public bool CopyOutFileRows { private get; set; } - public IEnumerable Extensions { private get; set; } + public IEnumerable Extensions { private get; set; } public IMessaging Messaging { private get; set; } diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/GenerateDatabaseCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/GenerateDatabaseCommand.cs index ee7cc61b..cc920ac2 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/GenerateDatabaseCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/GenerateDatabaseCommand.cs @@ -19,7 +19,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind { public int Codepage { private get; set; } - public IEnumerable Extensions { private get; set; } + public IEnumerable Extensions { private get; set; } /// /// Whether to keep columns added in a transform. diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/PathResolver.cs b/src/WixToolset.Core.WindowsInstaller/Bind/PathResolver.cs new file mode 100644 index 00000000..492c9137 --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/Bind/PathResolver.cs @@ -0,0 +1,105 @@ +// 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.Core.WindowsInstaller.Bind +{ + using System; + using System.Collections.Generic; + using System.IO; + using WixToolset.Data; + + internal static class PathResolver + { + /// + /// Get the source path of a directory. + /// + /// All cached directories. + /// Hash table of Component GUID generation seeds indexed by directory id. + /// Directory identifier. + /// Canonicalize the path for standard directories. + /// Source path of a directory. + public static string GetDirectoryPath(Dictionary directories, Dictionary componentIdGenSeeds, string directory, bool canonicalize) + { + if (!directories.TryGetValue(directory, out var resolvedDirectory)) + { + throw new WixException(ErrorMessages.ExpectedDirectory(directory)); + } + + if (null == resolvedDirectory.Path) + { + if (null != componentIdGenSeeds && componentIdGenSeeds.ContainsKey(directory)) + { + resolvedDirectory.Path = (string)componentIdGenSeeds[directory]; + } + else if (canonicalize && WindowsInstallerStandard.IsStandardDirectory(directory)) + { + // when canonicalization is on, standard directories are treated equally + resolvedDirectory.Path = directory; + } + else + { + string name = resolvedDirectory.Name; + + if (canonicalize) + { + name = name?.ToLowerInvariant(); + } + + if (String.IsNullOrEmpty(resolvedDirectory.DirectoryParent)) + { + resolvedDirectory.Path = name; + } + else + { + string parentPath = GetDirectoryPath(directories, componentIdGenSeeds, resolvedDirectory.DirectoryParent, canonicalize); + + if (null != resolvedDirectory.Name) + { + resolvedDirectory.Path = Path.Combine(parentPath, name); + } + else + { + resolvedDirectory.Path = parentPath; + } + } + } + } + + return resolvedDirectory.Path; + } + + /// + /// Gets the source path of a file. + /// + /// All cached directories in . + /// Parent directory identifier. + /// File name (in long|source format). + /// Specifies the package is compressed. + /// Specifies the package uses long file names. + /// Source path of file relative to package directory. + public static string GetFileSourcePath(Dictionary directories, string directoryId, string fileName, bool compressed, bool useLongName) + { + string fileSourcePath = Common.GetName(fileName, true, useLongName); + + if (compressed) + { + // Use just the file name of the file since all uncompressed files must appear + // in the root of the image in a compressed package. + } + else + { + // Get the relative path of where we want the file to be layed out as specified + // in the Directory table. + string directoryPath = PathResolver.GetDirectoryPath(directories, null, directoryId, false); + fileSourcePath = Path.Combine(directoryPath, fileSourcePath); + } + + // Strip off "SourceDir" if it's still on there. + if (fileSourcePath.StartsWith("SourceDir\\", StringComparison.Ordinal)) + { + fileSourcePath = fileSourcePath.Substring(10); + } + + return fileSourcePath; + } + } +} diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs index e1a26a67..39771508 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs @@ -5,14 +5,13 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System; using System.Collections.Generic; using System.IO; - using WixToolset.Data; - using WixToolset.Msi; - using WixToolset.Core.Native; - using WixToolset.Bind; + using System.Linq; using WixToolset.Core.Bind; + using WixToolset.Core.Native; + using WixToolset.Data; using WixToolset.Data.Bind; using WixToolset.Data.Tuples; - using System.Linq; + using WixToolset.Msi; /// /// Defines the file transfers necessary to layout the uncompressed files. @@ -100,7 +99,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind throw new WixException(ErrorMessages.FileIdentifierNotFound(facade.File.SourceLineNumbers, facade.File.File)); } - relativeFileLayoutPath = Binder.GetFileSourcePath(directories, fileRecord[1], fileRecord[2], this.Compressed, this.LongNamesInImage); + relativeFileLayoutPath = PathResolver.GetFileSourcePath(directories, fileRecord[1], fileRecord[2], this.Compressed, this.LongNamesInImage); } // finally put together the base media layout path and the relative file layout path diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/ResolvedDirectory.cs b/src/WixToolset.Core.WindowsInstaller/Bind/ResolvedDirectory.cs new file mode 100644 index 00000000..e06321cf --- /dev/null +++ b/src/WixToolset.Core.WindowsInstaller/Bind/ResolvedDirectory.cs @@ -0,0 +1,31 @@ +// 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.Core.WindowsInstaller.Bind +{ + /// + /// Structure used for resolved directory information. + /// + internal struct ResolvedDirectory + { + /// + /// Constructor for ResolvedDirectory. + /// + /// Parent directory. + /// The directory name. + public ResolvedDirectory(string directoryParent, string name) + { + this.DirectoryParent = directoryParent; + this.Name = name; + this.Path = null; + } + + /// The directory parent. + public string DirectoryParent { get; set; } + + /// The name of this directory. + public string Name { get; set; } + + /// The path of this directory. + public string Path { get; set; } + } +} diff --git a/src/WixToolset.Core.WindowsInstaller/MsiBackend.cs b/src/WixToolset.Core.WindowsInstaller/MsiBackend.cs index 4753677a..00f09db3 100644 --- a/src/WixToolset.Core.WindowsInstaller/MsiBackend.cs +++ b/src/WixToolset.Core.WindowsInstaller/MsiBackend.cs @@ -12,9 +12,11 @@ namespace WixToolset.Core.WindowsInstaller internal class MsiBackend : IBackend { - public BindResult Bind(IBindContext context) + public BindResult Bind(WixToolset.Extensibility.IBindContext context) { - var backendExtensions = context.ExtensionManager.Create(); + var extensionManager = context.ServiceProvider.GetService(); + + var backendExtensions = extensionManager.Create(); foreach (var extension in backendExtensions) { @@ -26,7 +28,7 @@ namespace WixToolset.Core.WindowsInstaller var command = new BindDatabaseCommand(context, backendExtensions, validator); command.Execute(); - var result = new BindResult(command.FileTransfers, command.ContentFilePaths); + var result = new BindResult { FileTransfers = command.FileTransfers, ContentFilePaths = command.ContentFilePaths }; foreach (var extension in backendExtensions) { diff --git a/src/WixToolset.Core.WindowsInstaller/MsmBackend.cs b/src/WixToolset.Core.WindowsInstaller/MsmBackend.cs index 2323f8dd..9c70860e 100644 --- a/src/WixToolset.Core.WindowsInstaller/MsmBackend.cs +++ b/src/WixToolset.Core.WindowsInstaller/MsmBackend.cs @@ -11,9 +11,11 @@ namespace WixToolset.Core.WindowsInstaller internal class MsmBackend : IBackend { - public BindResult Bind(IBindContext context) + public BindResult Bind(WixToolset.Extensibility.IBindContext context) { - var backendExtensions = context.ExtensionManager.Create(); + var extensionManager = context.ServiceProvider.GetService(); + + var backendExtensions = extensionManager.Create(); foreach (var extension in backendExtensions) { @@ -25,7 +27,7 @@ namespace WixToolset.Core.WindowsInstaller var command = new BindDatabaseCommand(context, backendExtensions, validator); command.Execute(); - var result = new BindResult(command.FileTransfers, command.ContentFilePaths); + var result = new BindResult { FileTransfers = command.FileTransfers, ContentFilePaths = command.ContentFilePaths }; foreach (var extension in backendExtensions) { diff --git a/src/WixToolset.Core.WindowsInstaller/MspBackend.cs b/src/WixToolset.Core.WindowsInstaller/MspBackend.cs index 8fb63665..5dbed241 100644 --- a/src/WixToolset.Core.WindowsInstaller/MspBackend.cs +++ b/src/WixToolset.Core.WindowsInstaller/MspBackend.cs @@ -16,7 +16,7 @@ namespace WixToolset.Core.WindowsInstaller internal class MspBackend : IBackend { - public BindResult Bind(IBindContext context) + public BindResult Bind(WixToolset.Extensibility.IBindContext context) { throw new NotImplementedException(); } diff --git a/src/WixToolset.Core.WindowsInstaller/MstBackend.cs b/src/WixToolset.Core.WindowsInstaller/MstBackend.cs index 17617dbc..4eb0901c 100644 --- a/src/WixToolset.Core.WindowsInstaller/MstBackend.cs +++ b/src/WixToolset.Core.WindowsInstaller/MstBackend.cs @@ -7,7 +7,6 @@ namespace WixToolset.Core.WindowsInstaller using WixToolset.Data; using WixToolset.Data.Bind; using WixToolset.Extensibility; - using WixToolset.Extensibility.Services; internal class MstBackend : IBackend { diff --git a/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindTranformCommand.cs b/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindTranformCommand.cs index 2b018013..00e5a755 100644 --- a/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindTranformCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Unbind/UnbindTranformCommand.cs @@ -244,7 +244,7 @@ namespace WixToolset.Core.WindowsInstaller.Unbind private void GenerateDatabase(Output output, string databaseFile) { var command = new GenerateDatabaseCommand(); - command.Extensions = Array.Empty(); + command.Extensions = Array.Empty(); command.Output = output; command.OutputPath = databaseFile; command.KeepAddedColumns = true; diff --git a/src/WixToolset.Core.WindowsInstaller/Validator.cs b/src/WixToolset.Core.WindowsInstaller/Validator.cs index d553cc71..5f41e88d 100644 --- a/src/WixToolset.Core.WindowsInstaller/Validator.cs +++ b/src/WixToolset.Core.WindowsInstaller/Validator.cs @@ -324,7 +324,7 @@ namespace WixToolset.Core.WindowsInstaller } } - public static Validator CreateFromContext(IBindContext context, string cubeFilename) + public static Validator CreateFromContext(WixToolset.Extensibility.IBindContext context, string cubeFilename) { Validator validator = null; diff --git a/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs b/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs index a7f58ed4..b66a4617 100644 --- a/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs +++ b/src/WixToolset.Core.WindowsInstaller/WindowsInstallerBackendFactory.cs @@ -5,7 +5,6 @@ namespace WixToolset.Core.WindowsInstaller using System; using System.IO; using WixToolset.Extensibility; - using WixToolset.Extensibility.Services; internal class WindowsInstallerBackendFactory : IBackendFactory { -- cgit v1.2.3-55-g6feb