@joebigelow / wix / commits / 854e616e

Support change of FileTransfer to interface

Rob Mensching committed Jul 26, 2018 at 23:52 UTC 854e616eb3516c7405691b679617aa08c1dd1cdd
10 files changed +143 -49
src/WixToolset.Core.Burn/Bind/BindBundleCommand.cs
+1 -1
@@ -99,7 +99,7 @@ namespace WixToolset.Core.Burn
99
100 public IVariableResolver VariableResolver { private get; set; }
101
102 - public IEnumerable<FileTransfer> FileTransfers { get; private set; }
102 + public IEnumerable<IFileTransfer> FileTransfers { get; private set; }
103
104 public IEnumerable<string> ContentFilePaths { get; private set; }
105
src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
+12 -11
@@ -26,6 +26,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
26 {
27 this.Messaging = context.ServiceProvider.GetService<IMessaging>();
28
29 + this.BackendHelper = context.ServiceProvider.GetService<IBackendHelper>();
30 +
31 this.TableDefinitions = WindowsInstallerStandardInternal.GetTableDefinitions();
32
33 this.CabbingThreadCount = context.CabbingThreadCount;
@@ -43,6 +45,10 @@ namespace WixToolset.Core.WindowsInstaller.Bind
45 this.BackendExtensions = backendExtension;
46 }
47
48 + private IMessaging Messaging { get; }
49 +
50 + private IBackendHelper BackendHelper { get; }
51 +
52 private int Codepage { get; }
53
54 private int CabbingThreadCount { get; }
@@ -63,8 +69,6 @@ namespace WixToolset.Core.WindowsInstaller.Bind
69
70 private Intermediate Intermediate { get; }
71
66 - private IMessaging Messaging { get; }
67 -
72 private string OutputPath { get; }
73
74 private bool SuppressAddingValidationRows { get; }
@@ -77,7 +81,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
81
82 private Validator Validator { get; }
83
80 - public IEnumerable<FileTransfer> FileTransfers { get; private set; }
84 + public IEnumerable<IFileTransfer> FileTransfers { get; private set; }
85
86 public IEnumerable<string> ContentFilePaths { get; private set; }
87
@@ -87,7 +91,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
91 {
92 var section = this.Intermediate.Sections.Single();
93
90 - var fileTransfers = new List<FileTransfer>();
94 + var fileTransfers = new List<IFileTransfer>();
95
96 var containsMergeModules = false;
97 var suppressedTableNames = new HashSet<string>();
@@ -375,7 +379,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
379 {
380 this.Messaging.Write(VerboseMessages.CreatingCabinetFiles());
381
378 - var command = new CreateCabinetsCommand();
382 + var command = new CreateCabinetsCommand(this.BackendHelper);
383 command.CabbingThreadCount = this.CabbingThreadCount;
384 command.CabCachePath = this.CabCachePath;
385 command.DefaultCompressionLevel = this.DefaultCompressionLevel;
@@ -415,11 +419,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
419 string tempDatabaseFile = Path.Combine(this.IntermediateFolder, Path.GetFileName(this.OutputPath));
420 this.GenerateDatabase(output, tempDatabaseFile, false, false);
421
418 - if (FileTransfer.TryCreate(tempDatabaseFile, this.OutputPath, true, output.Type.ToString(), null, out var transfer)) // note where this database needs to move in the future
419 - {
420 - transfer.Built = true;
421 - fileTransfers.Add(transfer);
422 - }
422 + var transfer = this.BackendHelper.CreateFileTransfer(tempDatabaseFile, this.OutputPath, true, FileTransferType.Built); // note where this database needs to move in the future
423 + fileTransfers.Add(transfer);
424
425 // Stop processing if an error previously occurred.
426 if (this.Messaging.EncounteredError)
@@ -491,7 +492,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
492 // Process uncompressed files.
493 if (!this.Messaging.EncounteredError && !this.SuppressLayout && uncompressedFiles.Any())
494 {
494 - var command = new ProcessUncompressedFilesCommand(section);
495 + var command = new ProcessUncompressedFilesCommand(section, this.BackendHelper);
496 command.Compressed = compressed;
497 command.FileFacades = uncompressedFiles;
498 command.LayoutDirectory = layoutDirectory;
src/WixToolset.Core.WindowsInstaller/Bind/CreateCabinetsCommand.cs
+18 -20
@@ -26,19 +26,23 @@ namespace WixToolset.Core.WindowsInstaller.Bind
26 public const int DefaultMaximumUncompressedMediaSize = 200; // Default value is 200 MB
27 public const int MaxValueOfMaxCabSizeForLargeFileSplitting = 2 * 1024; // 2048 MB (i.e. 2 GB)
28
29 - private List<FileTransfer> fileTransfers;
29 + private List<IFileTransfer> fileTransfers;
30
31 private FileSplitCabNamesCallback newCabNamesCallBack;
32
33 private Dictionary<string, string> lastCabinetAddedToMediaTable; // Key is First Cabinet Name, Value is Last Cabinet Added in the Split Sequence
34
35 - public CreateCabinetsCommand()
35 + public CreateCabinetsCommand(IBackendHelper backendHelper)
36 {
37 - this.fileTransfers = new List<FileTransfer>();
37 + this.fileTransfers = new List<IFileTransfer>();
38
39 this.newCabNamesCallBack = this.NewCabNamesCallBack;
40 +
41 + this.BackendHelper = backendHelper;
42 }
43
44 + public IBackendHelper BackendHelper { get; }
45 +
46 /// <summary>
47 /// Sets the number of threads to use for cabinet creation.
48 /// </summary>
@@ -72,7 +76,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
76
77 public IEnumerable<WixMediaTuple> WixMediaTuples { private get; set; }
78
75 - public IEnumerable<FileTransfer> FileTransfers => this.fileTransfers;
79 + public IEnumerable<IFileTransfer> FileTransfers => this.fileTransfers;
80
81 /// <param name="output">Output to generate image for.</param>
82 /// <param name="fileTransfers">Array of files to be transfered.</param>
@@ -186,7 +190,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
190 /// <param name="fileFacades">Collection of files in this cabinet.</param>
191 /// <param name="fileTransfers">Array of files to be transfered.</param>
192 /// <returns>created CabinetWorkItem object</returns>
189 - private CabinetWorkItem CreateCabinetWorkItem(Output output, string cabinetDir, MediaTuple mediaRow, CompressionLevel compressionLevel, IEnumerable<FileFacade> fileFacades, List<FileTransfer> fileTransfers)
193 + private CabinetWorkItem CreateCabinetWorkItem(Output output, string cabinetDir, MediaTuple mediaRow, CompressionLevel compressionLevel, IEnumerable<FileFacade> fileFacades, List<IFileTransfer> fileTransfers)
194 {
195 CabinetWorkItem cabinetWorkItem = null;
196 string tempCabinetFileX = Path.Combine(this.TempFilesLocation, mediaRow.Cabinet);
@@ -254,12 +258,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind
258 }
259 else
260 {
257 - string destinationPath = Path.Combine(cabinetDir, mediaRow.Cabinet);
258 - if (FileTransfer.TryCreate(resolvedCabinet.Path, destinationPath, CabinetBuildOption.BuildAndMove == resolvedCabinet.BuildOption, "Cabinet", mediaRow.SourceLineNumbers, out var transfer))
259 - {
260 - transfer.Built = true;
261 - fileTransfers.Add(transfer);
262 - }
261 + var destinationPath = Path.Combine(cabinetDir, mediaRow.Cabinet);
262 + var transfer = this.BackendHelper.CreateFileTransfer(resolvedCabinet.Path, destinationPath, CabinetBuildOption.BuildAndMove == resolvedCabinet.BuildOption, FileTransferType.Built, mediaRow.SourceLineNumbers);
263 + fileTransfers.Add(transfer);
264 }
265
266 return cabinetWorkItem;
@@ -315,21 +316,18 @@ namespace WixToolset.Core.WindowsInstaller.Bind
316 bool transferAdded = false; // Used for Error Handling
317
318 // Create File Transfer for new Cabinet using transfer of Base Cabinet
318 - foreach (FileTransfer transfer in this.FileTransfers)
319 + foreach (var transfer in this.FileTransfers)
320 {
321 if (firstCabinetName.Equals(Path.GetFileName(transfer.Source), StringComparison.InvariantCultureIgnoreCase))
322 {
323 string newCabSourcePath = Path.Combine(Path.GetDirectoryName(transfer.Source), newCabinetName);
324 string newCabTargetPath = Path.Combine(Path.GetDirectoryName(transfer.Destination), newCabinetName);
325
325 - FileTransfer newTransfer;
326 - if (FileTransfer.TryCreate(newCabSourcePath, newCabTargetPath, transfer.Move, "Cabinet", transfer.SourceLineNumbers, out newTransfer))
327 - {
328 - newTransfer.Built = true;
329 - this.fileTransfers.Add(newTransfer);
330 - transferAdded = true;
331 - break;
332 - }
326 + var newTransfer = this.BackendHelper.CreateFileTransfer(newCabSourcePath, newCabTargetPath, transfer.Move, FileTransferType.Built, transfer.SourceLineNumbers);
327 + this.fileTransfers.Add(newTransfer);
328 +
329 + transferAdded = true;
330 + break;
331 }
332 }
333
src/WixToolset.Core.WindowsInstaller/Bind/ProcessUncompressedFilesCommand.cs
+10 -8
@@ -11,6 +11,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
11 using WixToolset.Data;
12 using WixToolset.Data.Tuples;
13 using WixToolset.Extensibility.Data;
14 + using WixToolset.Extensibility.Services;
15 using WixToolset.Msi;
16
17 /// <summary>
@@ -18,13 +19,16 @@ namespace WixToolset.Core.WindowsInstaller.Bind
19 /// </summary>
20 internal class ProcessUncompressedFilesCommand
21 {
21 - public ProcessUncompressedFilesCommand(IntermediateSection section)
22 + public ProcessUncompressedFilesCommand(IntermediateSection section, IBackendHelper backendHelper)
23 {
24 this.Section = section;
25 + this.BackendHelper = backendHelper;
26 }
27
28 private IntermediateSection Section { get; }
29
30 + public IBackendHelper BackendHelper { get; }
31 +
32 public string DatabasePath { private get; set; }
33
34 public IEnumerable<FileFacade> FileFacades { private get; set; }
@@ -37,11 +41,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind
41
42 public Func<MediaTuple, string, string, string> ResolveMedia { private get; set; }
43
40 - public IEnumerable<FileTransfer> FileTransfers { get; private set; }
44 + public IEnumerable<IFileTransfer> FileTransfers { get; private set; }
45
46 public void Execute()
47 {
44 - var fileTransfers = new List<FileTransfer>();
48 + var fileTransfers = new List<IFileTransfer>();
49
50 var directories = new Dictionary<string, ResolvedDirectory>();
51
@@ -103,11 +107,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind
107 }
108
109 // finally put together the base media layout path and the relative file layout path
106 - string fileLayoutPath = Path.Combine(mediaLayoutDirectory, relativeFileLayoutPath);
107 - if (FileTransfer.TryCreate(facade.WixFile.Source.Path, fileLayoutPath, false, "File", facade.File.SourceLineNumbers, out var transfer))
108 - {
109 - fileTransfers.Add(transfer);
110 - }
110 + var fileLayoutPath = Path.Combine(mediaLayoutDirectory, relativeFileLayoutPath);
111 + var transfer = this.BackendHelper.CreateFileTransfer(facade.WixFile.Source.Path, fileLayoutPath, false, FileTransferType.Content, facade.File.SourceLineNumbers);
112 + fileTransfers.Add(transfer);
113 }
114 }
115 }
src/WixToolset.Core/Bind/TransferFilesCommand.cs
+2 -2
@@ -13,7 +13,7 @@ namespace WixToolset.Core.Bind
13
14 internal class TransferFilesCommand
15 {
16 - public TransferFilesCommand(IMessaging messaging, IEnumerable<ILayoutExtension> extensions, IEnumerable<FileTransfer> fileTransfers, bool suppressAclReset)
16 + public TransferFilesCommand(IMessaging messaging, IEnumerable<ILayoutExtension> extensions, IEnumerable<IFileTransfer> fileTransfers, bool suppressAclReset)
17 {
18 this.FileSystem = new FileSystem(extensions);
19 this.Messaging = messaging;
@@ -25,7 +25,7 @@ namespace WixToolset.Core.Bind
25
26 private IMessaging Messaging { get; }
27
28 - private IEnumerable<FileTransfer> FileTransfers { get; }
28 + private IEnumerable<IFileTransfer> FileTransfers { get; }
29
30 private bool SuppressAclReset { get; }
31
src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs new
+70
@@ -0,0 +1,70 @@
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.IO;
7 + using WixToolset.Data;
8 + using WixToolset.Extensibility.Data;
9 + using WixToolset.Extensibility.Services;
10 +
11 + internal class BackendHelper : IBackendHelper
12 + {
13 + private static readonly string[] ReservedFileNames = { "CON", "PRN", "AUX", "NUL", "COM1", "COM2", "COM3", "COM4", "COM5", "COM6", "COM7", "COM8", "COM9", "LPT1", "LPT2", "LPT3", "LPT4", "LPT5", "LPT6", "LPT7", "LPT8", "LPT9" };
14 +
15 + public BackendHelper(IServiceProvider serviceProvider)
16 + {
17 + this.Messaging = serviceProvider.GetService<IMessaging>();
18 + }
19 +
20 + private IMessaging Messaging { get; }
21 +
22 + public IFileTransfer CreateFileTransfer(string source, string destination, bool move, FileTransferType type, SourceLineNumber sourceLineNumbers)
23 + {
24 + var sourceFullPath = GetValidatedFullPath(sourceLineNumbers, source);
25 +
26 + var destinationFullPath = GetValidatedFullPath(sourceLineNumbers, destination);
27 +
28 + return (String.IsNullOrEmpty(sourceFullPath) || String.IsNullOrEmpty(destinationFullPath)) ? null : new FileTransfer
29 + {
30 + Source = sourceFullPath,
31 + Destination = destinationFullPath,
32 + Move = move,
33 + Type = type,
34 + SourceLineNumbers = sourceLineNumbers,
35 + Redundant = String.Equals(sourceFullPath, destinationFullPath, StringComparison.OrdinalIgnoreCase)
36 + };
37 + }
38 +
39 + private string GetValidatedFullPath(SourceLineNumber sourceLineNumbers, string path)
40 + {
41 + try
42 + {
43 + var result = Path.GetFullPath(path);
44 +
45 + var filename = Path.GetFileName(result);
46 +
47 + foreach (var reservedName in ReservedFileNames)
48 + {
49 + if (reservedName.Equals(filename, StringComparison.OrdinalIgnoreCase))
50 + {
51 + this.Messaging.Write(ErrorMessages.InvalidFileName(sourceLineNumbers, path));
52 + return null;
53 + }
54 + }
55 +
56 + return result;
57 + }
58 + catch (ArgumentException)
59 + {
60 + this.Messaging.Write(ErrorMessages.InvalidFileName(sourceLineNumbers, path));
61 + }
62 + catch (PathTooLongException)
63 + {
64 + this.Messaging.Write(ErrorMessages.PathTooLong(sourceLineNumbers, path));
65 + }
66 +
67 + return null;
68 + }
69 + }
70 +}
src/WixToolset.Core/FileTransfer.cs new
+22
@@ -0,0 +1,22 @@
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
4 +{
5 + using WixToolset.Data;
6 + using WixToolset.Extensibility.Data;
7 +
8 + internal class FileTransfer : IFileTransfer
9 + {
10 + public string Source { get; set; }
11 +
12 + public string Destination { get; set; }
13 +
14 + public bool Move { get; set; }
15 +
16 + public SourceLineNumber SourceLineNumbers { get; set; }
17 +
18 + public FileTransferType Type { get; set; }
19 +
20 + public bool Redundant { get; set; }
21 + }
22 +}
src/WixToolset.Core/Layout.cs
+6 -6
@@ -28,7 +28,7 @@ namespace WixToolset.Core
28
29 private IMessaging Messaging { get; }
30
31 - public IEnumerable<FileTransfer> FileTransfers { get; set; }
31 + public IEnumerable<IFileTransfer> FileTransfers { get; set; }
32
33 public IEnumerable<string> ContentFilePaths { get; set; }
34
@@ -124,14 +124,14 @@ namespace WixToolset.Core
124 /// </summary>
125 /// <param name="path">Path to write file.</param>
126 /// <param name="fileTransfers">Collection of files that were transferred to the output directory.</param>
127 - private void CreateOutputsFile(string path, IEnumerable<FileTransfer> fileTransfers)
127 + private void CreateOutputsFile(string path, IEnumerable<IFileTransfer> fileTransfers)
128 {
129 var directory = Path.GetDirectoryName(path);
130 Directory.CreateDirectory(directory);
131
132 using (var outputs = new StreamWriter(path, false))
133 {
134 - foreach (FileTransfer fileTransfer in fileTransfers)
134 + foreach (var fileTransfer in fileTransfers)
135 {
136 // Don't list files where the source is the same as the destination since
137 // that might be the only place the file exists. The outputs file is often
@@ -149,18 +149,18 @@ namespace WixToolset.Core
149 /// </summary>
150 /// <param name="path">Path to write file.</param>
151 /// <param name="fileTransfers">Collection of files that were transferred to the output directory.</param>
152 - private void CreateBuiltOutputsFile(string path, IEnumerable<FileTransfer> fileTransfers)
152 + private void CreateBuiltOutputsFile(string path, IEnumerable<IFileTransfer> fileTransfers)
153 {
154 var directory = Path.GetDirectoryName(path);
155 Directory.CreateDirectory(directory);
156
157 using (var outputs = new StreamWriter(path, false))
158 {
159 - foreach (FileTransfer fileTransfer in fileTransfers)
159 + foreach (var fileTransfer in fileTransfers)
160 {
161 // Only write the built file transfers. Also, skip redundant
162 // files for the same reason spelled out in this.CreateOutputsFile().
163 - if (fileTransfer.Built && !fileTransfer.Redundant)
163 + if (fileTransfer.Type == FileTransferType.Built && !fileTransfer.Redundant)
164 {
165 outputs.WriteLine(fileTransfer.Destination);
166 }
src/WixToolset.Core/LayoutContext.cs
+1 -1
@@ -20,7 +20,7 @@ namespace WixToolset.Core
20
21 public IEnumerable<IFileSystemExtension> FileSystemExtensions { get; set; }
22
23 - public IEnumerable<FileTransfer> FileTransfers { get; set; }
23 + public IEnumerable<IFileTransfer> FileTransfers { get; set; }
24
25 public IEnumerable<string> ContentFilePaths { get; set; }
26
src/WixToolset.Core/WixToolsetServiceProvider.cs
+1
@@ -22,6 +22,7 @@ namespace WixToolset.Core
22 { typeof(ITupleDefinitionCreator), (provider, singletons) => AddSingleton(singletons, typeof(ITupleDefinitionCreator), new TupleDefinitionCreator(provider)) },
23 { typeof(IParseHelper), (provider, singletons) => AddSingleton(singletons, typeof(IParseHelper), new ParseHelper(provider)) },
24 { typeof(IPreprocessHelper), (provider, singletons) => AddSingleton(singletons, typeof(IPreprocessHelper), new PreprocessHelper(provider)) },
25 + { typeof(IBackendHelper), (provider, singletons) => AddSingleton(singletons, typeof(IBackendHelper), new BackendHelper(provider)) },
26 { typeof(IWindowsInstallerBackendHelper), (provider, singletons) => AddSingleton(singletons, typeof(IWindowsInstallerBackendHelper), new WindowsInstallerBackendHelper(provider)) },
27
28 // Transients.