Move copy/move file operations to ILayoutExtension
Rob Mensching committed
Dec 26, 2017 at 15:12 UTC
eee0773fc35c4c2d37c95186f4bf686dcb1c8d8b
3 files changed
+14
-16
src/WixToolset.Core/Bind/FileSystem.cs
+10
-11
@@ -10,30 +10,29 @@ namespace WixToolset.Core.Bind
10
11
internal class FileSystem
12
{
13
- public FileSystem(IEnumerable<IFileSystemExtension> extensions)
13
+ public FileSystem(IEnumerable<ILayoutExtension> extensions)
14
{
15
- this.Extensions = extensions ?? Array.Empty<IFileSystemExtension>();
15
+ this.Extensions = extensions ?? Array.Empty<ILayoutExtension>();
16
}
17
18
- private IEnumerable<IFileSystemExtension> Extensions { get; }
18
+ private IEnumerable<ILayoutExtension> Extensions { get; }
19
20
/// <summary>
21
/// Copies a file.
22
/// </summary>
23
/// <param name="source">The file to copy.</param>
24
/// <param name="destination">The destination file.</param>
25
- /// <param name="overwrite">true if the destination file can be overwritten; otherwise, false.</param>
26
- public bool CopyFile(string source, string destination, bool overwrite)
25
+ public bool CopyFile(string source, string destination)
26
{
27
foreach (var extension in this.Extensions)
28
{
30
- if (extension.CopyFile(source, destination, overwrite))
29
+ if (extension.CopyFile(source, destination))
30
{
31
return true;
32
}
33
}
34
36
- if (overwrite && File.Exists(destination))
35
+ if (File.Exists(destination))
36
{
37
File.Delete(destination);
38
}
@@ -44,7 +43,7 @@ namespace WixToolset.Core.Bind
43
int er = Marshal.GetLastWin32Error();
44
#endif
45
47
- File.Copy(source, destination, overwrite);
46
+ File.Copy(source, destination, true);
47
}
48
49
return true;
@@ -55,17 +54,17 @@ namespace WixToolset.Core.Bind
54
/// </summary>
55
/// <param name="source">The file to move.</param>
56
/// <param name="destination">The destination file.</param>
58
- public bool MoveFile(string source, string destination, bool overwrite)
57
+ public bool MoveFile(string source, string destination)
58
{
59
foreach (var extension in this.Extensions)
60
{
62
- if (extension.MoveFile(source, destination, overwrite))
61
+ if (extension.MoveFile(source, destination))
62
{
63
return true;
64
}
65
}
66
68
- if (overwrite && File.Exists(destination))
67
+ if (File.Exists(destination))
68
{
69
File.Delete(destination);
70
}
src/WixToolset.Core/Bind/TransferFilesCommand.cs
+3
-3
@@ -13,7 +13,7 @@ namespace WixToolset.Core.Bind
13
14
internal class TransferFilesCommand
15
{
16
- public TransferFilesCommand(IMessaging messaging, IEnumerable<IFileSystemExtension> extensions, IEnumerable<FileTransfer> fileTransfers, bool suppressAclReset)
16
+ public TransferFilesCommand(IMessaging messaging, IEnumerable<ILayoutExtension> extensions, IEnumerable<FileTransfer> fileTransfers, bool suppressAclReset)
17
{
18
this.FileSystem = new FileSystem(extensions);
19
this.Messaging = messaging;
@@ -181,11 +181,11 @@ namespace WixToolset.Core.Bind
181
182
if (move)
183
{
184
- complete = this.FileSystem.MoveFile(source, destination, true);
184
+ complete = this.FileSystem.MoveFile(source, destination);
185
}
186
else
187
{
188
- complete = this.FileSystem.CopyFile(source, destination, true);
188
+ complete = this.FileSystem.CopyFile(source, destination);
189
}
190
191
if (!complete)
src/WixToolset.Core/Layout.cs
+1
-2
@@ -47,7 +47,6 @@ namespace WixToolset.Core
47
var context = this.ServiceProvider.GetService<ILayoutContext>();
48
context.Messaging = this.Messaging;
49
context.Extensions = extensionManager.Create<ILayoutExtension>();
50
- context.FileSystemExtensions = extensionManager.Create<IFileSystemExtension>();
50
context.FileTransfers = this.FileTransfers;
51
context.ContentFilePaths = this.ContentFilePaths;
52
context.ContentsFile = this.ContentsFile;
@@ -70,7 +69,7 @@ namespace WixToolset.Core
69
{
70
this.Messaging.Write(VerboseMessages.LayingOutMedia());
71
73
- var command = new TransferFilesCommand(context.Messaging, context.FileSystemExtensions, context.FileTransfers, context.SuppressAclReset);
72
+ var command = new TransferFilesCommand(context.Messaging, context.Extensions, context.FileTransfers, context.SuppressAclReset);
73
command.Execute();
74
}
75
}