예제 #1
0
        /// <summary>
        /// Resolves the source path of a file.
        /// </summary>
        /// <param name="source">Original source value.</param>
        /// <param name="type">Optional type of source file being resolved.</param>
        /// <param name="sourceLineNumbers">Optional source line of source file being resolved.</param>
        /// <param name="bindStage">The binding stage used to determine what collection of bind paths will be used</param>
        /// <returns>Should return a valid path for the stream to be imported.</returns>
        public virtual string ResolveFile(string source, string type, SourceLineNumber sourceLineNumbers, BindStage bindStage)
        {
            if (String.IsNullOrEmpty(source))
            {
                throw new ArgumentNullException("source");
            }

            if (BinderFileManager.CheckFileExists(source)) // if the file exists, we're good to go.
            {
                return(source);
            }
            else if (Path.IsPathRooted(source)) // path is rooted so bindpaths won't help, bail since the file apparently doesn't exist.
            {
                return(null);
            }
            else // not a rooted path so let's try applying all the different source resolution options.
            {
                const string bindPathOpenString = "!(bindpath.";

                string bindName             = String.Empty;
                string path                 = source;
                string pathWithoutSourceDir = null;

                if (source.StartsWith(bindPathOpenString, StringComparison.Ordinal))
                {
                    int closeParen = source.IndexOf(')', bindPathOpenString.Length);
                    if (-1 != closeParen)
                    {
                        bindName = source.Substring(bindPathOpenString.Length, closeParen - bindPathOpenString.Length);
                        path     = source.Substring(bindPathOpenString.Length + bindName.Length + 1); // +1 for the closing brace.
                        path     = path.TrimStart('\\');                                              // remove starting '\\' char so the path doesn't look rooted.
                    }
                }
                else if (source.StartsWith("SourceDir\\", StringComparison.Ordinal) || source.StartsWith("SourceDir/", StringComparison.Ordinal))
                {
                    pathWithoutSourceDir = path.Substring(10);
                }

                var bindPaths = this.Core.GetBindPaths(bindStage, bindName);
                foreach (string bindPath in bindPaths)
                {
                    string filePath;
                    if (!String.IsNullOrEmpty(pathWithoutSourceDir))
                    {
                        filePath = Path.Combine(bindPath, pathWithoutSourceDir);
                        if (BinderFileManager.CheckFileExists(filePath))
                        {
                            return(filePath);
                        }
                    }

                    filePath = Path.Combine(bindPath, path);
                    if (BinderFileManager.CheckFileExists(filePath))
                    {
                        return(filePath);
                    }
                }
            }

            // Didn't find the file.
            return(null);
        }
예제 #2
0
 /// <summary>
 /// Creates a PayloadInfoRow row that belongs to a table.
 /// </summary>
 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
 /// <param name="table">Table this Media row belongs to and should get its column definitions from.</param>
 public PayloadInfoRow(SourceLineNumber sourceLineNumbers, Table table) :
     base(sourceLineNumbers, table)
 {
 }
예제 #3
0
        /// <summary>
        /// Get the value of a variable.
        /// </summary>
        /// <param name="sourceLineNumbers">The source line information for the function.</param>
        /// <param name="prefix">The variable prefix.</param>
        /// <param name="name">The variable name.</param>
        /// <returns>The variable value or null if the variable is not set.</returns>
        public string GetVariableValue(SourceLineNumber sourceLineNumbers, string prefix, string name)
        {
            if (String.IsNullOrEmpty(prefix))
            {
                throw new ArgumentNullException("prefix");
            }

            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }

            switch (prefix)
            {
            case "env":
                return(Environment.GetEnvironmentVariable(name));

            case "sys":
                switch (name)
                {
                case "CURRENTDIR":
                    return(String.Concat(Directory.GetCurrentDirectory(), Path.DirectorySeparatorChar));

                case "SOURCEFILEDIR":
                    return(String.Concat(Path.GetDirectoryName(sourceLineNumbers.FileName), Path.DirectorySeparatorChar));

                case "SOURCEFILEPATH":
                    return(sourceLineNumbers.FileName);

                case "PLATFORM":
                    this.OnMessage(WixWarnings.DeprecatedPreProcVariable(sourceLineNumbers, "$(sys.PLATFORM)", "$(sys.BUILDARCH)"));

                    goto case "BUILDARCH";

                case "BUILDARCH":
                    switch (this.currentPlatform)
                    {
                    case Platform.X86:
                        return("x86");

                    case Platform.X64:
                        return("x64");

                    case Platform.IA64:
                        return("ia64");

                    case Platform.ARM:
                        return("arm");

                    default:
                        throw new ArgumentException(WixStrings.EXP_UnknownPlatformEnum, this.currentPlatform.ToString());
                    }

                default:
                    return(null);
                }

            case "var":
                string result = null;
                return(this.variables.TryGetValue(name, out result) ? result : null);

            default:
                PreprocessorExtension extension = (PreprocessorExtension)this.extensionsByPrefix[prefix];
                if (null != extension)
                {
                    try
                    {
                        return(extension.GetVariableValue(prefix, name));
                    }
                    catch (Exception e)
                    {
                        throw new WixException(WixErrors.PreprocessorExtensionGetVariableValueFailed(sourceLineNumbers, prefix, name, e.Message));
                    }
                }
                else
                {
                    return(null);
                }
            }
        }
 /// <summary>
 /// Called at the end of the validation of a database file.
 /// </summary>
 /// <remarks>
 /// <para>The default implementation will nullify source lines.</para>
 /// <para><b>Notes to Inheritors:</b> When overriding
 /// <b>FinalizeValidator</b> in a derived class, be sure to call
 /// the base class's <b>FinalizeValidator</b> to thoroughly
 /// finalize the extension.</para>
 /// </remarks>
 public virtual void FinalizeValidator()
 {
     this.sourceLineNumbers = null;
 }
예제 #5
0
        /// <summary>
        /// Parse a section from the xml.
        /// </summary>
        /// <param name="reader">XmlReader where the intermediate is persisted.</param>
        /// <param name="tableDefinitions">TableDefinitions to use in the intermediate.</param>
        /// <returns>The parsed Section.</returns>
        internal static Section Parse(XmlReader reader, TableDefinitionCollection tableDefinitions)
        {
            Debug.Assert("section" == reader.LocalName);

            int         codepage = 0;
            bool        empty    = reader.IsEmptyElement;
            string      id       = null;
            Section     section  = null;
            SectionType type     = SectionType.Unknown;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case "codepage":
                    codepage = Convert.ToInt32(reader.Value, CultureInfo.InvariantCulture);
                    break;

                case "id":
                    id = reader.Value;
                    break;

                case "type":
                    switch (reader.Value)
                    {
                    case "bundle":
                        type = SectionType.Bundle;
                        break;

                    case "fragment":
                        type = SectionType.Fragment;
                        break;

                    case "module":
                        type = SectionType.Module;
                        break;

                    case "patchCreation":
                        type = SectionType.PatchCreation;
                        break;

                    case "product":
                        type = SectionType.Product;
                        break;

                    case "patch":
                        type = SectionType.Patch;
                        break;

                    default:
                        throw new WixException(WixErrors.IllegalAttributeValue(SourceLineNumber.CreateFromUri(reader.BaseURI), "section", reader.Name, reader.Value, "fragment", "module", "patchCreation", "product", "patch"));
                    }
                    break;

                default:
                    if (!reader.NamespaceURI.StartsWith("http://www.w3.org/", StringComparison.Ordinal))
                    {
                        throw new WixException(WixErrors.UnexpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "section", reader.Name));
                    }
                    break;
                }
            }

            if (null == id && (SectionType.Unknown != type && SectionType.Fragment != type))
            {
                throw new WixException(WixErrors.ExpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "section", "id", "type", type.ToString()));
            }

            if (SectionType.Unknown == type)
            {
                throw new WixException(WixErrors.ExpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "section", "type"));
            }

            section = new Section(id, type, codepage);
            section.sourceLineNumbers = SourceLineNumber.CreateFromUri(reader.BaseURI);

            if (!empty)
            {
                bool done = false;

                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                        case "table":
                            section.Tables.Add(Table.Parse(reader, section, tableDefinitions));
                            break;

                        default:
                            throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "section", reader.Name));
                        }
                        break;

                    case XmlNodeType.EndElement:
                        done = true;
                        break;
                    }
                }

                if (!done)
                {
                    throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "section"));
                }
            }

            return(section);
        }
        /// <summary>
        /// Resolves the source path of a file.
        /// </summary>
        /// <param name="source">Original source value.</param>
        /// <param name="type">Optional type of source file being resolved.</param>
        /// <param name="sourceLineNumbers">Optional source line of source file being resolved.</param>
        /// <param name="bindStage">The binding stage used to determine what collection of bind paths will be used</param>
        /// <returns>Should return a valid path for the stream to be imported.</returns>
        public virtual string ResolveFile(string source, string type, SourceLineNumber sourceLineNumbers, BindStage bindStage)
        {
            // the following new local variables are used for bind path and protect the changes to object field.
            StringCollection    currentBindPaths      = null;
            NameValueCollection currentNamedBindPaths = null;
            StringCollection    currentSourcePaths    = null;

            if (String.IsNullOrEmpty(source))
            {
                throw new ArgumentNullException("source");
            }

            // Call the original override function first. If it returns an answer then return that,
            // otherwise using the default resolving logic
            string filePath = this.ResolveFile(source, type, sourceLineNumbers);

            if (!String.IsNullOrEmpty(filePath))
            {
                return(filePath);
            }

            // Assign the correct bind path to file manager
            currentSourcePaths    = this.sourcePaths[bindStage];
            currentNamedBindPaths = this.namedBindPaths[bindStage];
            if (BindStage.Target != bindStage && BindStage.Updated != bindStage)
            {
                currentBindPaths = this.bindPaths[bindStage];
            }
            else
            {
                currentBindPaths = this.sourcePaths[bindStage];
            }

            // If the path is rooted, it better exist or we're not going to find it.
            if (Path.IsPathRooted(source))
            {
                if (BinderFileManager.CheckFileExists(source))
                {
                    return(source);
                }
            }
            else // not a rooted path so let's try applying all the different source resolution options.
            {
                const string bindPathOpenString = "!(bindpath.";

                if (source.StartsWith(bindPathOpenString, StringComparison.Ordinal) && source.IndexOf(')') != -1)
                {
                    int      bindpathSignatureLength = bindPathOpenString.Length;
                    string   name   = source.Substring(bindpathSignatureLength, source.IndexOf(')') - bindpathSignatureLength);
                    string[] values = currentNamedBindPaths.GetValues(name);

                    if (null != values)
                    {
                        foreach (string bindPath in values)
                        {
                            // Parse out '\\' chars that separate the "bindpath" variable and the next part of the path,
                            // because Path.Combine() thinks that rooted second paths don't need the first path.
                            string nameSection = string.Empty;
                            int    nameStart   = bindpathSignatureLength + 1 + name.Length; // +1 for the closing bracket.

                            nameSection = source.Substring(nameStart).TrimStart('\\');
                            filePath    = Path.Combine(bindPath, nameSection);

                            if (BinderFileManager.CheckFileExists(filePath))
                            {
                                return(filePath);
                            }
                        }
                    }
                }
                else if (source.StartsWith("SourceDir\\", StringComparison.Ordinal) || source.StartsWith("SourceDir/", StringComparison.Ordinal))
                {
                    foreach (string bindPath in currentBindPaths)
                    {
                        filePath = Path.Combine(bindPath, source.Substring(10));
                        if (BinderFileManager.CheckFileExists(filePath))
                        {
                            return(filePath);
                        }
                    }
                }
                else if (BinderFileManager.CheckFileExists(source))
                {
                    return(source);
                }

                foreach (string path in currentSourcePaths)
                {
                    filePath = Path.Combine(path, source);
                    if (BinderFileManager.CheckFileExists(filePath))
                    {
                        return(filePath);
                    }

                    if (source.StartsWith("SourceDir\\", StringComparison.Ordinal) || source.StartsWith("SourceDir/", StringComparison.Ordinal))
                    {
                        filePath = Path.Combine(path, source.Substring(10));
                        if (BinderFileManager.CheckFileExists(filePath))
                        {
                            return(filePath);
                        }
                    }
                }
            }

            // Didn't find the file.
            throw new WixFileNotFoundException(sourceLineNumbers, source, type);
        }
예제 #7
0
 /// <summary>
 /// Creates a WixFile row that does not belong to a table.
 /// </summary>
 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
 /// <param name="tableDef">TableDefinition this Media row belongs to and should get its column definitions from.</param>
 public WixFileRow(SourceLineNumber sourceLineNumbers, TableDefinition tableDef) :
     base(sourceLineNumbers, tableDef)
 {
 }
 /// <summary>
 /// Creates a WixComplexReferenceRow row that belongs to a table.
 /// </summary>
 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
 /// <param name="table">Table this row belongs to and should get its column definitions from.</param>
 public WixComplexReferenceRow(SourceLineNumber sourceLineNumbers, Table table)
     : base(sourceLineNumbers, table)
 {
 }
예제 #9
0
 /// <summary>
 /// Creates a Control row that belongs to a table.
 /// </summary>
 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
 /// <param name="table">Table this Control row belongs to and should get its column definitions from.</param>
 public BBControlRow(SourceLineNumber sourceLineNumbers, Table table) :
     base(sourceLineNumbers, table)
 {
 }
예제 #10
0
 /// <summary>
 /// Creates a PatchTargetCodeRow row that does not belong to a table.
 /// </summary>
 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
 /// <param name="tableDef">TableDefinition this PatchTargetCode row belongs to and should get its column definitions from.</param>
 public WixBundlePatchTargetCodeRow(SourceLineNumber sourceLineNumbers, TableDefinition tableDef) :
     base(sourceLineNumbers, tableDef)
 {
 }
예제 #11
0
 /// <summary>
 /// Creates a PatchTargetCodeRow row that belongs to a table.
 /// </summary>
 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
 /// <param name="table">Table this PatchTargetCode row belongs to and should get its column definitions from.</param>
 public WixBundlePatchTargetCodeRow(SourceLineNumber sourceLineNumbers, Table table) :
     base(sourceLineNumbers, table)
 {
 }
예제 #12
0
 /// <summary>
 /// Creates an Upgrade row that belongs to a table.
 /// </summary>
 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
 /// <param name="table">Table this Upgrade row belongs to and should get its column definitions from.</param>
 public UpgradeRow(SourceLineNumber sourceLineNumbers, Table table) :
     base(sourceLineNumbers, table)
 {
 }
 /// <summary>
 /// Creates a WixUpdateRegistrationRow row that belongs to a table.
 /// </summary>
 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
 /// <param name="table">Table this WixUpdateRegistrationRow row belongs to and should get its column definitions from.</param>
 public WixUpdateRegistrationRow(SourceLineNumber sourceLineNumbers, Table table) :
     base(sourceLineNumbers, table)
 {
 }
 /// <summary>
 /// Creates a WixUpdateRegistrationRow row that does not belong to a table.
 /// </summary>
 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
 /// <param name="tableDef">TableDefinition this WixUpdateRegistrationRow row belongs to and should get its column definitions from.</param>
 public WixUpdateRegistrationRow(SourceLineNumber sourceLineNumbers, TableDefinition tableDef) :
     base(sourceLineNumbers, tableDef)
 {
 }
예제 #15
0
        /// <summary>
        /// Gets a valid code page from the given web name or integer value.
        /// </summary>
        /// <param name="value">A code page web name or integer value as a string.</param>
        /// <param name="allowNoChange">Whether to allow -1 which does not change the database code pages. This may be the case with wxl files.</param>
        /// <param name="onlyAnsi">Whether to allow Unicode (UCS) or UTF code pages.</param>
        /// <param name="sourceLineNumbers">Source line information for the current authoring.</param>
        /// <returns>A valid code page number.</returns>
        /// <exception cref="ArgumentOutOfRangeException">The value is an integer less than 0 or greater than 65535.</exception>
        /// <exception cref="ArgumentNullException"><paramref name="value"/> is null.</exception>
        /// <exception cref="NotSupportedException">The value doesn't not represent a valid code page name or integer value.</exception>
        /// <exception cref="WixException">The code page is invalid for summary information.</exception>
        internal static int GetValidCodePage(string value, bool allowNoChange, bool onlyAnsi, SourceLineNumber sourceLineNumbers)
        {
            int      codePage;
            Encoding enc;

            if (null == value)
            {
                throw new ArgumentNullException("value");
            }

            try
            {
                // check if a integer as a string was passed
                if (int.TryParse(value, out codePage))
                {
                    if (0 == codePage)
                    {
                        // 0 represents a neutral database
                        return(0);
                    }
                    else if (allowNoChange && -1 == codePage)
                    {
                        // -1 means no change to the database code page
                        return(-1);
                    }

                    enc = Encoding.GetEncoding(codePage);
                }
                else
                {
                    enc = Encoding.GetEncoding(value);
                }

                // Windows Installer parses some code page references
                // as unsigned shorts which fail to open the database.
                if (onlyAnsi)
                {
                    codePage = enc.CodePage;
                    if (0 > codePage || short.MaxValue < codePage)
                    {
                        throw new WixException(WixErrors.InvalidSummaryInfoCodePage(sourceLineNumbers, codePage));
                    }
                }

                return(enc.CodePage);
            }
            catch (ArgumentException ex)
            {
                // rethrow as NotSupportedException since either can be thrown
                // if the system does not support the specified code page
                throw new NotSupportedException(ex.Message, ex);
            }
        }
예제 #16
0
        /// <summary>
        /// Parses table definition from xml reader.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <returns>The TableDefintion represented by the Xml.</returns>
        internal static TableDefinition Parse(XmlReader reader)
        {
            Debug.Assert("tableDefinition" == reader.LocalName);

            bool   empty               = reader.IsEmptyElement;
            bool   createSymbols       = false;
            bool   hasPrimaryKeyColumn = false;
            string name   = null;
            bool   unreal = false;
            bool   bootstrapperApplicationData = false;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "createSymbols":
                    createSymbols = Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "createSymbols", reader.Name, reader.Value);
                    break;

                case "name":
                    name = reader.Value;
                    break;

                case "unreal":
                    unreal = Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "tableDefinition", reader.Name, reader.Value);
                    break;

                case "bootstrapperApplicationData":
                    bootstrapperApplicationData = Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "tableDefinition", reader.Name, reader.Value);
                    break;

                default:
                    if (!reader.NamespaceURI.StartsWith("http://www.w3.org/", StringComparison.Ordinal))
                    {
                        throw new WixException(WixErrors.UnexpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "tableDefinition", reader.Name));
                    }
                    break;
                }
            }

            if (null == name)
            {
                throw new WixException(WixErrors.ExpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "tableDefinition", "name"));
            }

            TableDefinition tableDefinition = new TableDefinition(name, createSymbols, unreal, bootstrapperApplicationData);

            // parse the child elements
            if (!empty)
            {
                bool done = false;

                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                        case "columnDefinition":
                            ColumnDefinition columnDefinition = ColumnDefinition.Parse(reader);
                            tableDefinition.columns.Add(columnDefinition);

                            if (columnDefinition.IsLocalizable)
                            {
                                tableDefinition.localizable = true;
                            }

                            if (columnDefinition.IsPrimaryKey)
                            {
                                hasPrimaryKeyColumn = true;
                            }
                            break;

                        default:
                            throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "tableDefinition", reader.Name));
                        }
                        break;

                    case XmlNodeType.EndElement:
                        done = true;
                        break;
                    }
                }

                if (!unreal && !bootstrapperApplicationData && !hasPrimaryKeyColumn)
                {
                    throw new WixException(WixErrors.RealTableMissingPrimaryKeyColumn(SourceLineNumber.CreateFromUri(reader.BaseURI), name));
                }

                if (!done)
                {
                    throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "tableDefinition"));
                }
            }

            return(tableDefinition);
        }
예제 #17
0
 /// <summary>
 /// Resolves the source path of a file.
 /// </summary>
 /// <param name="source">Original source value.</param>
 /// <param name="type">Optional type of source file being resolved.</param>
 /// <param name="sourceLineNumbers">Optional source line of source file being resolved.</param>
 /// <returns>Should return a valid path for the stream to be imported.</returns>
 public virtual string ResolveFile(string source, string type, SourceLineNumber sourceLineNumber)
 {
     return(ResolveFile(source));
 }
예제 #18
0
 /// <summary>
 /// Creates a new row in the table.
 /// </summary>
 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
 /// <returns>Row created in table.</returns>
 public Row CreateRow(SourceLineNumber sourceLineNumbers)
 {
     return(this.CreateRow(sourceLineNumbers, true));
 }
예제 #19
0
        /// <summary>
        /// Resolves the source path of a file related to another file's source.
        /// </summary>
        /// <param name="source">Original source value.</param>
        /// <param name="relatedSource">Source related to original source.</param>
        /// <param name="type">Optional type of source file being resolved.</param>
        /// <param name="sourceLineNumbers">Optional source line of source file being resolved.</param>
        /// <param name="bindStage">The binding stage used to determine what collection of bind paths will be used</param>
        /// <returns>Should return a valid path for the stream to be imported.</returns>
        public virtual string ResolveRelatedFile(string source, string relatedSource, string type, SourceLineNumber sourceLineNumbers, BindStage bindStage)
        {
            string resolvedSource = this.ResolveFile(source, type, sourceLineNumbers, bindStage);

            return(Path.Combine(Path.GetDirectoryName(resolvedSource), relatedSource));
        }
예제 #20
0
        /// <summary>
        /// Creates a new row in the table.
        /// </summary>
        /// <param name="sourceLineNumbers">Original source lines for this row.</param>
        /// <param name="add">Specifies whether to only create the row or add it to the table automatically.</param>
        /// <returns>Row created in table.</returns>
        public Row CreateRow(SourceLineNumber sourceLineNumbers, bool add)
        {
            Row row;

            switch (this.Name)
            {
            case "BBControl":
                row = new BBControlRow(sourceLineNumbers, this);
                break;

            case "ChainMsiPackage":
                row = new ChainMsiPackageRow(sourceLineNumbers, this);
                break;

            case "Component":
                row = new ComponentRow(sourceLineNumbers, this);
                break;

            case "Control":
                row = new ControlRow(sourceLineNumbers, this);
                break;

            case "File":
                row = new FileRow(sourceLineNumbers, this);
                break;

            case "Media":
                row = new MediaRow(sourceLineNumbers, this);
                break;

            case "PayloadInfo":
                row = new PayloadInfoRow(sourceLineNumbers, this);
                break;

            case "Upgrade":
                row = new UpgradeRow(sourceLineNumbers, this);
                break;

            case "Variable":
                row = new VariableRow(sourceLineNumbers, this);
                break;

            case "WixAction":
                row = new WixActionRow(sourceLineNumbers, this);
                break;

            case "WixComplexReference":
                row = new WixComplexReferenceRow(sourceLineNumbers, this);
                break;

            case "WixFile":
                row = new WixFileRow(sourceLineNumbers, this);
                break;

            case "WixMedia":
                row = new WixMediaRow(sourceLineNumbers, this);
                break;

            case "WixMediaTemplate":
                row = new WixMediaTemplateRow(sourceLineNumbers, this);
                break;

            case "WixMerge":
                row = new WixMergeRow(sourceLineNumbers, this);
                break;

            case "WixProperty":
                row = new WixPropertyRow(sourceLineNumbers, this);
                break;

            case "WixBundle":
                row = new WixBundleRow(sourceLineNumbers, this);
                break;

            case "WixBundlePatchTargetCode":
                row = new WixBundlePatchTargetCodeRow(sourceLineNumbers, this);
                break;

            case "WixBundleUpdate":
                row = new WixBundleUpdateRow(sourceLineNumbers, this);
                break;

            case "WixUpdateRegistration":
                row = new WixUpdateRegistrationRow(sourceLineNumbers, this);
                break;

            case "WixSimpleReference":
                row = new WixSimpleReferenceRow(sourceLineNumbers, this);
                break;

            case "WixVariable":
                row = new WixVariableRow(sourceLineNumbers, this);
                break;

            default:
                row = new Row(sourceLineNumbers, this);
                break;
            }

            if (add)
            {
                this.rows.Add(row);
            }

            return(row);
        }
예제 #21
0
 /// <summary>
 /// Creates a WixFile row that belongs to a table.
 /// </summary>
 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
 /// <param name="table">Table this File row belongs to and should get its column definitions from.</param>
 public WixFileRow(SourceLineNumber sourceLineNumbers, Table table) :
     base(sourceLineNumbers, table)
 {
 }
예제 #22
0
        /// <summary>
        /// Parse a table from the xml.
        /// </summary>
        /// <param name="reader">XmlReader where the intermediate is persisted.</param>
        /// <param name="section">Section to populate with persisted data.</param>
        /// <param name="tableDefinitions">TableDefinitions to use in the intermediate.</param>
        /// <returns>The parsed table.</returns>
        internal static Table Parse(XmlReader reader, Section section, TableDefinitionCollection tableDefinitions)
        {
            Debug.Assert("table" == reader.LocalName);

            bool           empty     = reader.IsEmptyElement;
            TableOperation operation = TableOperation.None;
            string         name      = null;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "name":
                    name = reader.Value;
                    break;

                case "op":
                    switch (reader.Value)
                    {
                    case "add":
                        operation = TableOperation.Add;
                        break;

                    case "drop":
                        operation = TableOperation.Drop;
                        break;

                    default:
                        throw new WixException(WixErrors.IllegalAttributeValue(SourceLineNumber.CreateFromUri(reader.BaseURI), "table", reader.Name, reader.Value, "Add", "Drop"));
                    }
                    break;

                default:
                    if (!reader.NamespaceURI.StartsWith("http://www.w3.org/", StringComparison.Ordinal))
                    {
                        throw new WixException(WixErrors.UnexpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "table", reader.Name));
                    }
                    break;
                }
            }

            if (null == name)
            {
                throw new WixException(WixErrors.ExpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "table", "name"));
            }

            TableDefinition tableDefinition = tableDefinitions[name];
            Table           table           = new Table(section, tableDefinition);

            table.Operation = operation;

            if (!empty)
            {
                bool done = false;

                // loop through all the rows in a table
                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                        case "row":
                            Row.Parse(reader, table);
                            break;

                        default:
                            throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "table", reader.Name));
                        }
                        break;

                    case XmlNodeType.EndElement:
                        done = true;
                        break;
                    }
                }

                if (!done)
                {
                    throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "table"));
                }
            }

            return(table);
        }
예제 #23
0
 /// <summary>
 /// Creates a Media row that belongs to a table.
 /// </summary>
 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
 /// <param name="table">Table this Media row belongs to and should get its column definitions from.</param>
 public MediaRow(SourceLineNumber sourceLineNumbers, Table table)
     : base(sourceLineNumbers, table)
 {
     // default the compression level to mszip
     this.compressionLevel = Cab.CompressionLevel.Mszip;
 }
예제 #24
0
 /// <summary>
 /// Instantiate a new WixFileNotFoundException.
 /// </summary>
 /// <param name="sourceLineNumbers">Source line information pertaining to the file that cannot be found.</param>
 /// <param name="file">The file that could not be found.</param>
 /// <param name="fileType">The type of file that cannot be found.</param>
 public WixFileNotFoundException(SourceLineNumber sourceLineNumbers, string file, string fileType) :
     base(WixErrors.FileNotFound(sourceLineNumbers, file, fileType))
 {
 }
예제 #25
0
 /// <summary>
 /// Creates a PayloadInfoRow row that does not belong to a table.
 /// </summary>
 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
 /// <param name="tableDef">TableDefinition this Media row belongs to and should get its column definitions from.</param>
 public PayloadInfoRow(SourceLineNumber sourceLineNumbers, TableDefinition tableDef) :
     base(sourceLineNumbers, tableDef)
 {
 }
예제 #26
0
        /// <summary>
        /// Creates a properly formatted message string.
        /// </summary>
        /// <param name="messageLevel">Level of the message, as generated by MessageLevel(MessageEventArgs).</param>
        /// <param name="mea">Event arguments for the message.</param>
        /// <returns>String containing the formatted message.</returns>
        private string GenerateMessageString(MessageLevel messageLevel, MessageEventArgs mea)
        {
            if (MessageLevel.Nothing == messageLevel)
            {
                return(String.Empty);
            }

            if (MessageLevel.Error == messageLevel)
            {
                this.EncounteredError = true;
            }

            List <string> fileNames     = new List <string>();
            string        errorFileName = this.longAppName ?? "WIX";

            for (SourceLineNumber sln = mea.SourceLineNumbers; null != sln; sln = sln.Parent)
            {
                if (sln.LineNumber.HasValue)
                {
                    if (0 == fileNames.Count)
                    {
                        errorFileName = String.Format(CultureInfo.CurrentUICulture, WixStrings.Format_FirstLineNumber, sln.FileName, sln.LineNumber);
                    }

                    fileNames.Add(String.Format(CultureInfo.CurrentUICulture, WixStrings.Format_LineNumber, sln.FileName, sln.LineNumber));
                }
                else
                {
                    if (0 == fileNames.Count)
                    {
                        errorFileName = sln.FileName;
                    }

                    fileNames.Add(sln.FileName);
                }
            }

            string messageType = String.Empty;

            if (MessageLevel.Warning == messageLevel)
            {
                messageType = WixStrings.MessageType_Warning;
            }
            else if (MessageLevel.Error == messageLevel)
            {
                this.LastErrorNumber = mea.Id;
                messageType          = WixStrings.MessageType_Error;
            }

            StringBuilder messageBuilder = new StringBuilder();
            string        message        = String.Format(CultureInfo.InvariantCulture, mea.ResourceManager.GetString(mea.ResourceName), mea.MessageArgs);

            if (MessageLevel.Information == messageLevel)
            {
                messageBuilder.AppendFormat(WixStrings.Format_InfoMessage, message);
            }
            else
            {
                messageBuilder.AppendFormat(WixStrings.Format_NonInfoMessage, errorFileName, messageType, this.shortAppName ?? "WIX", mea.Id, message);
            }

            if (1 < fileNames.Count)
            {
                messageBuilder.AppendFormat(WixStrings.INF_SourceTrace, Environment.NewLine);
                foreach (string fileName in fileNames)
                {
                    messageBuilder.AppendFormat(WixStrings.INF_SourceTraceLocation, fileName, Environment.NewLine);
                }

                messageBuilder.Append(Environment.NewLine);
            }

            return(messageBuilder.ToString());
        }
예제 #27
0
        /// <summary>
        /// Replaces parameters in the source text.
        /// </summary>
        /// <param name="sourceLineNumbers">The source line information for the function.</param>
        /// <param name="value">Text that may contain parameters to replace.</param>
        /// <returns>Text after parameters have been replaced.</returns>
        public string PreprocessString(SourceLineNumber sourceLineNumbers, string value)
        {
            StringBuilder sb = new StringBuilder();
            int           currentPosition = 0;
            int           end             = 0;

            while (-1 != (currentPosition = value.IndexOf('$', end)))
            {
                if (end < currentPosition)
                {
                    sb.Append(value, end, currentPosition - end);
                }

                end = currentPosition + 1;
                string remainder = value.Substring(end);
                if (remainder.StartsWith("$", StringComparison.Ordinal))
                {
                    sb.Append("$");
                    end++;
                }
                else if (remainder.StartsWith("(loc.", StringComparison.Ordinal))
                {
                    currentPosition = remainder.IndexOf(')');
                    if (-1 == currentPosition)
                    {
                        this.OnMessage(WixErrors.InvalidPreprocessorVariable(sourceLineNumbers, remainder));
                        break;
                    }

                    sb.Append("$");   // just put the resource reference back as was
                    sb.Append(remainder, 0, currentPosition + 1);

                    end += currentPosition + 1;
                }
                else if (remainder.StartsWith("(", StringComparison.Ordinal))
                {
                    int  openParenCount    = 1;
                    int  closingParenCount = 0;
                    bool isFunction        = false;
                    bool foundClosingParen = false;

                    // find the closing paren
                    int closingParenPosition;
                    for (closingParenPosition = 1; closingParenPosition < remainder.Length; closingParenPosition++)
                    {
                        switch (remainder[closingParenPosition])
                        {
                        case '(':
                            openParenCount++;
                            isFunction = true;
                            break;

                        case ')':
                            closingParenCount++;
                            break;
                        }
                        if (openParenCount == closingParenCount)
                        {
                            foundClosingParen = true;
                            break;
                        }
                    }

                    // move the currentPosition to the closing paren
                    currentPosition += closingParenPosition;

                    if (!foundClosingParen)
                    {
                        if (isFunction)
                        {
                            this.OnMessage(WixErrors.InvalidPreprocessorFunction(sourceLineNumbers, remainder));
                            break;
                        }
                        else
                        {
                            this.OnMessage(WixErrors.InvalidPreprocessorVariable(sourceLineNumbers, remainder));
                            break;
                        }
                    }

                    string subString = remainder.Substring(1, closingParenPosition - 1);
                    string result    = null;
                    if (isFunction)
                    {
                        result = this.EvaluateFunction(sourceLineNumbers, subString);
                    }
                    else
                    {
                        result = this.GetVariableValue(sourceLineNumbers, subString, false);
                    }

                    if (null == result)
                    {
                        if (isFunction)
                        {
                            this.OnMessage(WixErrors.UndefinedPreprocessorFunction(sourceLineNumbers, subString));
                            break;
                        }
                        else
                        {
                            this.OnMessage(WixErrors.UndefinedPreprocessorVariable(sourceLineNumbers, subString));
                            break;
                        }
                    }
                    else
                    {
                        if (!isFunction)
                        {
                            this.OnResolvedVariable(new ResolvedVariableEventArgs(sourceLineNumbers, subString, result));
                        }
                    }
                    sb.Append(result);
                    end += closingParenPosition + 1;
                }
                else   // just a floating "$" so put it in the final string (i.e. leave it alone) and keep processing
                {
                    sb.Append('$');
                }
            }

            if (end < value.Length)
            {
                sb.Append(value.Substring(end));
            }

            return(sb.ToString());
        }
예제 #28
0
 /// <summary>
 /// Creates a WixMedia row that belongs to a table.
 /// </summary>
 /// <param name="sourceLineNumbers">Original source lines for this row.</param>
 /// <param name="table">Table this Media row belongs to and should get its column definitions from.</param>
 public WixMediaRow(SourceLineNumber sourceLineNumbers, Table table) :
     base(sourceLineNumbers, table)
 {
 }
예제 #29
0
 /// <summary>
 /// Add a variable.
 /// </summary>
 /// <param name="sourceLineNumbers">The source line information of the variable.</param>
 /// <param name="name">The variable name.</param>
 /// <param name="value">The variable value.</param>
 internal void AddVariable(SourceLineNumber sourceLineNumbers, string name, string value)
 {
     this.AddVariable(sourceLineNumbers, name, value, true);
 }
예제 #30
0
        /// <summary>
        /// Parse a field from the xml.
        /// </summary>
        /// <param name="reader">XmlReader where the intermediate is persisted.</param>
        internal override void Parse(XmlReader reader)
        {
            Debug.Assert("field" == reader.LocalName);

            bool empty = reader.IsEmptyElement;

            this.baseUri = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "cabinetFileId":
                    this.cabinetFileId = reader.Value;
                    break;

                case "modified":
                    this.Modified = Common.IsYes(SourceLineNumber.CreateFromUri(reader.BaseURI), "field", reader.Name, reader.Value);
                    break;

                case "previousData":
                    this.PreviousData = reader.Value;
                    break;

                case "unresolvedPreviousData":
                    this.unresolvedPreviousData = reader.Value;
                    break;

                case "unresolvedData":
                    this.unresolvedData = reader.Value;
                    break;

                case "previousCabinetFileId":
                    this.previousCabinetFileId = reader.Value;
                    break;

                default:
                    if (!reader.NamespaceURI.StartsWith("http://www.w3.org/", StringComparison.Ordinal))
                    {
                        throw new WixException(WixErrors.UnexpectedAttribute(SourceLineNumber.CreateFromUri(reader.BaseURI), "field", reader.Name));
                    }
                    break;
                }
            }

            if (!empty)
            {
                bool done = false;

                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        throw new WixException(WixErrors.UnexpectedElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "field", reader.Name));

                    case XmlNodeType.CDATA:
                    case XmlNodeType.Text:
                        if (0 < reader.Value.Length)
                        {
                            this.Data = reader.Value;
                        }
                        break;

                    case XmlNodeType.EndElement:
                        done = true;
                        break;
                    }
                }

                if (!done)
                {
                    throw new WixException(WixErrors.ExpectedEndElement(SourceLineNumber.CreateFromUri(reader.BaseURI), "field"));
                }
            }
        }