aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
diff options
context:
space:
mode:
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs112
1 files changed, 49 insertions, 63 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
index 20058597..030bc4cc 100644
--- a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
@@ -1,10 +1,9 @@
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
3namespace WixToolset.Core.WindowsInstaller.Databases 3namespace WixToolset.Core.WindowsInstaller.Bind
4{ 4{
5 using System; 5 using System;
6 using System.Collections.Generic; 6 using System.Collections.Generic;
7 using System.Collections.Specialized;
8 using System.ComponentModel; 7 using System.ComponentModel;
9 using System.Globalization; 8 using System.Globalization;
10 using System.IO; 9 using System.IO;
@@ -14,7 +13,6 @@ namespace WixToolset.Core.WindowsInstaller.Databases
14 using WixToolset.Clr.Interop; 13 using WixToolset.Clr.Interop;
15 using WixToolset.Core.Bind; 14 using WixToolset.Core.Bind;
16 using WixToolset.Data; 15 using WixToolset.Data;
17 using WixToolset.Data.Rows;
18 using WixToolset.Data.Tuples; 16 using WixToolset.Data.Tuples;
19 using WixToolset.Msi; 17 using WixToolset.Msi;
20 18
@@ -23,13 +21,16 @@ namespace WixToolset.Core.WindowsInstaller.Databases
23 /// </summary> 21 /// </summary>
24 internal class UpdateFileFacadesCommand 22 internal class UpdateFileFacadesCommand
25 { 23 {
26 public IEnumerable<FileFacade> FileFacades { private get; set; } 24 public UpdateFileFacadesCommand(IntermediateSection section)
25 {
26 this.Section = section;
27 }
27 28
28 public IEnumerable<FileFacade> UpdateFileFacades { private get; set; } 29 private IntermediateSection Section { get; }
29 30
30 public string ModularizationGuid { private get; set; } 31 public IEnumerable<FileFacade> FileFacades { private get; set; }
31 32
32 public Output Output { private get; set; } 33 public IEnumerable<FileFacade> UpdateFileFacades { private get; set; }
33 34
34 public bool OverwriteHash { private get; set; } 35 public bool OverwriteHash { private get; set; }
35 36
@@ -47,6 +48,12 @@ namespace WixToolset.Core.WindowsInstaller.Databases
47 48
48 private void UpdateFileFacade(FileFacade file) 49 private void UpdateFileFacade(FileFacade file)
49 { 50 {
51 var assemblyNameTuples = new Dictionary<string, MsiAssemblyNameTuple>();
52 foreach (var assemblyTuple in this.Section.Tuples.OfType<MsiAssemblyNameTuple>())
53 {
54 assemblyNameTuples.Add(assemblyTuple.Component_ + "/" + assemblyTuple.Name, assemblyTuple);
55 }
56
50 FileInfo fileInfo = null; 57 FileInfo fileInfo = null;
51 try 58 try
52 { 59 {
@@ -149,9 +156,8 @@ namespace WixToolset.Core.WindowsInstaller.Databases
149 156
150 if (null == file.Hash) 157 if (null == file.Hash)
151 { 158 {
152 //Table msiFileHashTable = this.Output.EnsureTable(this.TableDefinitions["MsiFileHash"]); 159 file.Hash = new MsiFileHashTuple(file.File.SourceLineNumbers, file.File.Id);
153 //file.Hash = msiFileHashTable.CreateRow(file.File.SourceLineNumbers); 160 this.Section.Tuples.Add(file.Hash);
154 throw new NotImplementedException();
155 } 161 }
156 162
157 file.Hash.File_ = file.File.File; 163 file.Hash.File_ = file.File.File;
@@ -198,13 +204,13 @@ namespace WixToolset.Core.WindowsInstaller.Databases
198 { 204 {
199 if (!String.IsNullOrEmpty(file.File.Version)) 205 if (!String.IsNullOrEmpty(file.File.Version))
200 { 206 {
201 string key = String.Format(CultureInfo.InvariantCulture, "fileversion.{0}", Common.Demodularize(this.Output.Type, this.ModularizationGuid, file.File.File)); 207 var key = String.Format(CultureInfo.InvariantCulture, "fileversion.{0}", file.File.File);
202 this.VariableCache[key] = file.File.Version; 208 this.VariableCache[key] = file.File.Version;
203 } 209 }
204 210
205 if (!String.IsNullOrEmpty(file.File.Language)) 211 if (!String.IsNullOrEmpty(file.File.Language))
206 { 212 {
207 string key = String.Format(CultureInfo.InvariantCulture, "filelanguage.{0}", Common.Demodularize(this.Output.Type, ModularizationGuid, file.File.File)); 213 var key = String.Format(CultureInfo.InvariantCulture, "filelanguage.{0}", file.File.File);
208 this.VariableCache[key] = file.File.Language; 214 this.VariableCache[key] = file.File.Language;
209 } 215 }
210 } 216 }
@@ -214,14 +220,13 @@ namespace WixToolset.Core.WindowsInstaller.Databases
214 if (FileAssemblyType.DotNetAssembly == file.WixFile.AssemblyType) 220 if (FileAssemblyType.DotNetAssembly == file.WixFile.AssemblyType)
215 { 221 {
216 bool targetNetfx1 = false; 222 bool targetNetfx1 = false;
217 StringDictionary assemblyNameValues = new StringDictionary(); 223 var assemblyNameValues = new Dictionary<string, string>();
218 224
219 ClrInterop.IReferenceIdentity referenceIdentity = null;
220 Guid referenceIdentityGuid = ClrInterop.ReferenceIdentityGuid; 225 Guid referenceIdentityGuid = ClrInterop.ReferenceIdentityGuid;
221 uint result = ClrInterop.GetAssemblyIdentityFromFile(fileInfo.FullName, ref referenceIdentityGuid, out referenceIdentity); 226 var result = ClrInterop.GetAssemblyIdentityFromFile(fileInfo.FullName, ref referenceIdentityGuid, out var referenceIdentity);
222 if (0 == result && null != referenceIdentity) 227 if (0 == result && null != referenceIdentity)
223 { 228 {
224 string imageRuntimeVersion = referenceIdentity.GetAttribute(null, "ImageRuntimeVersion"); 229 var imageRuntimeVersion = referenceIdentity.GetAttribute(null, "ImageRuntimeVersion");
225 if (null != imageRuntimeVersion) 230 if (null != imageRuntimeVersion)
226 { 231 {
227 targetNetfx1 = imageRuntimeVersion.StartsWith("v1", StringComparison.OrdinalIgnoreCase); 232 targetNetfx1 = imageRuntimeVersion.StartsWith("v1", StringComparison.OrdinalIgnoreCase);
@@ -269,15 +274,14 @@ namespace WixToolset.Core.WindowsInstaller.Databases
269 return; 274 return;
270 } 275 }
271 276
272 Table assemblyNameTable = this.Output.EnsureTable(this.TableDefinitions["MsiAssemblyName"]); 277 if (assemblyNameValues.TryGetValue("name", out var value))
273 if (assemblyNameValues.ContainsKey("name"))
274 { 278 {
275 this.SetMsiAssemblyName(assemblyNameTable, file, "name", assemblyNameValues["name"]); 279 this.SetMsiAssemblyName(assemblyNameTuples, file, "name", value);
276 } 280 }
277 281
278 if (!String.IsNullOrEmpty(version)) 282 if (!String.IsNullOrEmpty(version))
279 { 283 {
280 this.SetMsiAssemblyName(assemblyNameTable, file, "fileVersion", version); 284 this.SetMsiAssemblyName(assemblyNameTuples, file, "fileVersion", version);
281 } 285 }
282 286
283 if (assemblyNameValues.ContainsKey("version")) 287 if (assemblyNameValues.ContainsKey("version"))
@@ -303,33 +307,33 @@ namespace WixToolset.Core.WindowsInstaller.Databases
303 } 307 }
304 } 308 }
305 309
306 this.SetMsiAssemblyName(assemblyNameTable, file, "version", assemblyVersion); 310 this.SetMsiAssemblyName(assemblyNameTuples, file, "version", assemblyVersion);
307 } 311 }
308 312
309 if (assemblyNameValues.ContainsKey("culture")) 313 if (assemblyNameValues.ContainsKey("culture"))
310 { 314 {
311 this.SetMsiAssemblyName(assemblyNameTable, file, "culture", assemblyNameValues["culture"]); 315 this.SetMsiAssemblyName(assemblyNameTuples, file, "culture", assemblyNameValues["culture"]);
312 } 316 }
313 317
314 if (assemblyNameValues.ContainsKey("publicKeyToken")) 318 if (assemblyNameValues.ContainsKey("publicKeyToken"))
315 { 319 {
316 this.SetMsiAssemblyName(assemblyNameTable, file, "publicKeyToken", assemblyNameValues["publicKeyToken"]); 320 this.SetMsiAssemblyName(assemblyNameTuples, file, "publicKeyToken", assemblyNameValues["publicKeyToken"]);
317 } 321 }
318 322
319 if (!String.IsNullOrEmpty(file.WixFile.ProcessorArchitecture)) 323 if (!String.IsNullOrEmpty(file.WixFile.ProcessorArchitecture))
320 { 324 {
321 this.SetMsiAssemblyName(assemblyNameTable, file, "processorArchitecture", file.WixFile.ProcessorArchitecture); 325 this.SetMsiAssemblyName(assemblyNameTuples, file, "processorArchitecture", file.WixFile.ProcessorArchitecture);
322 } 326 }
323 327
324 if (assemblyNameValues.ContainsKey("processorArchitecture")) 328 if (assemblyNameValues.ContainsKey("processorArchitecture"))
325 { 329 {
326 this.SetMsiAssemblyName(assemblyNameTable, file, "processorArchitecture", assemblyNameValues["processorArchitecture"]); 330 this.SetMsiAssemblyName(assemblyNameTuples, file, "processorArchitecture", assemblyNameValues["processorArchitecture"]);
327 } 331 }
328 332
329 // add the assembly name to the information cache 333 // add the assembly name to the information cache
330 if (null != this.VariableCache) 334 if (null != this.VariableCache)
331 { 335 {
332 string fileId = Common.Demodularize(this.Output.Type, this.ModularizationGuid, file.File.File); 336 string fileId = file.File.File;
333 string key = String.Concat("assemblyfullname.", fileId); 337 string key = String.Concat("assemblyfullname.", fileId);
334 string assemblyName = String.Concat(assemblyNameValues["name"], ", version=", assemblyNameValues["version"], ", culture=", assemblyNameValues["culture"], ", publicKeyToken=", String.IsNullOrEmpty(assemblyNameValues["publicKeyToken"]) ? "null" : assemblyNameValues["publicKeyToken"]); 338 string assemblyName = String.Concat(assemblyNameValues["name"], ", version=", assemblyNameValues["version"], ", culture=", assemblyNameValues["culture"], ", publicKeyToken=", String.IsNullOrEmpty(assemblyNameValues["publicKeyToken"]) ? "null" : assemblyNameValues["publicKeyToken"]);
335 if (assemblyNameValues.ContainsKey("processorArchitecture")) 339 if (assemblyNameValues.ContainsKey("processorArchitecture"))
@@ -437,30 +441,29 @@ namespace WixToolset.Core.WindowsInstaller.Databases
437 Messaging.Instance.OnMessage(WixErrors.InvalidXml(new SourceLineNumber(fileManifest.WixFile.Source), "manifest", xe.Message)); 441 Messaging.Instance.OnMessage(WixErrors.InvalidXml(new SourceLineNumber(fileManifest.WixFile.Source), "manifest", xe.Message));
438 } 442 }
439 443
440 Table assemblyNameTable = this.Output.EnsureTable(this.TableDefinitions["MsiAssemblyName"]);
441 if (!String.IsNullOrEmpty(win32Name)) 444 if (!String.IsNullOrEmpty(win32Name))
442 { 445 {
443 this.SetMsiAssemblyName(assemblyNameTable, file, "name", win32Name); 446 this.SetMsiAssemblyName(assemblyNameTuples, file, "name", win32Name);
444 } 447 }
445 448
446 if (!String.IsNullOrEmpty(win32Version)) 449 if (!String.IsNullOrEmpty(win32Version))
447 { 450 {
448 this.SetMsiAssemblyName(assemblyNameTable, file, "version", win32Version); 451 this.SetMsiAssemblyName(assemblyNameTuples, file, "version", win32Version);
449 } 452 }
450 453
451 if (!String.IsNullOrEmpty(win32Type)) 454 if (!String.IsNullOrEmpty(win32Type))
452 { 455 {
453 this.SetMsiAssemblyName(assemblyNameTable, file, "type", win32Type); 456 this.SetMsiAssemblyName(assemblyNameTuples, file, "type", win32Type);
454 } 457 }
455 458
456 if (!String.IsNullOrEmpty(win32ProcessorArchitecture)) 459 if (!String.IsNullOrEmpty(win32ProcessorArchitecture))
457 { 460 {
458 this.SetMsiAssemblyName(assemblyNameTable, file, "processorArchitecture", win32ProcessorArchitecture); 461 this.SetMsiAssemblyName(assemblyNameTuples, file, "processorArchitecture", win32ProcessorArchitecture);
459 } 462 }
460 463
461 if (!String.IsNullOrEmpty(win32PublicKeyToken)) 464 if (!String.IsNullOrEmpty(win32PublicKeyToken))
462 { 465 {
463 this.SetMsiAssemblyName(assemblyNameTable, file, "publicKeyToken", win32PublicKeyToken); 466 this.SetMsiAssemblyName(assemblyNameTuples, file, "publicKeyToken", win32PublicKeyToken);
464 } 467 }
465 } 468 }
466 } 469 }
@@ -469,11 +472,11 @@ namespace WixToolset.Core.WindowsInstaller.Databases
469 /// Set an MsiAssemblyName row. If it was directly authored, override the value, otherwise 472 /// Set an MsiAssemblyName row. If it was directly authored, override the value, otherwise
470 /// create a new row. 473 /// create a new row.
471 /// </summary> 474 /// </summary>
472 /// <param name="assemblyNameTable">MsiAssemblyName table.</param> 475 /// <param name="assemblyNameTuples">MsiAssemblyName table.</param>
473 /// <param name="file">FileFacade containing the assembly read for the MsiAssemblyName row.</param> 476 /// <param name="file">FileFacade containing the assembly read for the MsiAssemblyName row.</param>
474 /// <param name="name">MsiAssemblyName name.</param> 477 /// <param name="name">MsiAssemblyName name.</param>
475 /// <param name="value">MsiAssemblyName value.</param> 478 /// <param name="value">MsiAssemblyName value.</param>
476 private void SetMsiAssemblyName(Table assemblyNameTable, FileFacade file, string name, string value) 479 private void SetMsiAssemblyName(Dictionary<string, MsiAssemblyNameTuple> assemblyNameTuples, FileFacade file, string name, string value)
477 { 480 {
478 // check for null value (this can occur when grabbing the file version from an assembly without one) 481 // check for null value (this can occur when grabbing the file version from an assembly without one)
479 if (String.IsNullOrEmpty(value)) 482 if (String.IsNullOrEmpty(value))
@@ -482,18 +485,6 @@ namespace WixToolset.Core.WindowsInstaller.Databases
482 } 485 }
483 else 486 else
484 { 487 {
485 Row assemblyNameRow = null;
486
487 // override directly authored value
488 foreach (Row row in assemblyNameTable.Rows)
489 {
490 if ((string)row[0] == file.File.Component_ && (string)row[1] == name)
491 {
492 assemblyNameRow = row;
493 break;
494 }
495 }
496
497 // 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. 488 // 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.
498 if ("name" == name && FileAssemblyType.DotNetAssembly == file.WixFile.AssemblyType && 489 if ("name" == name && FileAssemblyType.DotNetAssembly == file.WixFile.AssemblyType &&
499 String.IsNullOrEmpty(file.WixFile.File_AssemblyApplication) && 490 String.IsNullOrEmpty(file.WixFile.File_AssemblyApplication) &&
@@ -502,17 +493,14 @@ namespace WixToolset.Core.WindowsInstaller.Databases
502 Messaging.Instance.OnMessage(WixErrors.GACAssemblyIdentityWarning(file.File.SourceLineNumbers, Path.GetFileNameWithoutExtension(file.File.LongFileName), value)); 493 Messaging.Instance.OnMessage(WixErrors.GACAssemblyIdentityWarning(file.File.SourceLineNumbers, Path.GetFileNameWithoutExtension(file.File.LongFileName), value));
503 } 494 }
504 495
505 if (null == assemblyNameRow) 496 // override directly authored value
497 var lookup = String.Concat(file.File.Component_, "/", name);
498 if (assemblyNameTuples.TryGetValue(lookup, out var assemblyNameRow))
506 { 499 {
507 throw new NotImplementedException(); 500 assemblyNameRow = new MsiAssemblyNameTuple(file.File.SourceLineNumbers);
508#if TODO 501 assemblyNameRow.Component_ = file.File.Component_;
509 assemblyNameRow = assemblyNameTable.CreateRow(file.File.SourceLineNumbers); 502 assemblyNameRow.Name = name;
510 assemblyNameRow[0] = file.File.Component_; 503 assemblyNameRow.Value = value;
511 assemblyNameRow[1] = name;
512 assemblyNameRow[2] = value;
513
514 // put the MsiAssemblyName row in the same section as the related File row
515 assemblyNameRow.SectionId = file.File.SectionId;
516 504
517 if (null == file.AssemblyNames) 505 if (null == file.AssemblyNames)
518 { 506 {
@@ -520,17 +508,15 @@ namespace WixToolset.Core.WindowsInstaller.Databases
520 } 508 }
521 509
522 file.AssemblyNames.Add(assemblyNameRow); 510 file.AssemblyNames.Add(assemblyNameRow);
523#endif 511 this.Section.Tuples.Add(assemblyNameRow);
524 }
525 else
526 {
527 assemblyNameRow[2] = value;
528 } 512 }
529 513
514 assemblyNameRow.Value = value;
515
530 if (this.VariableCache != null) 516 if (this.VariableCache != null)
531 { 517 {
532 string key = String.Format(CultureInfo.InvariantCulture, "assembly{0}.{1}", name, Common.Demodularize(this.Output.Type, this.ModularizationGuid, file.File.File)).ToLowerInvariant(); 518 var key = String.Format(CultureInfo.InvariantCulture, "assembly{0}.{1}", name, file.File.File).ToLowerInvariant();
533 this.VariableCache[key] = (string)assemblyNameRow[2]; 519 this.VariableCache[key] = value;
534 } 520 }
535 } 521 }
536 } 522 }