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 --- .../ExtensibilityServices/BackendHelper.cs | 11 ++- .../ExtensibilityServices/PathResolver.cs | 91 ++++++++++++++++++++++ .../ExtensibilityServices/ResolvedDirectory.cs | 15 ++++ .../WindowsInstallerBackendHelper.cs | 32 ++++---- 4 files changed, 133 insertions(+), 16 deletions(-) create mode 100644 src/WixToolset.Core/ExtensibilityServices/PathResolver.cs create mode 100644 src/WixToolset.Core/ExtensibilityServices/ResolvedDirectory.cs (limited to 'src/WixToolset.Core/ExtensibilityServices') diff --git a/src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs b/src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs index 6cc91487..0bdecf7a 100644 --- a/src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs +++ b/src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs @@ -1,4 +1,4 @@ -// 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. +// 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.ExtensibilityServices { @@ -40,6 +40,15 @@ namespace WixToolset.Core.ExtensibilityServices return Uuid.NewUuid(namespaceGuid, value).ToString("B").ToUpperInvariant(); } + public IResolvedDirectory CreateResolvedDirectory(string directoryParent, string name) + { + return new ResolvedDirectory + { + DirectoryParent = directoryParent, + Name = name + }; + } + public ITrackedFile TrackFile(string path, TrackedFileType type, SourceLineNumber sourceLineNumbers = null) { return new TrackedFile(path, type, sourceLineNumbers); diff --git a/src/WixToolset.Core/ExtensibilityServices/PathResolver.cs b/src/WixToolset.Core/ExtensibilityServices/PathResolver.cs new file mode 100644 index 00000000..15cd4fc9 --- /dev/null +++ b/src/WixToolset.Core/ExtensibilityServices/PathResolver.cs @@ -0,0 +1,91 @@ +// 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.ExtensibilityServices +{ + using System; + using System.Collections.Generic; + using System.IO; + using WixToolset.Data; + using WixToolset.Data.WindowsInstaller; + using WixToolset.Extensibility.Data; + using WixToolset.Extensibility.Services; + + internal class PathResolver : IPathResolver + { + public 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 + { + var parentPath = this.GetDirectoryPath(directories, componentIdGenSeeds, resolvedDirectory.DirectoryParent, canonicalize); + + if (null != resolvedDirectory.Name) + { + resolvedDirectory.Path = Path.Combine(parentPath, name); + } + else + { + resolvedDirectory.Path = parentPath; + } + } + } + } + + return resolvedDirectory.Path; + } + + public string GetFileSourcePath(Dictionary directories, string directoryId, string fileName, bool compressed, bool useLongName) + { + var 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. + var directoryPath = this.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/ExtensibilityServices/ResolvedDirectory.cs b/src/WixToolset.Core/ExtensibilityServices/ResolvedDirectory.cs new file mode 100644 index 00000000..cc8acfdd --- /dev/null +++ b/src/WixToolset.Core/ExtensibilityServices/ResolvedDirectory.cs @@ -0,0 +1,15 @@ +// 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.ExtensibilityServices +{ + using WixToolset.Extensibility.Data; + + internal class ResolvedDirectory : IResolvedDirectory + { + public string DirectoryParent { get; set; } + + public string Name { get; set; } + + public string Path { get; set; } + } +} diff --git a/src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs b/src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs index 6e0ffce6..26982ad6 100644 --- a/src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs +++ b/src/WixToolset.Core/ExtensibilityServices/WindowsInstallerBackendHelper.cs @@ -1,8 +1,7 @@ -// 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. +// 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.ExtensibilityServices { - using System; using System.Linq; using WixToolset.Data; using WixToolset.Data.WindowsInstaller; @@ -10,14 +9,9 @@ namespace WixToolset.Core.ExtensibilityServices internal class WindowsInstallerBackendHelper : IWindowsInstallerBackendHelper { - public WindowsInstallerBackendHelper(IServiceProvider serviceProvider) - { - this.ServiceProvider = serviceProvider; - } + public bool TryAddTupleToOutputMatchingTableDefinitions(IntermediateTuple tuple, Output output, TableDefinition[] tableDefinitions) => this.TryAddTupleToOutputMatchingTableDefinitions(tuple, output, tableDefinitions, false); - private IServiceProvider ServiceProvider { get; } - - public bool TryAddTupleToOutputMatchingTableDefinitions(IntermediateTuple tuple, Output output, TableDefinition[] tableDefinitions) + public bool TryAddTupleToOutputMatchingTableDefinitions(IntermediateTuple tuple, Output output, TableDefinition[] tableDefinitions, bool columnZeroIsId) { var tableDefinition = tableDefinitions.FirstOrDefault(t => t.Name == tuple.Definition.Name); @@ -28,6 +22,14 @@ namespace WixToolset.Core.ExtensibilityServices var table = output.EnsureTable(tableDefinition); var row = table.CreateRow(tuple.SourceLineNumbers); + var rowOffset = 0; + + if (columnZeroIsId) + { + row[0] = tuple.Id.Id; + rowOffset = 1; + } + for (var i = 0; i < tuple.Fields.Length; ++i) { if (i < tableDefinition.Columns.Length) @@ -36,13 +38,13 @@ namespace WixToolset.Core.ExtensibilityServices switch (column.Type) { - case ColumnType.Number: - row[i] = tuple.AsNumber(i); - break; + case ColumnType.Number: + row[i + rowOffset] = column.Nullable ? tuple.AsNullableNumber(i) : tuple.AsNumber(i); + break; - default: - row[i] = tuple.AsString(i); - break; + default: + row[i + rowOffset] = tuple.AsString(i); + break; } } } -- cgit v1.2.3-55-g6feb