From 860676fa5b40a1904478151e9b4934c004e7db63 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Mon, 7 Oct 2019 11:18:13 -0700 Subject: Implement Bundle build --- .../Bind/BindDatabaseCommand.cs | 8 +- .../Bind/CalculateComponentGuids.cs | 16 ++-- .../Bind/CreateCabinetsCommand.cs | 1 - .../Bind/CreateOutputFromIRCommand.cs | 16 ++++ .../Bind/PathResolver.cs | 106 --------------------- .../Bind/ProcessUncompressedFilesCommand.cs | 13 ++- .../Bind/ResolvedDirectory.cs | 31 ------ .../Bind/UpdateFileFacadesCommand.cs | 1 - 8 files changed, 41 insertions(+), 151 deletions(-) delete mode 100644 src/WixToolset.Core.WindowsInstaller/Bind/PathResolver.cs delete 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 830880ee..53451752 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs @@ -30,6 +30,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind this.BackendHelper = context.ServiceProvider.GetService(); + this.PathResolver = this.ServiceProvider.GetService(); + this.TableDefinitions = WindowsInstallerStandardInternal.GetTableDefinitions(); this.CabbingThreadCount = context.CabbingThreadCount; @@ -54,6 +56,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind private IBackendHelper BackendHelper { get; } + private IPathResolver PathResolver { get; } + private int Codepage { get; } private int CabbingThreadCount { get; } @@ -241,7 +245,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // Set generated component guids. { - var command = new CalculateComponentGuids(this.Messaging, this.BackendHelper, section); + var command = new CalculateComponentGuids(this.Messaging, this.BackendHelper, this.PathResolver, section); command.Execute(); } @@ -501,7 +505,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind // Process uncompressed files. if (!this.Messaging.EncounteredError && !this.SuppressLayout && uncompressedFiles.Any()) { - var command = new ProcessUncompressedFilesCommand(section, this.BackendHelper); + var command = new ProcessUncompressedFilesCommand(section, this.BackendHelper, this.PathResolver); command.Compressed = compressed; command.FileFacades = uncompressedFiles; command.LayoutDirectory = layoutDirectory; diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs index 835d9b8d..8135ae2e 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CalculateComponentGuids.cs @@ -6,9 +6,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System.Collections.Generic; using System.IO; using System.Linq; - using WixToolset.Core.Native; using WixToolset.Data; using WixToolset.Data.Tuples; + using WixToolset.Extensibility.Data; using WixToolset.Extensibility.Services; /// @@ -16,10 +16,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// internal class CalculateComponentGuids { - internal CalculateComponentGuids(IMessaging messaging, IBackendHelper helper, IntermediateSection section) + internal CalculateComponentGuids(IMessaging messaging, IBackendHelper helper, IPathResolver pathResolver, IntermediateSection section) { this.Messaging = messaging; this.BackendHelper = helper; + this.PathResolver = pathResolver; this.Section = section; } @@ -27,12 +28,14 @@ namespace WixToolset.Core.WindowsInstaller.Bind private IBackendHelper BackendHelper { get; } + private IPathResolver PathResolver { get; } + private IntermediateSection Section { get; } public void Execute() { Dictionary registryKeyRows = null; - Dictionary targetPathsByDirectoryId = null; + Dictionary targetPathsByDirectoryId = null; Dictionary componentIdGenSeeds = null; Dictionary> filesByComponentId = null; @@ -73,7 +76,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind { var directories = this.Section.Tuples.OfType().ToList(); - targetPathsByDirectoryId = new Dictionary(directories.Count); + targetPathsByDirectoryId = new Dictionary(directories.Count); // Get the target paths for all directories. foreach (var directory in directories) @@ -86,7 +89,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind continue; } - targetPathsByDirectoryId.Add(directory.Id.Id, new ResolvedDirectory(directory.ParentDirectoryRef, directory.Name)); + var resolvedDirectory = this.BackendHelper.CreateResolvedDirectory(directory.ParentDirectoryRef, directory.Name); + targetPathsByDirectoryId.Add(directory.Id.Id, resolvedDirectory); } } @@ -131,7 +135,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind if (fileRow.Id.Id == componentTuple.KeyPath) { // calculate the key file's canonical target path - string directoryPath = PathResolver.GetDirectoryPath(targetPathsByDirectoryId, componentIdGenSeeds, componentTuple.DirectoryRef, true); + string directoryPath = this.PathResolver.GetDirectoryPath(targetPathsByDirectoryId, componentIdGenSeeds, componentTuple.DirectoryRef, true); string fileName = Common.GetName(fileRow.Name, false, true).ToLowerInvariant(); path = Path.Combine(directoryPath, fileName); diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs index 95438f96..a9b0f5f5 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs @@ -8,7 +8,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind using System.IO; using System.Linq; using System.Runtime.InteropServices; - using System.Threading; using WixToolset.Core.Bind; using WixToolset.Data; using WixToolset.Data.Tuples; diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs index f76cd227..cd3a67fa 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs @@ -105,6 +105,10 @@ namespace WixToolset.Core.WindowsInstaller.Bind this.AddMsiEmbeddedUITuple((MsiEmbeddedUITuple)tuple, output); break; + case TupleDefinitionType.MsiFileHash: + this.AddMsiFileHashTuple((MsiFileHashTuple)tuple, output); + break; + case TupleDefinitionType.MsiServiceConfig: this.AddMsiServiceConfigTuple((MsiServiceConfigTuple)tuple, output); break; @@ -500,6 +504,18 @@ namespace WixToolset.Core.WindowsInstaller.Bind row[4] = tuple.Source; } + private void AddMsiFileHashTuple(MsiFileHashTuple tuple, Output output) + { + var table = output.EnsureTable(this.TableDefinitions["MsiFileHash"]); + var row = table.CreateRow(tuple.SourceLineNumbers); + row[0] = tuple.Id.Id; + row[1] = tuple.Options; + row[2] = tuple.HashPart1; + row[3] = tuple.HashPart2; + row[4] = tuple.HashPart3; + row[5] = tuple.HashPart4; + } + private void AddMsiServiceConfigTuple(MsiServiceConfigTuple tuple, Output output) { var events = tuple.OnInstall ? WindowsInstallerConstants.MsidbServiceConfigEventInstall : 0; diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/PathResolver.cs b/src/WixToolset.Core.WindowsInstaller/Bind/PathResolver.cs deleted file mode 100644 index 6dc18271..00000000 --- a/src/WixToolset.Core.WindowsInstaller/Bind/PathResolver.cs +++ /dev/null @@ -1,106 +0,0 @@ -// 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; - using WixToolset.Data.WindowsInstaller; - - 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 = 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 61e82f68..64fb3e4d 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs @@ -18,16 +18,19 @@ namespace WixToolset.Core.WindowsInstaller.Bind /// internal class ProcessUncompressedFilesCommand { - public ProcessUncompressedFilesCommand(IntermediateSection section, IBackendHelper backendHelper) + public ProcessUncompressedFilesCommand(IntermediateSection section, IBackendHelper backendHelper, IPathResolver pathResolver) { this.Section = section; this.BackendHelper = backendHelper; + this.PathResolver = pathResolver; } private IntermediateSection Section { get; } public IBackendHelper BackendHelper { get; } + public IPathResolver PathResolver { get; } + public string DatabasePath { private get; set; } public IEnumerable FileFacades { private get; set; } @@ -50,7 +53,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind var trackedFiles = new List(); - var directories = new Dictionary(); + var directories = new Dictionary(); var mediaRows = this.Section.Tuples.OfType().ToDictionary(t => t.DiskId); @@ -69,7 +72,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind string sourceName = Common.GetName(directoryRecord.GetString(3), true, this.LongNamesInImage); - directories.Add(directoryRecord.GetString(1), new ResolvedDirectory(directoryRecord.GetString(2), sourceName)); + var resolvedDirectory = this.BackendHelper.CreateResolvedDirectory(directoryRecord.GetString(2), sourceName); + + directories.Add(directoryRecord.GetString(1), resolvedDirectory); } } } @@ -99,7 +104,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind throw new WixException(ErrorMessages.FileIdentifierNotFound(facade.File.SourceLineNumbers, facade.File.Id.Id)); } - relativeFileLayoutPath = PathResolver.GetFileSourcePath(directories, fileRecord[1], fileRecord[2], this.Compressed, this.LongNamesInImage); + relativeFileLayoutPath = this.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 deleted file mode 100644 index e06321cf..00000000 --- a/src/WixToolset.Core.WindowsInstaller/Bind/ResolvedDirectory.cs +++ /dev/null @@ -1,31 +0,0 @@ -// 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/Bind/UpdateFileFacadesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs index 397092c4..1f2a22d9 100644 --- a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs +++ b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs @@ -162,7 +162,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind this.Section.Tuples.Add(facade.Hash); } - facade.Hash.FileRef = facade.File.Id.Id; facade.Hash.Options = 0; facade.Hash.HashPart1 = hash[0]; facade.Hash.HashPart2 = hash[1]; -- cgit v1.2.3-55-g6feb