Example #1
0
        private static EpubSpecialResources LoadSpecialResources(ZipFile epubArchive, EpubBook book, string password)
        {
            var entryOcf = epubArchive.Entries.FirstOrDefault(x => x.FileName.Equals(Constants.OcfPath));
            var entryOpf = epubArchive.Entries.FirstOrDefault(x => x.FileName.Equals(book.Format.Ocf.RootFilePath));

            var result = new EpubSpecialResources
            {
                Ocf = new EpubTextFile
                {
                    FileName    = Constants.OcfPath,
                    ContentType = EpubContentType.Xml,
                    MimeType    = ContentType.ContentTypeToMimeType[EpubContentType.Xml],
                    Content     = GetExtract(entryOcf, password)
                },
                Opf = new EpubTextFile
                {
                    FileName    = book.Format.Ocf.RootFilePath,
                    ContentType = EpubContentType.Xml,
                    MimeType    = ContentType.ContentTypeToMimeType[EpubContentType.Xml],
                    Content     = GetExtract(entryOpf, password)
                },
                HtmlInReadingOrder = new List <EpubTextFile>()
            };

            var htmlFiles = book.Format.Opf.Manifest.Items
                            .Where(item => ContentType.MimeTypeToContentType.ContainsKey(item.MediaType) && ContentType.MimeTypeToContentType[item.MediaType] == EpubContentType.Xhtml11)
                            .ToDictionary(item => item.Id, item => item.Href);

            foreach (var item in book.Format.Opf.Spine.ItemRefs)
            {
                string href;
                if (!htmlFiles.TryGetValue(item.IdRef, out href))
                {
                    continue;
                }

                var html = book.Resources.Html.SingleOrDefault(e => e.FileName == href);
                if (html != null)
                {
                    result.HtmlInReadingOrder.Add(html);
                }
            }

            return(result);
        }
Example #2
0
        private static EpubSpecialResources LoadSpecialResources(ZipArchive epubArchive, EpubBook book)
        {
            var result = new EpubSpecialResources
            {
                Ocf = new EpubTextFile
                {
                    AbsolutePath = Constants.OcfPath,
                    Href         = Constants.OcfPath,
                    ContentType  = EpubContentType.Xml,
                    MimeType     = ContentType.ContentTypeToMimeType[EpubContentType.Xml],
                    Content      = epubArchive.LoadBytes(Constants.OcfPath)
                },
                Opf = new EpubTextFile
                {
                    AbsolutePath = book.Format.Paths.OpfAbsolutePath,
                    Href         = book.Format.Paths.OpfAbsolutePath,
                    ContentType  = EpubContentType.Xml,
                    MimeType     = ContentType.ContentTypeToMimeType[EpubContentType.Xml],
                    Content      = epubArchive.LoadBytes(book.Format.Paths.OpfAbsolutePath)
                },
                HtmlInReadingOrder = new List <EpubTextFile>()
            };

            var htmlFiles = book.Format.Opf.Manifest.Items
                            .Where(item => ContentType.MimeTypeToContentType.ContainsKey(item.MediaType) && ContentType.MimeTypeToContentType[item.MediaType] == EpubContentType.Xhtml11)
                            .ToDictionary(item => item.Id, item => item.Href);

            foreach (var item in book.Format.Opf.Spine.ItemRefs)
            {
                if (!htmlFiles.TryGetValue(item.IdRef, out string href))
                {
                    continue;
                }

                var html = book.Resources.Html.SingleOrDefault(e => e.Href == href);
                if (html != null)
                {
                    result.HtmlInReadingOrder.Add(html);
                }
            }

            return(result);
        }