diff options
author | Rob Mensching <rob@firegiant.com> | 2018-07-26 23:52:12 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2018-07-27 11:31:18 -0700 |
commit | 854e616eb3516c7405691b679617aa08c1dd1cdd (patch) | |
tree | ce7694749bf88bc796825b84fbc4f9d8acae331d /src/WixToolset.Core | |
parent | c64faa7f6cb789a0756dff725146728889df8311 (diff) | |
download | wix-854e616eb3516c7405691b679617aa08c1dd1cdd.tar.gz wix-854e616eb3516c7405691b679617aa08c1dd1cdd.tar.bz2 wix-854e616eb3516c7405691b679617aa08c1dd1cdd.zip |
Support change of FileTransfer to interface
Diffstat (limited to 'src/WixToolset.Core')
-rw-r--r-- | src/WixToolset.Core/Bind/TransferFilesCommand.cs | 4 | ||||
-rw-r--r-- | src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs | 70 | ||||
-rw-r--r-- | src/WixToolset.Core/FileTransfer.cs | 22 | ||||
-rw-r--r-- | src/WixToolset.Core/Layout.cs | 12 | ||||
-rw-r--r-- | src/WixToolset.Core/LayoutContext.cs | 2 | ||||
-rw-r--r-- | src/WixToolset.Core/WixToolsetServiceProvider.cs | 1 |
6 files changed, 102 insertions, 9 deletions
diff --git a/src/WixToolset.Core/Bind/TransferFilesCommand.cs b/src/WixToolset.Core/Bind/TransferFilesCommand.cs index 79f0cd81..b89d3d03 100644 --- a/src/WixToolset.Core/Bind/TransferFilesCommand.cs +++ b/src/WixToolset.Core/Bind/TransferFilesCommand.cs | |||
@@ -13,7 +13,7 @@ namespace WixToolset.Core.Bind | |||
13 | 13 | ||
14 | internal class TransferFilesCommand | 14 | internal class TransferFilesCommand |
15 | { | 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 | { | 17 | { |
18 | this.FileSystem = new FileSystem(extensions); | 18 | this.FileSystem = new FileSystem(extensions); |
19 | this.Messaging = messaging; | 19 | this.Messaging = messaging; |
@@ -25,7 +25,7 @@ namespace WixToolset.Core.Bind | |||
25 | 25 | ||
26 | private IMessaging Messaging { get; } | 26 | private IMessaging Messaging { get; } |
27 | 27 | ||
28 | private IEnumerable<FileTransfer> FileTransfers { get; } | 28 | private IEnumerable<IFileTransfer> FileTransfers { get; } |
29 | 29 | ||
30 | private bool SuppressAclReset { get; } | 30 | private bool SuppressAclReset { get; } |
31 | 31 | ||
diff --git a/src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs b/src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs new file mode 100644 index 00000000..0e5c4b5b --- /dev/null +++ b/src/WixToolset.Core/ExtensibilityServices/BackendHelper.cs | |||
@@ -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 | } | ||
diff --git a/src/WixToolset.Core/FileTransfer.cs b/src/WixToolset.Core/FileTransfer.cs new file mode 100644 index 00000000..9da406eb --- /dev/null +++ b/src/WixToolset.Core/FileTransfer.cs | |||
@@ -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 | } | ||
diff --git a/src/WixToolset.Core/Layout.cs b/src/WixToolset.Core/Layout.cs index a5e885e5..28c9d5fc 100644 --- a/src/WixToolset.Core/Layout.cs +++ b/src/WixToolset.Core/Layout.cs | |||
@@ -28,7 +28,7 @@ namespace WixToolset.Core | |||
28 | 28 | ||
29 | private IMessaging Messaging { get; } | 29 | private IMessaging Messaging { get; } |
30 | 30 | ||
31 | public IEnumerable<FileTransfer> FileTransfers { get; set; } | 31 | public IEnumerable<IFileTransfer> FileTransfers { get; set; } |
32 | 32 | ||
33 | public IEnumerable<string> ContentFilePaths { get; set; } | 33 | public IEnumerable<string> ContentFilePaths { get; set; } |
34 | 34 | ||
@@ -124,14 +124,14 @@ namespace WixToolset.Core | |||
124 | /// </summary> | 124 | /// </summary> |
125 | /// <param name="path">Path to write file.</param> | 125 | /// <param name="path">Path to write file.</param> |
126 | /// <param name="fileTransfers">Collection of files that were transferred to the output directory.</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 | { | 128 | { |
129 | var directory = Path.GetDirectoryName(path); | 129 | var directory = Path.GetDirectoryName(path); |
130 | Directory.CreateDirectory(directory); | 130 | Directory.CreateDirectory(directory); |
131 | 131 | ||
132 | using (var outputs = new StreamWriter(path, false)) | 132 | using (var outputs = new StreamWriter(path, false)) |
133 | { | 133 | { |
134 | foreach (FileTransfer fileTransfer in fileTransfers) | 134 | foreach (var fileTransfer in fileTransfers) |
135 | { | 135 | { |
136 | // Don't list files where the source is the same as the destination since | 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 | 137 | // that might be the only place the file exists. The outputs file is often |
@@ -149,18 +149,18 @@ namespace WixToolset.Core | |||
149 | /// </summary> | 149 | /// </summary> |
150 | /// <param name="path">Path to write file.</param> | 150 | /// <param name="path">Path to write file.</param> |
151 | /// <param name="fileTransfers">Collection of files that were transferred to the output directory.</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 | { | 153 | { |
154 | var directory = Path.GetDirectoryName(path); | 154 | var directory = Path.GetDirectoryName(path); |
155 | Directory.CreateDirectory(directory); | 155 | Directory.CreateDirectory(directory); |
156 | 156 | ||
157 | using (var outputs = new StreamWriter(path, false)) | 157 | using (var outputs = new StreamWriter(path, false)) |
158 | { | 158 | { |
159 | foreach (FileTransfer fileTransfer in fileTransfers) | 159 | foreach (var fileTransfer in fileTransfers) |
160 | { | 160 | { |
161 | // Only write the built file transfers. Also, skip redundant | 161 | // Only write the built file transfers. Also, skip redundant |
162 | // files for the same reason spelled out in this.CreateOutputsFile(). | 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 | { | 164 | { |
165 | outputs.WriteLine(fileTransfer.Destination); | 165 | outputs.WriteLine(fileTransfer.Destination); |
166 | } | 166 | } |
diff --git a/src/WixToolset.Core/LayoutContext.cs b/src/WixToolset.Core/LayoutContext.cs index af0df518..172cea65 100644 --- a/src/WixToolset.Core/LayoutContext.cs +++ b/src/WixToolset.Core/LayoutContext.cs | |||
@@ -20,7 +20,7 @@ namespace WixToolset.Core | |||
20 | 20 | ||
21 | public IEnumerable<IFileSystemExtension> FileSystemExtensions { get; set; } | 21 | public IEnumerable<IFileSystemExtension> FileSystemExtensions { get; set; } |
22 | 22 | ||
23 | public IEnumerable<FileTransfer> FileTransfers { get; set; } | 23 | public IEnumerable<IFileTransfer> FileTransfers { get; set; } |
24 | 24 | ||
25 | public IEnumerable<string> ContentFilePaths { get; set; } | 25 | public IEnumerable<string> ContentFilePaths { get; set; } |
26 | 26 | ||
diff --git a/src/WixToolset.Core/WixToolsetServiceProvider.cs b/src/WixToolset.Core/WixToolsetServiceProvider.cs index dd6da8c8..ffcdbdd1 100644 --- a/src/WixToolset.Core/WixToolsetServiceProvider.cs +++ b/src/WixToolset.Core/WixToolsetServiceProvider.cs | |||
@@ -22,6 +22,7 @@ namespace WixToolset.Core | |||
22 | { typeof(ITupleDefinitionCreator), (provider, singletons) => AddSingleton(singletons, typeof(ITupleDefinitionCreator), new TupleDefinitionCreator(provider)) }, | 22 | { typeof(ITupleDefinitionCreator), (provider, singletons) => AddSingleton(singletons, typeof(ITupleDefinitionCreator), new TupleDefinitionCreator(provider)) }, |
23 | { typeof(IParseHelper), (provider, singletons) => AddSingleton(singletons, typeof(IParseHelper), new ParseHelper(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)) }, | 24 | { typeof(IPreprocessHelper), (provider, singletons) => AddSingleton(singletons, typeof(IPreprocessHelper), new PreprocessHelper(provider)) }, |
25 | { typeof(IBackendHelper), (provider, singletons) => AddSingleton(singletons, typeof(IBackendHelper), new BackendHelper(provider)) }, | ||
25 | { typeof(IWindowsInstallerBackendHelper), (provider, singletons) => AddSingleton(singletons, typeof(IWindowsInstallerBackendHelper), new WindowsInstallerBackendHelper(provider)) }, | 26 | { typeof(IWindowsInstallerBackendHelper), (provider, singletons) => AddSingleton(singletons, typeof(IWindowsInstallerBackendHelper), new WindowsInstallerBackendHelper(provider)) }, |
26 | 27 | ||
27 | // Transients. | 28 | // Transients. |