/// <summary> /// Step 2: Read Metadata (OPF file). /// </summary> /// <returns>Formatted OPFDocument with all the metadata and book info.</returns> private async Task <OPFDocument> ReadMetadata() { if (RootEpubFolder != null) { var metainfFolder = await RootEpubFolder.GetFolderAsync("META-INF"); if (metainfFolder != null) { //get container.xml file StorageFile containerFile = await StorageFile.GetFileFromPathAsync(Path.Combine(metainfFolder.Path, "container.xml")); //create a new XmlDeserializer to deserialize Container Content Deserializer = new XmlSerializer(typeof(Container)); using (var containerStream = await containerFile.OpenStreamForReadAsync()) { var containerXML = (Container)Deserializer.Deserialize(containerStream); //get contents.opf file from epub directory var opfFile = await StorageFile.GetFileFromPathAsync(Path.Combine(RootEpubFolder.Path, containerXML.Rootfiles.Rootfile.Fullpath.Replace('/', '\\'))); //set OPFFolder for later use. OPFFolder = await opfFile.GetParentAsync(); //Reset the deserializer with new content type Deserializer = new XmlSerializer(typeof(OPFDocument)); using (var opfStream = await opfFile.OpenStreamForReadAsync()) { return((OPFDocument)Deserializer.Deserialize(opfStream)); } } } } return(null); }
/// <summary> /// Step 2: Read & Save CSS Files /// </summary> /// <returns>Minified CSS</returns> private async Task <string> ReadCSSFiles() { if (RootEpubFolder != null) { //query for all css files var query = RootEpubFolder.CreateFileQueryWithOptions(DirectoryHelper.GetQueryOptions(new string[] { ".css" })); //variable to hold all the css. string css = ""; foreach (var file in await query.GetFilesAsync()) { //TODO: use a different method for reading text i.e. Filestreams css += await FileIO.ReadTextAsync(file); //Delete css file, we no longer need it. await file.DeleteAsync(StorageDeleteOption.PermanentDelete); } //minify CSS to decrease size (just removes whitespaces). return(Minifiers.MinifyCSS(css)); } return(null); }