diff options
Diffstat (limited to 'src/WixToolset.Core/Bind/FileTransfer.cs')
-rw-r--r-- | src/WixToolset.Core/Bind/FileTransfer.cs | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/src/WixToolset.Core/Bind/FileTransfer.cs b/src/WixToolset.Core/Bind/FileTransfer.cs deleted file mode 100644 index 64bbc5f1..00000000 --- a/src/WixToolset.Core/Bind/FileTransfer.cs +++ /dev/null | |||
@@ -1,113 +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.Bind | ||
4 | { | ||
5 | using System; | ||
6 | using System.IO; | ||
7 | using WixToolset; | ||
8 | using WixToolset.Data; | ||
9 | |||
10 | /// <summary> | ||
11 | /// Structure used for all file transfer information. | ||
12 | /// </summary> | ||
13 | internal class FileTransfer | ||
14 | { | ||
15 | /// <summary>Source path to file.</summary> | ||
16 | public string Source { get; set; } | ||
17 | |||
18 | /// <summary>Destination path for file.</summary> | ||
19 | public string Destination { get; set; } | ||
20 | |||
21 | /// <summary>Flag if file should be moved (optimal).</summary> | ||
22 | public bool Move { get; set; } | ||
23 | |||
24 | /// <summary>Optional source line numbers where this file transfer orginated.</summary> | ||
25 | public SourceLineNumber SourceLineNumbers { get; set; } | ||
26 | |||
27 | /// <summary>Optional type of file this transfer is moving or copying.</summary> | ||
28 | public string Type { get; set; } | ||
29 | |||
30 | /// <summary>Indicates whether the file transer was a built by this build or copied from other some build.</summary> | ||
31 | internal bool Built { get; set; } | ||
32 | |||
33 | /// <summary>Set during layout of media when the file transfer when the source and target resolve to the same path.</summary> | ||
34 | internal bool Redundant { get; set; } | ||
35 | |||
36 | /// <summary> | ||
37 | /// Prefer the TryCreate() method to create FileTransfer objects. | ||
38 | /// </summary> | ||
39 | /// <param name="source">Source path to file.</param> | ||
40 | /// <param name="destination">Destination path for file.</param> | ||
41 | /// <param name="move">File if file should be moved (optimal).</param> | ||
42 | /// <param name="type">Optional type of file this transfer is transferring.</param> | ||
43 | /// <param name="sourceLineNumbers">Optional source line numbers wher this transfer originated.</param> | ||
44 | public FileTransfer(string source, string destination, bool move, string type = null, SourceLineNumber sourceLineNumbers = null) | ||
45 | { | ||
46 | this.Source = source; | ||
47 | this.Destination = destination; | ||
48 | this.Move = move; | ||
49 | |||
50 | this.Type = type; | ||
51 | this.SourceLineNumbers = sourceLineNumbers; | ||
52 | } | ||
53 | |||
54 | /// <summary> | ||
55 | /// Creates a file transfer if the source and destination are different. | ||
56 | /// </summary> | ||
57 | /// <param name="source">Source path to file.</param> | ||
58 | /// <param name="destination">Destination path for file.</param> | ||
59 | /// <param name="move">File if file should be moved (optimal).</param> | ||
60 | /// <param name="type">Optional type of file this transfer is transferring.</param> | ||
61 | /// <param name="sourceLineNumbers">Optional source line numbers wher this transfer originated.</param> | ||
62 | /// <returns>true if the source and destination are the different, false if no file transfer is created.</returns> | ||
63 | public static bool TryCreate(string source, string destination, bool move, string type, SourceLineNumber sourceLineNumbers, out FileTransfer transfer) | ||
64 | { | ||
65 | string sourceFullPath = GetValidatedFullPath(sourceLineNumbers, source); | ||
66 | |||
67 | string fileLayoutFullPath = GetValidatedFullPath(sourceLineNumbers, destination); | ||
68 | |||
69 | // if the current source path (where we know that the file already exists) and the resolved | ||
70 | // path as dictated by the Directory table are not the same, then propagate the file. The | ||
71 | // image that we create may have already been done by some other process other than the linker, so | ||
72 | // there is no reason to copy the files to the resolved source if they are already there. | ||
73 | if (String.Equals(sourceFullPath, fileLayoutFullPath, StringComparison.OrdinalIgnoreCase)) | ||
74 | { | ||
75 | transfer = null; | ||
76 | return false; | ||
77 | } | ||
78 | |||
79 | transfer = new FileTransfer(source, destination, move, type, sourceLineNumbers); | ||
80 | return true; | ||
81 | } | ||
82 | |||
83 | private static string GetValidatedFullPath(SourceLineNumber sourceLineNumbers, string path) | ||
84 | { | ||
85 | string result; | ||
86 | |||
87 | try | ||
88 | { | ||
89 | result = Path.GetFullPath(path); | ||
90 | |||
91 | string filename = Path.GetFileName(result); | ||
92 | |||
93 | foreach (string reservedName in Common.ReservedFileNames) | ||
94 | { | ||
95 | if (reservedName.Equals(filename, StringComparison.OrdinalIgnoreCase)) | ||
96 | { | ||
97 | throw new WixException(WixErrors.InvalidFileName(sourceLineNumbers, path)); | ||
98 | } | ||
99 | } | ||
100 | } | ||
101 | catch (System.ArgumentException) | ||
102 | { | ||
103 | throw new WixException(WixErrors.InvalidFileName(sourceLineNumbers, path)); | ||
104 | } | ||
105 | catch (System.IO.PathTooLongException) | ||
106 | { | ||
107 | throw new WixException(WixErrors.PathTooLong(sourceLineNumbers, path)); | ||
108 | } | ||
109 | |||
110 | return result; | ||
111 | } | ||
112 | } | ||
113 | } | ||