aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Layout.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2017-12-21 13:42:52 -0800
committerRob Mensching <rob@firegiant.com>2017-12-21 13:42:52 -0800
commitdc9f4c329e6f55ce7595970463e0caf148096f4b (patch)
tree86155ac36c76acda0a4b1673c77f54a9780c6885 /src/WixToolset.Core/Layout.cs
parent155a6e96346e0cb3d9ab6f5372fa29b46ebaee89 (diff)
downloadwix-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/Layout.cs')
-rw-r--r--src/WixToolset.Core/Layout.cs188
1 files changed, 188 insertions, 0 deletions
diff --git a/src/WixToolset.Core/Layout.cs b/src/WixToolset.Core/Layout.cs
new file mode 100644
index 00000000..d7322a12
--- /dev/null
+++ b/src/WixToolset.Core/Layout.cs
@@ -0,0 +1,188 @@
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
4{
5 using System;
6 using System.Collections.Generic;
7 using System.IO;
8 using System.Linq;
9 using WixToolset.Core.Bind;
10 using WixToolset.Data;
11 using WixToolset.Data.Bind;
12 using WixToolset.Data.Tuples;
13 using WixToolset.Extensibility;
14 using WixToolset.Extensibility.Services;
15
16 /// <summary>
17 /// Layout for the WiX toolset.
18 /// </summary>
19 public sealed class Layout
20 {
21 public Layout(IServiceProvider serviceProvider, IEnumerable<FileTransfer> fileTransfers, IEnumerable<string> contentFilePaths, string contentsFile, string outputsFile, string builtOutputsFile, bool suppressAclReset)
22 {
23 this.ServiceProvider = serviceProvider;
24 this.FileTransfers = fileTransfers;
25 this.ContentFilePaths = contentFilePaths;
26 this.ContentsFile = contentsFile;
27 this.OutputsFile = outputsFile;
28 this.BuiltOutputsFile = builtOutputsFile;
29 this.SuppressAclReset = suppressAclReset;
30 this.Messaging = this.ServiceProvider.GetService<IMessaging>();
31 }
32
33 private IServiceProvider ServiceProvider { get; }
34
35 private IEnumerable<FileTransfer> FileTransfers { get; }
36
37 private IEnumerable<string> ContentFilePaths { get; }
38
39 private string ContentsFile { get; }
40
41 private string OutputsFile { get; }
42
43 private string BuiltOutputsFile { get; }
44
45 private bool SuppressAclReset { get; }
46
47 private IMessaging Messaging { get; }
48
49 public void Execute()
50 {
51 var extensionManager = this.ServiceProvider.GetService<IExtensionManager>();
52
53 var context = this.ServiceProvider.GetService<ILayoutContext>();
54 context.Messaging = this.Messaging;
55 context.Extensions = extensionManager.Create<ILayoutExtension>();
56 context.FileSystemExtensions = extensionManager.Create<IFileSystemExtension>();
57 context.FileTransfers = this.FileTransfers;
58 context.ContentFilePaths = this.ContentFilePaths;
59 context.ContentsFile = this.ContentsFile;
60 context.OutputPdbPath = this.OutputsFile;
61 context.BuiltOutputsFile = this.BuiltOutputsFile;
62 context.SuppressAclReset = this.SuppressAclReset;
63
64 // Pre-layout.
65 //
66 foreach (var extension in context.Extensions)
67 {
68 extension.PreLayout(context);
69 }
70
71 try
72 {
73 // Final step in binding that transfers (moves/copies) all files generated into the appropriate
74 // location in the source image.
75 if (context.FileTransfers?.Any() == true)
76 {
77 this.Messaging.Write(VerboseMessages.LayingOutMedia());
78
79 var command = new TransferFilesCommand(context.Messaging, context.FileSystemExtensions, context.FileTransfers, context.SuppressAclReset);
80 command.Execute();
81 }
82 }
83 finally
84 {
85 if (!String.IsNullOrEmpty(context.ContentsFile) && context.ContentFilePaths != null)
86 {
87 this.CreateContentsFile(context.ContentsFile, context.ContentFilePaths);
88 }
89
90 if (!String.IsNullOrEmpty(context.OutputsFile) && context.FileTransfers != null)
91 {
92 this.CreateOutputsFile(context.OutputsFile, context.FileTransfers, context.OutputPdbPath);
93 }
94
95 if (!String.IsNullOrEmpty(context.BuiltOutputsFile) && context.FileTransfers != null)
96 {
97 this.CreateBuiltOutputsFile(context.BuiltOutputsFile, context.FileTransfers, context.OutputPdbPath);
98 }
99 }
100
101 // Post-layout.
102 foreach (var extension in context.Extensions)
103 {
104 extension.PostLayout();
105 }
106 }
107
108 /// <summary>
109 /// Writes the paths to the content files to a text file.
110 /// </summary>
111 /// <param name="path">Path to write file.</param>
112 /// <param name="contentFilePaths">Collection of paths to content files that will be written to file.</param>
113 private void CreateContentsFile(string path, IEnumerable<string> contentFilePaths)
114 {
115 var directory = Path.GetDirectoryName(path);
116 Directory.CreateDirectory(directory);
117
118 using (var contents = new StreamWriter(path, false))
119 {
120 foreach (string contentPath in contentFilePaths)
121 {
122 contents.WriteLine(contentPath);
123 }
124 }
125 }
126
127 /// <summary>
128 /// Writes the paths to the output files to a text file.
129 /// </summary>
130 /// <param name="path">Path to write file.</param>
131 /// <param name="fileTransfers">Collection of files that were transferred to the output directory.</param>
132 /// <param name="pdbPath">Optional path to created .wixpdb.</param>
133 private void CreateOutputsFile(string path, IEnumerable<FileTransfer> fileTransfers, string pdbPath)
134 {
135 var directory = Path.GetDirectoryName(path);
136 Directory.CreateDirectory(directory);
137
138 using (var outputs = new StreamWriter(path, false))
139 {
140 foreach (FileTransfer fileTransfer in fileTransfers)
141 {
142 // Don't list files where the source is the same as the destination since
143 // that might be the only place the file exists. The outputs file is often
144 // used to delete stuff and losing the original source would be bad.
145 if (!fileTransfer.Redundant)
146 {
147 outputs.WriteLine(fileTransfer.Destination);
148 }
149 }
150
151 if (!String.IsNullOrEmpty(pdbPath))
152 {
153 outputs.WriteLine(Path.GetFullPath(pdbPath));
154 }
155 }
156 }
157
158 /// <summary>
159 /// Writes the paths to the built output files to a text file.
160 /// </summary>
161 /// <param name="path">Path to write file.</param>
162 /// <param name="fileTransfers">Collection of files that were transferred to the output directory.</param>
163 /// <param name="pdbPath">Optional path to created .wixpdb.</param>
164 private void CreateBuiltOutputsFile(string path, IEnumerable<FileTransfer> fileTransfers, string pdbPath)
165 {
166 var directory = Path.GetDirectoryName(path);
167 Directory.CreateDirectory(directory);
168
169 using (var outputs = new StreamWriter(path, false))
170 {
171 foreach (FileTransfer fileTransfer in fileTransfers)
172 {
173 // Only write the built file transfers. Also, skip redundant
174 // files for the same reason spelled out in this.CreateOutputsFile().
175 if (fileTransfer.Built && !fileTransfer.Redundant)
176 {
177 outputs.WriteLine(fileTransfer.Destination);
178 }
179 }
180
181 if (!String.IsNullOrEmpty(pdbPath))
182 {
183 outputs.WriteLine(Path.GetFullPath(pdbPath));
184 }
185 }
186 }
187 }
188}