From 86e59fdbc94ae661ca682f04cddb60d7830ae8a8 Mon Sep 17 00:00:00 2001 From: Rob Mensching Date: Tue, 6 Apr 2021 09:34:57 -0700 Subject: Introduce StandardDirectory for referencing standard directories Completes wixtoolset/issues#6416 --- src/WixToolset.Core/Compiler.cs | 72 +++++++++++++++++++++++++++++++++ src/WixToolset.Core/CompilerWarnings.cs | 12 ++++++ src/WixToolset.Core/Compiler_Module.cs | 3 ++ src/WixToolset.Core/Compiler_Package.cs | 3 ++ 4 files changed, 90 insertions(+) (limited to 'src/WixToolset.Core') diff --git a/src/WixToolset.Core/Compiler.cs b/src/WixToolset.Core/Compiler.cs index 184c5b3e..ca9385f6 100644 --- a/src/WixToolset.Core/Compiler.cs +++ b/src/WixToolset.Core/Compiler.cs @@ -4427,6 +4427,10 @@ namespace WixToolset.Core { this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id")); } + else if (WindowsInstallerStandard.IsStandardDirectory(id)) + { + this.Core.Write(CompilerWarnings.DirectoryRefStandardDirectoryDeprecated(sourceLineNumbers, id)); + } if (!String.IsNullOrEmpty(fileSource) && !fileSource.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)) { @@ -6324,6 +6328,9 @@ namespace WixToolset.Core string parentName = null; this.ParseSFPCatalogElement(child, ref parentName); break; + case "StandardDirectory": + this.ParseStandardDirectoryElement(child); + break; case "UI": this.ParseUIElement(child); break; @@ -7558,6 +7565,71 @@ namespace WixToolset.Core } } + /// + /// Parses a standard directory element. + /// + /// Element to parse. + private void ParseStandardDirectoryElement(XElement node) + { + var sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node); + string id = null; + + foreach (var attrib in node.Attributes()) + { + if (String.IsNullOrEmpty(attrib.Name.NamespaceName) || CompilerCore.WixNamespace == attrib.Name.Namespace) + { + switch (attrib.Name.LocalName) + { + case "Id": + id = this.Core.GetAttributeIdentifierValue(sourceLineNumbers, attrib); + break; + default: + this.Core.UnexpectedAttribute(node, attrib); + break; + } + } + else + { + this.Core.ParseExtensionAttribute(node, attrib); + } + } + + if (String.IsNullOrEmpty(id)) + { + this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id")); + } + else if (!WindowsInstallerStandard.IsStandardDirectory(id)) + { + this.Core.Write(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, node.Name.LocalName, "Id", id, String.Join(", \"", WindowsInstallerStandard.StandardDirectories().Select(d => d.Id.Id)))); + } + + foreach (var child in node.Elements()) + { + if (CompilerCore.WixNamespace == child.Name.Namespace) + { + switch (child.Name.LocalName) + { + case "Component": + this.ParseComponentElement(child, ComplexReferenceParentType.Unknown, null, null, diskId: CompilerConstants.IntegerNotSet, id, srcPath: String.Empty); + break; + case "Directory": + this.ParseDirectoryElement(child, id, diskId: CompilerConstants.IntegerNotSet, fileSource: String.Empty); + break; + case "Merge": + this.ParseMergeElement(child, id, diskId: CompilerConstants.IntegerNotSet); + break; + default: + this.Core.UnexpectedElement(node, child); + break; + } + } + else + { + this.Core.ParseExtensionElement(node, child); + } + } + } + /// /// Parses a configuration data element. /// diff --git a/src/WixToolset.Core/CompilerWarnings.cs b/src/WixToolset.Core/CompilerWarnings.cs index 3b9666dd..eb838ae2 100644 --- a/src/WixToolset.Core/CompilerWarnings.cs +++ b/src/WixToolset.Core/CompilerWarnings.cs @@ -6,6 +6,16 @@ namespace WixToolset.Core internal static class CompilerWarnings { + public static Message DirectoryRefStandardDirectoryDeprecated(SourceLineNumber sourceLineNumbers, string directoryId) + { + return Message(sourceLineNumbers, Ids.DirectoryRefStandardDirectoryDeprecated, "Using DirectoryRef to reference the standard directory '{0}' is deprecated. Use the StandardDirectory element instead.", directoryId); + } + + public static Message DefiningStandardDirectoryDeprecated(SourceLineNumber sourceLineNumbers, string directoryId) + { + return Message(sourceLineNumbers, Ids.DefiningStandardDirectoryDeprecated, "It is no longer necessary to define the standard directory '{0}'. Use the StandardDirectory element instead.", directoryId); + } + public static Message DiscouragedVersionAttribute(SourceLineNumber sourceLineNumbers) { return Message(sourceLineNumbers, Ids.DiscouragedVersionAttribute, "The Provides/@Version attribute should not be specified in an MSI package. The ProductVersion will be used by default."); @@ -48,6 +58,8 @@ namespace WixToolset.Core PropertyRemoved = 5433, DiscouragedVersionAttribute = 5434, Win64Component = 5435, + DirectoryRefStandardDirectoryDeprecated = 5436, + DefiningStandardDirectoryDeprecated = 5437, } } } diff --git a/src/WixToolset.Core/Compiler_Module.cs b/src/WixToolset.Core/Compiler_Module.cs index 59fe9164..3986c8da 100644 --- a/src/WixToolset.Core/Compiler_Module.cs +++ b/src/WixToolset.Core/Compiler_Module.cs @@ -203,6 +203,9 @@ namespace WixToolset.Core string parentName = null; this.ParseSFPCatalogElement(child, ref parentName); break; + case "StandardDirectory": + this.ParseStandardDirectoryElement(child); + break; case "Substitution": this.ParseSubstitutionElement(child); break; diff --git a/src/WixToolset.Core/Compiler_Package.cs b/src/WixToolset.Core/Compiler_Package.cs index 576450f4..f9d77873 100644 --- a/src/WixToolset.Core/Compiler_Package.cs +++ b/src/WixToolset.Core/Compiler_Package.cs @@ -316,6 +316,9 @@ namespace WixToolset.Core case "SoftwareTag": this.ParsePackageTagElement(child); break; + case "StandardDirectory": + this.ParseStandardDirectoryElement(child); + break; case "SummaryInformation": this.ParseSummaryInformationElement(child, ref isCodepageSet, ref isPackageNameSet, ref isKeywordsSet, ref isPackageAuthorSet); break; -- cgit v1.2.3-55-g6feb