Example #1
0
        //step 3
        #region Move Methods
        /// <summary>
        /// Step 3: Move all images to main folder.
        /// </summary>
        /// <param name="document"></param>
        /// <returns></returns>
        private async Task MoveAllImagesAsync(OPFDocument document)
        {
            //image can be any type so we don't specify the exact mediatype.
            foreach (var image in document.Manifest.Item.Where(t => t.Mediatype.Contains("image")))
            {
                //create image path from data we already have.
                var imagePath = Path.Combine(OPFFolder.Path, image.Href.Replace('/', '\\'));

                //we don't want to move a non-existing file.
                if (File.Exists(imagePath))
                {
                    //we are sure the file exists. Create a StorageFile out of it.
                    var imageFile = await StorageFile.GetFileFromPathAsync(imagePath);

                    //make sure the image doesn't already exists.
                    if (!File.Exists(Path.Combine(EpubTextFolder.Path, Path.GetFileName(imageFile.Path))))
                    {
                        await imageFile.CopyAsync(EpubTextFolder);

                        //delete file. We no longer need it.
                        await imageFile.DeleteAsync(StorageDeleteOption.PermanentDelete);
                    }
                }
            }
        }
Example #2
0
        //step 2
        #region Read Methods
        /// <summary>
        /// Step 2: Read TOC
        /// </summary>
        /// <param name="metadata"></param>
        /// <returns>Table Of Contents of the EPUB</returns>
        private async Task <TOC> ReadTOC(OPFDocument metadata)
        {
            Deserializer = new XmlSerializer(typeof(TOC));
            var tocFilePath = Path.Combine(OPFFolder.Path, metadata.Manifest.Item.FirstOrDefault(t => t.Mediatype == "application/x-dtbncx+xml").Href);
            var tocFile     = await StorageFile.GetFileFromPathAsync(tocFilePath);

            using (var stream = await tocFile.OpenStreamForReadAsync())
            {
                return((TOC)Deserializer.Deserialize(stream));
            }
        }
Example #3
0
        private async Task <StorageFile> GetCoverImageAsync(OPFDocument opfContent)
        {
            string coverPath = "";

            if (opfContent.Manifest.Item.Any(t => (t.Id.ToLower().Contains("cover") || t.Href.ToLower().Contains("cover")) && t.Mediatype.Contains("image")))
            {
                coverPath = opfContent.Manifest.Item.FirstOrDefault(t => (t.Id.ToLower().Contains("cover") || t.Href.ToLower().Contains("cover")) && t.Mediatype.Contains("image")).Href;
            }
            else
            {
                coverPath = opfContent.Manifest.Item.FirstOrDefault(t => t.Mediatype.Contains("image")).Href;
            }
            coverPath = coverPath.Remove(0, coverPath.LastIndexOf("/") + 1);
            return((StorageFile)(await EpubTextFolder.TryGetItemAsync(coverPath)));
        }