aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2020-01-24 15:27:20 -0800
committerRob Mensching <rob@firegiant.com>2020-02-05 16:15:47 -0800
commit6ff680e386b1543ad1a58d1b1d465ce8aa20bc7d (patch)
treec717333cd10d5592e59dfb898b391275bba1f389 /src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
parent6e2e67ab55c75f4655397588c0dcc64f50d22f92 (diff)
downloadwix-6ff680e386b1543ad1a58d1b1d465ce8aa20bc7d.tar.gz
wix-6ff680e386b1543ad1a58d1b1d465ce8aa20bc7d.tar.bz2
wix-6ff680e386b1543ad1a58d1b1d465ce8aa20bc7d.zip
Start on new patch infrastructure
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs102
1 files changed, 51 insertions, 51 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
index 1f2a22d9..81d46b41 100644
--- a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
@@ -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(facade.File.Source.Path); 62 fileInfo = new FileInfo(facade.SourcePath);
63 } 63 }
64 catch (ArgumentException) 64 catch (ArgumentException)
65 { 65 {
66 this.Messaging.Write(ErrorMessages.InvalidFileName(facade.File.SourceLineNumbers, facade.File.Source.Path)); 66 this.Messaging.Write(ErrorMessages.InvalidFileName(facade.SourceLineNumber, facade.SourcePath));
67 return; 67 return;
68 } 68 }
69 catch (PathTooLongException) 69 catch (PathTooLongException)
70 { 70 {
71 this.Messaging.Write(ErrorMessages.InvalidFileName(facade.File.SourceLineNumbers, facade.File.Source.Path)); 71 this.Messaging.Write(ErrorMessages.InvalidFileName(facade.SourceLineNumber, facade.SourcePath));
72 return; 72 return;
73 } 73 }
74 catch (NotSupportedException) 74 catch (NotSupportedException)
75 { 75 {
76 this.Messaging.Write(ErrorMessages.InvalidFileName(facade.File.SourceLineNumbers, facade.File.Source.Path)); 76 this.Messaging.Write(ErrorMessages.InvalidFileName(facade.SourceLineNumber, facade.SourcePath));
77 return; 77 return;
78 } 78 }
79 79
80 if (!fileInfo.Exists) 80 if (!fileInfo.Exists)
81 { 81 {
82 this.Messaging.Write(ErrorMessages.CannotFindFile(facade.File.SourceLineNumbers, facade.File.Id.Id, facade.File.Name, facade.File.Source.Path)); 82 this.Messaging.Write(ErrorMessages.CannotFindFile(facade.SourceLineNumber, facade.Id, facade.FileName, facade.SourcePath));
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(facade.File.SourceLineNumbers, facade.File.Source.Path)); 90 throw new WixException(ErrorMessages.FileTooLarge(facade.SourceLineNumber, facade.SourcePath));
91 } 91 }
92 92
93 facade.File.FileSize = Convert.ToInt32(fileStream.Length, CultureInfo.InvariantCulture); 93 facade.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(facade.File.SourceLineNumbers, fileInfo.FullName)); 106 throw new WixException(ErrorMessages.FileNotFound(facade.SourceLineNumber, 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 != facade.File.Version) 121 else if (null != facade.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 => facade.File.Version.Equals(r.File.Id.Id, StringComparison.Ordinal))) 130 if (!this.FileFacades.Any(r => facade.Version.Equals(r.Id, StringComparison.Ordinal)))
131 { 131 {
132 this.Messaging.Write(WarningMessages.DefaultVersionUsedForUnversionedFile(facade.File.SourceLineNumbers, facade.File.Version, facade.File.Id.Id)); 132 this.Messaging.Write(WarningMessages.DefaultVersionUsedForUnversionedFile(facade.SourceLineNumber, facade.Version, facade.Id));
133 } 133 }
134 } 134 }
135 else 135 else
136 { 136 {
137 if (null != facade.File.Language) 137 if (null != facade.Language)
138 { 138 {
139 this.Messaging.Write(WarningMessages.DefaultLanguageUsedForUnversionedFile(facade.File.SourceLineNumbers, facade.File.Language, facade.File.Id.Id)); 139 this.Messaging.Write(WarningMessages.DefaultLanguageUsedForUnversionedFile(facade.SourceLineNumber, facade.Language, facade.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(facade.File.SourceLineNumbers, fileInfo.FullName)); 151 throw new WixException(ErrorMessages.FileNotFound(facade.SourceLineNumber, fileInfo.FullName));
152 } 152 }
153 else 153 else
154 { 154 {
@@ -158,7 +158,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
158 158
159 if (null == facade.Hash) 159 if (null == facade.Hash)
160 { 160 {
161 facade.Hash = new MsiFileHashTuple(facade.File.SourceLineNumbers, facade.File.Id); 161 facade.Hash = new MsiFileHashTuple(facade.SourceLineNumber, facade.Identifier);
162 this.Section.Tuples.Add(facade.Hash); 162 this.Section.Tuples.Add(facade.Hash);
163 } 163 }
164 164
@@ -173,11 +173,11 @@ namespace WixToolset.Core.WindowsInstaller.Bind
173 { 173 {
174 // If no version was provided by the user, use the version from the file itself. 174 // If no version was provided by the user, use the version from the file itself.
175 // This is the most common case. 175 // This is the most common case.
176 if (String.IsNullOrEmpty(facade.File.Version)) 176 if (String.IsNullOrEmpty(facade.Version))
177 { 177 {
178 facade.File.Version = version; 178 facade.Version = version;
179 } 179 }
180 else if (!this.FileFacades.Any(r => facade.File.Version.Equals(r.File.Id.Id, StringComparison.Ordinal))) // this looks expensive, but see explanation below. 180 else if (!this.FileFacades.Any(r => facade.Version.Equals(r.Id, StringComparison.Ordinal))) // this looks expensive, but see explanation below.
181 { 181 {
182 // The user provided a default version for the file row so we looked for a companion file (a file row with Id matching 182 // 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 version value). We didn't find it so, we will override the default version they provided with the actual 183 // the version value). We didn't find it so, we will override the default version they provided with the actual
@@ -188,41 +188,41 @@ namespace WixToolset.Core.WindowsInstaller.Bind
188 // 188 //
189 // Also note this case can occur when the file is being updated using the WixBindUpdatedFiles extension mechanism. 189 // Also note this case can occur when the file is being updated using the WixBindUpdatedFiles extension mechanism.
190 // That's typically even more rare than companion files so again, no index, just search. 190 // That's typically even more rare than companion files so again, no index, just search.
191 facade.File.Version = version; 191 facade.Version = version;
192 } 192 }
193 193
194 if (!String.IsNullOrEmpty(facade.File.Language) && String.IsNullOrEmpty(language)) 194 if (!String.IsNullOrEmpty(facade.Language) && String.IsNullOrEmpty(language))
195 { 195 {
196 this.Messaging.Write(WarningMessages.DefaultLanguageUsedForVersionedFile(facade.File.SourceLineNumbers, facade.File.Language, facade.File.Id.Id)); 196 this.Messaging.Write(WarningMessages.DefaultLanguageUsedForVersionedFile(facade.SourceLineNumber, facade.Language, facade.Id));
197 } 197 }
198 else // override the default provided by the user (usually nothing) with the actual language from the file itself. 198 else // override the default provided by the user (usually nothing) with the actual language from the file itself.
199 { 199 {
200 facade.File.Language = language; 200 facade.Language = language;
201 } 201 }
202 202
203 // Populate the binder variables for this file information if requested. 203 // Populate the binder variables for this file information if requested.
204 if (null != this.VariableCache) 204 if (null != this.VariableCache)
205 { 205 {
206 if (!String.IsNullOrEmpty(facade.File.Version)) 206 if (!String.IsNullOrEmpty(facade.Version))
207 { 207 {
208 var key = String.Format(CultureInfo.InvariantCulture, "fileversion.{0}", facade.File.Id.Id); 208 var key = String.Format(CultureInfo.InvariantCulture, "fileversion.{0}", facade.Id);
209 this.VariableCache[key] = facade.File.Version; 209 this.VariableCache[key] = facade.Version;
210 } 210 }
211 211
212 if (!String.IsNullOrEmpty(facade.File.Language)) 212 if (!String.IsNullOrEmpty(facade.Language))
213 { 213 {
214 var key = String.Format(CultureInfo.InvariantCulture, "filelanguage.{0}", facade.File.Id.Id); 214 var key = String.Format(CultureInfo.InvariantCulture, "filelanguage.{0}", facade.Id);
215 this.VariableCache[key] = facade.File.Language; 215 this.VariableCache[key] = facade.Language;
216 } 216 }
217 } 217 }
218 } 218 }
219 219
220 // If this is a CLR assembly, load the assembly and get the assembly name information 220 // If this is a CLR assembly, load the assembly and get the assembly name information
221 if (AssemblyType.DotNetAssembly == facade.Assembly?.Type) 221 if (AssemblyType.DotNetAssembly == facade.AssemblyType)
222 { 222 {
223 try 223 try
224 { 224 {
225 var assemblyName = AssemblyNameReader.ReadAssembly(facade.File.SourceLineNumbers, fileInfo.FullName, version); 225 var assemblyName = AssemblyNameReader.ReadAssembly(facade.SourceLineNumber, fileInfo.FullName, version);
226 226
227 this.SetMsiAssemblyName(assemblyNameTuples, facade, "name", assemblyName.Name); 227 this.SetMsiAssemblyName(assemblyNameTuples, facade, "name", assemblyName.Name);
228 this.SetMsiAssemblyName(assemblyNameTuples, facade, "culture", assemblyName.Culture); 228 this.SetMsiAssemblyName(assemblyNameTuples, facade, "culture", assemblyName.Culture);
@@ -242,9 +242,9 @@ namespace WixToolset.Core.WindowsInstaller.Bind
242 { 242 {
243 this.SetMsiAssemblyName(assemblyNameTuples, facade, "publicKeyToken", assemblyName.PublicKeyToken); 243 this.SetMsiAssemblyName(assemblyNameTuples, facade, "publicKeyToken", assemblyName.PublicKeyToken);
244 } 244 }
245 else if (facade.Assembly.ApplicationFileRef == null) 245 else if (facade.AssemblyApplicationFileRef == null)
246 { 246 {
247 throw new WixException(ErrorMessages.GacAssemblyNoStrongName(facade.File.SourceLineNumbers, fileInfo.FullName, facade.File.ComponentRef)); 247 throw new WixException(ErrorMessages.GacAssemblyNoStrongName(facade.SourceLineNumber, fileInfo.FullName, facade.ComponentRef));
248 } 248 }
249 249
250 if (!String.IsNullOrEmpty(assemblyName.FileVersion)) 250 if (!String.IsNullOrEmpty(assemblyName.FileVersion))
@@ -255,7 +255,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
255 // add the assembly name to the information cache 255 // add the assembly name to the information cache
256 if (null != this.VariableCache) 256 if (null != this.VariableCache)
257 { 257 {
258 this.VariableCache[$"assemblyfullname.{facade.File.Id.Id}"] = assemblyName.GetFullName(); 258 this.VariableCache[$"assemblyfullname.{facade.Id}"] = assemblyName.GetFullName();
259 } 259 }
260 } 260 }
261 catch (WixException e) 261 catch (WixException e)
@@ -263,20 +263,20 @@ namespace WixToolset.Core.WindowsInstaller.Bind
263 this.Messaging.Write(e.Error); 263 this.Messaging.Write(e.Error);
264 } 264 }
265 } 265 }
266 else if (AssemblyType.Win32Assembly == facade.Assembly?.Type) 266 else if (AssemblyType.Win32Assembly == facade.AssemblyType)
267 { 267 {
268 // TODO: Consider passing in the this.FileFacades as an indexed collection instead of searching through 268 // TODO: Consider passing in the this.FileFacades as an indexed collection instead of searching through
269 // all files like this. Even though this is a rare case it looks like we might be able to index the 269 // all files like this. Even though this is a rare case it looks like we might be able to index the
270 // file earlier. 270 // file earlier.
271 var fileManifest = this.FileFacades.FirstOrDefault(r => r.File.Id.Id.Equals(facade.Assembly.ManifestFileRef, StringComparison.Ordinal)); 271 var fileManifest = this.FileFacades.FirstOrDefault(r => r.Id.Equals(facade.AssemblyManifestFileRef, StringComparison.Ordinal));
272 if (null == fileManifest) 272 if (null == fileManifest)
273 { 273 {
274 this.Messaging.Write(ErrorMessages.MissingManifestForWin32Assembly(facade.File.SourceLineNumbers, facade.File.Id.Id, facade.Assembly.ManifestFileRef)); 274 this.Messaging.Write(ErrorMessages.MissingManifestForWin32Assembly(facade.SourceLineNumber, facade.Id, facade.AssemblyManifestFileRef));
275 } 275 }
276 276
277 try 277 try
278 { 278 {
279 var assemblyName = AssemblyNameReader.ReadAssemblyManifest(facade.File.SourceLineNumbers, fileManifest.File.Source.Path); 279 var assemblyName = AssemblyNameReader.ReadAssemblyManifest(facade.SourceLineNumber, fileManifest.SourcePath);
280 280
281 if (!String.IsNullOrEmpty(assemblyName.Name)) 281 if (!String.IsNullOrEmpty(assemblyName.Name))
282 { 282 {
@@ -315,41 +315,41 @@ namespace WixToolset.Core.WindowsInstaller.Bind
315 /// create a new row. 315 /// create a new row.
316 /// </summary> 316 /// </summary>
317 /// <param name="assemblyNameTuples">MsiAssemblyName table.</param> 317 /// <param name="assemblyNameTuples">MsiAssemblyName table.</param>
318 /// <param name="file">FileFacade containing the assembly read for the MsiAssemblyName row.</param> 318 /// <param name="facade">FileFacade containing the assembly read for the MsiAssemblyName row.</param>
319 /// <param name="name">MsiAssemblyName name.</param> 319 /// <param name="name">MsiAssemblyName name.</param>
320 /// <param name="value">MsiAssemblyName value.</param> 320 /// <param name="value">MsiAssemblyName value.</param>
321 private void SetMsiAssemblyName(Dictionary<string, MsiAssemblyNameTuple> assemblyNameTuples, FileFacade file, string name, string value) 321 private void SetMsiAssemblyName(Dictionary<string, MsiAssemblyNameTuple> assemblyNameTuples, FileFacade facade, string name, string value)
322 { 322 {
323 // check for null value (this can occur when grabbing the file version from an assembly without one) 323 // check for null value (this can occur when grabbing the file version from an assembly without one)
324 if (String.IsNullOrEmpty(value)) 324 if (String.IsNullOrEmpty(value))
325 { 325 {
326 this.Messaging.Write(WarningMessages.NullMsiAssemblyNameValue(file.File.SourceLineNumbers, file.File.ComponentRef, name)); 326 this.Messaging.Write(WarningMessages.NullMsiAssemblyNameValue(facade.SourceLineNumber, facade.ComponentRef, name));
327 } 327 }
328 else 328 else
329 { 329 {
330 // 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. 330 // 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 ("name" == name && AssemblyType.DotNetAssembly == file.Assembly.Type && 331 if ("name" == name && AssemblyType.DotNetAssembly == facade.AssemblyType &&
332 String.IsNullOrEmpty(file.Assembly.ApplicationFileRef) && 332 String.IsNullOrEmpty(facade.AssemblyApplicationFileRef) &&
333 !String.Equals(Path.GetFileNameWithoutExtension(file.File.Name), value, StringComparison.OrdinalIgnoreCase)) 333 !String.Equals(Path.GetFileNameWithoutExtension(facade.FileName), value, StringComparison.OrdinalIgnoreCase))
334 { 334 {
335 this.Messaging.Write(ErrorMessages.GACAssemblyIdentityWarning(file.File.SourceLineNumbers, Path.GetFileNameWithoutExtension(file.File.Name), value)); 335 this.Messaging.Write(ErrorMessages.GACAssemblyIdentityWarning(facade.SourceLineNumber, Path.GetFileNameWithoutExtension(facade.FileName), value));
336 } 336 }
337 337
338 // override directly authored value 338 // override directly authored value
339 var lookup = String.Concat(file.File.ComponentRef, "/", name); 339 var lookup = String.Concat(facade.ComponentRef, "/", name);
340 if (!assemblyNameTuples.TryGetValue(lookup, out var assemblyNameRow)) 340 if (!assemblyNameTuples.TryGetValue(lookup, out var assemblyNameRow))
341 { 341 {
342 assemblyNameRow = new MsiAssemblyNameTuple(file.File.SourceLineNumbers); 342 assemblyNameRow = new MsiAssemblyNameTuple(facade.SourceLineNumber);
343 assemblyNameRow.ComponentRef = file.File.ComponentRef; 343 assemblyNameRow.ComponentRef = facade.ComponentRef;
344 assemblyNameRow.Name = name; 344 assemblyNameRow.Name = name;
345 assemblyNameRow.Value = value; 345 assemblyNameRow.Value = value;
346 346
347 if (null == file.AssemblyNames) 347 if (null == facade.AssemblyNames)
348 { 348 {
349 file.AssemblyNames = new List<MsiAssemblyNameTuple>(); 349 facade.AssemblyNames = new List<MsiAssemblyNameTuple>();
350 } 350 }
351 351
352 file.AssemblyNames.Add(assemblyNameRow); 352 facade.AssemblyNames.Add(assemblyNameRow);
353 this.Section.Tuples.Add(assemblyNameRow); 353 this.Section.Tuples.Add(assemblyNameRow);
354 } 354 }
355 355
@@ -357,7 +357,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
357 357
358 if (this.VariableCache != null) 358 if (this.VariableCache != null)
359 { 359 {
360 var key = String.Format(CultureInfo.InvariantCulture, "assembly{0}.{1}", name, file.File.Id.Id).ToLowerInvariant(); 360 var key = String.Format(CultureInfo.InvariantCulture, "assembly{0}.{1}", name, facade.Id).ToLowerInvariant();
361 this.VariableCache[key] = value; 361 this.VariableCache[key] = value;
362 } 362 }
363 } 363 }