aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core/Bind
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2017-12-21 13:42:52 -0800
committerRob Mensching <rob@firegiant.com>2017-12-21 13:42:52 -0800
commitdc9f4c329e6f55ce7595970463e0caf148096f4b (patch)
tree86155ac36c76acda0a4b1673c77f54a9780c6885 /src/WixToolset.Core/Bind
parent155a6e96346e0cb3d9ab6f5372fa29b46ebaee89 (diff)
downloadwix-dc9f4c329e6f55ce7595970463e0caf148096f4b.tar.gz
wix-dc9f4c329e6f55ce7595970463e0caf148096f4b.tar.bz2
wix-dc9f4c329e6f55ce7595970463e0caf148096f4b.zip
Support wixout and extract Resolve and Layout from Binder
Diffstat (limited to 'src/WixToolset.Core/Bind')
-rw-r--r--src/WixToolset.Core/Bind/FileResolver.cs92
-rw-r--r--src/WixToolset.Core/Bind/FileSystem.cs87
-rw-r--r--src/WixToolset.Core/Bind/ResolveFieldsCommand.cs17
-rw-r--r--src/WixToolset.Core/Bind/ResolveResult.cs14
-rw-r--r--src/WixToolset.Core/Bind/ResolvedDirectory.cs31
-rw-r--r--src/WixToolset.Core/Bind/TransferFilesCommand.cs22
6 files changed, 118 insertions, 145 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}
diff --git a/src/WixToolset.Core/Bind/FileSystem.cs b/src/WixToolset.Core/Bind/FileSystem.cs
new file mode 100644
index 00000000..7d1b223e
--- /dev/null
+++ b/src/WixToolset.Core/Bind/FileSystem.cs
@@ -0,0 +1,87 @@
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
3namespace 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<IFileSystemExtension> extensions)
14 {
15 this.Extensions = extensions ?? Array.Empty<IFileSystemExtension>();
16 }
17
18 private IEnumerable<IFileSystemExtension> 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)
27 {
28 foreach (var extension in this.Extensions)
29 {
30 if (extension.CopyFile(source, destination, overwrite))
31 {
32 return true;
33 }
34 }
35
36 if (overwrite && File.Exists(destination))
37 {
38 File.Delete(destination);
39 }
40
41 if (!CreateHardLink(destination, source, IntPtr.Zero))
42 {
43#if DEBUG
44 int er = Marshal.GetLastWin32Error();
45#endif
46
47 File.Copy(source, destination, overwrite);
48 }
49
50 return true;
51 }
52
53 /// <summary>
54 /// Moves a file.
55 /// </summary>
56 /// <param name="source">The file to move.</param>
57 /// <param name="destination">The destination file.</param>
58 public bool MoveFile(string source, string destination, bool overwrite)
59 {
60 foreach (var extension in this.Extensions)
61 {
62 if (extension.MoveFile(source, destination, overwrite))
63 {
64 return true;
65 }
66 }
67
68 if (overwrite && File.Exists(destination))
69 {
70 File.Delete(destination);
71 }
72
73 var directory = Path.GetDirectoryName(destination);
74 if (!String.IsNullOrEmpty(directory))
75 {
76 Directory.CreateDirectory(directory);
77 }
78
79 File.Move(source, destination);
80
81 return true;
82 }
83
84 [DllImport("Kernel32.dll", CharSet = CharSet.Unicode, SetLastError = true)]
85 private static extern bool CreateHardLink(string lpFileName, string lpExistingFileName, IntPtr lpSecurityAttributes);
86 }
87}
diff --git a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs
index e8c90956..824eb9a5 100644
--- a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs
+++ b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs
@@ -22,7 +22,7 @@ namespace WixToolset.Core.Bind
22 22
23 public IEnumerable<BindPath> BindPaths { private get; set; } 23 public IEnumerable<BindPath> BindPaths { private get; set; }
24 24
25 public IEnumerable<IBinderExtension> Extensions { private get; set; } 25 public IEnumerable<IResolverExtension> Extensions { private get; set; }
26 26
27 public ExtractEmbeddedFiles FilesWithEmbeddedFiles { private get; set; } 27 public ExtractEmbeddedFiles FilesWithEmbeddedFiles { private get; set; }
28 28
@@ -52,7 +52,6 @@ namespace WixToolset.Core.Bind
52 } 52 }
53 53
54 var isDefault = true; 54 var isDefault = true;
55 var delayedResolve = false;
56 55
57 // Check to make sure we're in a scenario where we can handle variable resolution. 56 // Check to make sure we're in a scenario where we can handle variable resolution.
58 if (null != delayedFields) 57 if (null != delayedFields)
@@ -63,16 +62,18 @@ namespace WixToolset.Core.Bind
63 var original = field.AsString(); 62 var original = field.AsString();
64 if (!String.IsNullOrEmpty(original)) 63 if (!String.IsNullOrEmpty(original))
65 { 64 {
66 var value = this.BindVariableResolver.ResolveVariables(row.SourceLineNumbers, original, false, out isDefault, out delayedResolve); 65 var resolution = this.BindVariableResolver.ResolveVariables(row.SourceLineNumbers, original, false);
67 if (original != value) 66 if (resolution.UpdatedValue)
68 { 67 {
69 field.Set(value); 68 field.Set(resolution.Value);
70 } 69 }
71 70
72 if (delayedResolve) 71 if (resolution.DelayedResolve)
73 { 72 {
74 delayedFields.Add(new DelayedField(row, field)); 73 delayedFields.Add(new DelayedField(row, field));
75 } 74 }
75
76 isDefault = resolution.IsDefault;
76 } 77 }
77 } 78 }
78 } 79 }
@@ -119,13 +120,13 @@ namespace WixToolset.Core.Bind
119#endif 120#endif
120 121
121 // resolve the path to the file 122 // resolve the path to the file
122 var value = fileResolver.ResolveFile(objectField.Path, row.Definition.Name, row.SourceLineNumbers, BindStage.Normal); 123 var value = fileResolver.ResolveFile(objectField.Path, row.Definition, row.SourceLineNumbers, BindStage.Normal);
123 field.Set(value); 124 field.Set(value);
124 } 125 }
125 else if (!fileResolver.RebaseTarget && !fileResolver.RebaseUpdated) // Normal binding for Patch Scenario (normal patch, no re-basing logic) 126 else if (!fileResolver.RebaseTarget && !fileResolver.RebaseUpdated) // Normal binding for Patch Scenario (normal patch, no re-basing logic)
126 { 127 {
127 // resolve the path to the file 128 // resolve the path to the file
128 var value = fileResolver.ResolveFile(objectField.Path, row.Definition.Name, row.SourceLineNumbers, BindStage.Normal); 129 var value = fileResolver.ResolveFile(objectField.Path, row.Definition, row.SourceLineNumbers, BindStage.Normal);
129 field.Set(value); 130 field.Set(value);
130 } 131 }
131#if REVISIT_FOR_PATCHING 132#if REVISIT_FOR_PATCHING
diff --git a/src/WixToolset.Core/Bind/ResolveResult.cs b/src/WixToolset.Core/Bind/ResolveResult.cs
deleted file mode 100644
index 13f25054..00000000
--- a/src/WixToolset.Core/Bind/ResolveResult.cs
+++ /dev/null
@@ -1,14 +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
3namespace WixToolset.Core.Bind
4{
5 using System.Collections.Generic;
6 using WixToolset.Extensibility;
7
8 public class ResolveResult
9 {
10 public IEnumerable<IExpectedExtractFile> ExpectedEmbeddedFiles { get; set; }
11
12 public IEnumerable<IDelayedField> DelayedFields { get; set; }
13 }
14} \ No newline at end of file
diff --git a/src/WixToolset.Core/Bind/ResolvedDirectory.cs b/src/WixToolset.Core/Bind/ResolvedDirectory.cs
deleted file mode 100644
index 9d07fc93..00000000
--- a/src/WixToolset.Core/Bind/ResolvedDirectory.cs
+++ /dev/null
@@ -1,31 +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
3namespace WixToolset.Bind
4{
5 /// <summary>
6 /// Structure used for resolved directory information.
7 /// </summary>
8 public struct ResolvedDirectory
9 {
10 /// <summary>
11 /// Constructor for ResolvedDirectory.
12 /// </summary>
13 /// <param name="directoryParent">Parent directory.</param>
14 /// <param name="name">The directory name.</param>
15 public ResolvedDirectory(string directoryParent, string name)
16 {
17 this.DirectoryParent = directoryParent;
18 this.Name = name;
19 this.Path = null;
20 }
21
22 /// <summary>The directory parent.</summary>
23 public string DirectoryParent { get; set; }
24
25 /// <summary>The name of this directory.</summary>
26 public string Name { get; set; }
27
28 /// <summary>The path of this directory.</summary>
29 public string Path { get; set; }
30 }
31}
diff --git a/src/WixToolset.Core/Bind/TransferFilesCommand.cs b/src/WixToolset.Core/Bind/TransferFilesCommand.cs
index 68d8b129..d4e143c3 100644
--- a/src/WixToolset.Core/Bind/TransferFilesCommand.cs
+++ b/src/WixToolset.Core/Bind/TransferFilesCommand.cs
@@ -13,15 +13,15 @@ namespace WixToolset.Core.Bind
13 13
14 internal class TransferFilesCommand 14 internal class TransferFilesCommand
15 { 15 {
16 public TransferFilesCommand(IMessaging messaging, IEnumerable<BindPath> bindPaths, IEnumerable<IBinderExtension> extensions, IEnumerable<FileTransfer> fileTransfers, bool suppressAclReset) 16 public TransferFilesCommand(IMessaging messaging, IEnumerable<IFileSystemExtension> extensions, IEnumerable<FileTransfer> fileTransfers, bool suppressAclReset)
17 { 17 {
18 this.FileResolver = new FileResolver(bindPaths, extensions); 18 this.FileSystem = new FileSystem(extensions);
19 this.Messaging = messaging; 19 this.Messaging = messaging;
20 this.FileTransfers = fileTransfers; 20 this.FileTransfers = fileTransfers;
21 this.SuppressAclReset = suppressAclReset; 21 this.SuppressAclReset = suppressAclReset;
22 } 22 }
23 23
24 private FileResolver FileResolver { get; } 24 private FileSystem FileSystem { get; }
25 25
26 private IMessaging Messaging { get; } 26 private IMessaging Messaging { get; }
27 27
@@ -35,10 +35,8 @@ namespace WixToolset.Core.Bind
35 35
36 foreach (var fileTransfer in this.FileTransfers) 36 foreach (var fileTransfer in this.FileTransfers)
37 { 37 {
38 string fileSource = this.FileResolver.ResolveFile(fileTransfer.Source, fileTransfer.Type, fileTransfer.SourceLineNumbers, BindStage.Normal);
39
40 // If the source and destination are identical, then there's nothing to do here 38 // If the source and destination are identical, then there's nothing to do here
41 if (0 == String.Compare(fileSource, fileTransfer.Destination, StringComparison.OrdinalIgnoreCase)) 39 if (0 == String.Compare(fileTransfer.Source, fileTransfer.Destination, StringComparison.OrdinalIgnoreCase))
42 { 40 {
43 fileTransfer.Redundant = true; 41 fileTransfer.Redundant = true;
44 continue; 42 continue;
@@ -51,13 +49,13 @@ namespace WixToolset.Core.Bind
51 { 49 {
52 if (fileTransfer.Move) 50 if (fileTransfer.Move)
53 { 51 {
54 this.Messaging.Write(VerboseMessages.MoveFile(fileSource, fileTransfer.Destination)); 52 this.Messaging.Write(VerboseMessages.MoveFile(fileTransfer.Source, fileTransfer.Destination));
55 this.TransferFile(true, fileSource, fileTransfer.Destination); 53 this.TransferFile(true, fileTransfer.Source, fileTransfer.Destination);
56 } 54 }
57 else 55 else
58 { 56 {
59 this.Messaging.Write(VerboseMessages.CopyFile(fileSource, fileTransfer.Destination)); 57 this.Messaging.Write(VerboseMessages.CopyFile(fileTransfer.Source, fileTransfer.Destination));
60 this.TransferFile(false, fileSource, fileTransfer.Destination); 58 this.TransferFile(false, fileTransfer.Source, fileTransfer.Destination);
61 } 59 }
62 60
63 retry = false; 61 retry = false;
@@ -183,11 +181,11 @@ namespace WixToolset.Core.Bind
183 181
184 if (move) 182 if (move)
185 { 183 {
186 complete = this.FileResolver.MoveFile(source, destination, true); 184 complete = this.FileSystem.MoveFile(source, destination, true);
187 } 185 }
188 else 186 else
189 { 187 {
190 complete = this.FileResolver.CopyFile(source, destination, true); 188 complete = this.FileSystem.CopyFile(source, destination, true);
191 } 189 }
192 190
193 if (!complete) 191 if (!complete)