aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/AddRequiredStandardDirectories.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2020-07-21 14:31:53 -0700
committerRob Mensching <rob@firegiant.com>2020-07-21 14:41:12 -0700
commitb62a7a0beb7ceb7987de28ec768c7814cadb83b9 (patch)
tree69a9183a3182334f0d48a39ab8e411ee3fc3aecd /src/WixToolset.Core.WindowsInstaller/Bind/AddRequiredStandardDirectories.cs
parent414c07f7adce9c9fd0132ab0fade0267f743f665 (diff)
downloadwix-b62a7a0beb7ceb7987de28ec768c7814cadb83b9.tar.gz
wix-b62a7a0beb7ceb7987de28ec768c7814cadb83b9.tar.bz2
wix-b62a7a0beb7ceb7987de28ec768c7814cadb83b9.zip
Support implicit standard directory reference and "3264" platform folders
Completes wixtoolset/issues#5798 and wixtoolset/issues#5835
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/AddRequiredStandardDirectories.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/AddRequiredStandardDirectories.cs95
1 files changed, 95 insertions, 0 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/AddRequiredStandardDirectories.cs b/src/WixToolset.Core.WindowsInstaller/Bind/AddRequiredStandardDirectories.cs
new file mode 100644
index 00000000..4597639b
--- /dev/null
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/AddRequiredStandardDirectories.cs
@@ -0,0 +1,95 @@
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.WindowsInstaller.Bind
4{
5 using System;
6 using System.Collections.Generic;
7 using System.Linq;
8 using WixToolset.Data;
9 using WixToolset.Data.Symbols;
10 using WixToolset.Data.WindowsInstaller;
11
12 /// <summary>
13 /// Add referenced standard directory symbols, if not already present.
14 /// </summary>
15 internal class AddRequiredStandardDirectories
16 {
17 internal AddRequiredStandardDirectories(IntermediateSection section, Platform platform)
18 {
19 this.Section = section;
20 this.Platform = platform;
21 }
22
23 private IntermediateSection Section { get; }
24
25 private Platform Platform { get; }
26
27 public void Execute()
28 {
29 var directories = this.Section.Symbols.OfType<DirectorySymbol>().ToList();
30 var directoriesById = directories.ToDictionary(d => d.Id.Id);
31
32 foreach (var directory in directories)
33 {
34 var parentDirectoryId = directory.ParentDirectoryRef;
35
36 if (String.IsNullOrEmpty(parentDirectoryId))
37 {
38 if (directory.Id.Id != "TARGETDIR")
39 {
40 directory.ParentDirectoryRef = "TARGETDIR";
41 }
42 }
43 else
44 {
45 this.EnsureStandardDirectoryAdded(directoriesById, parentDirectoryId, directory.SourceLineNumbers);
46 }
47 }
48
49 if (!directoriesById.ContainsKey("TARGETDIR") && WindowsInstallerStandard.TryGetStandardDirectory("TARGETDIR", out var targetDir))
50 {
51 directoriesById.Add(targetDir.Id.Id, targetDir);
52 this.Section.AddSymbol(targetDir);
53 }
54 }
55
56 private void EnsureStandardDirectoryAdded(Dictionary<string, DirectorySymbol> directoriesById, string directoryId, SourceLineNumber sourceLineNumbers)
57 {
58 if (!directoriesById.ContainsKey(directoryId) && WindowsInstallerStandard.TryGetStandardDirectory(directoryId, out var standardDirectory))
59 {
60 var parentDirectoryId = this.GetStandardDirectoryParent(directoryId);
61
62 var directory = new DirectorySymbol(sourceLineNumbers, standardDirectory.Id)
63 {
64 Name = standardDirectory.Name,
65 ParentDirectoryRef = parentDirectoryId,
66 };
67
68 directoriesById.Add(directory.Id.Id, directory);
69 this.Section.AddSymbol(directory);
70
71 if (!String.IsNullOrEmpty(parentDirectoryId))
72 {
73 this.EnsureStandardDirectoryAdded(directoriesById, parentDirectoryId, sourceLineNumbers);
74 }
75 }
76 }
77
78 private string GetStandardDirectoryParent(string directoryId)
79 {
80 switch (directoryId)
81 {
82 case "TARGETDIR":
83 return null;
84
85 case "CommonFiles6432Folder":
86 case "ProgramFiles6432Folder":
87 case "System6432Folder":
88 return WindowsInstallerStandard.GetPlatformSpecificDirectoryId(directoryId, this.Platform);
89
90 default:
91 return "TARGETDIR";
92 }
93 }
94 }
95}