diff options
| author | Rob Mensching <rob@firegiant.com> | 2017-12-21 13:42:52 -0800 |
|---|---|---|
| committer | Rob Mensching <rob@firegiant.com> | 2017-12-21 13:42:52 -0800 |
| commit | dc9f4c329e6f55ce7595970463e0caf148096f4b (patch) | |
| tree | 86155ac36c76acda0a4b1673c77f54a9780c6885 /src/WixToolset.Core.WindowsInstaller/Bind/PathResolver.cs | |
| parent | 155a6e96346e0cb3d9ab6f5372fa29b46ebaee89 (diff) | |
| download | wix-dc9f4c329e6f55ce7595970463e0caf148096f4b.tar.gz wix-dc9f4c329e6f55ce7595970463e0caf148096f4b.tar.bz2 wix-dc9f4c329e6f55ce7595970463e0caf148096f4b.zip | |
Support wixout and extract Resolve and Layout from Binder
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/PathResolver.cs')
| -rw-r--r-- | src/WixToolset.Core.WindowsInstaller/Bind/PathResolver.cs | 105 |
1 files changed, 105 insertions, 0 deletions
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 @@ | |||
| 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.WindowsInstaller.Bind | ||
| 4 | { | ||
| 5 | using System; | ||
| 6 | using System.Collections.Generic; | ||
| 7 | using System.IO; | ||
| 8 | using WixToolset.Data; | ||
| 9 | |||
| 10 | internal static class PathResolver | ||
| 11 | { | ||
| 12 | /// <summary> | ||
| 13 | /// Get the source path of a directory. | ||
| 14 | /// </summary> | ||
| 15 | /// <param name="directories">All cached directories.</param> | ||
| 16 | /// <param name="componentIdGenSeeds">Hash table of Component GUID generation seeds indexed by directory id.</param> | ||
| 17 | /// <param name="directory">Directory identifier.</param> | ||
| 18 | /// <param name="canonicalize">Canonicalize the path for standard directories.</param> | ||
| 19 | /// <returns>Source path of a directory.</returns> | ||
| 20 | public static string GetDirectoryPath(Dictionary<string, ResolvedDirectory> directories, Dictionary<string, string> componentIdGenSeeds, string directory, bool canonicalize) | ||
| 21 | { | ||
| 22 | if (!directories.TryGetValue(directory, out var resolvedDirectory)) | ||
| 23 | { | ||
| 24 | throw new WixException(ErrorMessages.ExpectedDirectory(directory)); | ||
| 25 | } | ||
| 26 | |||
| 27 | if (null == resolvedDirectory.Path) | ||
| 28 | { | ||
| 29 | if (null != componentIdGenSeeds && componentIdGenSeeds.ContainsKey(directory)) | ||
| 30 | { | ||
| 31 | resolvedDirectory.Path = (string)componentIdGenSeeds[directory]; | ||
| 32 | } | ||
| 33 | else if (canonicalize && WindowsInstallerStandard.IsStandardDirectory(directory)) | ||
| 34 | { | ||
| 35 | // when canonicalization is on, standard directories are treated equally | ||
| 36 | resolvedDirectory.Path = directory; | ||
| 37 | } | ||
| 38 | else | ||
| 39 | { | ||
| 40 | string name = resolvedDirectory.Name; | ||
| 41 | |||
| 42 | if (canonicalize) | ||
| 43 | { | ||
| 44 | name = name?.ToLowerInvariant(); | ||
| 45 | } | ||
| 46 | |||
| 47 | if (String.IsNullOrEmpty(resolvedDirectory.DirectoryParent)) | ||
| 48 | { | ||
| 49 | resolvedDirectory.Path = name; | ||
| 50 | } | ||
| 51 | else | ||
| 52 | { | ||
| 53 | string parentPath = GetDirectoryPath(directories, componentIdGenSeeds, resolvedDirectory.DirectoryParent, canonicalize); | ||
| 54 | |||
| 55 | if (null != resolvedDirectory.Name) | ||
| 56 | { | ||
| 57 | resolvedDirectory.Path = Path.Combine(parentPath, name); | ||
| 58 | } | ||
| 59 | else | ||
| 60 | { | ||
| 61 | resolvedDirectory.Path = parentPath; | ||
| 62 | } | ||
| 63 | } | ||
| 64 | } | ||
| 65 | } | ||
| 66 | |||
| 67 | return resolvedDirectory.Path; | ||
| 68 | } | ||
| 69 | |||
| 70 | /// <summary> | ||
| 71 | /// Gets the source path of a file. | ||
| 72 | /// </summary> | ||
| 73 | /// <param name="directories">All cached directories in <see cref="ResolvedDirectory"/>.</param> | ||
| 74 | /// <param name="directoryId">Parent directory identifier.</param> | ||
| 75 | /// <param name="fileName">File name (in long|source format).</param> | ||
| 76 | /// <param name="compressed">Specifies the package is compressed.</param> | ||
| 77 | /// <param name="useLongName">Specifies the package uses long file names.</param> | ||
| 78 | /// <returns>Source path of file relative to package directory.</returns> | ||
| 79 | public static string GetFileSourcePath(Dictionary<string, ResolvedDirectory> directories, string directoryId, string fileName, bool compressed, bool useLongName) | ||
| 80 | { | ||
| 81 | string fileSourcePath = Common.GetName(fileName, true, useLongName); | ||
| 82 | |||
| 83 | if (compressed) | ||
| 84 | { | ||
| 85 | // Use just the file name of the file since all uncompressed files must appear | ||
| 86 | // in the root of the image in a compressed package. | ||
| 87 | } | ||
| 88 | else | ||
| 89 | { | ||
| 90 | // Get the relative path of where we want the file to be layed out as specified | ||
| 91 | // in the Directory table. | ||
| 92 | string directoryPath = PathResolver.GetDirectoryPath(directories, null, directoryId, false); | ||
| 93 | fileSourcePath = Path.Combine(directoryPath, fileSourcePath); | ||
| 94 | } | ||
| 95 | |||
| 96 | // Strip off "SourceDir" if it's still on there. | ||
| 97 | if (fileSourcePath.StartsWith("SourceDir\\", StringComparison.Ordinal)) | ||
| 98 | { | ||
| 99 | fileSourcePath = fileSourcePath.Substring(10); | ||
| 100 | } | ||
| 101 | |||
| 102 | return fileSourcePath; | ||
| 103 | } | ||
| 104 | } | ||
| 105 | } | ||
