diff options
-rw-r--r-- | src/wix/WixToolset.Core/Compiler.cs | 174 |
1 files changed, 90 insertions, 84 deletions
diff --git a/src/wix/WixToolset.Core/Compiler.cs b/src/wix/WixToolset.Core/Compiler.cs index 069743aa..e359f3c1 100644 --- a/src/wix/WixToolset.Core/Compiler.cs +++ b/src/wix/WixToolset.Core/Compiler.cs | |||
@@ -5070,6 +5070,75 @@ namespace WixToolset.Core | |||
5070 | } | 5070 | } |
5071 | } | 5071 | } |
5072 | 5072 | ||
5073 | private void ParseFileNamingAttributes(XElement node, string sourcePath, string directoryId, bool isNakedFile, out Identifier id, out string name, out string shortName, out string source) | ||
5074 | { | ||
5075 | var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); | ||
5076 | name = null; | ||
5077 | id = null; | ||
5078 | shortName = null; | ||
5079 | source = sourcePath; // assume we'll use the parents as the source for this file | ||
5080 | var sourceSet = false; | ||
5081 | |||
5082 | foreach (var attrib in node.Attributes()) | ||
5083 | { | ||
5084 | if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || CompilerCore.WixNamespace == attrib.Name.Namespace) | ||
5085 | { | ||
5086 | switch (attrib.Name.LocalName) | ||
5087 | { | ||
5088 | case "Id": | ||
5089 | id = this.Core.GetAttributeIdentifier(sourceLineNumbers, attrib); | ||
5090 | break; | ||
5091 | case "Name": | ||
5092 | name = this.Core.GetAttributeLongFilename(sourceLineNumbers, attrib, false); | ||
5093 | break; | ||
5094 | case "ShortName": | ||
5095 | shortName = this.Core.GetAttributeShortFilename(sourceLineNumbers, attrib, false); | ||
5096 | break; | ||
5097 | case "Source": | ||
5098 | source = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | ||
5099 | sourceSet = true; | ||
5100 | break; | ||
5101 | } | ||
5102 | } | ||
5103 | } | ||
5104 | |||
5105 | if (sourceSet && !source.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) && null == name) | ||
5106 | { | ||
5107 | name = Path.GetFileName(source); | ||
5108 | if (!this.Core.IsValidLongFilename(name, false)) | ||
5109 | { | ||
5110 | this.Core.Write(ErrorMessages.IllegalLongFilename(sourceLineNumbers, node.Name.LocalName, "Source", name)); | ||
5111 | } | ||
5112 | } | ||
5113 | |||
5114 | if (name == null) | ||
5115 | { | ||
5116 | if (shortName == null) | ||
5117 | { | ||
5118 | this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Name")); | ||
5119 | } | ||
5120 | else | ||
5121 | { | ||
5122 | name = shortName; | ||
5123 | shortName = null; | ||
5124 | } | ||
5125 | } | ||
5126 | |||
5127 | if (String.IsNullOrEmpty(source)) | ||
5128 | { | ||
5129 | source = name; | ||
5130 | } | ||
5131 | else if (source.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)) // if source relies on parent directories, append the file name | ||
5132 | { | ||
5133 | source = Path.Combine(source, name); | ||
5134 | } | ||
5135 | |||
5136 | if (null == id && !isNakedFile) | ||
5137 | { | ||
5138 | id = this.Core.CreateIdentifier("fil", directoryId, name); | ||
5139 | } | ||
5140 | } | ||
5141 | |||
5073 | /// <summary> | 5142 | /// <summary> |
5074 | /// Parses a File element's attributes. | 5143 | /// Parses a File element's attributes. |
5075 | /// </summary> | 5144 | /// </summary> |
@@ -5077,6 +5146,9 @@ namespace WixToolset.Core | |||
5077 | /// <param name="componentId">Parent's component id.</param> | 5146 | /// <param name="componentId">Parent's component id.</param> |
5078 | /// <param name="directoryId">Ancestor's directory id.</param> | 5147 | /// <param name="directoryId">Ancestor's directory id.</param> |
5079 | /// <param name="diskId">Disk id inherited from parent component.</param> | 5148 | /// <param name="diskId">Disk id inherited from parent component.</param> |
5149 | /// <param name="id">Already-parsed or defaulted id.</param> | ||
5150 | /// <param name="name">Already-parsed or defaulted name.</param> | ||
5151 | /// <param name="shortName">Already-parsed short name.</param> | ||
5080 | /// <param name="sourcePath">Default source path of parent directory.</param> | 5152 | /// <param name="sourcePath">Default source path of parent directory.</param> |
5081 | /// <param name="possibleKeyPath">This will be set with the possible keyPath for the parent component.</param> | 5153 | /// <param name="possibleKeyPath">This will be set with the possible keyPath for the parent component.</param> |
5082 | /// <param name="componentGuid">Component GUID (including `*`).</param> | 5154 | /// <param name="componentGuid">Component GUID (including `*`).</param> |
@@ -5084,16 +5156,14 @@ namespace WixToolset.Core | |||
5084 | /// <param name="fileSymbol">Outgoing file symbol containing parsed attributes.</param> | 5156 | /// <param name="fileSymbol">Outgoing file symbol containing parsed attributes.</param> |
5085 | /// <param name="assemblySymbol">Outgoing assembly symbol containing parsed attributes.</param> | 5157 | /// <param name="assemblySymbol">Outgoing assembly symbol containing parsed attributes.</param> |
5086 | /// <returns>Yes if this element was marked as the parent component's key path, No if explicitly marked as not being a key path, or NotSet otherwise.</returns> | 5158 | /// <returns>Yes if this element was marked as the parent component's key path, No if explicitly marked as not being a key path, or NotSet otherwise.</returns> |
5087 | private YesNoType ParseFileElementAttributes(XElement node, string componentId, string directoryId, int diskId, string sourcePath, out Identifier possibleKeyPath, string componentGuid, bool isNakedFile, out FileSymbol fileSymbol, out AssemblySymbol assemblySymbol) | 5159 | private YesNoType ParseFileElementOtherAttributes(XElement node, string componentId, string directoryId, int diskId, Identifier id, string name, string shortName, string sourcePath, out Identifier possibleKeyPath, string componentGuid, bool isNakedFile, out FileSymbol fileSymbol, out AssemblySymbol assemblySymbol) |
5088 | { | 5160 | { |
5089 | var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); | 5161 | var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); |
5090 | Identifier id = null; | ||
5091 | var assemblyType = AssemblyType.NotAnAssembly; | 5162 | var assemblyType = AssemblyType.NotAnAssembly; |
5092 | string assemblyApplication = null; | 5163 | string assemblyApplication = null; |
5093 | string assemblyManifest = null; | 5164 | string assemblyManifest = null; |
5094 | string bindPath = null; | 5165 | string bindPath = null; |
5095 | 5166 | ||
5096 | //int bits = MsiInterop.MsidbFileAttributesVital; | ||
5097 | var readOnly = false; | 5167 | var readOnly = false; |
5098 | var checksum = false; | 5168 | var checksum = false; |
5099 | bool? compressed = null; | 5169 | bool? compressed = null; |
@@ -5107,7 +5177,6 @@ namespace WixToolset.Core | |||
5107 | string defaultVersion = null; | 5177 | string defaultVersion = null; |
5108 | string fontTitle = null; | 5178 | string fontTitle = null; |
5109 | var keyPath = YesNoType.NotSet; | 5179 | var keyPath = YesNoType.NotSet; |
5110 | string name = null; | ||
5111 | var patchGroup = CompilerConstants.IntegerNotSet; | 5180 | var patchGroup = CompilerConstants.IntegerNotSet; |
5112 | var patchIgnore = false; | 5181 | var patchIgnore = false; |
5113 | var patchIncludeWholeFile = false; | 5182 | var patchIncludeWholeFile = false; |
@@ -5121,9 +5190,6 @@ namespace WixToolset.Core | |||
5121 | 5190 | ||
5122 | string procArch = null; | 5191 | string procArch = null; |
5123 | int? selfRegCost = null; | 5192 | int? selfRegCost = null; |
5124 | string shortName = null; | ||
5125 | var source = sourcePath; // assume we'll use the parents as the source for this file | ||
5126 | var sourceSet = false; | ||
5127 | 5193 | ||
5128 | fileSymbol = null; | 5194 | fileSymbol = null; |
5129 | assemblySymbol = null; | 5195 | assemblySymbol = null; |
@@ -5134,6 +5200,13 @@ namespace WixToolset.Core | |||
5134 | { | 5200 | { |
5135 | switch (attrib.Name.LocalName) | 5201 | switch (attrib.Name.LocalName) |
5136 | { | 5202 | { |
5203 | case "Id": | ||
5204 | case "Name": | ||
5205 | case "ShortName": | ||
5206 | case "Source": | ||
5207 | // Handled in ParseFileNamingAttributes | ||
5208 | break; | ||
5209 | |||
5137 | case "Bitness": | 5210 | case "Bitness": |
5138 | case "Condition": | 5211 | case "Condition": |
5139 | case "Directory": | 5212 | case "Directory": |
@@ -5144,9 +5217,6 @@ namespace WixToolset.Core | |||
5144 | this.Messaging.Write(ErrorMessages.IllegalAttributeWhenNested(sourceLineNumbers, attrib.Name.LocalName)); | 5217 | this.Messaging.Write(ErrorMessages.IllegalAttributeWhenNested(sourceLineNumbers, attrib.Name.LocalName)); |
5145 | } | 5218 | } |
5146 | break; | 5219 | break; |
5147 | case "Id": | ||
5148 | id = this.Core.GetAttributeIdentifier(sourceLineNumbers, attrib); | ||
5149 | break; | ||
5150 | case "Assembly": | 5220 | case "Assembly": |
5151 | var assemblyValue = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | 5221 | var assemblyValue = this.Core.GetAttributeValue(sourceLineNumbers, attrib); |
5152 | switch (assemblyValue) | 5222 | switch (assemblyValue) |
@@ -5225,9 +5295,6 @@ namespace WixToolset.Core | |||
5225 | case "KeyPath": | 5295 | case "KeyPath": |
5226 | keyPath = this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib); | 5296 | keyPath = this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib); |
5227 | break; | 5297 | break; |
5228 | case "Name": | ||
5229 | name = this.Core.GetAttributeLongFilename(sourceLineNumbers, attrib, false); | ||
5230 | break; | ||
5231 | case "PatchGroup": | 5298 | case "PatchGroup": |
5232 | patchGroup = this.Core.GetAttributeIntegerValue(sourceLineNumbers, attrib, 1, Int32.MaxValue); | 5299 | patchGroup = this.Core.GetAttributeIntegerValue(sourceLineNumbers, attrib, 1, Int32.MaxValue); |
5233 | break; | 5300 | break; |
@@ -5273,13 +5340,6 @@ namespace WixToolset.Core | |||
5273 | case "SelfRegCost": | 5340 | case "SelfRegCost": |
5274 | selfRegCost = this.Core.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, Int16.MaxValue); | 5341 | selfRegCost = this.Core.GetAttributeIntegerValue(sourceLineNumbers, attrib, 0, Int16.MaxValue); |
5275 | break; | 5342 | break; |
5276 | case "ShortName": | ||
5277 | shortName = this.Core.GetAttributeShortFilename(sourceLineNumbers, attrib, false); | ||
5278 | break; | ||
5279 | case "Source": | ||
5280 | source = this.Core.GetAttributeValue(sourceLineNumbers, attrib); | ||
5281 | sourceSet = true; | ||
5282 | break; | ||
5283 | case "System": | 5343 | case "System": |
5284 | if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib)) | 5344 | if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib)) |
5285 | { | 5345 | { |
@@ -5326,33 +5386,6 @@ namespace WixToolset.Core | |||
5326 | } | 5386 | } |
5327 | } | 5387 | } |
5328 | 5388 | ||
5329 | if (sourceSet && !source.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal) && null == name) | ||
5330 | { | ||
5331 | name = Path.GetFileName(source); | ||
5332 | if (!this.Core.IsValidLongFilename(name, false)) | ||
5333 | { | ||
5334 | this.Core.Write(ErrorMessages.IllegalLongFilename(sourceLineNumbers, node.Name.LocalName, "Source", name)); | ||
5335 | } | ||
5336 | } | ||
5337 | |||
5338 | if (name == null) | ||
5339 | { | ||
5340 | if (shortName == null) | ||
5341 | { | ||
5342 | this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Name")); | ||
5343 | } | ||
5344 | else | ||
5345 | { | ||
5346 | name = shortName; | ||
5347 | shortName = null; | ||
5348 | } | ||
5349 | } | ||
5350 | |||
5351 | if (null == id && !isNakedFile) | ||
5352 | { | ||
5353 | id = this.Core.CreateIdentifier("fil", directoryId, name); | ||
5354 | } | ||
5355 | |||
5356 | if (null != defaultVersion && null != companionFile) | 5389 | if (null != defaultVersion && null != companionFile) |
5357 | { | 5390 | { |
5358 | this.Core.Write(ErrorMessages.IllegalAttributeWithOtherAttribute(sourceLineNumbers, node.Name.LocalName, "DefaultVersion", "CompanionFile", companionFile)); | 5391 | this.Core.Write(ErrorMessages.IllegalAttributeWithOtherAttribute(sourceLineNumbers, node.Name.LocalName, "DefaultVersion", "CompanionFile", companionFile)); |
@@ -5400,15 +5433,6 @@ namespace WixToolset.Core | |||
5400 | patchAttributes |= PatchAttributeType.AllowIgnoreOnError; | 5433 | patchAttributes |= PatchAttributeType.AllowIgnoreOnError; |
5401 | } | 5434 | } |
5402 | 5435 | ||
5403 | if (String.IsNullOrEmpty(source)) | ||
5404 | { | ||
5405 | source = name; | ||
5406 | } | ||
5407 | else if (source.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)) // if source relies on parent directories, append the file name | ||
5408 | { | ||
5409 | source = Path.Combine(source, name); | ||
5410 | } | ||
5411 | |||
5412 | var attributes = FileSymbolAttributes.None; | 5436 | var attributes = FileSymbolAttributes.None; |
5413 | attributes |= readOnly ? FileSymbolAttributes.ReadOnly : 0; | 5437 | attributes |= readOnly ? FileSymbolAttributes.ReadOnly : 0; |
5414 | attributes |= hidden ? FileSymbolAttributes.Hidden : 0; | 5438 | attributes |= hidden ? FileSymbolAttributes.Hidden : 0; |
@@ -5430,7 +5454,7 @@ namespace WixToolset.Core | |||
5430 | 5454 | ||
5431 | DirectoryRef = directoryId, | 5455 | DirectoryRef = directoryId, |
5432 | DiskId = (CompilerConstants.IntegerNotSet == diskId) ? null : (int?)diskId, | 5456 | DiskId = (CompilerConstants.IntegerNotSet == diskId) ? null : (int?)diskId, |
5433 | Source = new IntermediateFieldPathValue { Path = source }, | 5457 | Source = new IntermediateFieldPathValue { Path = sourcePath }, |
5434 | 5458 | ||
5435 | FontTitle = fontTitle, | 5459 | FontTitle = fontTitle, |
5436 | SelfRegCost = selfRegCost, | 5460 | SelfRegCost = selfRegCost, |
@@ -5577,7 +5601,9 @@ namespace WixToolset.Core | |||
5577 | /// <returns>Yes if this element was marked as the parent component's key path, No if explicitly marked as not being a key path, or NotSet otherwise.</returns> | 5601 | /// <returns>Yes if this element was marked as the parent component's key path, No if explicitly marked as not being a key path, or NotSet otherwise.</returns> |
5578 | private YesNoType ParseFileElement(XElement node, string componentId, string directoryId, int diskId, string sourcePath, out Identifier possibleKeyPath, bool win64Component, string componentGuid) | 5602 | private YesNoType ParseFileElement(XElement node, string componentId, string directoryId, int diskId, string sourcePath, out Identifier possibleKeyPath, bool win64Component, string componentGuid) |
5579 | { | 5603 | { |
5580 | var keyPath = this.ParseFileElementAttributes(node, componentId, directoryId, diskId, sourcePath, out possibleKeyPath, componentGuid, isNakedFile: false, out var fileSymbol, out var assemblySymbol); | 5604 | this.ParseFileNamingAttributes(node, sourcePath, directoryId, isNakedFile: false, out var id, out var name, out var shortName, out var source); |
5605 | |||
5606 | var keyPath = this.ParseFileElementOtherAttributes(node, componentId, directoryId, diskId, id, name, shortName, source, out possibleKeyPath, componentGuid, isNakedFile: false, out var fileSymbol, out var assemblySymbol); | ||
5581 | 5607 | ||
5582 | if (!this.Core.EncounteredError) | 5608 | if (!this.Core.EncounteredError) |
5583 | { | 5609 | { |
@@ -5659,35 +5685,15 @@ namespace WixToolset.Core | |||
5659 | 5685 | ||
5660 | directoryId = this.HandleSubdirectory(sourceLineNumbers, node, directoryId, subdirectory, "Directory", "Subdirectory"); | 5686 | directoryId = this.HandleSubdirectory(sourceLineNumbers, node, directoryId, subdirectory, "Directory", "Subdirectory"); |
5661 | 5687 | ||
5662 | var keyPath = this.ParseFileElementAttributes(node, "@WixTemporaryComponentId", directoryId, diskId: CompilerConstants.IntegerNotSet, sourcePath, out var _, componentGuid: "*", isNakedFile: true, out var fileSymbol, out var assemblySymbol); | 5688 | this.ParseFileNamingAttributes(node, sourcePath, directoryId, isNakedFile: true, out var id, out var name, out var shortName, out var source); |
5663 | 5689 | ||
5664 | // Now that we have all the data we need to generate a good id, do | 5690 | // Now that we have all the data we need to generate a good id, do |
5665 | // so and create a file and component symbol with the right data. | 5691 | // so and create a file and component symbol with the right data. |
5666 | var id = fileSymbol.Id ?? this.Core.CreateIdentifier("nkf", directoryId, fileSymbol.Name, condition, win64.ToString()); | 5692 | id = id ?? this.Core.CreateIdentifier("nkf", directoryId, name, condition, win64.ToString()); |
5667 | 5693 | ||
5668 | this.Core.AddSymbol(new FileSymbol(sourceLineNumbers, id) | 5694 | var keyPath = this.ParseFileElementOtherAttributes(node, id.Id, directoryId, diskId: CompilerConstants.IntegerNotSet, id, name, shortName, source, out var _, componentGuid: "*", isNakedFile: true, fileSymbol: out var fileSymbol, assemblySymbol: out var assemblySymbol); |
5669 | { | 5695 | |
5670 | ComponentRef = id.Id, | 5696 | this.Core.AddSymbol(fileSymbol); |
5671 | Name = fileSymbol.Name, | ||
5672 | ShortName = fileSymbol.ShortName, | ||
5673 | FileSize = fileSymbol.FileSize, | ||
5674 | Version = fileSymbol.Version, | ||
5675 | Language = fileSymbol.Language, | ||
5676 | Attributes = fileSymbol.Attributes, | ||
5677 | DirectoryRef = fileSymbol.DirectoryRef, | ||
5678 | DiskId = fileSymbol.DiskId, | ||
5679 | Source = fileSymbol.Source, | ||
5680 | FontTitle = fileSymbol.FontTitle, | ||
5681 | SelfRegCost = fileSymbol.SelfRegCost, | ||
5682 | BindPath = fileSymbol.BindPath, | ||
5683 | PatchGroup = fileSymbol.PatchGroup, | ||
5684 | PatchAttributes = fileSymbol.PatchAttributes, | ||
5685 | RetainLengths = fileSymbol.RetainLengths, | ||
5686 | IgnoreOffsets = fileSymbol.IgnoreOffsets, | ||
5687 | IgnoreLengths = fileSymbol.IgnoreLengths, | ||
5688 | RetainOffsets = fileSymbol.RetainOffsets, | ||
5689 | SymbolPaths = fileSymbol.SymbolPaths, | ||
5690 | }); | ||
5691 | 5697 | ||
5692 | this.Core.AddSymbol(new ComponentSymbol(sourceLineNumbers, id) | 5698 | this.Core.AddSymbol(new ComponentSymbol(sourceLineNumbers, id) |
5693 | { | 5699 | { |