コード例 #1
0
 public WixUnexpectedFileFormatException(string path, FileFormat expectedFormat, FileFormat format, Exception innerException = null)
     : base(WixDataErrors.UnexpectedFileFormat(path, expectedFormat.ToString().ToLowerInvariant(), format.ToString().ToLowerInvariant()), innerException)
 {
     this.Path = path;
     this.ExpectedFileFormat = expectedFormat;
     this.FileFormat         = format;
 }
コード例 #2
0
ファイル: Library.cs プロジェクト: fyodorkor/Data
        /// <summary>
        /// Saves a library to a path on disk.
        /// </summary>
        /// <param name="path">Path to save library file to on disk.</param>
        /// <param name="resolver">The WiX path resolver.</param>
        public void Save(string path, ILibraryBinaryFileResolver resolver)
        {
            List <string> embedFilePaths = new List <string>();

            // Resolve paths to files that are to be embedded in the library.
            if (null != resolver)
            {
                foreach (Table table in this.sections.SelectMany(s => s.Tables))
                {
                    foreach (Row row in table.Rows)
                    {
                        foreach (ObjectField objectField in row.Fields.Where(f => f is ObjectField))
                        {
                            if (null != objectField.Data)
                            {
                                string file = resolver.Resolve(row.SourceLineNumbers, table.Name, (string)objectField.Data);
                                if (!String.IsNullOrEmpty(file))
                                {
                                    // File was successfully resolved so track the embedded index as the embedded file index.
                                    objectField.EmbeddedFileIndex = embedFilePaths.Count;
                                    embedFilePaths.Add(file);
                                }
                                else
                                {
                                    Messaging.Instance.OnMessage(WixDataErrors.FileNotFound(row.SourceLineNumbers, (string)objectField.Data, table.Name));
                                }
                            }
                            else // clear out embedded file id in case there was one there before.
                            {
                                objectField.EmbeddedFileIndex = null;
                            }
                        }
                    }
                }
            }

            // Do not save the library if errors were found while resolving object paths.
            if (Messaging.Instance.EncounteredError)
            {
                return;
            }

            // Ensure the location to output the library exists and write it out.
            Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path)));

            using (FileStream stream = File.Create(path))
                using (FileStructure fs = FileStructure.Create(stream, FileFormat.Wixlib, embedFilePaths))
                    using (XmlWriter writer = XmlWriter.Create(fs.GetDataStream()))
                    {
                        writer.WriteStartDocument();

                        this.Write(writer);

                        writer.WriteEndDocument();
                    }
        }
コード例 #3
0
        /// <summary>
        /// Gets a table definition by name.
        /// </summary>
        /// <param name="tableName">Name of table to locate.</param>
        public TableDefinition this[string tableName]
        {
            get
            {
                TableDefinition table;
                if (!this.collection.TryGetValue(tableName, out table))
                {
                    throw new WixMissingTableDefinitionException(WixDataErrors.MissingTableDefinition(tableName));
                }

                return(table);
            }
        }
コード例 #4
0
ファイル: Table.cs プロジェクト: fyodorkor/Data
        /// <summary>
        /// Writes the table in IDT format to the provided stream.
        /// </summary>
        /// <param name="writer">Stream to write the table to.</param>
        /// <param name="keepAddedColumns">Whether to keep columns added in a transform.</param>
        public void ToIdtDefinition(StreamWriter writer, bool keepAddedColumns)
        {
            if (this.Definition.Unreal)
            {
                return;
            }

            if (TableDefinition.MaxColumnsInRealTable < this.Definition.Columns.Count)
            {
                throw new WixException(WixDataErrors.TooManyColumnsInRealTable(this.Definition.Name, this.Definition.Columns.Count, TableDefinition.MaxColumnsInRealTable));
            }

            // Tack on the table header, and flush before we start writing bytes directly to the stream.
            writer.Write(this.Definition.ToIdtDefinition(keepAddedColumns));
            writer.Flush();

            using (NonClosingStreamWrapper wrapper = new NonClosingStreamWrapper(writer.BaseStream))
                using (BufferedStream buffStream = new BufferedStream(wrapper))
                {
                    // Create an encoding that replaces characters with question marks, and doesn't throw. We'll
                    // use this in case of errors
                    Encoding convertEncoding = Encoding.GetEncoding(writer.Encoding.CodePage);

                    foreach (Row row in this.Rows)
                    {
                        if (row.Redundant)
                        {
                            continue;
                        }

                        string rowString = row.ToIdtDefinition(keepAddedColumns);
                        byte[] rowBytes;

                        try
                        {
                            // GetBytes will throw an exception if any character doesn't match our current encoding
                            rowBytes = writer.Encoding.GetBytes(rowString);
                        }
                        catch (EncoderFallbackException)
                        {
                            Messaging.Instance.OnMessage(WixDataErrors.InvalidStringForCodepage(row.SourceLineNumbers, Convert.ToString(writer.Encoding.WindowsCodePage, CultureInfo.InvariantCulture)));

                            rowBytes = convertEncoding.GetBytes(rowString);
                        }

                        buffStream.Write(rowBytes, 0, rowBytes.Length);
                    }
                }
        }
コード例 #5
0
 /// <summary>
 /// Merge the information from another localization object into this one.
 /// </summary>
 /// <param name="localization">The localization object to be merged into this one.</param>
 public void Merge(Localization localization)
 {
     foreach (WixVariableRow wixVariableRow in localization.Variables)
     {
         WixVariableRow existingWixVariableRow;
         if (!this.variables.TryGetValue(wixVariableRow.Id, out existingWixVariableRow) || (existingWixVariableRow.Overridable && !wixVariableRow.Overridable))
         {
             variables[wixVariableRow.Id] = wixVariableRow;
         }
         else if (!wixVariableRow.Overridable)
         {
             throw new WixException(WixDataErrors.DuplicateLocalizationIdentifier(wixVariableRow.SourceLineNumbers, wixVariableRow.Id));
         }
     }
 }
コード例 #6
0
ファイル: Table.cs プロジェクト: fyodorkor/Data
        /// <summary>
        /// Validates the rows of this OutputTable and throws if it collides on
        /// primary keys.
        /// </summary>
        public void ValidateRows()
        {
            Dictionary <string, SourceLineNumber> primaryKeys = new Dictionary <string, SourceLineNumber>();

            foreach (Row row in this.Rows)
            {
                string primaryKey = row.GetPrimaryKey();

                SourceLineNumber collisionSourceLineNumber;
                if (primaryKeys.TryGetValue(primaryKey, out collisionSourceLineNumber))
                {
                    throw new WixException(WixDataErrors.DuplicatePrimaryKey(collisionSourceLineNumber, primaryKey, this.Definition.Name));
                }

                primaryKeys.Add(primaryKey, row.SourceLineNumbers);
            }
        }
コード例 #7
0
ファイル: Librarian.cs プロジェクト: jeason0813/Core
        private static List <string> ResolveFilePathsToEmbed(IEnumerable <Section> sections, ILibraryBinaryFileResolver resolver)
        {
            var embedFilePaths = new List <string>();

            // Resolve paths to files that are to be embedded in the library.
            if (null != resolver)
            {
                foreach (Table table in sections.SelectMany(s => s.Tables))
                {
                    foreach (Row row in table.Rows)
                    {
                        foreach (ObjectField objectField in row.Fields.OfType <ObjectField>())
                        {
                            if (null != objectField.Data)
                            {
                                string file = resolver.Resolve(row.SourceLineNumbers, table.Name, (string)objectField.Data);
                                if (!String.IsNullOrEmpty(file))
                                {
                                    // File was successfully resolved so track the embedded index as the embedded file index.
                                    objectField.EmbeddedFileIndex = embedFilePaths.Count;
                                    embedFilePaths.Add(file);
                                }
                                else
                                {
                                    Messaging.Instance.OnMessage(WixDataErrors.FileNotFound(row.SourceLineNumbers, (string)objectField.Data, table.Name));
                                }
                            }
                            else // clear out embedded file id in case there was one there before.
                            {
                                objectField.EmbeddedFileIndex = null;
                            }
                        }
                    }
                }
            }

            return(embedFilePaths);
        }
コード例 #8
0
        /// <summary>
        /// Processes an XmlReader and builds up the pdb object.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param>
        /// <returns>The Pdb represented by the Xml.</returns>
        internal static Pdb Read(XmlReader reader, bool suppressVersionCheck)
        {
            if ("wixPdb" != reader.LocalName)
            {
                throw new XmlException();
            }

            bool    empty   = reader.IsEmptyElement;
            Pdb     pdb     = new Pdb();
            Version version = null;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "version":
                    version = new Version(reader.Value);
                    break;
                }
            }

            if (!suppressVersionCheck && null != version && !Pdb.CurrentVersion.Equals(version))
            {
                throw new WixException(WixDataErrors.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixPdb", version.ToString(), Pdb.CurrentVersion.ToString()));
            }

            // loop through the rest of the pdb building up the Output object
            if (!empty)
            {
                bool done = false;

                // loop through all the fields in a row
                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                        case "wixOutput":
                            pdb.Output = Output.Read(reader, suppressVersionCheck);
                            break;

                        default:
                            throw new XmlException();
                        }
                        break;

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

                if (!done)
                {
                    throw new XmlException();
                }
            }

            return(pdb);
        }
コード例 #9
0
        /// <summary>
        /// Parse an intermediate from an XML format.
        /// </summary>
        /// <param name="reader">XmlReader where the intermediate is persisted.</param>
        /// <param name="tableDefinitions">TableDefinitions to use in the intermediate.</param>
        /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatch.</param>
        /// <returns>The parsed Intermediate.</returns>
        private static Intermediate Read(XmlReader reader, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck)
        {
            if ("wixObject" != reader.LocalName)
            {
                throw new XmlException();
            }

            bool    empty      = reader.IsEmptyElement;
            Version objVersion = null;
            string  id         = null;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.LocalName)
                {
                case "version":
                    objVersion = new Version(reader.Value);
                    break;

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

            if (!suppressVersionCheck && null != objVersion && !Intermediate.CurrentVersion.Equals(objVersion))
            {
                throw new WixException(WixDataErrors.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), "object", objVersion.ToString(), Intermediate.CurrentVersion.ToString()));
            }

            Intermediate intermediate = new Intermediate();

            intermediate.id = id;

            if (!empty)
            {
                bool done = false;

                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                        case "section":
                            intermediate.AddSection(Section.Read(reader, tableDefinitions));
                            break;

                        default:
                            throw new XmlException();
                        }
                        break;

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

                if (!done)
                {
                    throw new XmlException();
                }
            }

            return(intermediate);
        }
コード例 #10
0
 /// <summary>
 /// Instantiate a new WixInvalidIdtException.
 /// </summary>
 /// <param name="idtFile">The invalid idt file.</param>
 /// <param name="tableName">The table name of the invalid idt file.</param>
 public WixInvalidIdtException(string idtFile, string tableName) :
     base(WixDataErrors.InvalidIdt(new SourceLineNumber(idtFile), idtFile, tableName))
 {
 }
コード例 #11
0
ファイル: TableDefinition.cs プロジェクト: fyodorkor/Data
        /// <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 Read(XmlReader reader)
        {
            bool   empty         = reader.IsEmptyElement;
            bool   createSymbols = false;
            string name          = null;
            bool   unreal        = false;
            bool   bootstrapperApplicationData = false;

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

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

                case "unreal":
                    unreal = reader.Value.Equals("yes");
                    break;

                case "bootstrapperApplicationData":
                    bootstrapperApplicationData = reader.Value.Equals("yes");
                    break;
                }
            }

            if (null == name)
            {
                throw new XmlException();
            }

            List <ColumnDefinition> columns = new List <ColumnDefinition>();
            bool hasPrimaryKeyColumn        = false;

            // 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.Read(reader);
                            columns.Add(columnDefinition);

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

                        default:
                            throw new XmlException();
                        }
                        break;

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

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

                if (!done)
                {
                    throw new XmlException();
                }
            }

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

            return(tableDefinition);
        }
コード例 #12
0
ファイル: Library.cs プロジェクト: fyodorkor/Data
        /// <summary>
        /// Parse the root library element.
        /// </summary>
        /// <param name="reader">XmlReader with library persisted as Xml.</param>
        /// <param name="tableDefinitions">Collection containing TableDefinitions to use when reconstituting the intermediates.</param>
        /// <param name="suppressVersionCheck">Suppresses check for wix.dll version mismatch.</param>
        /// <returns>The parsed Library.</returns>
        private static Library Read(XmlReader reader, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck)
        {
            if (!reader.LocalName.Equals("wixLibrary"))
            {
                throw new XmlException();
            }

            bool    empty   = reader.IsEmptyElement;
            Library library = new Library();
            Version version = null;

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

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

            if (!suppressVersionCheck && null != version && !Library.CurrentVersion.Equals(version))
            {
                throw new WixException(WixDataErrors.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), "library", version.ToString(), Library.CurrentVersion.ToString()));
            }

            if (!empty)
            {
                bool done = false;

                while (!done && (XmlNodeType.Element == reader.NodeType || reader.Read()))
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                        case "localization":
                            Localization localization = Localization.Read(reader, tableDefinitions);
                            library.localizations.Add(localization.Culture, localization);
                            break;

                        case "section":
                            Section section = Section.Read(reader, tableDefinitions);
                            section.LibraryId = library.id;
                            library.sections.Add(section);
                            break;

                        default:
                            throw new XmlException();
                        }
                        break;

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

                if (!done)
                {
                    throw new XmlException();
                }
            }

            return(library);
        }
コード例 #13
0
ファイル: Output.cs プロジェクト: fyodorkor/Data
        /// <summary>
        /// Processes an XmlReader and builds up the output object.
        /// </summary>
        /// <param name="reader">Reader to get data from.</param>
        /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param>
        /// <returns>The Output represented by the Xml.</returns>
        internal static Output Read(XmlReader reader, bool suppressVersionCheck)
        {
            if (!reader.LocalName.Equals("wixOutput"))
            {
                throw new XmlException();
            }

            bool        empty       = reader.IsEmptyElement;
            Output      output      = new Output(SourceLineNumber.CreateFromUri(reader.BaseURI));
            SectionType sectionType = SectionType.Unknown;
            Version     version     = null;

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

                case "type":
                    switch (reader.Value)
                    {
                    case "Bundle":
                        output.Type = OutputType.Bundle;
                        sectionType = SectionType.Bundle;
                        break;

                    case "Module":
                        output.Type = OutputType.Module;
                        sectionType = SectionType.Module;
                        break;

                    case "Patch":
                        output.Type = OutputType.Patch;
                        break;

                    case "PatchCreation":
                        output.Type = OutputType.PatchCreation;
                        sectionType = SectionType.PatchCreation;
                        break;

                    case "Product":
                        output.Type = OutputType.Product;
                        sectionType = SectionType.Product;
                        break;

                    case "Transform":
                        output.Type = OutputType.Transform;
                        break;

                    default:
                        throw new XmlException();
                    }
                    break;

                case "version":
                    version = new Version(reader.Value);
                    break;
                }
            }

            if (!suppressVersionCheck && null != version && !Output.CurrentVersion.Equals(version))
            {
                throw new WixException(WixDataErrors.VersionMismatch(SourceLineNumber.CreateFromUri(reader.BaseURI), "wixOutput", version.ToString(), Output.CurrentVersion.ToString()));
            }

            // create a section for all the rows to belong to
            output.entrySection = new Section(null, sectionType, output.Codepage);

            // loop through the rest of the xml building up the Output object
            TableDefinitionCollection tableDefinitions = null;
            List <Table> tables = new List <Table>();

            if (!empty)
            {
                bool done = false;

                // loop through all the fields in a row
                while (!done && reader.Read())
                {
                    switch (reader.NodeType)
                    {
                    case XmlNodeType.Element:
                        switch (reader.LocalName)
                        {
                        case "subStorage":
                            output.SubStorages.Add(SubStorage.Read(reader));
                            break;

                        case "table":
                            if (null == tableDefinitions)
                            {
                                throw new XmlException();
                            }
                            tables.Add(Table.Read(reader, output.entrySection, tableDefinitions));
                            break;

                        case "tableDefinitions":
                            tableDefinitions = TableDefinitionCollection.Read(reader);
                            break;

                        default:
                            throw new XmlException();
                        }
                        break;

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

                if (!done)
                {
                    throw new XmlException();
                }
            }

            output.Tables = new TableIndexedCollection(tables);
            return(output);
        }
コード例 #14
0
 public WixCorruptFileException(string path, FileFormat format, Exception innerException = null)
     : base(WixDataErrors.CorruptFileFormat(path, format.ToString().ToLowerInvariant()), innerException)
 {
     this.Path       = path;
     this.FileFormat = format;
 }