diff options
Diffstat (limited to 'src/WixToolset.Core/Common.cs')
| -rw-r--r-- | src/WixToolset.Core/Common.cs | 53 |
1 files changed, 27 insertions, 26 deletions
diff --git a/src/WixToolset.Core/Common.cs b/src/WixToolset.Core/Common.cs index 9a0d3aec..ebcbd36f 100644 --- a/src/WixToolset.Core/Common.cs +++ b/src/WixToolset.Core/Common.cs | |||
| @@ -14,6 +14,7 @@ namespace WixToolset.Core | |||
| 14 | using System.Xml.Linq; | 14 | using System.Xml.Linq; |
| 15 | using WixToolset.Data; | 15 | using WixToolset.Data; |
| 16 | using WixToolset.Extensibility; | 16 | using WixToolset.Extensibility; |
| 17 | using WixToolset.Extensibility.Services; | ||
| 17 | 18 | ||
| 18 | /// <summary> | 19 | /// <summary> |
| 19 | /// Common Wix utility methods and types. | 20 | /// Common Wix utility methods and types. |
| @@ -111,7 +112,7 @@ namespace WixToolset.Core | |||
| 111 | /// <param name="path">The temporary directory to delete.</param> | 112 | /// <param name="path">The temporary directory to delete.</param> |
| 112 | /// <param name="messageHandler">The message handler.</param> | 113 | /// <param name="messageHandler">The message handler.</param> |
| 113 | /// <returns>True if all files were deleted, false otherwise.</returns> | 114 | /// <returns>True if all files were deleted, false otherwise.</returns> |
| 114 | internal static bool DeleteTempFiles(string path, IMessageHandler messageHandler) | 115 | internal static bool DeleteTempFiles(string path, IMessaging messageHandler) |
| 115 | { | 116 | { |
| 116 | // try three times and give up with a warning if the temp files aren't gone by then | 117 | // try three times and give up with a warning if the temp files aren't gone by then |
| 117 | int retryLimit = 3; | 118 | int retryLimit = 3; |
| @@ -133,7 +134,7 @@ namespace WixToolset.Core | |||
| 133 | } | 134 | } |
| 134 | else | 135 | else |
| 135 | { | 136 | { |
| 136 | messageHandler.OnMessage(WixWarnings.AccessDeniedForDeletion(null, path)); | 137 | messageHandler.Write(WarningMessages.AccessDeniedForDeletion(null, path)); |
| 137 | return false; | 138 | return false; |
| 138 | } | 139 | } |
| 139 | } | 140 | } |
| @@ -146,7 +147,7 @@ namespace WixToolset.Core | |||
| 146 | { | 147 | { |
| 147 | if (i == (retryLimit - 1)) // last try failed still, give up | 148 | if (i == (retryLimit - 1)) // last try failed still, give up |
| 148 | { | 149 | { |
| 149 | messageHandler.OnMessage(WixWarnings.DirectoryInUse(null, path)); | 150 | messageHandler.Write(WarningMessages.DirectoryInUse(null, path)); |
| 150 | return false; | 151 | return false; |
| 151 | } | 152 | } |
| 152 | 153 | ||
| @@ -203,7 +204,7 @@ namespace WixToolset.Core | |||
| 203 | codePage = encoding.CodePage; | 204 | codePage = encoding.CodePage; |
| 204 | if (0 > codePage || Int16.MaxValue < codePage) | 205 | if (0 > codePage || Int16.MaxValue < codePage) |
| 205 | { | 206 | { |
| 206 | throw new WixException(WixErrors.InvalidSummaryInfoCodePage(sourceLineNumbers, codePage)); | 207 | throw new WixException(ErrorMessages.InvalidSummaryInfoCodePage(sourceLineNumbers, codePage)); |
| 207 | } | 208 | } |
| 208 | } | 209 | } |
| 209 | 210 | ||
| @@ -327,7 +328,7 @@ namespace WixToolset.Core | |||
| 327 | case "true": | 328 | case "true": |
| 328 | return true; | 329 | return true; |
| 329 | default: | 330 | default: |
| 330 | throw new WixException(WixErrors.IllegalAttributeValue(sourceLineNumbers, elementName, attributeName, value, "no", "yes")); | 331 | throw new WixException(ErrorMessages.IllegalAttributeValue(sourceLineNumbers, elementName, attributeName, value, "no", "yes")); |
| 331 | } | 332 | } |
| 332 | } | 333 | } |
| 333 | 334 | ||
| @@ -433,7 +434,7 @@ namespace WixToolset.Core | |||
| 433 | /// <param name="fileAttribute">The FileAttribute to change on each file.</param> | 434 | /// <param name="fileAttribute">The FileAttribute to change on each file.</param> |
| 434 | /// <param name="messageHandler">The message handler.</param> | 435 | /// <param name="messageHandler">The message handler.</param> |
| 435 | /// <param name="markAttribute">If true, add the attribute to each file. If false, remove it.</param> | 436 | /// <param name="markAttribute">If true, add the attribute to each file. If false, remove it.</param> |
| 436 | private static void RecursiveFileAttributes(string path, FileAttributes fileAttribute, bool markAttribute, IMessageHandler messageHandler) | 437 | private static void RecursiveFileAttributes(string path, FileAttributes fileAttribute, bool markAttribute, IMessaging messageHandler) |
| 437 | { | 438 | { |
| 438 | foreach (string subDirectory in Directory.GetDirectories(path)) | 439 | foreach (string subDirectory in Directory.GetDirectories(path)) |
| 439 | { | 440 | { |
| @@ -458,7 +459,7 @@ namespace WixToolset.Core | |||
| 458 | } | 459 | } |
| 459 | catch (UnauthorizedAccessException) | 460 | catch (UnauthorizedAccessException) |
| 460 | { | 461 | { |
| 461 | messageHandler.OnMessage(WixWarnings.AccessDeniedForSettingAttributes(null, filePath)); | 462 | messageHandler.Write(WarningMessages.AccessDeniedForSettingAttributes(null, filePath)); |
| 462 | } | 463 | } |
| 463 | } | 464 | } |
| 464 | } | 465 | } |
| @@ -624,14 +625,14 @@ namespace WixToolset.Core | |||
| 624 | /// <param name="emptyRule">A rule for the contents of the value. If the contents do not follow the rule, an error is thrown.</param> | 625 | /// <param name="emptyRule">A rule for the contents of the value. If the contents do not follow the rule, an error is thrown.</param> |
| 625 | /// <param name="messageHandler">A delegate that receives error messages.</param> | 626 | /// <param name="messageHandler">A delegate that receives error messages.</param> |
| 626 | /// <returns>The attribute's value.</returns> | 627 | /// <returns>The attribute's value.</returns> |
| 627 | internal static string GetAttributeValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, EmptyRule emptyRule) | 628 | internal static string GetAttributeValue(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute, EmptyRule emptyRule) |
| 628 | { | 629 | { |
| 629 | string value = attribute.Value; | 630 | string value = attribute.Value; |
| 630 | 631 | ||
| 631 | if ((emptyRule == EmptyRule.MustHaveNonWhitespaceCharacters && String.IsNullOrEmpty(value.Trim())) || | 632 | if ((emptyRule == EmptyRule.MustHaveNonWhitespaceCharacters && String.IsNullOrEmpty(value.Trim())) || |
| 632 | (emptyRule == EmptyRule.CanBeWhitespaceOnly && String.IsNullOrEmpty(value))) | 633 | (emptyRule == EmptyRule.CanBeWhitespaceOnly && String.IsNullOrEmpty(value))) |
| 633 | { | 634 | { |
| 634 | Messaging.Instance.OnMessage(WixErrors.IllegalEmptyAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName)); | 635 | messaging.Write(ErrorMessages.IllegalEmptyAttributeValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName)); |
| 635 | return String.Empty; | 636 | return String.Empty; |
| 636 | } | 637 | } |
| 637 | 638 | ||
| @@ -663,15 +664,15 @@ namespace WixToolset.Core | |||
| 663 | /// <param name="attribute">The attribute containing the value to get.</param> | 664 | /// <param name="attribute">The attribute containing the value to get.</param> |
| 664 | /// <param name="messageHandler">A delegate that receives error messages.</param> | 665 | /// <param name="messageHandler">A delegate that receives error messages.</param> |
| 665 | /// <returns>The attribute's identifier value or a special value if an error occurred.</returns> | 666 | /// <returns>The attribute's identifier value or a special value if an error occurred.</returns> |
| 666 | internal static string GetAttributeIdentifierValue(SourceLineNumber sourceLineNumbers, XAttribute attribute) | 667 | internal static string GetAttributeIdentifierValue(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute) |
| 667 | { | 668 | { |
| 668 | string value = Common.GetAttributeValue(sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); | 669 | string value = Common.GetAttributeValue(messaging, sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); |
| 669 | 670 | ||
| 670 | if (Common.IsIdentifier(value)) | 671 | if (Common.IsIdentifier(value)) |
| 671 | { | 672 | { |
| 672 | if (72 < value.Length) | 673 | if (72 < value.Length) |
| 673 | { | 674 | { |
| 674 | Messaging.Instance.OnMessage(WixWarnings.IdentifierTooLong(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); | 675 | messaging.Write(WarningMessages.IdentifierTooLong(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); |
| 675 | } | 676 | } |
| 676 | 677 | ||
| 677 | return value; | 678 | return value; |
| @@ -680,11 +681,11 @@ namespace WixToolset.Core | |||
| 680 | { | 681 | { |
| 681 | if (value.StartsWith("[", StringComparison.Ordinal) && value.EndsWith("]", StringComparison.Ordinal)) | 682 | if (value.StartsWith("[", StringComparison.Ordinal) && value.EndsWith("]", StringComparison.Ordinal)) |
| 682 | { | 683 | { |
| 683 | Messaging.Instance.OnMessage(WixErrors.IllegalIdentifierLooksLikeFormatted(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); | 684 | messaging.Write(ErrorMessages.IllegalIdentifierLooksLikeFormatted(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); |
| 684 | } | 685 | } |
| 685 | else | 686 | else |
| 686 | { | 687 | { |
| 687 | Messaging.Instance.OnMessage(WixErrors.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); | 688 | messaging.Write(ErrorMessages.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); |
| 688 | } | 689 | } |
| 689 | 690 | ||
| 690 | return String.Empty; | 691 | return String.Empty; |
| @@ -700,11 +701,11 @@ namespace WixToolset.Core | |||
| 700 | /// <param name="maximum">The maximum legal value.</param> | 701 | /// <param name="maximum">The maximum legal value.</param> |
| 701 | /// <param name="messageHandler">A delegate that receives error messages.</param> | 702 | /// <param name="messageHandler">A delegate that receives error messages.</param> |
| 702 | /// <returns>The attribute's integer value or a special value if an error occurred during conversion.</returns> | 703 | /// <returns>The attribute's integer value or a special value if an error occurred during conversion.</returns> |
| 703 | public static int GetAttributeIntegerValue(SourceLineNumber sourceLineNumbers, XAttribute attribute, int minimum, int maximum) | 704 | public static int GetAttributeIntegerValue(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute, int minimum, int maximum) |
| 704 | { | 705 | { |
| 705 | Debug.Assert(minimum > CompilerConstants.IntegerNotSet && minimum > CompilerConstants.IllegalInteger, "The legal values for this attribute collide with at least one sentinel used during parsing."); | 706 | Debug.Assert(minimum > CompilerConstants.IntegerNotSet && minimum > CompilerConstants.IllegalInteger, "The legal values for this attribute collide with at least one sentinel used during parsing."); |
| 706 | 707 | ||
| 707 | string value = Common.GetAttributeValue(sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); | 708 | string value = Common.GetAttributeValue(messaging, sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); |
| 708 | int integer = CompilerConstants.IllegalInteger; | 709 | int integer = CompilerConstants.IllegalInteger; |
| 709 | 710 | ||
| 710 | if (0 < value.Length) | 711 | if (0 < value.Length) |
| @@ -713,17 +714,17 @@ namespace WixToolset.Core | |||
| 713 | { | 714 | { |
| 714 | if (CompilerConstants.IntegerNotSet == integer || CompilerConstants.IllegalInteger == integer) | 715 | if (CompilerConstants.IntegerNotSet == integer || CompilerConstants.IllegalInteger == integer) |
| 715 | { | 716 | { |
| 716 | Messaging.Instance.OnMessage(WixErrors.IntegralValueSentinelCollision(sourceLineNumbers, integer)); | 717 | messaging.Write(ErrorMessages.IntegralValueSentinelCollision(sourceLineNumbers, integer)); |
| 717 | } | 718 | } |
| 718 | else if (minimum > integer || maximum < integer) | 719 | else if (minimum > integer || maximum < integer) |
| 719 | { | 720 | { |
| 720 | Messaging.Instance.OnMessage(WixErrors.IntegralValueOutOfRange(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, integer, minimum, maximum)); | 721 | messaging.Write(ErrorMessages.IntegralValueOutOfRange(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, integer, minimum, maximum)); |
| 721 | integer = CompilerConstants.IllegalInteger; | 722 | integer = CompilerConstants.IllegalInteger; |
| 722 | } | 723 | } |
| 723 | } | 724 | } |
| 724 | else | 725 | else |
| 725 | { | 726 | { |
| 726 | Messaging.Instance.OnMessage(WixErrors.IllegalIntegerValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); | 727 | messaging.Write(ErrorMessages.IllegalIntegerValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); |
| 727 | } | 728 | } |
| 728 | } | 729 | } |
| 729 | 730 | ||
| @@ -737,9 +738,9 @@ namespace WixToolset.Core | |||
| 737 | /// <param name="attribute">The attribute containing the value to get.</param> | 738 | /// <param name="attribute">The attribute containing the value to get.</param> |
| 738 | /// <param name="messageHandler">A delegate that receives error messages.</param> | 739 | /// <param name="messageHandler">A delegate that receives error messages.</param> |
| 739 | /// <returns>The attribute's YesNoType value.</returns> | 740 | /// <returns>The attribute's YesNoType value.</returns> |
| 740 | internal static YesNoType GetAttributeYesNoValue(SourceLineNumber sourceLineNumbers, XAttribute attribute) | 741 | internal static YesNoType GetAttributeYesNoValue(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute) |
| 741 | { | 742 | { |
| 742 | string value = Common.GetAttributeValue(sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); | 743 | string value = Common.GetAttributeValue(messaging, sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly); |
| 743 | YesNoType yesNo = YesNoType.IllegalValue; | 744 | YesNoType yesNo = YesNoType.IllegalValue; |
| 744 | 745 | ||
| 745 | if ("yes".Equals(value) || "true".Equals(value)) | 746 | if ("yes".Equals(value) || "true".Equals(value)) |
| @@ -752,7 +753,7 @@ namespace WixToolset.Core | |||
| 752 | } | 753 | } |
| 753 | else | 754 | else |
| 754 | { | 755 | { |
| 755 | Messaging.Instance.OnMessage(WixErrors.IllegalYesNoValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); | 756 | messaging.Write(ErrorMessages.IllegalYesNoValue(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value)); |
| 756 | } | 757 | } |
| 757 | 758 | ||
| 758 | return yesNo; | 759 | return yesNo; |
| @@ -776,13 +777,13 @@ namespace WixToolset.Core | |||
| 776 | /// </summary> | 777 | /// </summary> |
| 777 | /// <param name="sourceLineNumbers">Source line information about the owner element.</param> | 778 | /// <param name="sourceLineNumbers">Source line information about the owner element.</param> |
| 778 | /// <param name="attribute">The attribute.</param> | 779 | /// <param name="attribute">The attribute.</param> |
| 779 | public static void UnexpectedAttribute(SourceLineNumber sourceLineNumbers, XAttribute attribute) | 780 | public static void UnexpectedAttribute(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute) |
| 780 | { | 781 | { |
| 781 | // Ignore elements defined by the W3C because we'll assume they are always right. | 782 | // Ignore elements defined by the W3C because we'll assume they are always right. |
| 782 | if (!((String.IsNullOrEmpty(attribute.Name.NamespaceName) && attribute.Name.LocalName.Equals("xmlns", StringComparison.Ordinal)) || | 783 | if (!((String.IsNullOrEmpty(attribute.Name.NamespaceName) && attribute.Name.LocalName.Equals("xmlns", StringComparison.Ordinal)) || |
| 783 | attribute.Name.NamespaceName.StartsWith(CompilerCore.W3SchemaPrefix.NamespaceName, StringComparison.Ordinal))) | 784 | attribute.Name.NamespaceName.StartsWith(CompilerCore.W3SchemaPrefix.NamespaceName, StringComparison.Ordinal))) |
| 784 | { | 785 | { |
| 785 | Messaging.Instance.OnMessage(WixErrors.UnexpectedAttribute(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName)); | 786 | messaging.Write(ErrorMessages.UnexpectedAttribute(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName)); |
| 786 | } | 787 | } |
| 787 | } | 788 | } |
| 788 | 789 | ||
| @@ -791,13 +792,13 @@ namespace WixToolset.Core | |||
| 791 | /// </summary> | 792 | /// </summary> |
| 792 | /// <param name="sourceLineNumbers">Source line information about the owner element.</param> | 793 | /// <param name="sourceLineNumbers">Source line information about the owner element.</param> |
| 793 | /// <param name="extensionAttribute">The extension attribute.</param> | 794 | /// <param name="extensionAttribute">The extension attribute.</param> |
| 794 | internal static void UnsupportedExtensionAttribute(SourceLineNumber sourceLineNumbers, XAttribute extensionAttribute) | 795 | internal static void UnsupportedExtensionAttribute(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute extensionAttribute) |
| 795 | { | 796 | { |
| 796 | // Ignore elements defined by the W3C because we'll assume they are always right. | 797 | // Ignore elements defined by the W3C because we'll assume they are always right. |
| 797 | if (!((String.IsNullOrEmpty(extensionAttribute.Name.NamespaceName) && extensionAttribute.Name.LocalName.Equals("xmlns", StringComparison.Ordinal)) || | 798 | if (!((String.IsNullOrEmpty(extensionAttribute.Name.NamespaceName) && extensionAttribute.Name.LocalName.Equals("xmlns", StringComparison.Ordinal)) || |
| 798 | extensionAttribute.Name.NamespaceName.StartsWith(CompilerCore.W3SchemaPrefix.NamespaceName, StringComparison.Ordinal))) | 799 | extensionAttribute.Name.NamespaceName.StartsWith(CompilerCore.W3SchemaPrefix.NamespaceName, StringComparison.Ordinal))) |
| 799 | { | 800 | { |
| 800 | Messaging.Instance.OnMessage(WixErrors.UnsupportedExtensionAttribute(sourceLineNumbers, extensionAttribute.Parent.Name.LocalName, extensionAttribute.Name.LocalName)); | 801 | messaging.Write(ErrorMessages.UnsupportedExtensionAttribute(sourceLineNumbers, extensionAttribute.Parent.Name.LocalName, extensionAttribute.Name.LocalName)); |
| 801 | } | 802 | } |
| 802 | } | 803 | } |
| 803 | } | 804 | } |
