Ejemplo n.º 1
0
        /// <summary>
        /// Loads json form of intermedaite from stream.
        /// </summary>
        /// <param name="stream">Stream to intermediate file.</param>
        /// <param name="baseUri">Path name of intermediate file.</param>
        /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param>
        /// <returns>Returns the loaded json.</returns>
        private static JsonObject LoadJson(Stream stream, Uri baseUri, bool suppressVersionCheck)
        {
            JsonObject jsonObject;

            using (var fs = FileStructure.Read(stream))
            {
                if (FileFormat.WixIR != fs.FileFormat)
                {
                    throw new WixUnexpectedFileFormatException(baseUri.LocalPath, FileFormat.WixIR, fs.FileFormat);
                }

                var json = fs.GetData();
                jsonObject = SimpleJson.DeserializeObject(json) as JsonObject;
            }

            if (!suppressVersionCheck)
            {
                var versionJson = jsonObject.GetValueOrDefault <string>("version");

                if (!Version.TryParse(versionJson, out var version) || !Intermediate.CurrentVersion.Equals(version))
                {
                    throw new WixException(ErrorMessages.VersionMismatch(SourceLineNumber.CreateFromUri(baseUri.AbsoluteUri), "intermediate", versionJson, Intermediate.CurrentVersion.ToString()));
                }
            }

            return(jsonObject);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads json form of intermediate.
        /// </summary>
        /// <param name="json">Source to load from.</param>
        /// <param name="baseUri">Path name of intermediate file.</param>
        /// <param name="suppressVersionCheck">Suppress checking for wix.dll version mismatches.</param>
        /// <returns>Returns the loaded json.</returns>
        private static JsonObject LoadJson(string json, Uri baseUri, bool suppressVersionCheck)
        {
            var jsonObject = SimpleJson.DeserializeObject(json) as JsonObject;

            if (!suppressVersionCheck)
            {
                var versionJson = jsonObject.GetValueOrDefault <string>("version");

                if (!Version.TryParse(versionJson, out var version) || !Intermediate.CurrentVersion.Equals(version))
                {
                    throw new WixException(ErrorMessages.VersionMismatch(SourceLineNumber.CreateFromUri(baseUri.AbsoluteUri), "intermediate", versionJson, Intermediate.CurrentVersion.ToString()));
                }
            }

            return(jsonObject);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads a localization file from a stream.
        /// </summary>
        /// <param name="reader">XmlReader where the intermediate is persisted.</param>
        /// <param name="tableDefinitions">Collection containing TableDefinitions to use when loading the localization file.</param>
        /// <returns>Returns the loaded localization.</returns>
        private static WixVariableRow ReadString(XmlReader reader, TableDefinition wixVariableTable)
        {
            Debug.Assert("string" == reader.LocalName);

            string id          = null;
            string value       = null;
            bool   overridable = false;
            bool   empty       = reader.IsEmptyElement;

            while (reader.MoveToNextAttribute())
            {
                switch (reader.Name)
                {
                case "id":
                    id = reader.Value;
                    break;

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


            if (!empty)
            {
                reader.Read();

                value = reader.Value;

                reader.Read();

                if (XmlNodeType.EndElement != reader.NodeType)
                {
                    throw new XmlException();
                }
            }

            WixVariableRow wixVariableRow = new WixVariableRow(SourceLineNumber.CreateFromUri(reader.BaseURI), wixVariableTable);

            wixVariableRow.Id          = id;
            wixVariableRow.Overridable = overridable;
            wixVariableRow.Value       = value;

            return(wixVariableRow);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
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);
        }
Ejemplo n.º 6
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 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);
        }
Ejemplo n.º 7
0
        /// <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);
        }
Ejemplo n.º 8
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 Read(XmlReader reader, TableDefinitionCollection tableDefinitions)
        {
            Debug.Assert("section" == reader.LocalName);

            int         codepage = 0;
            bool        empty    = reader.IsEmptyElement;
            string      id       = 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 XmlException();
                    }
                    break;
                }
            }

            if (null == id && (SectionType.Unknown != type && SectionType.Fragment != type))
            {
                throw new XmlException();
            }

            if (SectionType.Unknown == type)
            {
                throw new XmlException();
            }

            Section section = new Section(id, type, codepage);

            section.SourceLineNumbers = SourceLineNumber.CreateFromUri(reader.BaseURI);

            List <Table> tables = new List <Table>();

            if (!empty)
            {
                bool done = false;

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

                        default:
                            throw new XmlException();
                        }
                        break;

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

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

            section.Tables = new TableIndexedCollection(tables);

            return(section);
        }
Ejemplo n.º 9
0
        /// <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);
        }