//step 5 #region Save Methods /// <summary> /// Step 5: Save the book into a .html file /// </summary> /// <param name="html"></param> /// <param name="data"></param> /// <returns></returns> private async Task <StorageFile> SaveBookAsync(string html, Metadata data) { //get bookname and append the extension to it. string bookName = DirectoryHelper.GetSafeFilename(data.Title) + ".html"; //create Path out of the bookname. We will use this to create the final book html file. string path = Path.Combine(EpubTextFolder.Path, bookName); //make sure it doesn't already exist if (!File.Exists(path)) { //try to create file. I say try because...well...we never know. var fullBook = await EpubTextFolder.CreateFileAsync(bookName, CreationCollisionOption.OpenIfExists); //Write all the html to the file. //TODO: Use a better way to write to file. await FileIO.WriteTextAsync(fullBook, EReader.Epub.Helpers.Minifiers.MinifyHTML(html), Windows.Storage.Streams.UnicodeEncoding.Utf8); //return the new complete book file. return(fullBook); } else { //the book exists. Just reuse it. return(await StorageFile.GetFileFromPathAsync(path)); } }
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))); }