Esempio n. 1
0
        /// <summary>
        /// Loads a pdb from a path on disk.
        /// </summary>
        /// <param name="path">Path to pdb file saved on disk.</param>
        /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param>
        /// <returns>Pdb pdb.</returns>
        public static Pdb Load(string path, bool suppressVersionCheck)
        {
            using (FileStream stream = File.OpenRead(path))
                using (FileStructure fs = FileStructure.Read(stream))
                {
                    if (FileFormat.Wixpdb != fs.FileFormat)
                    {
                        throw new WixUnexpectedFileFormatException(path, FileFormat.Wixpdb, fs.FileFormat);
                    }

                    Uri uri = new Uri(Path.GetFullPath(path));
                    using (XmlReader reader = XmlReader.Create(fs.GetDataStream(), null, uri.AbsoluteUri))
                    {
                        try
                        {
                            reader.MoveToContent();
                            return(Pdb.Read(reader, suppressVersionCheck));
                        }
                        catch (XmlException xe)
                        {
                            throw new WixCorruptFileException(path, fs.FileFormat, xe);
                        }
                    }
                }
        }
Esempio n. 2
0
        /// <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();
                    }
        }
Esempio n. 3
0
        /// <summary>
        /// Saves a pdb to a path on disk.
        /// </summary>
        /// <param name="path">Path to save pdb file to on disk.</param>
        public void Save(string path)
        {
            Directory.CreateDirectory(Path.GetDirectoryName(Path.GetFullPath(path)));

            using (FileStream stream = File.Create(path))
                using (FileStructure fs = FileStructure.Create(stream, FileFormat.Wixpdb, null))
                    using (XmlWriter writer = XmlWriter.Create(fs.GetDataStream()))
                    {
                        writer.WriteStartDocument();
                        this.Write(writer);
                        writer.WriteEndDocument();
                    }
        }
Esempio n. 4
0
        /// <summary>
        /// Loads a library from a stream.
        /// </summary>
        /// <param name="stream">Stream containing the library file.</param>
        /// <param name="uri">Uri for finding this stream.</param>
        /// <param name="tableDefinitions">Collection containing TableDefinitions to use when reconstituting the intermediates.</param>
        /// <param name="suppressVersionCheck">Suppresses wix.dll version mismatch check.</param>
        /// <returns>Returns the loaded library.</returns>
        public static Library Load(Stream stream, Uri uri, TableDefinitionCollection tableDefinitions, bool suppressVersionCheck)
        {
            using (FileStructure fs = FileStructure.Read(stream))
            {
                if (FileFormat.Wixlib != fs.FileFormat)
                {
                    throw new WixUnexpectedFileFormatException(uri.LocalPath, FileFormat.Wixlib, fs.FileFormat);
                }

                using (XmlReader reader = XmlReader.Create(fs.GetDataStream(), null, uri.AbsoluteUri))
                {
                    try
                    {
                        reader.MoveToContent();
                        return(Library.Read(reader, tableDefinitions, suppressVersionCheck));
                    }
                    catch (XmlException xe)
                    {
                        throw new WixCorruptFileException(uri.LocalPath, fs.FileFormat, xe);
                    }
                }
            }
        }