From 7b583330fd42356930bdc5a28820e546f6ca45a4 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Sun, 5 Jul 2020 23:08:20 -0700 Subject: Move short filename generation to the WindowsInstallerBackend --- src/WixToolset.Core/Common.cs | 2 +- src/WixToolset.Core/Compiler.cs | 124 +++++---------------- src/WixToolset.Core/CompilerCore.cs | 1 + src/WixToolset.Core/Compiler_2.cs | 46 +------- .../ExtensibilityServices/ParseHelper.cs | 14 +-- 5 files changed, 34 insertions(+), 153 deletions(-) (limited to 'src/WixToolset.Core') diff --git a/src/WixToolset.Core/Common.cs b/src/WixToolset.Core/Common.cs index 183d7abd..a9fc9538 100644 --- a/src/WixToolset.Core/Common.cs +++ b/src/WixToolset.Core/Common.cs @@ -188,7 +188,7 @@ namespace WixToolset.Core /// Filename to verify. /// true if wildcards are allowed in the filename. /// True if the filename is a valid short filename - internal static bool IsValidShortFilename(string filename, bool allowWildcards) + public static bool IsValidShortFilename(string filename, bool allowWildcards) { if (String.IsNullOrEmpty(filename)) { diff --git a/src/WixToolset.Core/Compiler.cs b/src/WixToolset.Core/Compiler.cs index 4d0e608b..b29821b0 100644 --- a/src/WixToolset.Core/Compiler.cs +++ b/src/WixToolset.Core/Compiler.cs @@ -299,24 +299,6 @@ namespace WixToolset.Core return s?.ToLowerInvariant(); } - /// - /// Given a possible short and long file name, create an msi filename value. - /// - /// The short file name. - /// Possibly the long file name. - /// The value in the msi filename data type. - private string GetMsiFilenameValue(string shortName, string longName) - { - if (null != shortName && null != longName && !String.Equals(shortName, longName, StringComparison.OrdinalIgnoreCase)) - { - return String.Concat(shortName, "|", longName); - } - else - { - return this.Core.IsValidShortFilename(longName, false) ? longName : shortName; - } - } - /// /// Adds a search property to the active section. /// @@ -3036,12 +3018,6 @@ namespace WixToolset.Core this.Core.Write(ErrorMessages.IllegalAttributeWithOtherAttribute(sourceLineNumbers, node.Name.LocalName, "DestinationProperty", "DestinationDirectory")); } - // generate a short file name - if (null == destinationShortName && (null != destinationName && !this.Core.IsValidShortFilename(destinationName, false))) - { - destinationShortName = this.Core.CreateShortName(destinationName, true, false, node.Name.LocalName, componentId); - } - if (null == id) { id = this.Core.CreateIdentifier("cf", sourceFolder, sourceDirectory, sourceProperty, destinationDirectory, destinationProperty, destinationName); @@ -3063,7 +3039,8 @@ namespace WixToolset.Core { ComponentRef = componentId, SourceName = sourceName, - DestName= String.IsNullOrEmpty(destinationShortName) && String.IsNullOrEmpty(destinationName) ? null : this.GetMsiFilenameValue(destinationShortName, destinationName), + DestinationName = destinationName, + DestinationShortName = destinationShortName, SourceFolder = sourceDirectory ?? sourceProperty, DestFolder = destinationDirectory ?? destinationProperty, Delete = delete, @@ -3108,7 +3085,8 @@ namespace WixToolset.Core { ComponentRef = componentId, FileRef = fileId, - DestinationName = String.IsNullOrEmpty(destinationShortName) && String.IsNullOrEmpty(destinationName) ? null : this.GetMsiFilenameValue(destinationShortName, destinationName), + DestinationName = destinationName, + DestinationShortName = destinationShortName, DestinationFolder = destinationDirectory ?? destinationProperty, }); } @@ -4184,16 +4162,12 @@ namespace WixToolset.Core { if (String.IsNullOrEmpty(shortName)) { - if (!name.Equals(".") && !name.Equals("SourceDir") && !this.Core.IsValidShortFilename(name, false)) - { - shortName = this.Core.CreateShortName(name, false, false, "Directory", parentId); - } } - else if (name.Equals(".")) + else if (name == ".") { this.Core.Write(ErrorMessages.IllegalAttributeWithOtherAttribute(sourceLineNumbers, node.Name.LocalName, "ShortName", "Name", name)); } - else if (name.Equals(shortName)) + else if (name.Equals(shortName, StringComparison.OrdinalIgnoreCase)) { this.Core.Write(WarningMessages.DirectoryRedundantNames(sourceLineNumbers, node.Name.LocalName, "Name", "ShortName", name)); } @@ -4210,16 +4184,12 @@ namespace WixToolset.Core { if (String.IsNullOrEmpty(shortSourceName)) { - if (!sourceName.Equals(".") && !this.Core.IsValidShortFilename(sourceName, false)) - { - shortSourceName = this.Core.CreateShortName(sourceName, false, false, "Directory", parentId); - } } - else if (sourceName.Equals(".")) + else if (sourceName == ".") { this.Core.Write(ErrorMessages.IllegalAttributeWithOtherAttribute(sourceLineNumbers, node.Name.LocalName, "ShortSourceName", "SourceName", sourceName)); } - else if (sourceName.Equals(shortSourceName)) + else if (sourceName.Equals(shortSourceName, StringComparison.OrdinalIgnoreCase)) { this.Core.Write(WarningMessages.DirectoryRedundantNames(sourceLineNumbers, node.Name.LocalName, "SourceName", "ShortSourceName", sourceName)); } @@ -5463,7 +5433,6 @@ namespace WixToolset.Core var defaultSize = 0; string defaultVersion = null; string fontTitle = null; - var generatedShortFileName = false; var keyPath = YesNoType.NotSet; string name = null; var patchGroup = CompilerConstants.IntegerNotSet; @@ -5686,16 +5655,22 @@ namespace WixToolset.Core } } - // generate a short file name - if (null == shortName && (null != name && !this.Core.IsValidShortFilename(name, false))) + if (name == null) { - shortName = this.Core.CreateShortName(name, true, false, node.Name.LocalName, directoryId); - generatedShortFileName = true; + if (shortName == null) + { + this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Name")); + } + else + { + name = shortName; + shortName = null; + } } if (null == id) { - id = this.Core.CreateIdentifier("fil", directoryId, name ?? shortName); + id = this.Core.CreateIdentifier("fil", directoryId, name); } if (null != defaultVersion && null != companionFile) @@ -5811,11 +5786,11 @@ namespace WixToolset.Core if (String.IsNullOrEmpty(source)) { - source = name ?? shortName; + source = name; } else if (source.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)) // if source relies on parent directories, append the file name { - source = null == name ? Path.Combine(source, shortName) : Path.Combine(source, name); + source = Path.Combine(source, name); } var attributes = FileSymbolAttributes.None; @@ -5826,7 +5801,6 @@ namespace WixToolset.Core attributes |= checksum ? FileSymbolAttributes.Checksum : 0; attributes |= compressed.HasValue && compressed == true ? FileSymbolAttributes.Compressed : 0; attributes |= compressed.HasValue && compressed == false ? FileSymbolAttributes.Uncompressed : 0; - attributes |= generatedShortFileName ? FileSymbolAttributes.GeneratedShortFileName : 0; this.Core.AddSymbol(new FileSymbol(sourceLineNumbers, id) { @@ -5838,14 +5812,6 @@ namespace WixToolset.Core Language = defaultLanguage, Attributes = attributes, - //ReadOnly = readOnly, - //Hidden = hidden, - //System = system, - //Vital = vital, - //Checksum = checksum, - //Compressed = compressed, - //GeneratedShortFileName = generatedShortFileName, - DirectoryRef = directoryId, DiskId = (CompilerConstants.IntegerNotSet == diskId) ? null : (int?)diskId, Source = new IntermediateFieldPathValue { Path = source }, @@ -6454,28 +6420,6 @@ namespace WixToolset.Core { this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Name")); } - else if (0 < name.Length) - { - if (this.Core.IsValidShortFilename(name, false)) - { - if (null == shortName) - { - shortName = name; - name = null; - } - else - { - this.Core.Write(ErrorMessages.IllegalAttributeValueWithOtherAttribute(sourceLineNumbers, node.Name.LocalName, "Name", name, "ShortName")); - } - } - else // generate a short file name. - { - if (null == shortName) - { - shortName = this.Core.CreateShortName(name, true, false, node.Name.LocalName, componentId); - } - } - } if (null == section) { @@ -6493,7 +6437,8 @@ namespace WixToolset.Core { this.Core.AddSymbol(new IniFileSymbol(sourceLineNumbers, id) { - FileName = this.GetMsiFilenameValue(shortName, name), + FileName = name, + ShortFileName = shortName, DirProperty = directory, Section = section, Key = key, @@ -6585,25 +6530,6 @@ namespace WixToolset.Core { this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Name")); } - else if (0 < name.Length) - { - if (this.Core.IsValidShortFilename(name, false)) - { - if (null == shortName) - { - shortName = name; - name = null; - } - else - { - this.Core.Write(ErrorMessages.IllegalAttributeValueWithOtherAttribute(sourceLineNumbers, node.Name.LocalName, "Name", name, "ShortName")); - } - } - else if (null == shortName) // generate a short file name. - { - shortName = this.Core.CreateShortName(name, true, false, node.Name.LocalName); - } - } if (null == section) { @@ -6677,8 +6603,8 @@ namespace WixToolset.Core { var symbol = this.Core.AddSymbol(new IniLocatorSymbol(sourceLineNumbers, id) { - SignatureRef = id.Id, - FileName = this.GetMsiFilenameValue(shortName, name), + FileName = name, + ShortFileName = shortName, Section = section, Key = key, Type = type diff --git a/src/WixToolset.Core/CompilerCore.cs b/src/WixToolset.Core/CompilerCore.cs index 7ec83a7d..c2724f6b 100644 --- a/src/WixToolset.Core/CompilerCore.cs +++ b/src/WixToolset.Core/CompilerCore.cs @@ -286,6 +286,7 @@ namespace WixToolset.Core /// true if wildcards are allowed in the filename. /// Any additional information to include in the hash for the generated short name. /// The generated 8.3-compliant short file/directory name. + [Obsolete] public string CreateShortName(string longName, bool keepExtension, bool allowWildcards, params string[] args) { return this.parseHelper.CreateShortName(longName, keepExtension, allowWildcards, args); diff --git a/src/WixToolset.Core/Compiler_2.cs b/src/WixToolset.Core/Compiler_2.cs index 72550ed9..7e2485e1 100644 --- a/src/WixToolset.Core/Compiler_2.cs +++ b/src/WixToolset.Core/Compiler_2.cs @@ -2309,25 +2309,6 @@ namespace WixToolset.Core { this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Name")); } - else if (0 < name.Length) - { - if (this.Core.IsValidShortFilename(name, true)) - { - if (null == shortName) - { - shortName = name; - name = null; - } - else - { - this.Core.Write(ErrorMessages.IllegalAttributeValueWithOtherAttribute(sourceLineNumbers, node.Name.LocalName, "Name", name, "ShortName")); - } - } - else if (null == shortName) // generate a short file name. - { - shortName = this.Core.CreateShortName(name, true, true, node.Name.LocalName, componentId); - } - } if (!onInstall.HasValue && !onUninstall.HasValue) { @@ -2352,8 +2333,9 @@ namespace WixToolset.Core this.Core.AddSymbol(new RemoveFileSymbol(sourceLineNumbers, id) { ComponentRef = componentId, - FileName = this.GetMsiFilenameValue(shortName, name), - DirProperty = directory ?? property ?? parentDirectory, + FileName = name, + ShortFileName = shortName, + DirPropertyRef = directory ?? property ?? parentDirectory, OnInstall = onInstall, OnUninstall = onUninstall, }); @@ -2440,7 +2422,7 @@ namespace WixToolset.Core this.Core.AddSymbol(new RemoveFileSymbol(sourceLineNumbers, id) { ComponentRef = componentId, - DirProperty = directory ?? property ?? parentDirectory, + DirPropertyRef = directory ?? property ?? parentDirectory, OnInstall = onInstall, OnUninstall = onUninstall }); @@ -4293,24 +4275,6 @@ namespace WixToolset.Core { this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Name")); } - else if (0 < name.Length) - { - if (this.Core.IsValidShortFilename(name, false)) - { - if (null == shortName) - { - shortName = name; - } - else - { - this.Core.Write(ErrorMessages.IllegalAttributeValueWithOtherAttribute(sourceLineNumbers, node.Name.LocalName, "Name", name, "ShortName")); - } - } - else if (null == shortName) // generate a short file name. - { - shortName = this.Core.CreateShortName(name, true, false, node.Name.LocalName, componentId, directory); - } - } if ("Component" != parentElementLocalName && null != target) { @@ -4319,7 +4283,7 @@ namespace WixToolset.Core if (null == id) { - id = this.Core.CreateIdentifier("sct", directory, LowercaseOrNull(name) ?? LowercaseOrNull(shortName)); + id = this.Core.CreateIdentifier("sct", directory, LowercaseOrNull(name)); } foreach (var child in node.Elements()) diff --git a/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs b/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs index 7160c32e..db465354 100644 --- a/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs +++ b/src/WixToolset.Core/ExtensibilityServices/ParseHelper.cs @@ -75,16 +75,6 @@ namespace WixToolset.Core.ExtensibilityServices public Identifier CreateDirectorySymbol(IntermediateSection section, SourceLineNumber sourceLineNumbers, Identifier id, string parentId, string name, ISet sectionInlinedDirectoryIds, string shortName = null, string sourceName = null, string shortSourceName = null) { - if (String.IsNullOrEmpty(shortName) && !name.Equals("SourceDir") && !this.IsValidShortFilename(name)) - { - shortName = this.CreateShortName(name, false, false, "Directory", parentId); - } - - if (String.IsNullOrEmpty(shortSourceName) && !String.IsNullOrEmpty(sourceName) && !this.IsValidShortFilename(sourceName)) - { - shortSourceName = this.CreateShortName(sourceName, false, false, "Directory", parentId); - } - // For anonymous directories, create the identifier. If this identifier already exists in the // active section, bail so we don't add duplicate anonymous directory symbols (which are legal // but bloat the intermediate and ultimately make the linker do "busy work"). @@ -243,7 +233,7 @@ namespace WixToolset.Core.ExtensibilityServices if (null == childId) { - throw new ArgumentNullException("childId"); + throw new ArgumentNullException(nameof(childId)); } section.AddSymbol(new WixGroupSymbol(sourceLineNumbers) @@ -419,7 +409,7 @@ namespace WixToolset.Core.ExtensibilityServices { if (null == attribute) { - throw new ArgumentNullException("attribute"); + throw new ArgumentNullException(nameof(attribute)); } var emptyRule = canBeEmpty ? EmptyRule.CanBeEmpty : EmptyRule.CanBeWhitespaceOnly; -- cgit v1.2.3-55-g6feb