aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/ExtensibilityServices/PathResolver.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/ExtensibilityServices/PathResolver.cs')
-rw-r--r--src/WixToolset.Core/ExtensibilityServices/PathResolver.cs91
1 files changed, 91 insertions, 0 deletions
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
3namespace 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}