diff options
Diffstat (limited to 'src/WixToolset.Core/ExtensibilityServices')
4 files changed, 133 insertions, 16 deletions
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 @@ | |||
| 1 | // 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. | 1 | // 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. |
| 2 | 2 | ||
| 3 | namespace WixToolset.Core.ExtensibilityServices | 3 | namespace WixToolset.Core.ExtensibilityServices |
| 4 | { | 4 | { |
| @@ -40,6 +40,15 @@ namespace WixToolset.Core.ExtensibilityServices | |||
| 40 | return Uuid.NewUuid(namespaceGuid, value).ToString("B").ToUpperInvariant(); | 40 | return Uuid.NewUuid(namespaceGuid, value).ToString("B").ToUpperInvariant(); |
| 41 | } | 41 | } |
| 42 | 42 | ||
| 43 | public IResolvedDirectory CreateResolvedDirectory(string directoryParent, string name) | ||
| 44 | { | ||
| 45 | return new ResolvedDirectory | ||
| 46 | { | ||
| 47 | DirectoryParent = directoryParent, | ||
| 48 | Name = name | ||
| 49 | }; | ||
| 50 | } | ||
| 51 | |||
| 43 | public ITrackedFile TrackFile(string path, TrackedFileType type, SourceLineNumber sourceLineNumbers = null) | 52 | public ITrackedFile TrackFile(string path, TrackedFileType type, SourceLineNumber sourceLineNumbers = null) |
| 44 | { | 53 | { |
| 45 | return new TrackedFile(path, type, sourceLineNumbers); | 54 | 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 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | namespace WixToolset.Core.ExtensibilityServices | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using System.IO; | ||
| 8 | using WixToolset.Data; | ||
| 9 | using WixToolset.Data.WindowsInstaller; | ||
| 10 | using WixToolset.Extensibility.Data; | ||
| 11 | using WixToolset.Extensibility.Services; | ||
| 12 | |||
| 13 | internal class PathResolver : IPathResolver | ||
| 14 | { | ||
| 15 | public string GetDirectoryPath(Dictionary<string, IResolvedDirectory> directories, Dictionary<string, string> componentIdGenSeeds, string directory, bool canonicalize) | ||
| 16 | { | ||
| 17 | if (!directories.TryGetValue(directory, out var resolvedDirectory)) | ||
| 18 | { | ||
| 19 | throw new WixException(ErrorMessages.ExpectedDirectory(directory)); | ||
| 20 | } | ||
| 21 | |||
| 22 | if (null == resolvedDirectory.Path) | ||
| 23 | { | ||
| 24 | if (null != componentIdGenSeeds && componentIdGenSeeds.ContainsKey(directory)) | ||
| 25 | { | ||
| 26 | resolvedDirectory.Path = componentIdGenSeeds[directory]; | ||
| 27 | } | ||
| 28 | else if (canonicalize && WindowsInstallerStandard.IsStandardDirectory(directory)) | ||
| 29 | { | ||
| 30 | // when canonicalization is on, standard directories are treated equally | ||
| 31 | resolvedDirectory.Path = directory; | ||
| 32 | } | ||
| 33 | else | ||
| 34 | { | ||
| 35 | string name = resolvedDirectory.Name; | ||
| 36 | |||
| 37 | if (canonicalize) | ||
| 38 | { | ||
| 39 | name = name?.ToLowerInvariant(); | ||
| 40 | } | ||
| 41 | |||
| 42 | if (String.IsNullOrEmpty(resolvedDirectory.DirectoryParent)) | ||
| 43 | { | ||
| 44 | resolvedDirectory.Path = name; | ||
| 45 | } | ||
| 46 | else | ||
| 47 | { | ||
| 48 | var parentPath = this.GetDirectoryPath(directories, componentIdGenSeeds, resolvedDirectory.DirectoryParent, canonicalize); | ||
| 49 | |||
| 50 | if (null != resolvedDirectory.Name) | ||
| 51 | { | ||
| 52 | resolvedDirectory.Path = Path.Combine(parentPath, name); | ||
| 53 | } | ||
| 54 | else | ||
| 55 | { | ||
| 56 | resolvedDirectory.Path = parentPath; | ||
| 57 | } | ||
| 58 | } | ||
| 59 | } | ||
| 60 | } | ||
| 61 | |||
| 62 | return resolvedDirectory.Path; | ||
| 63 | } | ||
| 64 | |||
| 65 | public string GetFileSourcePath(Dictionary<string, IResolvedDirectory> directories, string directoryId, string fileName, bool compressed, bool useLongName) | ||
| 66 | { | ||
| 67 | var fileSourcePath = Common.GetName(fileName, true, useLongName); | ||
| 68 | |||
| 69 | if (compressed) | ||
| 70 | { | ||
| 71 | // Use just the file name of the file since all uncompressed files must appear | ||
| 72 | // in the root of the image in a compressed package. | ||
| 73 | } | ||
| 74 | else | ||
| 75 | { | ||
| 76 | // Get the relative path of where we want the file to be layed out as specified | ||
| 77 | // in the Directory table. | ||
| 78 | var directoryPath = this.GetDirectoryPath(directories, null, directoryId, false); | ||
| 79 | fileSourcePath = Path.Combine(directoryPath, fileSourcePath); | ||
| 80 | } | ||
| 81 | |||
| 82 | // Strip off "SourceDir" if it's still on there. | ||
| 83 | if (fileSourcePath.StartsWith("SourceDir\\", StringComparison.Ordinal)) | ||
| 84 | { | ||
| 85 | fileSourcePath = fileSourcePath.Substring(10); | ||
| 86 | } | ||
| 87 | |||
| 88 | return fileSourcePath; | ||
| 89 | } | ||
| 90 | } | ||
| 91 | } | ||
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 @@ | |||
| 1 | // 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. | ||
| 2 | |||
| 3 | namespace WixToolset.Core.ExtensibilityServices | ||
| 4 | { | ||
| 5 | using WixToolset.Extensibility.Data; | ||
| 6 | |||
| 7 | internal class ResolvedDirectory : IResolvedDirectory | ||
| 8 | { | ||
| 9 | public string DirectoryParent { get; set; } | ||
| 10 | |||
| 11 | public string Name { get; set; } | ||
| 12 | |||
| 13 | public string Path { get; set; } | ||
| 14 | } | ||
| 15 | } | ||
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 @@ | |||
| 1 | // 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. | 1 | // 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. |
| 2 | 2 | ||
| 3 | namespace WixToolset.Core.ExtensibilityServices | 3 | namespace WixToolset.Core.ExtensibilityServices |
| 4 | { | 4 | { |
| 5 | using System; | ||
| 6 | using System.Linq; | 5 | using System.Linq; |
| 7 | using WixToolset.Data; | 6 | using WixToolset.Data; |
| 8 | using WixToolset.Data.WindowsInstaller; | 7 | using WixToolset.Data.WindowsInstaller; |
| @@ -10,14 +9,9 @@ namespace WixToolset.Core.ExtensibilityServices | |||
| 10 | 9 | ||
| 11 | internal class WindowsInstallerBackendHelper : IWindowsInstallerBackendHelper | 10 | internal class WindowsInstallerBackendHelper : IWindowsInstallerBackendHelper |
| 12 | { | 11 | { |
| 13 | public WindowsInstallerBackendHelper(IServiceProvider serviceProvider) | 12 | public bool TryAddTupleToOutputMatchingTableDefinitions(IntermediateTuple tuple, Output output, TableDefinition[] tableDefinitions) => this.TryAddTupleToOutputMatchingTableDefinitions(tuple, output, tableDefinitions, false); |
| 14 | { | ||
| 15 | this.ServiceProvider = serviceProvider; | ||
| 16 | } | ||
| 17 | 13 | ||
| 18 | private IServiceProvider ServiceProvider { get; } | 14 | public bool TryAddTupleToOutputMatchingTableDefinitions(IntermediateTuple tuple, Output output, TableDefinition[] tableDefinitions, bool columnZeroIsId) |
| 19 | |||
| 20 | public bool TryAddTupleToOutputMatchingTableDefinitions(IntermediateTuple tuple, Output output, TableDefinition[] tableDefinitions) | ||
| 21 | { | 15 | { |
| 22 | var tableDefinition = tableDefinitions.FirstOrDefault(t => t.Name == tuple.Definition.Name); | 16 | var tableDefinition = tableDefinitions.FirstOrDefault(t => t.Name == tuple.Definition.Name); |
| 23 | 17 | ||
| @@ -28,6 +22,14 @@ namespace WixToolset.Core.ExtensibilityServices | |||
| 28 | 22 | ||
| 29 | var table = output.EnsureTable(tableDefinition); | 23 | var table = output.EnsureTable(tableDefinition); |
| 30 | var row = table.CreateRow(tuple.SourceLineNumbers); | 24 | var row = table.CreateRow(tuple.SourceLineNumbers); |
| 25 | var rowOffset = 0; | ||
| 26 | |||
| 27 | if (columnZeroIsId) | ||
| 28 | { | ||
| 29 | row[0] = tuple.Id.Id; | ||
| 30 | rowOffset = 1; | ||
| 31 | } | ||
| 32 | |||
| 31 | for (var i = 0; i < tuple.Fields.Length; ++i) | 33 | for (var i = 0; i < tuple.Fields.Length; ++i) |
| 32 | { | 34 | { |
| 33 | if (i < tableDefinition.Columns.Length) | 35 | if (i < tableDefinition.Columns.Length) |
| @@ -36,13 +38,13 @@ namespace WixToolset.Core.ExtensibilityServices | |||
| 36 | 38 | ||
| 37 | switch (column.Type) | 39 | switch (column.Type) |
| 38 | { | 40 | { |
| 39 | case ColumnType.Number: | 41 | case ColumnType.Number: |
| 40 | row[i] = tuple.AsNumber(i); | 42 | row[i + rowOffset] = column.Nullable ? tuple.AsNullableNumber(i) : tuple.AsNumber(i); |
| 41 | break; | 43 | break; |
| 42 | 44 | ||
| 43 | default: | 45 | default: |
| 44 | row[i] = tuple.AsString(i); | 46 | row[i + rowOffset] = tuple.AsString(i); |
| 45 | break; | 47 | break; |
| 46 | } | 48 | } |
| 47 | } | 49 | } |
| 48 | } | 50 | } |
