diff options
Diffstat (limited to '')
-rw-r--r-- | src/WixToolset.Core/Bind/FileSystem.cs | 86 |
1 files changed, 0 insertions, 86 deletions
diff --git a/src/WixToolset.Core/Bind/FileSystem.cs b/src/WixToolset.Core/Bind/FileSystem.cs deleted file mode 100644 index bdd65503..00000000 --- a/src/WixToolset.Core/Bind/FileSystem.cs +++ /dev/null | |||
@@ -1,86 +0,0 @@ | |||
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.Bind | ||
4 | { | ||
5 | using System; | ||
6 | using System.Collections.Generic; | ||
7 | using System.IO; | ||
8 | using System.Runtime.InteropServices; | ||
9 | using WixToolset.Extensibility; | ||
10 | |||
11 | internal class FileSystem | ||
12 | { | ||
13 | public FileSystem(IEnumerable<ILayoutExtension> extensions) | ||
14 | { | ||
15 | this.Extensions = extensions ?? Array.Empty<ILayoutExtension>(); | ||
16 | } | ||
17 | |||
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 | public bool CopyFile(string source, string destination) | ||
26 | { | ||
27 | foreach (var extension in this.Extensions) | ||
28 | { | ||
29 | if (extension.CopyFile(source, destination)) | ||
30 | { | ||
31 | return true; | ||
32 | } | ||
33 | } | ||
34 | |||
35 | if (File.Exists(destination)) | ||
36 | { | ||
37 | File.Delete(destination); | ||
38 | } | ||
39 | |||
40 | if (!CreateHardLink(destination, source, IntPtr.Zero)) | ||
41 | { | ||
42 | #if DEBUG | ||
43 | int er = Marshal.GetLastWin32Error(); | ||
44 | #endif | ||
45 | |||
46 | File.Copy(source, destination, true); | ||
47 | } | ||
48 | |||
49 | return true; | ||
50 | } | ||
51 | |||
52 | /// <summary> | ||
53 | /// Moves a file. | ||
54 | /// </summary> | ||
55 | /// <param name="source">The file to move.</param> | ||
56 | /// <param name="destination">The destination file.</param> | ||
57 | public bool MoveFile(string source, string destination) | ||
58 | { | ||
59 | foreach (var extension in this.Extensions) | ||
60 | { | ||
61 | if (extension.MoveFile(source, destination)) | ||
62 | { | ||
63 | return true; | ||
64 | } | ||
65 | } | ||
66 | |||
67 | if (File.Exists(destination)) | ||
68 | { | ||
69 | File.Delete(destination); | ||
70 | } | ||
71 | |||
72 | var directory = Path.GetDirectoryName(destination); | ||
73 | if (!String.IsNullOrEmpty(directory)) | ||
74 | { | ||
75 | Directory.CreateDirectory(directory); | ||
76 | } | ||
77 | |||
78 | File.Move(source, destination); | ||
79 | |||
80 | return true; | ||
81 | } | ||
82 | |||
83 | [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)] | ||
84 | private static extern bool CreateHardLink(string lpFileName, string lpExistingFileName, IntPtr lpSecurityAttributes); | ||
85 | } | ||
86 | } | ||