diff options
author | Rob Mensching <rob@firegiant.com> | 2017-10-14 16:12:07 -0700 |
---|---|---|
committer | Rob Mensching <rob@firegiant.com> | 2017-10-14 16:12:07 -0700 |
commit | dbde9e7104b907bbbaea17e21247d8cafc8b3a4c (patch) | |
tree | 0f5fbbb6fe12c6b2e5e622a0e18ce4c5b4eb2b96 /src/WixToolset.Core/Bind/ResolveFieldsCommand.cs | |
parent | fbf986eb97f68396797a89fc7d40dec07b775440 (diff) | |
download | wix-dbde9e7104b907bbbaea17e21247d8cafc8b3a4c.tar.gz wix-dbde9e7104b907bbbaea17e21247d8cafc8b3a4c.tar.bz2 wix-dbde9e7104b907bbbaea17e21247d8cafc8b3a4c.zip |
Massive refactoring to introduce the concept of IBackend
Diffstat (limited to 'src/WixToolset.Core/Bind/ResolveFieldsCommand.cs')
-rw-r--r-- | src/WixToolset.Core/Bind/ResolveFieldsCommand.cs | 71 |
1 files changed, 40 insertions, 31 deletions
diff --git a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs index 4caec9b4..f4f4f9e8 100644 --- a/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs +++ b/src/WixToolset.Core/Bind/ResolveFieldsCommand.cs | |||
@@ -1,29 +1,32 @@ | |||
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. | 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 | 2 | ||
3 | namespace WixToolset.Bind | 3 | namespace WixToolset.Core.Bind |
4 | { | 4 | { |
5 | using System.Collections.Generic; | 5 | using System.Collections.Generic; |
6 | using WixToolset.Data; | 6 | using WixToolset.Data; |
7 | using WixToolset.Data.Bind; | ||
7 | using WixToolset.Extensibility; | 8 | using WixToolset.Extensibility; |
8 | 9 | ||
9 | /// <summary> | 10 | /// <summary> |
10 | /// Resolve source fields in the tables included in the output | 11 | /// Resolve source fields in the tables included in the output |
11 | /// </summary> | 12 | /// </summary> |
12 | internal class ResolveFieldsCommand : ICommand | 13 | internal class ResolveFieldsCommand |
13 | { | 14 | { |
14 | public TableIndexedCollection Tables { private get; set; } | 15 | public bool BuildingPatch { private get; set; } |
15 | 16 | ||
16 | public ExtractEmbeddedFiles FilesWithEmbeddedFiles { private get; set; } | 17 | public IBindVariableResolver BindVariableResolver { private get; set; } |
17 | 18 | ||
18 | public BinderFileManagerCore FileManagerCore { private get; set; } | 19 | public IEnumerable<BindPath> BindPaths { private get; set; } |
19 | 20 | ||
20 | public IEnumerable<IBinderFileManager> FileManagers { private get; set; } | 21 | public IEnumerable<IBinderExtension> Extensions { private get; set; } |
21 | 22 | ||
22 | public bool SupportDelayedResolution { private get; set; } | 23 | public ExtractEmbeddedFiles FilesWithEmbeddedFiles { private get; set; } |
24 | |||
25 | public string IntermediateFolder { private get; set; } | ||
23 | 26 | ||
24 | public string TempFilesLocation { private get; set; } | 27 | public TableIndexedCollection Tables { private get; set; } |
25 | 28 | ||
26 | public WixVariableResolver WixVariableResolver { private get; set; } | 29 | public bool SupportDelayedResolution { private get; set; } |
27 | 30 | ||
28 | public IEnumerable<DelayedField> DelayedFields { get; private set; } | 31 | public IEnumerable<DelayedField> DelayedFields { get; private set; } |
29 | 32 | ||
@@ -31,6 +34,8 @@ namespace WixToolset.Bind | |||
31 | { | 34 | { |
32 | List<DelayedField> delayedFields = this.SupportDelayedResolution ? new List<DelayedField>() : null; | 35 | List<DelayedField> delayedFields = this.SupportDelayedResolution ? new List<DelayedField>() : null; |
33 | 36 | ||
37 | var fileResolver = new FileResolver(this.BindPaths, this.Extensions); | ||
38 | |||
34 | foreach (Table table in this.Tables) | 39 | foreach (Table table in this.Tables) |
35 | { | 40 | { |
36 | foreach (Row row in table.Rows) | 41 | foreach (Row row in table.Rows) |
@@ -46,7 +51,7 @@ namespace WixToolset.Bind | |||
46 | // resolve localization and wix variables | 51 | // resolve localization and wix variables |
47 | if (field.Data is string) | 52 | if (field.Data is string) |
48 | { | 53 | { |
49 | field.Data = this.WixVariableResolver.ResolveVariables(row.SourceLineNumbers, field.AsString(), false, ref isDefault, ref delayedResolve); | 54 | field.Data = this.BindVariableResolver.ResolveVariables(row.SourceLineNumbers, field.AsString(), false, out isDefault, out delayedResolve); |
50 | if (delayedResolve) | 55 | if (delayedResolve) |
51 | { | 56 | { |
52 | delayedFields.Add(new DelayedField(row, field)); | 57 | delayedFields.Add(new DelayedField(row, field)); |
@@ -74,7 +79,7 @@ namespace WixToolset.Bind | |||
74 | // File is embedded and path to it was not modified above. | 79 | // File is embedded and path to it was not modified above. |
75 | if (objectField.EmbeddedFileIndex.HasValue && isDefault) | 80 | if (objectField.EmbeddedFileIndex.HasValue && isDefault) |
76 | { | 81 | { |
77 | string extractPath = this.FilesWithEmbeddedFiles.AddEmbeddedFileIndex(objectField.BaseUri, objectField.EmbeddedFileIndex.Value, this.TempFilesLocation); | 82 | string extractPath = this.FilesWithEmbeddedFiles.AddEmbeddedFileIndex(objectField.BaseUri, objectField.EmbeddedFileIndex.Value, this.IntermediateFolder); |
78 | 83 | ||
79 | // Set the path to the embedded file once where it will be extracted. | 84 | // Set the path to the embedded file once where it will be extracted. |
80 | objectField.Data = extractPath; | 85 | objectField.Data = extractPath; |
@@ -83,7 +88,7 @@ namespace WixToolset.Bind | |||
83 | { | 88 | { |
84 | try | 89 | try |
85 | { | 90 | { |
86 | if (OutputType.Patch != this.FileManagerCore.Output.Type) // Normal binding for non-Patch scenario such as link (light.exe) | 91 | if (!this.BuildingPatch) // Normal binding for non-Patch scenario such as link (light.exe) |
87 | { | 92 | { |
88 | // keep a copy of the un-resolved data for future replay. This will be saved into wixpdb file | 93 | // keep a copy of the un-resolved data for future replay. This will be saved into wixpdb file |
89 | if (null == objectField.UnresolvedData) | 94 | if (null == objectField.UnresolvedData) |
@@ -92,12 +97,12 @@ namespace WixToolset.Bind | |||
92 | } | 97 | } |
93 | 98 | ||
94 | // resolve the path to the file | 99 | // resolve the path to the file |
95 | objectField.Data = this.ResolveFile((string)objectField.Data, table.Name, row.SourceLineNumbers, BindStage.Normal); | 100 | objectField.Data = fileResolver.ResolveFile((string)objectField.Data, table.Name, row.SourceLineNumbers, BindStage.Normal); |
96 | } | 101 | } |
97 | else if (!(this.FileManagerCore.RebaseTarget || this.FileManagerCore.RebaseUpdated)) // Normal binding for Patch Scenario (normal patch, no re-basing logic) | 102 | else if (!fileResolver.RebaseTarget && !fileResolver.RebaseUpdated) // Normal binding for Patch Scenario (normal patch, no re-basing logic) |
98 | { | 103 | { |
99 | // resolve the path to the file | 104 | // resolve the path to the file |
100 | objectField.Data = this.ResolveFile((string)objectField.Data, table.Name, row.SourceLineNumbers, BindStage.Normal); | 105 | objectField.Data = fileResolver.ResolveFile((string)objectField.Data, table.Name, row.SourceLineNumbers, BindStage.Normal); |
101 | } | 106 | } |
102 | else // Re-base binding path scenario caused by pyro.exe -bt -bu | 107 | else // Re-base binding path scenario caused by pyro.exe -bt -bu |
103 | { | 108 | { |
@@ -106,7 +111,7 @@ namespace WixToolset.Bind | |||
106 | 111 | ||
107 | // if -bu is used in pyro command, this condition holds true and the tool | 112 | // if -bu is used in pyro command, this condition holds true and the tool |
108 | // will use pre-resolved source for new wixpdb file | 113 | // will use pre-resolved source for new wixpdb file |
109 | if (this.FileManagerCore.RebaseUpdated) | 114 | if (fileResolver.RebaseUpdated) |
110 | { | 115 | { |
111 | // try to use the unResolved Source if it exists. | 116 | // try to use the unResolved Source if it exists. |
112 | // New version of wixpdb file keeps a copy of pre-resolved Source. i.e. !(bindpath.test)\foo.dll | 117 | // New version of wixpdb file keeps a copy of pre-resolved Source. i.e. !(bindpath.test)\foo.dll |
@@ -117,7 +122,7 @@ namespace WixToolset.Bind | |||
117 | } | 122 | } |
118 | } | 123 | } |
119 | 124 | ||
120 | objectField.Data = this.ResolveFile(filePathToResolve, table.Name, row.SourceLineNumbers, BindStage.Updated); | 125 | objectField.Data = fileResolver.ResolveFile(filePathToResolve, table.Name, row.SourceLineNumbers, BindStage.Updated); |
121 | } | 126 | } |
122 | } | 127 | } |
123 | catch (WixFileNotFoundException) | 128 | catch (WixFileNotFoundException) |
@@ -127,10 +132,10 @@ namespace WixToolset.Bind | |||
127 | } | 132 | } |
128 | } | 133 | } |
129 | 134 | ||
130 | isDefault = true; | ||
131 | if (null != objectField.PreviousData) | 135 | if (null != objectField.PreviousData) |
132 | { | 136 | { |
133 | objectField.PreviousData = this.WixVariableResolver.ResolveVariables(row.SourceLineNumbers, objectField.PreviousData, false, ref isDefault); | 137 | objectField.PreviousData = this.BindVariableResolver.ResolveVariables(row.SourceLineNumbers, objectField.PreviousData, false, out isDefault); |
138 | |||
134 | if (!Messaging.Instance.EncounteredError) // TODO: make this error handling more specific to just the failure to resolve variables in this field. | 139 | if (!Messaging.Instance.EncounteredError) // TODO: make this error handling more specific to just the failure to resolve variables in this field. |
135 | { | 140 | { |
136 | // file is compressed in a cabinet (and not modified above) | 141 | // file is compressed in a cabinet (and not modified above) |
@@ -142,7 +147,7 @@ namespace WixToolset.Bind | |||
142 | objectField.PreviousBaseUri = objectField.BaseUri; | 147 | objectField.PreviousBaseUri = objectField.BaseUri; |
143 | } | 148 | } |
144 | 149 | ||
145 | string extractPath = this.FilesWithEmbeddedFiles.AddEmbeddedFileIndex(objectField.PreviousBaseUri, objectField.PreviousEmbeddedFileIndex.Value, this.TempFilesLocation); | 150 | string extractPath = this.FilesWithEmbeddedFiles.AddEmbeddedFileIndex(objectField.PreviousBaseUri, objectField.PreviousEmbeddedFileIndex.Value, this.IntermediateFolder); |
146 | 151 | ||
147 | // set the path to the file once its extracted from the cabinet | 152 | // set the path to the file once its extracted from the cabinet |
148 | objectField.PreviousData = extractPath; | 153 | objectField.PreviousData = extractPath; |
@@ -151,14 +156,14 @@ namespace WixToolset.Bind | |||
151 | { | 156 | { |
152 | try | 157 | try |
153 | { | 158 | { |
154 | if (!this.FileManagerCore.RebaseTarget && !this.FileManagerCore.RebaseUpdated) | 159 | if (!fileResolver.RebaseTarget && !fileResolver.RebaseUpdated) |
155 | { | 160 | { |
156 | // resolve the path to the file | 161 | // resolve the path to the file |
157 | objectField.PreviousData = this.ResolveFile((string)objectField.PreviousData, table.Name, row.SourceLineNumbers, BindStage.Normal); | 162 | objectField.PreviousData = fileResolver.ResolveFile((string)objectField.PreviousData, table.Name, row.SourceLineNumbers, BindStage.Normal); |
158 | } | 163 | } |
159 | else | 164 | else |
160 | { | 165 | { |
161 | if (this.FileManagerCore.RebaseTarget) | 166 | if (fileResolver.RebaseTarget) |
162 | { | 167 | { |
163 | // if -bt is used, it come here | 168 | // if -bt is used, it come here |
164 | // Try to use the original unresolved source from either target build or update build | 169 | // Try to use the original unresolved source from either target build or update build |
@@ -172,7 +177,7 @@ namespace WixToolset.Bind | |||
172 | } | 177 | } |
173 | 178 | ||
174 | // resolve the path to the file | 179 | // resolve the path to the file |
175 | objectField.PreviousData = this.ResolveFile((string)objectField.PreviousData, table.Name, row.SourceLineNumbers, BindStage.Target); | 180 | objectField.PreviousData = fileResolver.ResolveFile((string)objectField.PreviousData, table.Name, row.SourceLineNumbers, BindStage.Target); |
176 | 181 | ||
177 | } | 182 | } |
178 | } | 183 | } |
@@ -192,24 +197,28 @@ namespace WixToolset.Bind | |||
192 | this.DelayedFields = delayedFields; | 197 | this.DelayedFields = delayedFields; |
193 | } | 198 | } |
194 | 199 | ||
200 | #if false | ||
195 | private string ResolveFile(string source, string type, SourceLineNumber sourceLineNumbers, BindStage bindStage = BindStage.Normal) | 201 | private string ResolveFile(string source, string type, SourceLineNumber sourceLineNumbers, BindStage bindStage = BindStage.Normal) |
196 | { | 202 | { |
197 | string path = null; | 203 | string path = null; |
198 | foreach (IBinderFileManager fileManager in this.FileManagers) | 204 | foreach (var extension in this.Extensions) |
199 | { | 205 | { |
200 | path = fileManager.ResolveFile(source, type, sourceLineNumbers, bindStage); | 206 | path = extension.ResolveFile(source, type, sourceLineNumbers, bindStage); |
201 | if (null != path) | 207 | if (null != path) |
202 | { | 208 | { |
203 | break; | 209 | break; |
204 | } | 210 | } |
205 | } | 211 | } |
206 | 212 | ||
207 | if (null == path) | 213 | throw new NotImplementedException(); // need to do default binder stuff |
208 | { | 214 | |
209 | throw new WixFileNotFoundException(sourceLineNumbers, source, type); | 215 | //if (null == path) |
210 | } | 216 | //{ |
217 | // throw new WixFileNotFoundException(sourceLineNumbers, source, type); | ||
218 | //} | ||
211 | 219 | ||
212 | return path; | 220 | //return path; |
213 | } | 221 | } |
222 | #endif | ||
214 | } | 223 | } |
215 | } | 224 | } |