Beispiel #1
0
        /// <summary>
        /// Get an identifier attribute value and displays an error for an illegal identifier value.
        /// </summary>
        /// <param name="messaging"></param>
        /// <param name="sourceLineNumbers">Source line information about the owner element.</param>
        /// <param name="attribute">The attribute containing the value to get.</param>
        /// <returns>The attribute's identifier value or a special value if an error occurred.</returns>
        internal static string GetAttributeIdentifierValue(IMessaging messaging, SourceLineNumber sourceLineNumbers, XAttribute attribute)
        {
            string value = Common.GetAttributeValue(messaging, sourceLineNumbers, attribute, EmptyRule.CanBeWhitespaceOnly);

            if (Common.IsIdentifier(value))
            {
                if (72 < value.Length)
                {
                    messaging.Write(WarningMessages.IdentifierTooLong(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                }

                return(value);
            }
            else
            {
                if (value.StartsWith("[", StringComparison.Ordinal) && value.EndsWith("]", StringComparison.Ordinal))
                {
                    messaging.Write(ErrorMessages.IllegalIdentifierLooksLikeFormatted(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                }
                else
                {
                    messaging.Write(ErrorMessages.IllegalIdentifier(sourceLineNumbers, attribute.Parent.Name.LocalName, attribute.Name.LocalName, value));
                }

                return(String.Empty);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Checks if the string contains a property (i.e. "foo[Property]bar")
        /// </summary>
        /// <param name="possibleProperty">String to evaluate for properties.</param>
        /// <returns>True if a property is found in the string.</returns>
        internal static bool ContainsProperty(string possibleProperty)
        {
            var start = possibleProperty.IndexOf('[');

            if (start != -1 && start < possibleProperty.Length - 2)
            {
                var end = possibleProperty.IndexOf(']', start + 1);
                if (end > start + 1)
                {
                    // Skip supported property modifiers.
                    if (possibleProperty[start + 1] == '#' || possibleProperty[start + 1] == '$' || possibleProperty[start + 1] == '!')
                    {
                        ++start;
                    }

                    var id = possibleProperty.Substring(start + 1, end - 1);

                    if (Common.IsIdentifier(id))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
Beispiel #3
0
        internal static bool TryParseWixVariable(string value, int start, out ParsedWixVariable parsedVariable)
        {
            parsedVariable = null;

            if (String.IsNullOrEmpty(value) || start >= value.Length)
            {
                return(false);
            }

            var startWixVariable = value.IndexOf("!(", start, StringComparison.Ordinal);

            if (startWixVariable == -1)
            {
                return(false);
            }

            var firstDot = value.IndexOf('.', startWixVariable + 1);

            if (firstDot == -1)
            {
                return(false);
            }

            var ns = value.Substring(startWixVariable + 2, firstDot - startWixVariable - 2);

            if (ns != "loc" && ns != "bind" && ns != "wix")
            {
                return(false);
            }

            var closeParen = value.IndexOf(')', firstDot);

            if (closeParen == -1)
            {
                return(false);
            }

            string name;
            string scope        = null;
            string defaultValue = null;

            var secondDot          = value.IndexOf('.', firstDot + 1, closeParen - firstDot);
            var equalsDefaultValue = value.IndexOf('=', firstDot + 1, closeParen - firstDot);
            var end = equalsDefaultValue == -1 ? closeParen : equalsDefaultValue;

            if (secondDot == -1)
            {
                name = value.Substring(firstDot + 1, end - firstDot - 1);
            }
            else
            {
                name  = value.Substring(firstDot + 1, secondDot - firstDot - 1);
                scope = value.Substring(secondDot + 1, end - secondDot - 1);

                if (!Common.IsIdentifier(scope))
                {
                    return(false);
                }
            }

            if (!Common.IsIdentifier(name))
            {
                return(false);
            }

            if (equalsDefaultValue != -1 && equalsDefaultValue < closeParen)
            {
                defaultValue = value.Substring(equalsDefaultValue + 1, end - equalsDefaultValue - 1);
            }

            parsedVariable = new ParsedWixVariable
            {
                Index        = startWixVariable,
                Length       = closeParen - startWixVariable + 1,
                Namespace    = ns,
                Name         = name,
                Scope        = scope,
                DefaultValue = defaultValue
            };

            return(true);
        }
        /// <summary>
        /// Parses a embedded UI resource element.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        private void ParseEmbeddedUIResourceElement(XElement node)
        {
            var        sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);
            Identifier id         = null;
            string     name       = null;
            string     sourceFile = 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.GetAttributeIdentifier(sourceLineNumbers, attrib);
                        break;

                    case "Name":
                        name = this.Core.GetAttributeLongFilename(sourceLineNumbers, attrib, false);
                        break;

                    case "SourceFile":
                        sourceFile = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
                        break;

                    default:
                        this.Core.UnexpectedAttribute(node, attrib);
                        break;
                    }
                }
                else
                {
                    this.Core.ParseExtensionAttribute(node, attrib);
                }
            }

            if (String.IsNullOrEmpty(sourceFile))
            {
                this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "SourceFile"));
            }
            else if (String.IsNullOrEmpty(name))
            {
                name = Path.GetFileName(sourceFile);
                if (!this.Core.IsValidLongFilename(name, false))
                {
                    this.Core.Write(ErrorMessages.IllegalLongFilename(sourceLineNumbers, node.Name.LocalName, "Source", name));
                }
            }

            if (null == id)
            {
                if (!String.IsNullOrEmpty(name))
                {
                    id = this.Core.CreateIdentifierFromFilename(name);
                }

                if (null == id)
                {
                    this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id"));
                }
                else if (!Common.IsIdentifier(id.Id))
                {
                    this.Core.Write(ErrorMessages.IllegalIdentifier(sourceLineNumbers, node.Name.LocalName, "Id", id.Id));
                }
            }
            else if (String.IsNullOrEmpty(name))
            {
                name = id.Id;
            }

            this.Core.ParseForExtensionElements(node);

            if (!this.Core.EncounteredError)
            {
                this.Core.AddSymbol(new MsiEmbeddedUISymbol(sourceLineNumbers, id)
                {
                    FileName = name,
                    Source   = sourceFile
                });
            }
        }
        /// <summary>
        /// Parses an EmbeddedUI element.
        /// </summary>
        /// <param name="node">Element to parse.</param>
        private void ParseEmbeddedUIElement(XElement node)
        {
            var        sourceLineNumbers = Preprocessor.GetSourceLineNumbers(node);
            Identifier id              = null;
            string     name            = null;
            var        supportsBasicUI = false;
            var        messageFilter   = WindowsInstallerConstants.INSTALLLOGMODE_FATALEXIT | WindowsInstallerConstants.INSTALLLOGMODE_ERROR | WindowsInstallerConstants.INSTALLLOGMODE_WARNING | WindowsInstallerConstants.INSTALLLOGMODE_USER
                                         | WindowsInstallerConstants.INSTALLLOGMODE_INFO | WindowsInstallerConstants.INSTALLLOGMODE_FILESINUSE | WindowsInstallerConstants.INSTALLLOGMODE_RESOLVESOURCE
                                         | WindowsInstallerConstants.INSTALLLOGMODE_OUTOFDISKSPACE | WindowsInstallerConstants.INSTALLLOGMODE_ACTIONSTART | WindowsInstallerConstants.INSTALLLOGMODE_ACTIONDATA
                                         | WindowsInstallerConstants.INSTALLLOGMODE_PROGRESS | WindowsInstallerConstants.INSTALLLOGMODE_COMMONDATA | WindowsInstallerConstants.INSTALLLOGMODE_INITIALIZE
                                         | WindowsInstallerConstants.INSTALLLOGMODE_TERMINATE | WindowsInstallerConstants.INSTALLLOGMODE_SHOWDIALOG | WindowsInstallerConstants.INSTALLLOGMODE_RMFILESINUSE
                                         | WindowsInstallerConstants.INSTALLLOGMODE_INSTALLSTART | WindowsInstallerConstants.INSTALLLOGMODE_INSTALLEND;
            string sourceFile = 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.GetAttributeIdentifier(sourceLineNumbers, attrib);
                        break;

                    case "Name":
                        name = this.Core.GetAttributeLongFilename(sourceLineNumbers, attrib, false);
                        break;

                    case "IgnoreFatalExit":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_FATALEXIT;
                        }
                        break;

                    case "IgnoreError":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_ERROR;
                        }
                        break;

                    case "IgnoreWarning":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_WARNING;
                        }
                        break;

                    case "IgnoreUser":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_USER;
                        }
                        break;

                    case "IgnoreInfo":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_INFO;
                        }
                        break;

                    case "IgnoreFilesInUse":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_FILESINUSE;
                        }
                        break;

                    case "IgnoreResolveSource":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_RESOLVESOURCE;
                        }
                        break;

                    case "IgnoreOutOfDiskSpace":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_OUTOFDISKSPACE;
                        }
                        break;

                    case "IgnoreActionStart":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_ACTIONSTART;
                        }
                        break;

                    case "IgnoreActionData":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_ACTIONDATA;
                        }
                        break;

                    case "IgnoreProgress":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_PROGRESS;
                        }
                        break;

                    case "IgnoreCommonData":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_COMMONDATA;
                        }
                        break;

                    case "IgnoreInitialize":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_INITIALIZE;
                        }
                        break;

                    case "IgnoreTerminate":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_TERMINATE;
                        }
                        break;

                    case "IgnoreShowDialog":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_SHOWDIALOG;
                        }
                        break;

                    case "IgnoreRMFilesInUse":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_RMFILESINUSE;
                        }
                        break;

                    case "IgnoreInstallStart":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_INSTALLSTART;
                        }
                        break;

                    case "IgnoreInstallEnd":
                        if (YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib))
                        {
                            messageFilter ^= WindowsInstallerConstants.INSTALLLOGMODE_INSTALLEND;
                        }
                        break;

                    case "SourceFile":
                        sourceFile = this.Core.GetAttributeValue(sourceLineNumbers, attrib);
                        break;

                    case "SupportBasicUI":
                        supportsBasicUI = YesNoType.Yes == this.Core.GetAttributeYesNoValue(sourceLineNumbers, attrib);
                        break;

                    default:
                        this.Core.UnexpectedAttribute(node, attrib);
                        break;
                    }
                }
                else
                {
                    this.Core.ParseExtensionAttribute(node, attrib);
                }
            }

            if (String.IsNullOrEmpty(sourceFile))
            {
                this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "SourceFile"));
            }
            else if (String.IsNullOrEmpty(name))
            {
                name = Path.GetFileName(sourceFile);
                if (!this.Core.IsValidLongFilename(name, false))
                {
                    this.Core.Write(ErrorMessages.IllegalLongFilename(sourceLineNumbers, node.Name.LocalName, "Source", name));
                }
            }

            if (null == id)
            {
                if (!String.IsNullOrEmpty(name))
                {
                    id = this.Core.CreateIdentifierFromFilename(name);
                }

                if (null == id)
                {
                    this.Core.Write(ErrorMessages.ExpectedAttribute(sourceLineNumbers, node.Name.LocalName, "Id"));
                }
                else if (!Common.IsIdentifier(id.Id))
                {
                    this.Core.Write(ErrorMessages.IllegalIdentifier(sourceLineNumbers, node.Name.LocalName, "Id", id.Id));
                }
            }
            else if (String.IsNullOrEmpty(name))
            {
                name = id.Id;
            }

            if (!name.Contains("."))
            {
                this.Core.Write(ErrorMessages.InvalidEmbeddedUIFileName(sourceLineNumbers, name));
            }

            foreach (var child in node.Elements())
            {
                if (CompilerCore.WixNamespace == child.Name.Namespace)
                {
                    switch (child.Name.LocalName)
                    {
                    case "EmbeddedUIResource":
                        this.ParseEmbeddedUIResourceElement(child);
                        break;

                    default:
                        this.Core.UnexpectedElement(node, child);
                        break;
                    }
                }
                else
                {
                    this.Core.ParseExtensionElement(node, child);
                }
            }

            if (!this.Core.EncounteredError)
            {
                this.Core.AddSymbol(new MsiEmbeddedUISymbol(sourceLineNumbers, id)
                {
                    FileName        = name,
                    EntryPoint      = true,
                    SupportsBasicUI = supportsBasicUI,
                    MessageFilter   = messageFilter,
                    Source          = sourceFile
                });
            }
        }