aboutsummaryrefslogtreecommitdiff
path: root/src/WixToolset.Core.WindowsInstaller
diff options
context:
space:
mode:
authorRob Mensching <rob@firegiant.com>2021-02-25 09:58:20 -0800
committerRob Mensching <rob@firegiant.com>2021-02-27 07:47:08 -0800
commit760fb810ba5ecc3c6ce752a9bfa3755f7b7c0f6a (patch)
tree3ad06ffe520f31142e23ce9e752473110d232ec5 /src/WixToolset.Core.WindowsInstaller
parent4536440f8d76346bcd120fe9e1410e428f855ee9 (diff)
downloadwix-760fb810ba5ecc3c6ce752a9bfa3755f7b7c0f6a.tar.gz
wix-760fb810ba5ecc3c6ce752a9bfa3755f7b7c0f6a.tar.bz2
wix-760fb810ba5ecc3c6ce752a9bfa3755f7b7c0f6a.zip
Absorb Tag.wixext into Core as SoftwareTag element
Resolves wixtoolset/issues#5949
Diffstat (limited to 'src/WixToolset.Core.WindowsInstaller')
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs12
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs3
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/ProcessPackageSoftwareTagsCommand.cs131
-rw-r--r--src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs2
4 files changed, 146 insertions, 2 deletions
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
index 012c7c4c..25a093fd 100644
--- a/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/BindDatabaseCommand.cs
@@ -282,6 +282,18 @@ namespace WixToolset.Core.WindowsInstaller.Bind
282 return null; 282 return null;
283 } 283 }
284 284
285 // Process SoftwareTags in MSI packages.
286 if (SectionType.Product == section.Type)
287 {
288 var softwareTags = section.Symbols.OfType<WixProductTagSymbol>().ToList();
289
290 if (softwareTags.Any())
291 {
292 var command = new ProcessPackageSoftwareTagsCommand(section, softwareTags, this.IntermediateFolder);
293 command.Execute();
294 }
295 }
296
285 // Gather information about files that do not come from merge modules. 297 // Gather information about files that do not come from merge modules.
286 { 298 {
287 var command = new UpdateFileFacadesCommand(this.Messaging, section, fileFacades, fileFacades.Where(f => !f.FromModule), variableCache, overwriteHash: true); 299 var command = new UpdateFileFacadesCommand(this.Messaging, section, fileFacades, fileFacades.Where(f => !f.FromModule), variableCache, overwriteHash: true);
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs
index b52ff434..37383caa 100644
--- a/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/CreateOutputFromIRCommand.cs
@@ -231,6 +231,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
231 case SymbolDefinitionType.WixPatchRef: 231 case SymbolDefinitionType.WixPatchRef:
232 case SymbolDefinitionType.WixPatchTarget: 232 case SymbolDefinitionType.WixPatchTarget:
233 case SymbolDefinitionType.WixProperty: 233 case SymbolDefinitionType.WixProperty:
234 case SymbolDefinitionType.WixProductTag:
234 case SymbolDefinitionType.WixSimpleReference: 235 case SymbolDefinitionType.WixSimpleReference:
235 case SymbolDefinitionType.WixSuppressAction: 236 case SymbolDefinitionType.WixSuppressAction:
236 case SymbolDefinitionType.WixSuppressModularization: 237 case SymbolDefinitionType.WixSuppressModularization:
@@ -456,7 +457,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
456 457
457 private void AddDirectorySymbol(DirectorySymbol symbol) 458 private void AddDirectorySymbol(DirectorySymbol symbol)
458 { 459 {
459 if (String.IsNullOrEmpty(symbol.ShortName) && !symbol.Name.Equals(".") && !symbol.Name.Equals("SourceDir") && !Common.IsValidShortFilename(symbol.Name, false)) 460 if (String.IsNullOrEmpty(symbol.ShortName) && symbol.Name != null && !symbol.Name.Equals(".") && !symbol.Name.Equals("SourceDir") && !Common.IsValidShortFilename(symbol.Name, false))
460 { 461 {
461 symbol.ShortName = CreateShortName(symbol.Name, false, false, "Directory", symbol.ParentDirectoryRef); 462 symbol.ShortName = CreateShortName(symbol.Name, false, false, "Directory", symbol.ParentDirectoryRef);
462 } 463 }
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/ProcessPackageSoftwareTagsCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/ProcessPackageSoftwareTagsCommand.cs
new file mode 100644
index 00000000..9a068603
--- /dev/null
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/ProcessPackageSoftwareTagsCommand.cs
@@ -0,0 +1,131 @@
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.WindowsInstaller.Bind
4{
5 using System;
6 using System.Collections.Generic;
7 using System.IO;
8 using System.Linq;
9 using System.Xml;
10 using WixToolset.Data;
11 using WixToolset.Data.Symbols;
12
13 internal class ProcessPackageSoftwareTagsCommand
14 {
15 public ProcessPackageSoftwareTagsCommand(IntermediateSection section, IEnumerable<WixProductTagSymbol> softwareTags, string intermediateFolder)
16 {
17 this.Section = section;
18 this.SoftwareTags = softwareTags;
19 this.IntermediateFolder = intermediateFolder;
20 }
21
22 private string IntermediateFolder { get; }
23
24 private IntermediateSection Section { get; }
25
26 private IEnumerable<WixProductTagSymbol> SoftwareTags { get; }
27
28 public void Execute()
29 {
30 string productName = null;
31 string productVersion = null;
32 string manufacturer = null;
33 string upgradeCode = null;
34
35 var summaryInfo = this.Section.Symbols.OfType<SummaryInformationSymbol>().FirstOrDefault(s => s.PropertyId == SummaryInformationType.PackageCode);
36 var packageCode = NormalizeGuid(summaryInfo?.Value);
37
38 foreach (var property in this.Section.Symbols.OfType<PropertySymbol>())
39 {
40 switch (property.Id.Id)
41 {
42 case "ProductName":
43 productName = property.Value;
44 break;
45 case "ProductVersion":
46 productVersion = property.Value;
47 break;
48 case "Manufacturer":
49 manufacturer = property.Value;
50 break;
51 case "UpgradeCode":
52 upgradeCode = NormalizeGuid(property.Value);
53 break;
54 }
55 }
56
57 var fileSymbolsById = this.Section.Symbols.OfType<FileSymbol>().Where(f => f.Id != null).ToDictionary(f => f.Id.Id);
58
59 var workingFolder = Path.Combine(this.IntermediateFolder, "_swidtag");
60
61 Directory.CreateDirectory(workingFolder);
62
63 foreach (var tagRow in this.SoftwareTags)
64 {
65 if (fileSymbolsById.TryGetValue(tagRow.FileRef, out var fileSymbol))
66 {
67 var uniqueId = String.Concat("msi:package/", packageCode);
68 var persistentId = String.IsNullOrEmpty(upgradeCode) ? null : String.Concat("msi:upgrade/", upgradeCode);
69
70 // Write the tag file.
71 fileSymbol.Source = new IntermediateFieldPathValue { Path = Path.Combine(workingFolder, fileSymbol.Name) };
72
73 using (var fs = new FileStream(fileSymbol.Source.Path, FileMode.Create))
74 {
75 CreateTagFile(fs, uniqueId, productName, productVersion, tagRow.Regid, manufacturer, persistentId);
76 }
77
78 // Ensure the matching "SoftwareIdentificationTag" row exists and
79 // is populated correctly.
80 this.Section.AddSymbol(new SoftwareIdentificationTagSymbol(tagRow.SourceLineNumbers, tagRow.Id)
81 {
82 FileRef = fileSymbol.Id.Id,
83 Regid = tagRow.Regid,
84 TagId = uniqueId,
85 PersistentId = persistentId
86 });
87 }
88 }
89 }
90
91 private static string NormalizeGuid(string guidString)
92 {
93 if (Guid.TryParse(guidString, out var guid))
94 {
95 return guid.ToString("D").ToUpperInvariant();
96 }
97
98 return guidString;
99 }
100
101 private static void CreateTagFile(Stream stream, string uniqueId, string name, string version, string regid, string manufacturer, string persistendId)
102 {
103 var versionScheme = Version.TryParse(version, out _) ? "multipartnumeric" : "alphanumeric";
104
105 using (var writer = XmlWriter.Create(stream, new XmlWriterSettings { Indent = true }))
106 {
107 writer.WriteStartDocument();
108 writer.WriteStartElement("SoftwareIdentity", "http://standards.iso.org/iso/19770/-2/2015/schema.xsd");
109 writer.WriteAttributeString("tagId", uniqueId);
110 writer.WriteAttributeString("name", name);
111 writer.WriteAttributeString("version", version);
112 writer.WriteAttributeString("versionScheme", versionScheme);
113
114 writer.WriteStartElement("Entity");
115 writer.WriteAttributeString("name", manufacturer);
116 writer.WriteAttributeString("regid", regid);
117 writer.WriteAttributeString("role", "softwareCreator tagCreator");
118 writer.WriteEndElement(); // </Entity>
119
120 if (!String.IsNullOrEmpty(persistendId))
121 {
122 writer.WriteStartElement("Meta");
123 writer.WriteAttributeString("persistentId", persistendId);
124 writer.WriteEndElement(); // </Meta>
125 }
126
127 writer.WriteEndElement(); // </SoftwareIdentity>
128 }
129 }
130 }
131}
diff --git a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
index 938627ed..d5bdc797 100644
--- a/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
+++ b/src/WixToolset.Core.WindowsInstaller/Bind/UpdateFileFacadesCommand.cs
@@ -45,7 +45,7 @@ namespace WixToolset.Core.WindowsInstaller.Bind
45 { 45 {
46 var assemblyNameSymbols = this.Section.Symbols.OfType<MsiAssemblyNameSymbol>().ToDictionary(t => t.Id.Id); 46 var assemblyNameSymbols = this.Section.Symbols.OfType<MsiAssemblyNameSymbol>().ToDictionary(t => t.Id.Id);
47 47
48 foreach (var file in this.UpdateFileFacades) 48 foreach (var file in this.UpdateFileFacades.Where(f => f.SourcePath != null))
49 { 49 {
50 this.UpdateFileFacade(file, assemblyNameSymbols); 50 this.UpdateFileFacade(file, assemblyNameSymbols);
51 } 51 }