Beispiel #1
0
        /// <summary>
        /// Opens the book asynchronously without reading its content. Holds the handle to the EPUB file.
        /// </summary>
        /// <param name="filePath">path to the EPUB file</param>
        /// <returns></returns>
        public static async Task <EpubBookRef> OpenBookAsync(string filePath)
        {
            if (UrlUtils.FileIsUrl(filePath))
            {
                var localFilePath = await UrlUtils.UrlToFile(filePath);

                if (string.IsNullOrEmpty(localFilePath))
                {
                    throw new FileNotFoundException("Specified remote ePub file could not be downloaded to local filesystem.", filePath);
                }

                filePath = localFilePath;
            }

            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException("Specified local ePub file not found.", filePath);
            }

            ZipArchive  epubArchive = ZipFile.OpenRead(filePath);
            EpubBookRef bookRef     = new EpubBookRef(epubArchive);

            bookRef.FilePath = filePath;
            bookRef.Schema   = await SchemaReader.ReadSchemaAsync(epubArchive).ConfigureAwait(false);

            bookRef.Title      = bookRef.Schema.Package.Metadata.Titles.FirstOrDefault() ?? String.Empty;
            bookRef.AuthorList = bookRef.Schema.Package.Metadata.Creators.Select(creator => creator.Creator).ToList();
            bookRef.Author     = String.Join(", ", bookRef.AuthorList);
            bookRef.Content    = await Task.Run(() => ContentReader.ParseContentMap(bookRef)).ConfigureAwait(false);

            return(bookRef);
        }
Beispiel #2
0
        /// <summary>
        ///     Opens the book asynchronously without reading its content. Holds the handle to the EPUB file.
        /// </summary>
        /// <param name="stream">Stream of file to be parsed</param>
        /// <returns></returns>
        private static async Task <EpubBookRef> OpenBookAsync(Stream stream)
        {
            var epubArchive = new ZipArchive(stream);
            var bookRef     = new EpubBookRef(epubArchive)
            {
                Schema = await SchemaReader.ReadSchemaAsync(epubArchive).ConfigureAwait(false)
            };

            bookRef.Title      = bookRef.Schema.Package.Metadata.Titles.FirstOrDefault() ?? string.Empty;
            bookRef.AuthorList = bookRef.Schema.Package.Metadata.Creators.Select(creator => creator.Creator).ToList();
            bookRef.Content    = ContentReader.ParseContentMap(bookRef);
            return(bookRef);
        }
Beispiel #3
0
        /// <summary>
        /// Opens the book asynchronously without reading its content. Holds the handle to the EPUB file.
        /// </summary>
        /// <param name="stream">stream from the EPUB file</param>
        /// <returns></returns>
        public static async Task <EpubBookRef> OpenBookAsync(Stream stream)
        {
            ZipArchive  epubArchive = new ZipArchive(stream);
            EpubBookRef bookRef     = new EpubBookRef(epubArchive);

            bookRef.Schema = await SchemaReader.ReadSchemaAsync(epubArchive).ConfigureAwait(false);

            bookRef.Title      = bookRef.Schema.Package.Metadata.Titles.FirstOrDefault() ?? String.Empty;
            bookRef.AuthorList = bookRef.Schema.Package.Metadata.Creators.Select(creator => creator.Creator).ToList();
            bookRef.Author     = String.Join(", ", bookRef.AuthorList);
            bookRef.Content    = await Task.Run(() => ContentReader.ParseContentMap(bookRef)).ConfigureAwait(false);

            return(bookRef);
        }
Beispiel #4
0
        /// <summary>
        /// Opens the book asynchronously without reading its content. Holds the handle to the EPUB file.
        /// </summary>
        /// <param name="filePath">path to the EPUB file</param>
        /// <returns></returns>
        public static async Task <EpubBookRef> OpenBookAsync(string filePath)
        {
            if (!File.Exists(filePath))
            {
                throw new FileNotFoundException("Specified epub file not found.", filePath);
            }
            ZipArchive  epubArchive = ZipFile.OpenRead(filePath);
            EpubBookRef bookRef     = new EpubBookRef(epubArchive);

            bookRef.FilePath = filePath;
            bookRef.Schema   = await SchemaReader.ReadSchemaAsync(epubArchive).ConfigureAwait(false);

            bookRef.Title      = bookRef.Schema.Package.Metadata.Titles.FirstOrDefault() ?? String.Empty;
            bookRef.AuthorList = bookRef.Schema.Package.Metadata.Creators.Select(creator => creator.Creator).ToList();
            bookRef.Author     = String.Join(", ", bookRef.AuthorList);
            bookRef.Content    = await Task.Run(() => ContentReader.ParseContentMap(bookRef)).ConfigureAwait(false);

            return(bookRef);
        }
Beispiel #5
0
        private static async Task <EpubBookRef> OpenBookAsync(ZipArchive zipArchive, string filePath = null)
        {
            EpubBookRef result = null;

            try
            {
                result          = new EpubBookRef(zipArchive);
                result.FilePath = filePath;
                result.Schema   = await SchemaReader.ReadSchemaAsync(zipArchive).ConfigureAwait(false);

                result.Title      = result.Schema.Package.Metadata.Titles.FirstOrDefault() ?? string.Empty;
                result.AuthorList = result.Schema.Package.Metadata.Creators.Select(creator => creator.Creator).ToList();
                result.Author     = string.Join(", ", result.AuthorList);
                return(result);
            }
            catch
            {
                result?.Dispose();
                throw;
            }
        }
Beispiel #6
0
        public static async Task <EpubBook> OpenBookAsync(string filePath)
        {
            //Changed from .NET function File.Exits to handmade async function
            bool fileExist = await DoesFileExistAsync(Windows.ApplicationModel.Package.Current.InstalledLocation, filePath);

            if (!fileExist)
            {
                throw new FileNotFoundException("Specified epub file not found.", filePath);
            }

            EpubBook book = new EpubBook();

            //File path is now derived from app Local folder
            book.FilePath = filePath;

            //Reworking old Unzip code to comply with Win 8.1 RT framework
            //Opening using LocalFolder as a root dir, file_path may still contain additional sudirectories
            var zipLocalFile = await Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(filePath);

            using (var zipFileStream = await zipLocalFile.OpenStreamForReadAsync())
            {
                using (ZipArchive epubArchive = new ZipArchive(zipFileStream, ZipArchiveMode.Read))
                {
                    book.Schema = await SchemaReader.ReadSchemaAsync(epubArchive);

                    //ItemPage.ShowLoadingProgress(20.0);
                    book.Title      = book.Schema.Package.Metadata.Titles.FirstOrDefault() ?? String.Empty;
                    book.AuthorList = book.Schema.Package.Metadata.Creators.Select(creator => creator.Creator).ToList();
                    book.Author     = String.Join(", ", book.AuthorList);
                    book.Content    = ContentReader.ReadContentFilesToMemory(epubArchive, book);
                    book.CoverImage = await LoadCoverImageAsync(book);

                    book.Chapters = LoadChapters(book, epubArchive);
                    //await ContentReader.ExtractContentFilesToDiskAsync(epubArchive, book);
                }
            }

            return(book);
        }