From 8b3488c8c77959f425d0e5f70d27c5b2b1c86125 Mon Sep 17 00:00:00 2001 From: Sean Hall Date: Sun, 28 Feb 2021 21:05:49 -0600 Subject: Use new PackagePayload symbols for the package's payload. #4183 --- src/WixToolset.Core/Compile/CompilerPayload.cs | 93 +++++++++++++++++++------- 1 file changed, 68 insertions(+), 25 deletions(-) (limited to 'src/WixToolset.Core/Compile') diff --git a/src/WixToolset.Core/Compile/CompilerPayload.cs b/src/WixToolset.Core/Compile/CompilerPayload.cs index 4eda56f8..7a5fd1b2 100644 --- a/src/WixToolset.Core/Compile/CompilerPayload.cs +++ b/src/WixToolset.Core/Compile/CompilerPayload.cs @@ -23,6 +23,8 @@ namespace WixToolset.Core public Identifier Id { get; set; } + public bool IsRemoteAllowed { get; set; } + public bool IsRequired { get; set; } = true; public string Name { get; set; } @@ -48,26 +50,17 @@ namespace WixToolset.Core private SourceLineNumber SourceLineNumbers { get; } - private void CalculateAndVerifyFields(CompilerPayload remotePayload = null) + private void CalculateAndVerifyFields() { + var isRemote = this.IsRemoteAllowed && !String.IsNullOrEmpty(this.Hash); + if (String.IsNullOrEmpty(this.SourceFile)) { - if (String.IsNullOrEmpty(this.Name)) - { - if (this.IsRequired) - { - this.Core.Write(ErrorMessages.ExpectedAttributesWithOtherAttribute(this.SourceLineNumbers, this.Element.Name.LocalName, "Name", "SourceFile")); - } - } - else if (remotePayload == null) + if (!String.IsNullOrEmpty(this.Name) && !isRemote) { this.SourceFile = Path.Combine("SourceDir", this.Name); } } - else if (remotePayload != null) - { - this.Core.Write(ErrorMessages.UnexpectedElementWithAttribute(this.SourceLineNumbers, this.Element.Name.LocalName, "RemotePayload", "SourceFile")); - } else if (this.SourceFile.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal)) { if (String.IsNullOrEmpty(this.Name)) @@ -80,24 +73,67 @@ namespace WixToolset.Core } } - if (remotePayload != null) + if (String.IsNullOrEmpty(this.SourceFile) && !isRemote) { - if (this.DownloadUrl == null) + if (this.IsRequired) { - this.Core.Write(ErrorMessages.ExpectedAttributeWithElement(this.SourceLineNumbers, this.Element.Name.LocalName, "DownloadUrl", "RemotePayload")); + if (!this.IsRemoteAllowed) + { + this.Core.Write(ErrorMessages.ExpectedAttributes(this.SourceLineNumbers, this.Element.Name.LocalName, "Name", "SourceFile")); + } + else + { + this.Core.Write(ErrorMessages.ExpectedAttributes(this.SourceLineNumbers, this.Element.Name.LocalName, "SourceFile", "Hash")); + } } + } + else if (this.IsRemoteAllowed) + { + var isLocal = !String.IsNullOrEmpty(this.SourceFile); - if (YesNoDefaultType.No != this.Compressed) + if (isLocal) + { + if (isRemote) + { + this.Core.Write(ErrorMessages.IllegalAttributeWithOtherAttribute(this.SourceLineNumbers, this.Element.Name.LocalName, "Hash", "SourceFile")); + } + } + else { + if (String.IsNullOrEmpty(this.DownloadUrl)) + { + this.Core.Write(ErrorMessages.ExpectedAttribute(this.SourceLineNumbers, this.Element.Name.LocalName, "DownloadUrl", "Hash")); + } + + if (String.IsNullOrEmpty(this.Name)) + { + this.Core.Write(ErrorMessages.ExpectedAttribute(this.SourceLineNumbers, this.Element.Name.LocalName, "Name", "Hash")); + } + + if (YesNoDefaultType.Yes == this.Compressed) + { + this.Core.Write(WarningMessages.RemotePayloadsMustNotAlsoBeCompressed(this.SourceLineNumbers, this.Element.Name.LocalName)); + } + this.Compressed = YesNoDefaultType.No; - this.Core.Write(WarningMessages.RemotePayloadsMustNotAlsoBeCompressed(this.SourceLineNumbers, this.Element.Name.LocalName)); } - this.Description = remotePayload.Description; - this.DisplayName = remotePayload.DisplayName; - this.Hash = remotePayload.Hash; - this.Size = remotePayload.Size; - this.Version = remotePayload.Version; + VerifyValidValue("Description", !String.IsNullOrEmpty(this.Description)); + VerifyValidValue("ProductName", !String.IsNullOrEmpty(this.ProductName)); + VerifyValidValue("Size", this.Size.HasValue); + VerifyValidValue("Version", !String.IsNullOrEmpty(this.Version)); + + void VerifyValidValue(string attributeName, bool isSpecified) + { + if (isLocal && isSpecified) + { + this.Core.Write(ErrorMessages.IllegalAttributeWithOtherAttribute(this.SourceLineNumbers, this.Element.Name.LocalName, attributeName, "SourceFile")); + } + else if (!isLocal && !isSpecified) + { + this.Core.Write(ErrorMessages.ExpectedAttribute(this.SourceLineNumbers, this.Element.Name.LocalName, attributeName, "Hash")); + } + } } } @@ -143,9 +179,9 @@ namespace WixToolset.Core return symbol; } - public void FinishCompilingPackage(CompilerPayload remotePayload) + public void FinishCompilingPackage() { - this.CalculateAndVerifyFields(remotePayload); + this.CalculateAndVerifyFields(); this.GenerateIdFromFilename(); if (this.Id == null) @@ -155,6 +191,13 @@ namespace WixToolset.Core } } + public void FinishCompilingPackagePayload() + { + this.CalculateAndVerifyFields(); + this.GenerateIdFromFilename(); + this.GenerateIdFromPrefix("ppy"); + } + public void FinishCompilingPayload() { this.CalculateAndVerifyFields(); -- cgit v1.2.3-55-g6feb