aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Bind/FileResolver.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core/Bind/FileResolver.cs')
-rw-r--r--src/WixToolset.Core/Bind/FileResolver.cs92
1 files changed, 12 insertions, 80 deletions
diff --git a/src/WixToolset.Core/Bind/FileResolver.cs b/src/WixToolset.Core/Bind/FileResolver.cs
index 2142d261..a20d3f34 100644
--- a/src/WixToolset.Core/Bind/FileResolver.cs
+++ b/src/WixToolset.Core/Bind/FileResolver.cs
@@ -6,7 +6,6 @@ namespace WixToolset.Core.Bind
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.IO; 7 using System.IO;
8 using System.Linq; 8 using System.Linq;
9 using System.Runtime.InteropServices;
10 using WixToolset.Data; 9 using WixToolset.Data;
11 using WixToolset.Data.Bind; 10 using WixToolset.Data.Bind;
12 using WixToolset.Extensibility; 11 using WixToolset.Extensibility;
@@ -22,9 +21,9 @@ namespace WixToolset.Core.Bind
22 this.RebaseUpdated = this.BindPaths[BindStage.Updated].Any(); 21 this.RebaseUpdated = this.BindPaths[BindStage.Updated].Any();
23 } 22 }
24 23
25 public FileResolver(IEnumerable<BindPath> bindPaths, IEnumerable<IBinderExtension> extensions) : this(bindPaths) 24 public FileResolver(IEnumerable<BindPath> bindPaths, IEnumerable<IResolverExtension> extensions) : this(bindPaths)
26 { 25 {
27 this.BinderExtensions = extensions ?? Array.Empty<IBinderExtension>(); 26 this.ResolverExtensions = extensions ?? Array.Empty<IResolverExtension>();
28 } 27 }
29 28
30 public FileResolver(IEnumerable<BindPath> bindPaths, IEnumerable<ILibrarianExtension> extensions) : this(bindPaths) 29 public FileResolver(IEnumerable<BindPath> bindPaths, IEnumerable<ILibrarianExtension> extensions) : this(bindPaths)
@@ -38,79 +37,15 @@ namespace WixToolset.Core.Bind
38 37
39 public bool RebaseUpdated { get; } 38 public bool RebaseUpdated { get; }
40 39
41 private IEnumerable<IBinderExtension> BinderExtensions { get; } 40 private IEnumerable<IResolverExtension> ResolverExtensions { get; }
42 41
43 private IEnumerable<ILibrarianExtension> LibrarianExtensions { get; } 42 private IEnumerable<ILibrarianExtension> LibrarianExtensions { get; }
44 43
45 /// <summary> 44 public string Resolve(SourceLineNumber sourceLineNumbers, IntermediateTupleDefinition tupleDefinition, string source)
46 /// Copies a file.
47 /// </summary>
48 /// <param name="source">The file to copy.</param>
49 /// <param name="destination">The destination file.</param>
50 /// <param name="overwrite">true if the destination file can be overwritten; otherwise, false.</param>
51 public bool CopyFile(string source, string destination, bool overwrite)
52 {
53 foreach (var extension in this.BinderExtensions)
54 {
55 if (extension.CopyFile(source, destination, overwrite))
56 {
57 return true;
58 }
59 }
60
61 if (overwrite && File.Exists(destination))
62 {
63 File.Delete(destination);
64 }
65
66 if (!CreateHardLink(destination, source, IntPtr.Zero))
67 {
68#if DEBUG
69 int er = Marshal.GetLastWin32Error();
70#endif
71
72 File.Copy(source, destination, overwrite);
73 }
74
75 return true;
76 }
77
78 /// <summary>
79 /// Moves a file.
80 /// </summary>
81 /// <param name="source">The file to move.</param>
82 /// <param name="destination">The destination file.</param>
83 public bool MoveFile(string source, string destination, bool overwrite)
84 {
85 foreach (var extension in this.BinderExtensions)
86 {
87 if (extension.MoveFile(source, destination, overwrite))
88 {
89 return true;
90 }
91 }
92
93 if (overwrite && File.Exists(destination))
94 {
95 File.Delete(destination);
96 }
97
98 var directory = Path.GetDirectoryName(destination);
99 if (!String.IsNullOrEmpty(directory))
100 {
101 Directory.CreateDirectory(directory);
102 }
103
104 File.Move(source, destination);
105
106 return true;
107 }
108
109 public string Resolve(SourceLineNumber sourceLineNumbers, string table, string path)
110 { 45 {
111 foreach (var extension in this.LibrarianExtensions) 46 foreach (var extension in this.LibrarianExtensions)
112 { 47 {
113 var resolved = extension.Resolve(sourceLineNumbers, table, path); 48 var resolved = extension.Resolve(sourceLineNumbers, tupleDefinition, source);
114 49
115 if (null != resolved) 50 if (null != resolved)
116 { 51 {
@@ -118,7 +53,7 @@ namespace WixToolset.Core.Bind
118 } 53 }
119 } 54 }
120 55
121 return this.ResolveUsingBindPaths(path, table, sourceLineNumbers, BindStage.Normal); 56 return this.ResolveUsingBindPaths(source, tupleDefinition, sourceLineNumbers, BindStage.Normal);
122 } 57 }
123 58
124 /// <summary> 59 /// <summary>
@@ -129,11 +64,11 @@ namespace WixToolset.Core.Bind
129 /// <param name="sourceLineNumbers">Optional source line of source file being resolved.</param> 64 /// <param name="sourceLineNumbers">Optional source line of source file being resolved.</param>
130 /// <param name="bindStage">The binding stage used to determine what collection of bind paths will be used</param> 65 /// <param name="bindStage">The binding stage used to determine what collection of bind paths will be used</param>
131 /// <returns>Should return a valid path for the stream to be imported.</returns> 66 /// <returns>Should return a valid path for the stream to be imported.</returns>
132 public string ResolveFile(string source, string type, SourceLineNumber sourceLineNumbers, BindStage bindStage) 67 public string ResolveFile(string source, IntermediateTupleDefinition tupleDefinition, SourceLineNumber sourceLineNumbers, BindStage bindStage)
133 { 68 {
134 foreach (var extension in this.BinderExtensions) 69 foreach (var extension in this.ResolverExtensions)
135 { 70 {
136 var resolved = extension.ResolveFile(source, type, sourceLineNumbers, bindStage); 71 var resolved = extension.ResolveFile(source, tupleDefinition, sourceLineNumbers, bindStage);
137 72
138 if (null != resolved) 73 if (null != resolved)
139 { 74 {
@@ -141,10 +76,10 @@ namespace WixToolset.Core.Bind
141 } 76 }
142 } 77 }
143 78
144 return this.ResolveUsingBindPaths(source, type, sourceLineNumbers, bindStage); 79 return this.ResolveUsingBindPaths(source, tupleDefinition, sourceLineNumbers, bindStage);
145 } 80 }
146 81
147 private string ResolveUsingBindPaths(string source, string type, SourceLineNumber sourceLineNumbers, BindStage bindStage) 82 private string ResolveUsingBindPaths(string source, IntermediateTupleDefinition tupleDefinition, SourceLineNumber sourceLineNumbers, BindStage bindStage)
148 { 83 {
149 string resolved = null; 84 string resolved = null;
150 85
@@ -206,7 +141,7 @@ namespace WixToolset.Core.Bind
206 141
207 if (null == resolved) 142 if (null == resolved)
208 { 143 {
209 throw new WixFileNotFoundException(sourceLineNumbers, source, type); 144 throw new WixFileNotFoundException(sourceLineNumbers, source, tupleDefinition.Name);
210 } 145 }
211 146
212 // Didn't find the file. 147 // Didn't find the file.
@@ -224,8 +159,5 @@ namespace WixToolset.Core.Bind
224 throw new WixException(ErrorMessages.IllegalCharactersInPath(path)); 159 throw new WixException(ErrorMessages.IllegalCharactersInPath(path));
225 } 160 }
226 } 161 }
227
228 [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
229 private static extern bool CreateHardLink(string lpFileName, string lpExistingFileName, IntPtr lpSecurityAttributes);
230 } 162 }
231} 163}