aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2019-05-23 15:37:56 -0700
committerRob Mensching <rob@firegiant.com>2019-05-23 16:02:37 -0700
commit354f6d5b79404544cb7c0e11a0d9212b4780ce09 (patch)
tree1082ce6dd66604f7da315d6a15c85ac3f56b745a /src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
parent3051bf2fc300df125115c9538a0bfc8256bfde6a (diff)
downloadwix-354f6d5b79404544cb7c0e11a0d9212b4780ce09.tar.gz
wix-354f6d5b79404544cb7c0e11a0d9212b4780ce09.tar.bz2
wix-354f6d5b79404544cb7c0e11a0d9212b4780ce09.zip
Integrate latest Data changes for FileTuple and AssemblyTuple
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs118
1 files changed, 59 insertions, 59 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
index 0d15bf2e..397092c4 100644
--- a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
@@ -48,7 +48,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
48 } 48 }
49 } 49 }
50 50
51 private void UpdateFileFacade(FileFacade file) 51 private void UpdateFileFacade(FileFacade facade)
52 { 52 {
53 var assemblyNameTuples = new Dictionary<string, MsiAssemblyNameTuple>(); 53 var assemblyNameTuples = new Dictionary<string, MsiAssemblyNameTuple>();
54 foreach (var assemblyTuple in this.Section.Tuples.OfType<MsiAssemblyNameTuple>()) 54 foreach (var assemblyTuple in this.Section.Tuples.OfType<MsiAssemblyNameTuple>())
@@ -59,27 +59,27 @@ namespace WixToolset.Core.WindowsInstaller.Bind
59 FileInfo fileInfo = null; 59 FileInfo fileInfo = null;
60 try 60 try
61 { 61 {
62 fileInfo = new FileInfo(file.WixFile.Source.Path); 62 fileInfo = new FileInfo(facade.File.Source.Path);
63 } 63 }
64 catch (ArgumentException) 64 catch (ArgumentException)
65 { 65 {
66 this.Messaging.Write(ErrorMessages.InvalidFileName(file.File.SourceLineNumbers, file.WixFile.Source.Path)); 66 this.Messaging.Write(ErrorMessages.InvalidFileName(facade.File.SourceLineNumbers, facade.File.Source.Path));
67 return; 67 return;
68 } 68 }
69 catch (PathTooLongException) 69 catch (PathTooLongException)
70 { 70 {
71 this.Messaging.Write(ErrorMessages.InvalidFileName(file.File.SourceLineNumbers, file.WixFile.Source.Path)); 71 this.Messaging.Write(ErrorMessages.InvalidFileName(facade.File.SourceLineNumbers, facade.File.Source.Path));
72 return; 72 return;
73 } 73 }
74 catch (NotSupportedException) 74 catch (NotSupportedException)
75 { 75 {
76 this.Messaging.Write(ErrorMessages.InvalidFileName(file.File.SourceLineNumbers, file.WixFile.Source.Path)); 76 this.Messaging.Write(ErrorMessages.InvalidFileName(facade.File.SourceLineNumbers, facade.File.Source.Path));
77 return; 77 return;
78 } 78 }
79 79
80 if (!fileInfo.Exists) 80 if (!fileInfo.Exists)
81 { 81 {
82 this.Messaging.Write(ErrorMessages.CannotFindFile(file.File.SourceLineNumbers, file.File.Id.Id, file.File.Name, file.WixFile.Source.Path)); 82 this.Messaging.Write(ErrorMessages.CannotFindFile(facade.File.SourceLineNumbers, facade.File.Id.Id, facade.File.Name, facade.File.Source.Path));
83 return; 83 return;
84 } 84 }
85 85
@@ -87,10 +87,10 @@ namespace WixToolset.Core.WindowsInstaller.Bind
87 { 87 {
88 if (Int32.MaxValue < fileStream.Length) 88 if (Int32.MaxValue < fileStream.Length)
89 { 89 {
90 throw new WixException(ErrorMessages.FileTooLarge(file.File.SourceLineNumbers, file.WixFile.Source.Path)); 90 throw new WixException(ErrorMessages.FileTooLarge(facade.File.SourceLineNumbers, facade.File.Source.Path));
91 } 91 }
92 92
93 file.File.FileSize = Convert.ToInt32(fileStream.Length, CultureInfo.InvariantCulture); 93 facade.File.FileSize = Convert.ToInt32(fileStream.Length, CultureInfo.InvariantCulture);
94 } 94 }
95 95
96 string version = null; 96 string version = null;
@@ -103,7 +103,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
103 { 103 {
104 if (0x2 == e.NativeErrorCode) // ERROR_FILE_NOT_FOUND 104 if (0x2 == e.NativeErrorCode) // ERROR_FILE_NOT_FOUND
105 { 105 {
106 throw new WixException(ErrorMessages.FileNotFound(file.File.SourceLineNumbers, fileInfo.FullName)); 106 throw new WixException(ErrorMessages.FileNotFound(facade.File.SourceLineNumbers, fileInfo.FullName));
107 } 107 }
108 else 108 else
109 { 109 {
@@ -118,7 +118,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
118 { 118 {
119 // not overwriting hash, so don't do the rest of these options. 119 // not overwriting hash, so don't do the rest of these options.
120 } 120 }
121 else if (null != file.File.Version) 121 else if (null != facade.File.Version)
122 { 122 {
123 // Search all of the file rows available to see if the specified version is actually a companion file. Yes, this looks 123 // Search all of the file rows available to see if the specified version is actually a companion file. Yes, this looks
124 // very expensive and you're probably thinking it would be better to create an index of some sort to do an O(1) look up. 124 // very expensive and you're probably thinking it would be better to create an index of some sort to do an O(1) look up.
@@ -127,16 +127,16 @@ namespace WixToolset.Core.WindowsInstaller.Bind
127 // 127 //
128 // Also, if we do not find a matching file identifier then the user provided a default version and is providing a version 128 // Also, if we do not find a matching file identifier then the user provided a default version and is providing a version
129 // for unversioned file. That's allowed but generally a dangerous thing to do so let's point that out to the user. 129 // for unversioned file. That's allowed but generally a dangerous thing to do so let's point that out to the user.
130 if (!this.FileFacades.Any(r => file.File.Version.Equals(r.File.Id.Id, StringComparison.Ordinal))) 130 if (!this.FileFacades.Any(r => facade.File.Version.Equals(r.File.Id.Id, StringComparison.Ordinal)))
131 { 131 {
132 this.Messaging.Write(WarningMessages.DefaultVersionUsedForUnversionedFile(file.File.SourceLineNumbers, file.File.Version, file.File.Id.Id)); 132 this.Messaging.Write(WarningMessages.DefaultVersionUsedForUnversionedFile(facade.File.SourceLineNumbers, facade.File.Version, facade.File.Id.Id));
133 } 133 }
134 } 134 }
135 else 135 else
136 { 136 {
137 if (null != file.File.Language) 137 if (null != facade.File.Language)
138 { 138 {
139 this.Messaging.Write(WarningMessages.DefaultLanguageUsedForUnversionedFile(file.File.SourceLineNumbers, file.File.Language, file.File.Id.Id)); 139 this.Messaging.Write(WarningMessages.DefaultLanguageUsedForUnversionedFile(facade.File.SourceLineNumbers, facade.File.Language, facade.File.Id.Id));
140 } 140 }
141 141
142 int[] hash; 142 int[] hash;
@@ -148,7 +148,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
148 { 148 {
149 if (0x2 == e.NativeErrorCode) // ERROR_FILE_NOT_FOUND 149 if (0x2 == e.NativeErrorCode) // ERROR_FILE_NOT_FOUND
150 { 150 {
151 throw new WixException(ErrorMessages.FileNotFound(file.File.SourceLineNumbers, fileInfo.FullName)); 151 throw new WixException(ErrorMessages.FileNotFound(facade.File.SourceLineNumbers, fileInfo.FullName));
152 } 152 }
153 else 153 else
154 { 154 {
@@ -156,29 +156,29 @@ namespace WixToolset.Core.WindowsInstaller.Bind
156 } 156 }
157 } 157 }
158 158
159 if (null == file.Hash) 159 if (null == facade.Hash)
160 { 160 {
161 file.Hash = new MsiFileHashTuple(file.File.SourceLineNumbers, file.File.Id); 161 facade.Hash = new MsiFileHashTuple(facade.File.SourceLineNumbers, facade.File.Id);
162 this.Section.Tuples.Add(file.Hash); 162 this.Section.Tuples.Add(facade.Hash);
163 } 163 }
164 164
165 file.Hash.FileRef = file.File.Id.Id; 165 facade.Hash.FileRef = facade.File.Id.Id;
166 file.Hash.Options = 0; 166 facade.Hash.Options = 0;
167 file.Hash.HashPart1 = hash[0]; 167 facade.Hash.HashPart1 = hash[0];
168 file.Hash.HashPart2 = hash[1]; 168 facade.Hash.HashPart2 = hash[1];
169 file.Hash.HashPart3 = hash[2]; 169 facade.Hash.HashPart3 = hash[2];
170 file.Hash.HashPart4 = hash[3]; 170 facade.Hash.HashPart4 = hash[3];
171 } 171 }
172 } 172 }
173 else // update the file row with the version and language information. 173 else // update the file row with the version and language information.
174 { 174 {
175 // If no version was provided by the user, use the version from the file itself. 175 // If no version was provided by the user, use the version from the file itself.
176 // This is the most common case. 176 // This is the most common case.
177 if (String.IsNullOrEmpty(file.File.Version)) 177 if (String.IsNullOrEmpty(facade.File.Version))
178 { 178 {
179 file.File.Version = version; 179 facade.File.Version = version;
180 } 180 }
181 else if (!this.FileFacades.Any(r => file.File.Version.Equals(r.File.Id.Id, StringComparison.Ordinal))) // this looks expensive, but see explanation below. 181 else if (!this.FileFacades.Any(r => facade.File.Version.Equals(r.File.Id.Id, StringComparison.Ordinal))) // this looks expensive, but see explanation below.
182 { 182 {
183 // The user provided a default version for the file row so we looked for a companion file (a file row with Id matching 183 // The user provided a default version for the file row so we looked for a companion file (a file row with Id matching
184 // the version value). We didn't find it so, we will override the default version they provided with the actual 184 // the version value). We didn't find it so, we will override the default version they provided with the actual
@@ -189,49 +189,49 @@ namespace WixToolset.Core.WindowsInstaller.Bind
189 // 189 //
190 // Also note this case can occur when the file is being updated using the WixBindUpdatedFiles extension mechanism. 190 // Also note this case can occur when the file is being updated using the WixBindUpdatedFiles extension mechanism.
191 // That's typically even more rare than companion files so again, no index, just search. 191 // That's typically even more rare than companion files so again, no index, just search.
192 file.File.Version = version; 192 facade.File.Version = version;
193 } 193 }
194 194
195 if (!String.IsNullOrEmpty(file.File.Language) && String.IsNullOrEmpty(language)) 195 if (!String.IsNullOrEmpty(facade.File.Language) && String.IsNullOrEmpty(language))
196 { 196 {
197 this.Messaging.Write(WarningMessages.DefaultLanguageUsedForVersionedFile(file.File.SourceLineNumbers, file.File.Language, file.File.Id.Id)); 197 this.Messaging.Write(WarningMessages.DefaultLanguageUsedForVersionedFile(facade.File.SourceLineNumbers, facade.File.Language, facade.File.Id.Id));
198 } 198 }
199 else // override the default provided by the user (usually nothing) with the actual language from the file itself. 199 else // override the default provided by the user (usually nothing) with the actual language from the file itself.
200 { 200 {
201 file.File.Language = language; 201 facade.File.Language = language;
202 } 202 }
203 203
204 // Populate the binder variables for this file information if requested. 204 // Populate the binder variables for this file information if requested.
205 if (null != this.VariableCache) 205 if (null != this.VariableCache)
206 { 206 {
207 if (!String.IsNullOrEmpty(file.File.Version)) 207 if (!String.IsNullOrEmpty(facade.File.Version))
208 { 208 {
209 var key = String.Format(CultureInfo.InvariantCulture, "fileversion.{0}", file.File.Id.Id); 209 var key = String.Format(CultureInfo.InvariantCulture, "fileversion.{0}", facade.File.Id.Id);
210 this.VariableCache[key] = file.File.Version; 210 this.VariableCache[key] = facade.File.Version;
211 } 211 }
212 212
213 if (!String.IsNullOrEmpty(file.File.Language)) 213 if (!String.IsNullOrEmpty(facade.File.Language))
214 { 214 {
215 var key = String.Format(CultureInfo.InvariantCulture, "filelanguage.{0}", file.File.Id.Id); 215 var key = String.Format(CultureInfo.InvariantCulture, "filelanguage.{0}", facade.File.Id.Id);
216 this.VariableCache[key] = file.File.Language; 216 this.VariableCache[key] = facade.File.Language;
217 } 217 }
218 } 218 }
219 } 219 }
220 220
221 // If this is a CLR assembly, load the assembly and get the assembly name information 221 // If this is a CLR assembly, load the assembly and get the assembly name information
222 if (FileAssemblyType.DotNetAssembly == file.WixFile.AssemblyType) 222 if (AssemblyType.DotNetAssembly == facade.Assembly?.Type)
223 { 223 {
224 try 224 try
225 { 225 {
226 var assemblyName = AssemblyNameReader.ReadAssembly(file.File.SourceLineNumbers, fileInfo.FullName, version); 226 var assemblyName = AssemblyNameReader.ReadAssembly(facade.File.SourceLineNumbers, fileInfo.FullName, version);
227 227
228 this.SetMsiAssemblyName(assemblyNameTuples, file, "name", assemblyName.Name); 228 this.SetMsiAssemblyName(assemblyNameTuples, facade, "name", assemblyName.Name);
229 this.SetMsiAssemblyName(assemblyNameTuples, file, "culture", assemblyName.Culture); 229 this.SetMsiAssemblyName(assemblyNameTuples, facade, "culture", assemblyName.Culture);
230 this.SetMsiAssemblyName(assemblyNameTuples, file, "version", assemblyName.Version); 230 this.SetMsiAssemblyName(assemblyNameTuples, facade, "version", assemblyName.Version);
231 231
232 if (!String.IsNullOrEmpty(assemblyName.Architecture)) 232 if (!String.IsNullOrEmpty(assemblyName.Architecture))
233 { 233 {
234 this.SetMsiAssemblyName(assemblyNameTuples, file, "processorArchitecture", assemblyName.Architecture); 234 this.SetMsiAssemblyName(assemblyNameTuples, facade, "processorArchitecture", assemblyName.Architecture);
235 } 235 }
236 // TODO: WiX v3 seemed to do this but not clear it should actually be done. 236 // TODO: WiX v3 seemed to do this but not clear it should actually be done.
237 //else if (!String.IsNullOrEmpty(file.WixFile.ProcessorArchitecture)) 237 //else if (!String.IsNullOrEmpty(file.WixFile.ProcessorArchitecture))
@@ -241,22 +241,22 @@ namespace WixToolset.Core.WindowsInstaller.Bind
241 241
242 if (assemblyName.StrongNamedSigned) 242 if (assemblyName.StrongNamedSigned)
243 { 243 {
244 this.SetMsiAssemblyName(assemblyNameTuples, file, "publicKeyToken", assemblyName.PublicKeyToken); 244 this.SetMsiAssemblyName(assemblyNameTuples, facade, "publicKeyToken", assemblyName.PublicKeyToken);
245 } 245 }
246 else if (file.WixFile.AssemblyApplicationFileRef == null) 246 else if (facade.Assembly.ApplicationFileRef == null)
247 { 247 {
248 throw new WixException(ErrorMessages.GacAssemblyNoStrongName(file.File.SourceLineNumbers, fileInfo.FullName, file.File.ComponentRef)); 248 throw new WixException(ErrorMessages.GacAssemblyNoStrongName(facade.File.SourceLineNumbers, fileInfo.FullName, facade.File.ComponentRef));
249 } 249 }
250 250
251 if (!String.IsNullOrEmpty(assemblyName.FileVersion)) 251 if (!String.IsNullOrEmpty(assemblyName.FileVersion))
252 { 252 {
253 this.SetMsiAssemblyName(assemblyNameTuples, file, "fileVersion", assemblyName.FileVersion); 253 this.SetMsiAssemblyName(assemblyNameTuples, facade, "fileVersion", assemblyName.FileVersion);
254 } 254 }
255 255
256 // add the assembly name to the information cache 256 // add the assembly name to the information cache
257 if (null != this.VariableCache) 257 if (null != this.VariableCache)
258 { 258 {
259 this.VariableCache[$"assemblyfullname.{file.File.Id.Id}"] = assemblyName.GetFullName(); 259 this.VariableCache[$"assemblyfullname.{facade.File.Id.Id}"] = assemblyName.GetFullName();
260 } 260 }
261 } 261 }
262 catch (WixException e) 262 catch (WixException e)
@@ -264,44 +264,44 @@ namespace WixToolset.Core.WindowsInstaller.Bind
264 this.Messaging.Write(e.Error); 264 this.Messaging.Write(e.Error);
265 } 265 }
266 } 266 }
267 else if (FileAssemblyType.Win32Assembly == file.WixFile.AssemblyType) 267 else if (AssemblyType.Win32Assembly == facade.Assembly?.Type)
268 { 268 {
269 // TODO: Consider passing in the this.FileFacades as an indexed collection instead of searching through 269 // TODO: Consider passing in the this.FileFacades as an indexed collection instead of searching through
270 // all files like this. Even though this is a rare case it looks like we might be able to index the 270 // all files like this. Even though this is a rare case it looks like we might be able to index the
271 // file earlier. 271 // file earlier.
272 var fileManifest = this.FileFacades.FirstOrDefault(r => r.File.Id.Id.Equals(file.WixFile.AssemblyManifestFileRef, StringComparison.Ordinal)); 272 var fileManifest = this.FileFacades.FirstOrDefault(r => r.File.Id.Id.Equals(facade.Assembly.ManifestFileRef, StringComparison.Ordinal));
273 if (null == fileManifest) 273 if (null == fileManifest)
274 { 274 {
275 this.Messaging.Write(ErrorMessages.MissingManifestForWin32Assembly(file.File.SourceLineNumbers, file.File.Id.Id, file.WixFile.AssemblyManifestFileRef)); 275 this.Messaging.Write(ErrorMessages.MissingManifestForWin32Assembly(facade.File.SourceLineNumbers, facade.File.Id.Id, facade.Assembly.ManifestFileRef));
276 } 276 }
277 277
278 try 278 try
279 { 279 {
280 var assemblyName = AssemblyNameReader.ReadAssemblyManifest(file.File.SourceLineNumbers, fileManifest.WixFile.Source.Path); 280 var assemblyName = AssemblyNameReader.ReadAssemblyManifest(facade.File.SourceLineNumbers, fileManifest.File.Source.Path);
281 281
282 if (!String.IsNullOrEmpty(assemblyName.Name)) 282 if (!String.IsNullOrEmpty(assemblyName.Name))
283 { 283 {
284 this.SetMsiAssemblyName(assemblyNameTuples, file, "name", assemblyName.Name); 284 this.SetMsiAssemblyName(assemblyNameTuples, facade, "name", assemblyName.Name);
285 } 285 }
286 286
287 if (!String.IsNullOrEmpty(assemblyName.Version)) 287 if (!String.IsNullOrEmpty(assemblyName.Version))
288 { 288 {
289 this.SetMsiAssemblyName(assemblyNameTuples, file, "version", assemblyName.Version); 289 this.SetMsiAssemblyName(assemblyNameTuples, facade, "version", assemblyName.Version);
290 } 290 }
291 291
292 if (!String.IsNullOrEmpty(assemblyName.Type)) 292 if (!String.IsNullOrEmpty(assemblyName.Type))
293 { 293 {
294 this.SetMsiAssemblyName(assemblyNameTuples, file, "type", assemblyName.Type); 294 this.SetMsiAssemblyName(assemblyNameTuples, facade, "type", assemblyName.Type);
295 } 295 }
296 296
297 if (!String.IsNullOrEmpty(assemblyName.Architecture)) 297 if (!String.IsNullOrEmpty(assemblyName.Architecture))
298 { 298 {
299 this.SetMsiAssemblyName(assemblyNameTuples, file, "processorArchitecture", assemblyName.Architecture); 299 this.SetMsiAssemblyName(assemblyNameTuples, facade, "processorArchitecture", assemblyName.Architecture);
300 } 300 }
301 301
302 if (!String.IsNullOrEmpty(assemblyName.PublicKeyToken)) 302 if (!String.IsNullOrEmpty(assemblyName.PublicKeyToken))
303 { 303 {
304 this.SetMsiAssemblyName(assemblyNameTuples, file, "publicKeyToken", assemblyName.PublicKeyToken); 304 this.SetMsiAssemblyName(assemblyNameTuples, facade, "publicKeyToken", assemblyName.PublicKeyToken);
305 } 305 }
306 } 306 }
307 catch (WixException e) 307 catch (WixException e)
@@ -329,8 +329,8 @@ namespace WixToolset.Core.WindowsInstaller.Bind
329 else 329 else
330 { 330 {
331 // if the assembly will be GAC'd and the name in the file table doesn't match the name in the MsiAssemblyName table, error because the install will fail. 331 // if the assembly will be GAC'd and the name in the file table doesn't match the name in the MsiAssemblyName table, error because the install will fail.
332 if ("name" == name && FileAssemblyType.DotNetAssembly == file.WixFile.AssemblyType && 332 if ("name" == name && AssemblyType.DotNetAssembly == file.Assembly.Type &&
333 String.IsNullOrEmpty(file.WixFile.AssemblyApplicationFileRef) && 333 String.IsNullOrEmpty(file.Assembly.ApplicationFileRef) &&
334 !String.Equals(Path.GetFileNameWithoutExtension(file.File.Name), value, StringComparison.OrdinalIgnoreCase)) 334 !String.Equals(Path.GetFileNameWithoutExtension(file.File.Name), value, StringComparison.OrdinalIgnoreCase))
335 { 335 {
336 this.Messaging.Write(ErrorMessages.GACAssemblyIdentityWarning(file.File.SourceLineNumbers, Path.GetFileNameWithoutExtension(file.File.Name), value)); 336 this.Messaging.Write(ErrorMessages.GACAssemblyIdentityWarning(file.File.SourceLineNumbers, Path.GetFileNameWithoutExtension(file.File.Name), value));