From e7aee219b31855413a54479b5444ce8cb10a829b Mon Sep 17 00:00:00 2001 From: Paddy Xu Date: Tue, 24 Jul 2018 22:06:06 +0300 Subject: [PATCH] Code reformat and UI tweaks --- .../BookHtmlContent.cs | 80 ++--- .../EpubReader/Entities/EpubBook.cs | 21 +- .../Entities/EpubByteContentFile.cs | 21 +- .../EpubReader/Entities/EpubChapter.cs | 22 +- .../EpubReader/Entities/EpubContent.cs | 21 +- .../EpubReader/Entities/EpubContentFile.cs | 21 +- .../EpubReader/Entities/EpubContentType.cs | 21 +- .../EpubReader/Entities/EpubSchema.cs | 21 +- .../Entities/EpubTextContentFile.cs | 21 +- .../EpubReader/EpubReader.cs | 107 ++++--- .../EpubReader/Readers/BookCoverReader.cs | 59 ++-- .../EpubReader/Readers/ChapterReader.cs | 52 ++-- .../EpubReader/Readers/ContentReader.cs | 39 ++- .../EpubReader/Readers/NavigationReader.cs | 286 ++++++++---------- .../EpubReader/Readers/PackageReader.cs | 224 +++++++------- .../EpubReader/Readers/RootFilePathReader.cs | 37 ++- .../EpubReader/Readers/SchemaReader.cs | 33 +- .../EpubReader/RefEntities/EpubBookRef.cs | 50 +-- .../RefEntities/EpubByteContentFileRef.cs | 21 +- .../EpubReader/RefEntities/EpubChapterRef.cs | 24 +- .../RefEntities/EpubContentFileRef.cs | 57 ++-- .../EpubReader/RefEntities/EpubContentRef.cs | 21 +- .../RefEntities/EpubTextContentFileRef.cs | 21 +- .../Schema/Navigation/EpubNavigation.cs | 21 +- .../Navigation/EpubNavigationContent.cs | 21 +- .../Navigation/EpubNavigationDocAuthor.cs | 21 +- .../Navigation/EpubNavigationDocTitle.cs | 21 +- .../Schema/Navigation/EpubNavigationHead.cs | 21 +- .../Navigation/EpubNavigationHeadMeta.cs | 21 +- .../Schema/Navigation/EpubNavigationLabel.cs | 21 +- .../Schema/Navigation/EpubNavigationList.cs | 21 +- .../Schema/Navigation/EpubNavigationMap.cs | 21 +- .../Navigation/EpubNavigationPageList.cs | 21 +- .../Navigation/EpubNavigationPageTarget.cs | 21 +- .../EpubNavigationPageTargetType.cs | 21 +- .../Schema/Navigation/EpubNavigationPoint.cs | 22 +- .../Schema/Navigation/EpubNavigationTarget.cs | 21 +- .../EpubReader/Schema/Opf/EpubGuide.cs | 21 +- .../Schema/Opf/EpubGuideReference.cs | 21 +- .../EpubReader/Schema/Opf/EpubManifest.cs | 21 +- .../EpubReader/Schema/Opf/EpubManifestItem.cs | 21 +- .../EpubReader/Schema/Opf/EpubMetadata.cs | 21 +- .../Schema/Opf/EpubMetadataContributor.cs | 21 +- .../Schema/Opf/EpubMetadataCreator.cs | 21 +- .../EpubReader/Schema/Opf/EpubMetadataDate.cs | 21 +- .../Schema/Opf/EpubMetadataIdentifier.cs | 21 +- .../EpubReader/Schema/Opf/EpubMetadataMeta.cs | 21 +- .../EpubReader/Schema/Opf/EpubPackage.cs | 21 +- .../EpubReader/Schema/Opf/EpubSpine.cs | 21 +- .../EpubReader/Schema/Opf/EpubSpineItemRef.cs | 21 +- .../EpubReader/Schema/Opf/EpubVersion.cs | 21 +- .../EpubReader/Utils/XmlUtils.cs | 27 +- .../EpubReader/Utils/ZipPathUtils.cs | 39 +-- .../EpubViewerControl.xaml | 44 +-- .../EpubViewerControl.xaml.cs | 153 +++++----- .../QuickLook.Plugin.EpubViewer/Plugin.cs | 31 +- .../Properties/AssemblyInfo.cs | 19 +- .../QuickLook.Plugin.EpubViewer.csproj | 10 - .../packages.config | 1 + 59 files changed, 1490 insertions(+), 703 deletions(-) diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/BookHtmlContent.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/BookHtmlContent.cs index ecdf1aa..7511523 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/BookHtmlContent.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/BookHtmlContent.cs @@ -1,4 +1,20 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + using System.Diagnostics; using System.IO; using System.Windows; @@ -11,51 +27,46 @@ namespace QuickLook.Plugin.EpubViewer { public class BookHtmlContent : HtmlPanel { - public static readonly DependencyProperty ChapterRefProperty = DependencyProperty.Register("ChapterRef", typeof(EpubChapterRef), typeof(BookHtmlContent), new PropertyMetadata(OnChapterRefChanged)); + public static readonly DependencyProperty ChapterRefProperty = DependencyProperty.Register("ChapterRef", + typeof(EpubChapterRef), typeof(BookHtmlContent), new PropertyMetadata(OnChapterRefChanged)); + + public static readonly DependencyProperty EpubBookProperty = DependencyProperty.Register("EpubBook", + typeof(EpubBookRef), typeof(BookHtmlContent), new PropertyMetadata(null)); public EpubChapterRef ChapterRef { - get { return (EpubChapterRef)GetValue(ChapterRefProperty); } - set { SetValue(ChapterRefProperty, value); } + get => (EpubChapterRef) GetValue(ChapterRefProperty); + set => SetValue(ChapterRefProperty, value); } - public static readonly DependencyProperty EpubBookProperty = DependencyProperty.Register("EpubBook", typeof(EpubBookRef), typeof(BookHtmlContent), new PropertyMetadata(null)); - public EpubBookRef EpubBook { - get { return (EpubBookRef)GetValue(EpubBookProperty); } - set { SetValue(EpubBookProperty, value); } + get => (EpubBookRef) GetValue(EpubBookProperty); + set => SetValue(EpubBookProperty, value); } protected override void OnStylesheetLoad(HtmlStylesheetLoadEventArgs args) { - string styleSheetFilePath = GetFullPath(ChapterRef.ContentFileName, args.Src); - if (EpubBook.Content.Css.TryGetValue(styleSheetFilePath, out EpubTextContentFileRef styleSheetContent)) - { + var styleSheetFilePath = GetFullPath(ChapterRef.ContentFileName, args.Src); + if (EpubBook.Content.Css.TryGetValue(styleSheetFilePath, out var styleSheetContent)) args.SetStyleSheet = styleSheetContent.ReadContentAsText(); - } } protected override async void OnImageLoad(HtmlImageLoadEventArgs args) { - string imageFilePath = ChapterRef != null ? GetFullPath(ChapterRef.ContentFileName, args.Src) : null; + var imageFilePath = ChapterRef != null ? GetFullPath(ChapterRef.ContentFileName, args.Src) : null; byte[] imageBytes = null; if (args.Src == "COVER") - { imageBytes = await EpubBook.ReadCoverAsync(); - } - else if (EpubBook.Content.Images.TryGetValue(imageFilePath, out EpubByteContentFileRef imageContent)) - { + else if (EpubBook.Content.Images.TryGetValue(imageFilePath, out var imageContent)) imageBytes = await imageContent.ReadContentAsBytesAsync(); - } if (imageBytes != null) - { - using (MemoryStream imageStream = new MemoryStream(imageBytes)) + using (var imageStream = new MemoryStream(imageBytes)) { try { - BitmapImage bitmapImage = new BitmapImage(); + var bitmapImage = new BitmapImage(); bitmapImage.BeginInit(); bitmapImage.StreamSource = imageStream; bitmapImage.CacheOption = BitmapCacheOption.OnLoad; @@ -69,33 +80,28 @@ namespace QuickLook.Plugin.EpubViewer Debug.WriteLine($"Failed to load image: {args.Src}"); } } - } } private string GetFullPath(string htmlFilePath, string relativePath) { - if (relativePath.StartsWith("/")) - { - return relativePath.Length > 1 ? relativePath.Substring(1) : String.Empty; - } - string basePath = System.IO.Path.GetDirectoryName(htmlFilePath); + if (relativePath.StartsWith("/")) return relativePath.Length > 1 ? relativePath.Substring(1) : string.Empty; + var basePath = Path.GetDirectoryName(htmlFilePath); while (relativePath.StartsWith("../")) { - relativePath = relativePath.Length > 3 ? relativePath.Substring(3) : String.Empty; - basePath = System.IO.Path.GetDirectoryName(basePath); + relativePath = relativePath.Length > 3 ? relativePath.Substring(3) : string.Empty; + basePath = Path.GetDirectoryName(basePath); } - string fullPath = String.Concat(basePath.Replace('\\', '/'), '/', relativePath); - return fullPath.StartsWith("/") ? fullPath.Length > 1 ? fullPath.Substring(1) : String.Empty : fullPath; + + var fullPath = string.Concat(basePath.Replace('\\', '/'), '/', relativePath); + return fullPath.StartsWith("/") ? fullPath.Length > 1 ? fullPath.Substring(1) : string.Empty : fullPath; } - private static async void OnChapterRefChanged(DependencyObject dependencyObject, DependencyPropertyChangedEventArgs e) + private static async void OnChapterRefChanged(DependencyObject dependencyObject, + DependencyPropertyChangedEventArgs e) { - BookHtmlContent bookHtmlContent = dependencyObject as BookHtmlContent; - if (bookHtmlContent == null || bookHtmlContent.ChapterRef == null) - { + if (!(dependencyObject is BookHtmlContent bookHtmlContent) || bookHtmlContent.ChapterRef == null) return; - } bookHtmlContent.Text = await bookHtmlContent.ChapterRef.ReadHtmlContentAsync(); } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubBook.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubBook.cs index b704d1a..ce63e79 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubBook.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubBook.cs @@ -1,4 +1,21 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub { @@ -13,4 +30,4 @@ namespace VersOne.Epub public byte[] CoverImage { get; set; } public List Chapters { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubByteContentFile.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubByteContentFile.cs index 1e88ec0..a9c81da 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubByteContentFile.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubByteContentFile.cs @@ -1,7 +1,24 @@ -namespace VersOne.Epub +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace VersOne.Epub { public class EpubByteContentFile : EpubContentFile { public byte[] Content { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubChapter.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubChapter.cs index cf022f3..0c7cab7 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubChapter.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubChapter.cs @@ -1,4 +1,20 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + using System.Collections.Generic; namespace VersOne.Epub @@ -13,7 +29,7 @@ namespace VersOne.Epub public override string ToString() { - return String.Format("Title: {0}, Subchapter count: {1}", Title, SubChapters.Count); + return string.Format("Title: {0}, Subchapter count: {1}", Title, SubChapters.Count); } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubContent.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubContent.cs index c7ce4a5..1ae5536 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubContent.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubContent.cs @@ -1,4 +1,21 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub { @@ -10,4 +27,4 @@ namespace VersOne.Epub public Dictionary Fonts { get; set; } public Dictionary AllFiles { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubContentFile.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubContentFile.cs index 3da6239..0a3ed54 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubContentFile.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubContentFile.cs @@ -1,4 +1,21 @@ -namespace VersOne.Epub +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace VersOne.Epub { public abstract class EpubContentFile { @@ -6,4 +23,4 @@ public EpubContentType ContentType { get; set; } public string ContentMimeType { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubContentType.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubContentType.cs index 77f3fa9..eeb8c95 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubContentType.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubContentType.cs @@ -1,4 +1,21 @@ -namespace VersOne.Epub +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace VersOne.Epub { public enum EpubContentType { @@ -17,4 +34,4 @@ FONT_OPENTYPE, OTHER } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubSchema.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubSchema.cs index 80f524f..8368744 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubSchema.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubSchema.cs @@ -1,4 +1,21 @@ -using VersOne.Epub.Schema; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using VersOne.Epub.Schema; namespace VersOne.Epub { @@ -8,4 +25,4 @@ namespace VersOne.Epub public EpubNavigation Navigation { get; set; } public string ContentDirectoryPath { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubTextContentFile.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubTextContentFile.cs index 642b1be..3b6d538 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubTextContentFile.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Entities/EpubTextContentFile.cs @@ -1,7 +1,24 @@ -namespace VersOne.Epub +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace VersOne.Epub { public class EpubTextContentFile : EpubContentFile { public string Content { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/EpubReader.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/EpubReader.cs index 4f07c93..973d618 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/EpubReader.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/EpubReader.cs @@ -1,4 +1,20 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + using System.Collections.Generic; using System.IO; using System.IO.Compression; @@ -11,7 +27,7 @@ namespace VersOne.Epub public static class EpubReader { /// - /// Opens the book synchronously without reading its whole content. Holds the handle to the EPUB file. + /// Opens the book synchronously without reading its whole content. Holds the handle to the EPUB file. /// /// path to the EPUB file /// @@ -21,7 +37,7 @@ namespace VersOne.Epub } /// - /// Opens the book synchronously without reading its whole content. + /// Opens the book synchronously without reading its whole content. /// /// path to the EPUB file /// @@ -31,21 +47,18 @@ namespace VersOne.Epub } /// - /// Opens the book asynchronously without reading its whole content. Holds the handle to the EPUB file. + /// Opens the book asynchronously without reading its whole content. Holds the handle to the EPUB file. /// /// path to the EPUB file /// public static Task OpenBookAsync(string filePath) { - if (!File.Exists(filePath)) - { - throw new FileNotFoundException("Specified epub file not found.", filePath); - } + if (!File.Exists(filePath)) throw new FileNotFoundException("Specified epub file not found.", filePath); return OpenBookAsync(GetZipArchive(filePath)); } /// - /// Opens the book asynchronously without reading its whole content. + /// Opens the book asynchronously without reading its whole content. /// /// path to the EPUB file /// @@ -55,7 +68,8 @@ namespace VersOne.Epub } /// - /// Opens the book synchronously and reads all of its content into the memory. Does not hold the handle to the EPUB file. + /// Opens the book synchronously and reads all of its content into the memory. Does not hold the handle to the EPUB + /// file. /// /// path to the EPUB file /// @@ -65,7 +79,8 @@ namespace VersOne.Epub } /// - /// Opens the book synchronously and reads all of its content into the memory. Does not hold the handle to the EPUB file. + /// Opens the book synchronously and reads all of its content into the memory. Does not hold the handle to the EPUB + /// file. /// /// path to the EPUB file /// @@ -75,24 +90,25 @@ namespace VersOne.Epub } /// - /// Opens the book asynchronously and reads all of its content into the memory. Does not hold the handle to the EPUB file. + /// Opens the book asynchronously and reads all of its content into the memory. Does not hold the handle to the EPUB + /// file. /// /// path to the EPUB file /// public static async Task ReadBookAsync(string filePath) { - EpubBookRef epubBookRef = await OpenBookAsync(filePath).ConfigureAwait(false); + var epubBookRef = await OpenBookAsync(filePath).ConfigureAwait(false); return await ReadBookAsync(epubBookRef).ConfigureAwait(false); } /// - /// Opens the book asynchronously and reads all of its content into the memory. + /// Opens the book asynchronously and reads all of its content into the memory. /// /// path to the EPUB file /// public static async Task ReadBookAsync(Stream stream) { - EpubBookRef epubBookRef = await OpenBookAsync(stream).ConfigureAwait(false); + var epubBookRef = await OpenBookAsync(stream).ConfigureAwait(false); return await ReadBookAsync(epubBookRef).ConfigureAwait(false); } @@ -104,9 +120,9 @@ namespace VersOne.Epub 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.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); + result.Author = string.Join(", ", result.AuthorList); result.Content = await Task.Run(() => ContentReader.ParseContentMap(result)).ConfigureAwait(false); return result; } @@ -119,7 +135,7 @@ namespace VersOne.Epub private static async Task ReadBookAsync(EpubBookRef epubBookRef) { - EpubBook result = new EpubBook(); + var result = new EpubBook(); using (epubBookRef) { result.FilePath = epubBookRef.FilePath; @@ -129,9 +145,10 @@ namespace VersOne.Epub result.Author = epubBookRef.Author; result.Content = await ReadContent(epubBookRef.Content).ConfigureAwait(false); result.CoverImage = await epubBookRef.ReadCoverAsync().ConfigureAwait(false); - List chapterRefs = await epubBookRef.GetChaptersAsync().ConfigureAwait(false); + var chapterRefs = await epubBookRef.GetChaptersAsync().ConfigureAwait(false); result.Chapters = await ReadChapters(chapterRefs).ConfigureAwait(false); } + return result; } @@ -147,36 +164,30 @@ namespace VersOne.Epub private static async Task ReadContent(EpubContentRef contentRef) { - EpubContent result = new EpubContent(); + var result = new EpubContent(); result.Html = await ReadTextContentFiles(contentRef.Html).ConfigureAwait(false); result.Css = await ReadTextContentFiles(contentRef.Css).ConfigureAwait(false); result.Images = await ReadByteContentFiles(contentRef.Images).ConfigureAwait(false); result.Fonts = await ReadByteContentFiles(contentRef.Fonts).ConfigureAwait(false); result.AllFiles = new Dictionary(); - foreach (KeyValuePair textContentFile in result.Html.Concat(result.Css)) - { + foreach (var textContentFile in result.Html.Concat(result.Css)) result.AllFiles.Add(textContentFile.Key, textContentFile.Value); - } - foreach (KeyValuePair byteContentFile in result.Images.Concat(result.Fonts)) - { + foreach (var byteContentFile in result.Images.Concat(result.Fonts)) result.AllFiles.Add(byteContentFile.Key, byteContentFile.Value); - } - foreach (KeyValuePair contentFileRef in contentRef.AllFiles) - { + foreach (var contentFileRef in contentRef.AllFiles) if (!result.AllFiles.ContainsKey(contentFileRef.Key)) - { - result.AllFiles.Add(contentFileRef.Key, await ReadByteContentFile(contentFileRef.Value).ConfigureAwait(false)); - } - } + result.AllFiles.Add(contentFileRef.Key, + await ReadByteContentFile(contentFileRef.Value).ConfigureAwait(false)); return result; } - private static async Task> ReadTextContentFiles(Dictionary textContentFileRefs) + private static async Task> ReadTextContentFiles( + Dictionary textContentFileRefs) { - Dictionary result = new Dictionary(); - foreach (KeyValuePair textContentFileRef in textContentFileRefs) + var result = new Dictionary(); + foreach (var textContentFileRef in textContentFileRefs) { - EpubTextContentFile textContentFile = new EpubTextContentFile + var textContentFile = new EpubTextContentFile { FileName = textContentFileRef.Value.FileName, ContentType = textContentFileRef.Value.ContentType, @@ -185,22 +196,23 @@ namespace VersOne.Epub textContentFile.Content = await textContentFileRef.Value.ReadContentAsTextAsync().ConfigureAwait(false); result.Add(textContentFileRef.Key, textContentFile); } + return result; } - private static async Task> ReadByteContentFiles(Dictionary byteContentFileRefs) + private static async Task> ReadByteContentFiles( + Dictionary byteContentFileRefs) { - Dictionary result = new Dictionary(); - foreach (KeyValuePair byteContentFileRef in byteContentFileRefs) - { - result.Add(byteContentFileRef.Key, await ReadByteContentFile(byteContentFileRef.Value).ConfigureAwait(false)); - } + var result = new Dictionary(); + foreach (var byteContentFileRef in byteContentFileRefs) + result.Add(byteContentFileRef.Key, + await ReadByteContentFile(byteContentFileRef.Value).ConfigureAwait(false)); return result; } private static async Task ReadByteContentFile(EpubContentFileRef contentFileRef) { - EpubByteContentFile result = new EpubByteContentFile + var result = new EpubByteContentFile { FileName = contentFileRef.FileName, ContentType = contentFileRef.ContentType, @@ -212,10 +224,10 @@ namespace VersOne.Epub private static async Task> ReadChapters(List chapterRefs) { - List result = new List(); - foreach (EpubChapterRef chapterRef in chapterRefs) + var result = new List(); + foreach (var chapterRef in chapterRefs) { - EpubChapter chapter = new EpubChapter + var chapter = new EpubChapter { Title = chapterRef.Title, ContentFileName = chapterRef.ContentFileName, @@ -225,7 +237,8 @@ namespace VersOne.Epub chapter.SubChapters = await ReadChapters(chapterRef.SubChapters).ConfigureAwait(false); result.Add(chapter); } + return result; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/BookCoverReader.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/BookCoverReader.cs index 5f99b64..73d60df 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/BookCoverReader.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/BookCoverReader.cs @@ -1,8 +1,23 @@ -using System; -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; using System.Linq; using System.Threading.Tasks; -using VersOne.Epub.Schema; namespace VersOne.Epub.Internal { @@ -10,31 +25,23 @@ namespace VersOne.Epub.Internal { public static async Task ReadBookCoverAsync(EpubBookRef bookRef) { - List metaItems = bookRef.Schema.Package.Metadata.MetaItems; - if (metaItems == null || !metaItems.Any()) - { - return null; - } - EpubMetadataMeta coverMetaItem = metaItems.FirstOrDefault(metaItem => String.Compare(metaItem.Name, "cover", StringComparison.OrdinalIgnoreCase) == 0); - if (coverMetaItem == null) - { - return null; - } - if (String.IsNullOrEmpty(coverMetaItem.Content)) - { + var metaItems = bookRef.Schema.Package.Metadata.MetaItems; + if (metaItems == null || !metaItems.Any()) return null; + var coverMetaItem = metaItems.FirstOrDefault(metaItem => + string.Compare(metaItem.Name, "cover", StringComparison.OrdinalIgnoreCase) == 0); + if (coverMetaItem == null) return null; + if (string.IsNullOrEmpty(coverMetaItem.Content)) throw new Exception("Incorrect EPUB metadata: cover item content is missing."); - } - EpubManifestItem coverManifestItem = bookRef.Schema.Package.Manifest.FirstOrDefault(manifestItem => String.Compare(manifestItem.Id, coverMetaItem.Content, StringComparison.OrdinalIgnoreCase) == 0); + var coverManifestItem = bookRef.Schema.Package.Manifest.FirstOrDefault(manifestItem => + string.Compare(manifestItem.Id, coverMetaItem.Content, StringComparison.OrdinalIgnoreCase) == 0); if (coverManifestItem == null) - { - throw new Exception(String.Format("Incorrect EPUB manifest: item with ID = \"{0}\" is missing.", coverMetaItem.Content)); - } - if (!bookRef.Content.Images.TryGetValue(coverManifestItem.Href, out EpubByteContentFileRef coverImageContentFileRef)) - { - throw new Exception(String.Format("Incorrect EPUB manifest: item with href = \"{0}\" is missing.", coverManifestItem.Href)); - } - byte[] coverImageContent = await coverImageContentFileRef.ReadContentAsBytesAsync().ConfigureAwait(false); + throw new Exception(string.Format("Incorrect EPUB manifest: item with ID = \"{0}\" is missing.", + coverMetaItem.Content)); + if (!bookRef.Content.Images.TryGetValue(coverManifestItem.Href, out var coverImageContentFileRef)) + throw new Exception(string.Format("Incorrect EPUB manifest: item with href = \"{0}\" is missing.", + coverManifestItem.Href)); + var coverImageContent = await coverImageContentFileRef.ReadContentAsBytesAsync().ConfigureAwait(false); return coverImageContent; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/ChapterReader.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/ChapterReader.cs index f6a44ab..d002521 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/ChapterReader.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/ChapterReader.cs @@ -1,4 +1,21 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; using System.Collections.Generic; using System.Linq; using System.Net; @@ -13,37 +30,38 @@ namespace VersOne.Epub.Internal return GetChapters(bookRef, bookRef.Schema.Package.Spine, bookRef.Schema.Navigation.NavMap); } - public static List GetChapters(EpubBookRef bookRef, EpubSpine spine, List navigationPoints) + public static List GetChapters(EpubBookRef bookRef, EpubSpine spine, + List navigationPoints) { - List result = new List(); - for (int s = 0; s < spine.Count; s++) + var result = new List(); + for (var s = 0; s < spine.Count; s++) { - EpubSpineItemRef itemRef = spine[s]; + var itemRef = spine[s]; string contentFileName; string anchor; - contentFileName = WebUtility.UrlDecode(bookRef.Schema.Package.Manifest.FirstOrDefault(e => e.Id == itemRef.IdRef)?.Href); + contentFileName = WebUtility.UrlDecode(bookRef.Schema.Package.Manifest + .FirstOrDefault(e => e.Id == itemRef.IdRef)?.Href); anchor = null; - if (!bookRef.Content.Html.TryGetValue(contentFileName, out EpubTextContentFileRef htmlContentFileRef)) - { - throw new Exception(String.Format("Incorrect EPUB manifest: item with href = \"{0}\" is missing.", contentFileName)); - } - EpubChapterRef chapterRef = new EpubChapterRef(htmlContentFileRef); + if (!bookRef.Content.Html.TryGetValue(contentFileName, out var htmlContentFileRef)) + throw new Exception(string.Format("Incorrect EPUB manifest: item with href = \"{0}\" is missing.", + contentFileName)); + var chapterRef = new EpubChapterRef(htmlContentFileRef); chapterRef.ContentFileName = contentFileName; chapterRef.Anchor = anchor; chapterRef.Parent = null; - var navPoint = navigationPoints.LastOrDefault(nav => spine.Take(s + 1).Select(sp => bookRef.Schema.Package.Manifest.FirstOrDefault(e => e.Id == sp.IdRef)?.Href).Contains(nav.Content.Source.Split('#')[0])); + var navPoint = navigationPoints.LastOrDefault(nav => + spine.Take(s + 1) + .Select(sp => bookRef.Schema.Package.Manifest.FirstOrDefault(e => e.Id == sp.IdRef)?.Href) + .Contains(nav.Content.Source.Split('#')[0])); if (navPoint != null) - { chapterRef.Title = navPoint.NavigationLabels.First().Text; - } else - { chapterRef.Title = $"Chapter {s + 1}"; - } chapterRef.SubChapters = new List(); result.Add(chapterRef); } + return result; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/ContentReader.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/ContentReader.cs index 03be95f..a05b540 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/ContentReader.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/ContentReader.cs @@ -1,5 +1,21 @@ -using System.Collections.Generic; -using VersOne.Epub.Schema; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub.Internal { @@ -7,7 +23,7 @@ namespace VersOne.Epub.Internal { public static EpubContentRef ParseContentMap(EpubBookRef bookRef) { - EpubContentRef result = new EpubContentRef + var result = new EpubContentRef { Html = new Dictionary(), Css = new Dictionary(), @@ -15,11 +31,11 @@ namespace VersOne.Epub.Internal Fonts = new Dictionary(), AllFiles = new Dictionary() }; - foreach (EpubManifestItem manifestItem in bookRef.Schema.Package.Manifest) + foreach (var manifestItem in bookRef.Schema.Package.Manifest) { - string fileName = manifestItem.Href; - string contentMimeType = manifestItem.MediaType; - EpubContentType contentType = GetContentTypeByContentMimeType(contentMimeType); + var fileName = manifestItem.Href; + var contentMimeType = manifestItem.MediaType; + var contentType = GetContentTypeByContentMimeType(contentMimeType); switch (contentType) { case EpubContentType.XHTML_1_1: @@ -29,7 +45,7 @@ namespace VersOne.Epub.Internal case EpubContentType.XML: case EpubContentType.DTBOOK: case EpubContentType.DTBOOK_NCX: - EpubTextContentFileRef epubTextContentFile = new EpubTextContentFileRef(bookRef) + var epubTextContentFile = new EpubTextContentFileRef(bookRef) { FileName = fileName, ContentMimeType = contentMimeType, @@ -44,10 +60,11 @@ namespace VersOne.Epub.Internal result.Css[fileName] = epubTextContentFile; break; } + result.AllFiles[fileName] = epubTextContentFile; break; default: - EpubByteContentFileRef epubByteContentFile = new EpubByteContentFileRef(bookRef) + var epubByteContentFile = new EpubByteContentFileRef(bookRef) { FileName = fileName, ContentMimeType = contentMimeType, @@ -66,10 +83,12 @@ namespace VersOne.Epub.Internal result.Fonts[fileName] = epubByteContentFile; break; } + result.AllFiles[fileName] = epubByteContentFile; break; } } + return result; } @@ -110,4 +129,4 @@ namespace VersOne.Epub.Internal } } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/NavigationReader.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/NavigationReader.cs index 970ab11..3ebc4cb 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/NavigationReader.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/NavigationReader.cs @@ -1,6 +1,22 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; using System.Collections.Generic; -using System.IO; using System.IO.Compression; using System.Linq; using System.Threading.Tasks; @@ -11,93 +27,82 @@ namespace VersOne.Epub.Internal { internal static class NavigationReader { - public static async Task ReadNavigationAsync(ZipArchive epubArchive, string contentDirectoryPath, EpubPackage package) + public static async Task ReadNavigationAsync(ZipArchive epubArchive, + string contentDirectoryPath, EpubPackage package) { - EpubNavigation result = new EpubNavigation(); - string tocId = package.Spine.Toc; - if (String.IsNullOrEmpty(tocId)) - { - throw new Exception("EPUB parsing error: TOC ID is empty."); - } - EpubManifestItem tocManifestItem = package.Manifest.FirstOrDefault(item => String.Compare(item.Id, tocId, StringComparison.OrdinalIgnoreCase) == 0); + var result = new EpubNavigation(); + var tocId = package.Spine.Toc; + if (string.IsNullOrEmpty(tocId)) throw new Exception("EPUB parsing error: TOC ID is empty."); + var tocManifestItem = package.Manifest.FirstOrDefault(item => + string.Compare(item.Id, tocId, StringComparison.OrdinalIgnoreCase) == 0); if (tocManifestItem == null) - { - throw new Exception(String.Format("EPUB parsing error: TOC item {0} not found in EPUB manifest.", tocId)); - } - string tocFileEntryPath = ZipPathUtils.Combine(contentDirectoryPath, tocManifestItem.Href); - ZipArchiveEntry tocFileEntry = epubArchive.GetEntry(tocFileEntryPath); + throw new Exception( + string.Format("EPUB parsing error: TOC item {0} not found in EPUB manifest.", tocId)); + var tocFileEntryPath = ZipPathUtils.Combine(contentDirectoryPath, tocManifestItem.Href); + var tocFileEntry = epubArchive.GetEntry(tocFileEntryPath); if (tocFileEntry == null) - { - throw new Exception(String.Format("EPUB parsing error: TOC file {0} not found in archive.", tocFileEntryPath)); - } - if (tocFileEntry.Length > Int32.MaxValue) - { - throw new Exception(String.Format("EPUB parsing error: TOC file {0} is larger than 2 Gb.", tocFileEntryPath)); - } + throw new Exception(string.Format("EPUB parsing error: TOC file {0} not found in archive.", + tocFileEntryPath)); + if (tocFileEntry.Length > int.MaxValue) + throw new Exception(string.Format("EPUB parsing error: TOC file {0} is larger than 2 Gb.", + tocFileEntryPath)); XDocument containerDocument; - using (Stream containerStream = tocFileEntry.Open()) + using (var containerStream = tocFileEntry.Open()) { containerDocument = await XmlUtils.LoadDocumentAsync(containerStream).ConfigureAwait(false); } + XNamespace ncxNamespace = "http://www.daisy.org/z3986/2005/ncx/"; - XElement ncxNode = containerDocument.Element(ncxNamespace + "ncx"); - if (ncxNode == null) - { - throw new Exception("EPUB parsing error: TOC file does not contain ncx element."); - } - XElement headNode = ncxNode.Element(ncxNamespace + "head"); - if (headNode == null) - { - throw new Exception("EPUB parsing error: TOC file does not contain head element."); - } - EpubNavigationHead navigationHead = ReadNavigationHead(headNode); + var ncxNode = containerDocument.Element(ncxNamespace + "ncx"); + if (ncxNode == null) throw new Exception("EPUB parsing error: TOC file does not contain ncx element."); + var headNode = ncxNode.Element(ncxNamespace + "head"); + if (headNode == null) throw new Exception("EPUB parsing error: TOC file does not contain head element."); + var navigationHead = ReadNavigationHead(headNode); result.Head = navigationHead; - XElement docTitleNode = ncxNode.Element(ncxNamespace + "docTitle"); + var docTitleNode = ncxNode.Element(ncxNamespace + "docTitle"); if (docTitleNode == null) - { throw new Exception("EPUB parsing error: TOC file does not contain docTitle element."); - } - EpubNavigationDocTitle navigationDocTitle = ReadNavigationDocTitle(docTitleNode); + var navigationDocTitle = ReadNavigationDocTitle(docTitleNode); result.DocTitle = navigationDocTitle; result.DocAuthors = new List(); - foreach (XElement docAuthorNode in ncxNode.Elements(ncxNamespace + "docAuthor")) + foreach (var docAuthorNode in ncxNode.Elements(ncxNamespace + "docAuthor")) { - EpubNavigationDocAuthor navigationDocAuthor = ReadNavigationDocAuthor(docAuthorNode); + var navigationDocAuthor = ReadNavigationDocAuthor(docAuthorNode); result.DocAuthors.Add(navigationDocAuthor); } - XElement navMapNode = ncxNode.Element(ncxNamespace + "navMap"); + + var navMapNode = ncxNode.Element(ncxNamespace + "navMap"); if (navMapNode == null) - { throw new Exception("EPUB parsing error: TOC file does not contain navMap element."); - } - EpubNavigationMap navMap = ReadNavigationMap(navMapNode); + var navMap = ReadNavigationMap(navMapNode); result.NavMap = navMap; - XElement pageListNode = ncxNode.Element(ncxNamespace + "pageList"); + var pageListNode = ncxNode.Element(ncxNamespace + "pageList"); if (pageListNode != null) { - EpubNavigationPageList pageList = ReadNavigationPageList(pageListNode); + var pageList = ReadNavigationPageList(pageListNode); result.PageList = pageList; } + result.NavLists = new List(); - foreach (XElement navigationListNode in ncxNode.Elements(ncxNamespace + "navList")) + foreach (var navigationListNode in ncxNode.Elements(ncxNamespace + "navList")) { - EpubNavigationList navigationList = ReadNavigationList(navigationListNode); + var navigationList = ReadNavigationList(navigationListNode); result.NavLists.Add(navigationList); } + return result; } private static EpubNavigationHead ReadNavigationHead(XElement headNode) { - EpubNavigationHead result = new EpubNavigationHead(); - foreach (XElement metaNode in headNode.Elements()) - { - if (String.Compare(metaNode.Name.LocalName, "meta", StringComparison.OrdinalIgnoreCase) == 0) + var result = new EpubNavigationHead(); + foreach (var metaNode in headNode.Elements()) + if (string.Compare(metaNode.Name.LocalName, "meta", StringComparison.OrdinalIgnoreCase) == 0) { - EpubNavigationHeadMeta meta = new EpubNavigationHeadMeta(); - foreach (XAttribute metaNodeAttribute in metaNode.Attributes()) + var meta = new EpubNavigationHeadMeta(); + foreach (var metaNodeAttribute in metaNode.Attributes()) { - string attributeValue = metaNodeAttribute.Value; + var attributeValue = metaNodeAttribute.Value; switch (metaNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "name": @@ -111,66 +116,55 @@ namespace VersOne.Epub.Internal break; } } - if (String.IsNullOrWhiteSpace(meta.Name)) - { + + if (string.IsNullOrWhiteSpace(meta.Name)) throw new Exception("Incorrect EPUB navigation meta: meta name is missing."); - } if (meta.Content == null) - { throw new Exception("Incorrect EPUB navigation meta: meta content is missing."); - } result.Add(meta); } - } + return result; } private static EpubNavigationDocTitle ReadNavigationDocTitle(XElement docTitleNode) { - EpubNavigationDocTitle result = new EpubNavigationDocTitle(); - foreach (XElement textNode in docTitleNode.Elements()) - { - if (String.Compare(textNode.Name.LocalName, "text", StringComparison.OrdinalIgnoreCase) == 0) - { + var result = new EpubNavigationDocTitle(); + foreach (var textNode in docTitleNode.Elements()) + if (string.Compare(textNode.Name.LocalName, "text", StringComparison.OrdinalIgnoreCase) == 0) result.Add(textNode.Value); - } - } return result; } private static EpubNavigationDocAuthor ReadNavigationDocAuthor(XElement docAuthorNode) { - EpubNavigationDocAuthor result = new EpubNavigationDocAuthor(); - foreach (XElement textNode in docAuthorNode.Elements()) - { - if (String.Compare(textNode.Name.LocalName, "text", StringComparison.OrdinalIgnoreCase) == 0) - { + var result = new EpubNavigationDocAuthor(); + foreach (var textNode in docAuthorNode.Elements()) + if (string.Compare(textNode.Name.LocalName, "text", StringComparison.OrdinalIgnoreCase) == 0) result.Add(textNode.Value); - } - } return result; } private static EpubNavigationMap ReadNavigationMap(XElement navigationMapNode) { - EpubNavigationMap result = new EpubNavigationMap(); - foreach (XElement navigationPointNode in navigationMapNode.Elements()) - { - if (String.Compare(navigationPointNode.Name.LocalName, "navPoint", StringComparison.OrdinalIgnoreCase) == 0) + var result = new EpubNavigationMap(); + foreach (var navigationPointNode in navigationMapNode.Elements()) + if (string.Compare(navigationPointNode.Name.LocalName, "navPoint", + StringComparison.OrdinalIgnoreCase) == 0) { - EpubNavigationPoint navigationPoint = ReadNavigationPoint(navigationPointNode); + var navigationPoint = ReadNavigationPoint(navigationPointNode); result.Add(navigationPoint); } - } + return result; } private static EpubNavigationPoint ReadNavigationPoint(XElement navigationPointNode) { - EpubNavigationPoint result = new EpubNavigationPoint(); - foreach (XAttribute navigationPointNodeAttribute in navigationPointNode.Attributes()) + var result = new EpubNavigationPoint(); + foreach (var navigationPointNodeAttribute in navigationPointNode.Attributes()) { - string attributeValue = navigationPointNodeAttribute.Value; + var attributeValue = navigationPointNodeAttribute.Value; switch (navigationPointNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "id": @@ -184,59 +178,53 @@ namespace VersOne.Epub.Internal break; } } - if (String.IsNullOrWhiteSpace(result.Id)) - { + + if (string.IsNullOrWhiteSpace(result.Id)) throw new Exception("Incorrect EPUB navigation point: point ID is missing."); - } result.NavigationLabels = new List(); result.ChildNavigationPoints = new List(); - foreach (XElement navigationPointChildNode in navigationPointNode.Elements()) - { + foreach (var navigationPointChildNode in navigationPointNode.Elements()) switch (navigationPointChildNode.Name.LocalName.ToLowerInvariant()) { case "navlabel": - EpubNavigationLabel navigationLabel = ReadNavigationLabel(navigationPointChildNode); + var navigationLabel = ReadNavigationLabel(navigationPointChildNode); result.NavigationLabels.Add(navigationLabel); break; case "content": - EpubNavigationContent content = ReadNavigationContent(navigationPointChildNode); + var content = ReadNavigationContent(navigationPointChildNode); result.Content = content; break; case "navpoint": - EpubNavigationPoint childNavigationPoint = ReadNavigationPoint(navigationPointChildNode); + var childNavigationPoint = ReadNavigationPoint(navigationPointChildNode); result.ChildNavigationPoints.Add(childNavigationPoint); break; } - } if (!result.NavigationLabels.Any()) - { - throw new Exception(String.Format("EPUB parsing error: navigation point {0} should contain at least one navigation label.", result.Id)); - } + throw new Exception(string.Format( + "EPUB parsing error: navigation point {0} should contain at least one navigation label.", + result.Id)); if (result.Content == null) - { - throw new Exception(String.Format("EPUB parsing error: navigation point {0} should contain content.", result.Id)); - } + throw new Exception(string.Format("EPUB parsing error: navigation point {0} should contain content.", + result.Id)); return result; } private static EpubNavigationLabel ReadNavigationLabel(XElement navigationLabelNode) { - EpubNavigationLabel result = new EpubNavigationLabel(); - XElement navigationLabelTextNode = navigationLabelNode.Element(navigationLabelNode.Name.Namespace + "text"); + var result = new EpubNavigationLabel(); + var navigationLabelTextNode = navigationLabelNode.Element(navigationLabelNode.Name.Namespace + "text"); if (navigationLabelTextNode == null) - { throw new Exception("Incorrect EPUB navigation label: label text element is missing."); - } result.Text = navigationLabelTextNode.Value; return result; } private static EpubNavigationContent ReadNavigationContent(XElement navigationContentNode) { - EpubNavigationContent result = new EpubNavigationContent(); - foreach (XAttribute navigationContentNodeAttribute in navigationContentNode.Attributes()) + var result = new EpubNavigationContent(); + foreach (var navigationContentNodeAttribute in navigationContentNode.Attributes()) { - string attributeValue = navigationContentNodeAttribute.Value; + var attributeValue = navigationContentNodeAttribute.Value; switch (navigationContentNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "id": @@ -247,33 +235,32 @@ namespace VersOne.Epub.Internal break; } } - if (String.IsNullOrWhiteSpace(result.Source)) - { + + if (string.IsNullOrWhiteSpace(result.Source)) throw new Exception("Incorrect EPUB navigation content: content source is missing."); - } return result; } private static EpubNavigationPageList ReadNavigationPageList(XElement navigationPageListNode) { - EpubNavigationPageList result = new EpubNavigationPageList(); - foreach (XElement pageTargetNode in navigationPageListNode.Elements()) - { - if (String.Compare(pageTargetNode.Name.LocalName, "pageTarget", StringComparison.OrdinalIgnoreCase) == 0) + var result = new EpubNavigationPageList(); + foreach (var pageTargetNode in navigationPageListNode.Elements()) + if (string.Compare(pageTargetNode.Name.LocalName, "pageTarget", StringComparison.OrdinalIgnoreCase) == + 0) { - EpubNavigationPageTarget pageTarget = ReadNavigationPageTarget(pageTargetNode); + var pageTarget = ReadNavigationPageTarget(pageTargetNode); result.Add(pageTarget); } - } + return result; } private static EpubNavigationPageTarget ReadNavigationPageTarget(XElement navigationPageTargetNode) { - EpubNavigationPageTarget result = new EpubNavigationPageTarget(); - foreach (XAttribute navigationPageTargetNodeAttribute in navigationPageTargetNode.Attributes()) + var result = new EpubNavigationPageTarget(); + foreach (var navigationPageTargetNodeAttribute in navigationPageTargetNode.Attributes()) { - string attributeValue = navigationPageTargetNodeAttribute.Value; + var attributeValue = navigationPageTargetNodeAttribute.Value; switch (navigationPageTargetNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "id": @@ -285,9 +272,9 @@ namespace VersOne.Epub.Internal case "type": EpubNavigationPageTargetType type; if (!Enum.TryParse(attributeValue, out type)) - { - throw new Exception(String.Format("Incorrect EPUB navigation page target: {0} is incorrect value for page target type.", attributeValue)); - } + throw new Exception(string.Format( + "Incorrect EPUB navigation page target: {0} is incorrect value for page target type.", + attributeValue)); result.Type = type; break; case "class": @@ -298,35 +285,33 @@ namespace VersOne.Epub.Internal break; } } + if (result.Type == default(EpubNavigationPageTargetType)) - { throw new Exception("Incorrect EPUB navigation page target: page target type is missing."); - } - foreach (XElement navigationPageTargetChildNode in navigationPageTargetNode.Elements()) + foreach (var navigationPageTargetChildNode in navigationPageTargetNode.Elements()) switch (navigationPageTargetChildNode.Name.LocalName.ToLowerInvariant()) { case "navlabel": - EpubNavigationLabel navigationLabel = ReadNavigationLabel(navigationPageTargetChildNode); + var navigationLabel = ReadNavigationLabel(navigationPageTargetChildNode); result.NavigationLabels.Add(navigationLabel); break; case "content": - EpubNavigationContent content = ReadNavigationContent(navigationPageTargetChildNode); + var content = ReadNavigationContent(navigationPageTargetChildNode); result.Content = content; break; } if (!result.NavigationLabels.Any()) - { - throw new Exception("Incorrect EPUB navigation page target: at least one navLabel element is required."); - } + throw new Exception( + "Incorrect EPUB navigation page target: at least one navLabel element is required."); return result; } private static EpubNavigationList ReadNavigationList(XElement navigationListNode) { - EpubNavigationList result = new EpubNavigationList(); - foreach (XAttribute navigationListNodeAttribute in navigationListNode.Attributes()) + var result = new EpubNavigationList(); + foreach (var navigationListNodeAttribute in navigationListNode.Attributes()) { - string attributeValue = navigationListNodeAttribute.Value; + var attributeValue = navigationListNodeAttribute.Value; switch (navigationListNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "id": @@ -337,33 +322,31 @@ namespace VersOne.Epub.Internal break; } } - foreach (XElement navigationListChildNode in navigationListNode.Elements()) - { + + foreach (var navigationListChildNode in navigationListNode.Elements()) switch (navigationListChildNode.Name.LocalName.ToLowerInvariant()) { case "navlabel": - EpubNavigationLabel navigationLabel = ReadNavigationLabel(navigationListChildNode); + var navigationLabel = ReadNavigationLabel(navigationListChildNode); result.NavigationLabels.Add(navigationLabel); break; case "navTarget": - EpubNavigationTarget navigationTarget = ReadNavigationTarget(navigationListChildNode); + var navigationTarget = ReadNavigationTarget(navigationListChildNode); result.NavigationTargets.Add(navigationTarget); break; } - } if (!result.NavigationLabels.Any()) - { - throw new Exception("Incorrect EPUB navigation page target: at least one navLabel element is required."); - } + throw new Exception( + "Incorrect EPUB navigation page target: at least one navLabel element is required."); return result; } private static EpubNavigationTarget ReadNavigationTarget(XElement navigationTargetNode) { - EpubNavigationTarget result = new EpubNavigationTarget(); - foreach (XAttribute navigationPageTargetNodeAttribute in navigationTargetNode.Attributes()) + var result = new EpubNavigationTarget(); + foreach (var navigationPageTargetNodeAttribute in navigationTargetNode.Attributes()) { - string attributeValue = navigationPageTargetNodeAttribute.Value; + var attributeValue = navigationPageTargetNodeAttribute.Value; switch (navigationPageTargetNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "id": @@ -380,29 +363,24 @@ namespace VersOne.Epub.Internal break; } } - if (String.IsNullOrWhiteSpace(result.Id)) - { + + if (string.IsNullOrWhiteSpace(result.Id)) throw new Exception("Incorrect EPUB navigation target: navigation target ID is missing."); - } - foreach (XElement navigationTargetChildNode in navigationTargetNode.Elements()) - { + foreach (var navigationTargetChildNode in navigationTargetNode.Elements()) switch (navigationTargetChildNode.Name.LocalName.ToLowerInvariant()) { case "navlabel": - EpubNavigationLabel navigationLabel = ReadNavigationLabel(navigationTargetChildNode); + var navigationLabel = ReadNavigationLabel(navigationTargetChildNode); result.NavigationLabels.Add(navigationLabel); break; case "content": - EpubNavigationContent content = ReadNavigationContent(navigationTargetChildNode); + var content = ReadNavigationContent(navigationTargetChildNode); result.Content = content; break; } - } if (!result.NavigationLabels.Any()) - { throw new Exception("Incorrect EPUB navigation target: at least one navLabel element is required."); - } return result; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/PackageReader.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/PackageReader.cs index 230d9fb..2961afc 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/PackageReader.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/PackageReader.cs @@ -1,6 +1,22 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; using System.Collections.Generic; -using System.IO; using System.IO.Compression; using System.Threading.Tasks; using System.Xml.Linq; @@ -12,65 +28,49 @@ namespace VersOne.Epub.Internal { public static async Task ReadPackageAsync(ZipArchive epubArchive, string rootFilePath) { - ZipArchiveEntry rootFileEntry = epubArchive.GetEntry(rootFilePath); - if (rootFileEntry == null) - { - throw new Exception("EPUB parsing error: root file not found in archive."); - } + var rootFileEntry = epubArchive.GetEntry(rootFilePath); + if (rootFileEntry == null) throw new Exception("EPUB parsing error: root file not found in archive."); XDocument containerDocument; - using (Stream containerStream = rootFileEntry.Open()) + using (var containerStream = rootFileEntry.Open()) { containerDocument = await XmlUtils.LoadDocumentAsync(containerStream).ConfigureAwait(false); } + XNamespace opfNamespace = "http://www.idpf.org/2007/opf"; - XElement packageNode = containerDocument.Element(opfNamespace + "package"); - EpubPackage result = new EpubPackage(); - string epubVersionValue = packageNode.Attribute("version").Value; + var packageNode = containerDocument.Element(opfNamespace + "package"); + var result = new EpubPackage(); + var epubVersionValue = packageNode.Attribute("version").Value; if (epubVersionValue == "2.0") - { result.EpubVersion = EpubVersion.EPUB_2; - } else if (epubVersionValue == "3.0") - { result.EpubVersion = EpubVersion.EPUB_3; - } else - { - throw new Exception(String.Format("Unsupported EPUB version: {0}.", epubVersionValue)); - } - XElement metadataNode = packageNode.Element(opfNamespace + "metadata"); - if (metadataNode == null) - { - throw new Exception("EPUB parsing error: metadata not found in the package."); - } - EpubMetadata metadata = ReadMetadata(metadataNode, result.EpubVersion); + throw new Exception(string.Format("Unsupported EPUB version: {0}.", epubVersionValue)); + var metadataNode = packageNode.Element(opfNamespace + "metadata"); + if (metadataNode == null) throw new Exception("EPUB parsing error: metadata not found in the package."); + var metadata = ReadMetadata(metadataNode, result.EpubVersion); result.Metadata = metadata; - XElement manifestNode = packageNode.Element(opfNamespace + "manifest"); - if (manifestNode == null) - { - throw new Exception("EPUB parsing error: manifest not found in the package."); - } - EpubManifest manifest = ReadManifest(manifestNode); + var manifestNode = packageNode.Element(opfNamespace + "manifest"); + if (manifestNode == null) throw new Exception("EPUB parsing error: manifest not found in the package."); + var manifest = ReadManifest(manifestNode); result.Manifest = manifest; - XElement spineNode = packageNode.Element(opfNamespace + "spine"); - if (spineNode == null) - { - throw new Exception("EPUB parsing error: spine not found in the package."); - } - EpubSpine spine = ReadSpine(spineNode); + var spineNode = packageNode.Element(opfNamespace + "spine"); + if (spineNode == null) throw new Exception("EPUB parsing error: spine not found in the package."); + var spine = ReadSpine(spineNode); result.Spine = spine; - XElement guideNode = packageNode.Element(opfNamespace + "guide"); + var guideNode = packageNode.Element(opfNamespace + "guide"); if (guideNode != null) { - EpubGuide guide = ReadGuide(guideNode); + var guide = ReadGuide(guideNode); result.Guide = guide; } + return result; } private static EpubMetadata ReadMetadata(XElement metadataNode, EpubVersion epubVersion) { - EpubMetadata result = new EpubMetadata + var result = new EpubMetadata { Titles = new List(), Creators = new List(), @@ -88,16 +88,16 @@ namespace VersOne.Epub.Internal Rights = new List(), MetaItems = new List() }; - foreach (XElement metadataItemNode in metadataNode.Elements()) + foreach (var metadataItemNode in metadataNode.Elements()) { - string innerText = metadataItemNode.Value; + var innerText = metadataItemNode.Value; switch (metadataItemNode.Name.LocalName.ToLowerInvariant()) { case "title": result.Titles.Add(innerText); break; case "creator": - EpubMetadataCreator creator = ReadMetadataCreator(metadataItemNode); + var creator = ReadMetadataCreator(metadataItemNode); result.Creators.Add(creator); break; case "subject": @@ -110,11 +110,11 @@ namespace VersOne.Epub.Internal result.Publishers.Add(innerText); break; case "contributor": - EpubMetadataContributor contributor = ReadMetadataContributor(metadataItemNode); + var contributor = ReadMetadataContributor(metadataItemNode); result.Contributors.Add(contributor); break; case "date": - EpubMetadataDate date = ReadMetadataDate(metadataItemNode); + var date = ReadMetadataDate(metadataItemNode); result.Dates.Add(date); break; case "type": @@ -124,7 +124,7 @@ namespace VersOne.Epub.Internal result.Formats.Add(innerText); break; case "identifier": - EpubMetadataIdentifier identifier = ReadMetadataIdentifier(metadataItemNode); + var identifier = ReadMetadataIdentifier(metadataItemNode); result.Identifiers.Add(identifier); break; case "source": @@ -145,26 +145,28 @@ namespace VersOne.Epub.Internal case "meta": if (epubVersion == EpubVersion.EPUB_2) { - EpubMetadataMeta meta = ReadMetadataMetaVersion2(metadataItemNode); + var meta = ReadMetadataMetaVersion2(metadataItemNode); result.MetaItems.Add(meta); } else if (epubVersion == EpubVersion.EPUB_3) { - EpubMetadataMeta meta = ReadMetadataMetaVersion3(metadataItemNode); + var meta = ReadMetadataMetaVersion3(metadataItemNode); result.MetaItems.Add(meta); } + break; } } + return result; } private static EpubMetadataCreator ReadMetadataCreator(XElement metadataCreatorNode) { - EpubMetadataCreator result = new EpubMetadataCreator(); - foreach (XAttribute metadataCreatorNodeAttribute in metadataCreatorNode.Attributes()) + var result = new EpubMetadataCreator(); + foreach (var metadataCreatorNodeAttribute in metadataCreatorNode.Attributes()) { - string attributeValue = metadataCreatorNodeAttribute.Value; + var attributeValue = metadataCreatorNodeAttribute.Value; switch (metadataCreatorNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "role": @@ -175,16 +177,17 @@ namespace VersOne.Epub.Internal break; } } + result.Creator = metadataCreatorNode.Value; return result; } private static EpubMetadataContributor ReadMetadataContributor(XElement metadataContributorNode) { - EpubMetadataContributor result = new EpubMetadataContributor(); - foreach (XAttribute metadataContributorNodeAttribute in metadataContributorNode.Attributes()) + var result = new EpubMetadataContributor(); + foreach (var metadataContributorNodeAttribute in metadataContributorNode.Attributes()) { - string attributeValue = metadataContributorNodeAttribute.Value; + var attributeValue = metadataContributorNodeAttribute.Value; switch (metadataContributorNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "role": @@ -195,28 +198,26 @@ namespace VersOne.Epub.Internal break; } } + result.Contributor = metadataContributorNode.Value; return result; } private static EpubMetadataDate ReadMetadataDate(XElement metadataDateNode) { - EpubMetadataDate result = new EpubMetadataDate(); - XAttribute eventAttribute = metadataDateNode.Attribute(metadataDateNode.Name.Namespace + "event"); - if (eventAttribute != null) - { - result.Event = eventAttribute.Value; - } + var result = new EpubMetadataDate(); + var eventAttribute = metadataDateNode.Attribute(metadataDateNode.Name.Namespace + "event"); + if (eventAttribute != null) result.Event = eventAttribute.Value; result.Date = metadataDateNode.Value; return result; } private static EpubMetadataIdentifier ReadMetadataIdentifier(XElement metadataIdentifierNode) { - EpubMetadataIdentifier result = new EpubMetadataIdentifier(); - foreach (XAttribute metadataIdentifierNodeAttribute in metadataIdentifierNode.Attributes()) + var result = new EpubMetadataIdentifier(); + foreach (var metadataIdentifierNodeAttribute in metadataIdentifierNode.Attributes()) { - string attributeValue = metadataIdentifierNodeAttribute.Value; + var attributeValue = metadataIdentifierNodeAttribute.Value; switch (metadataIdentifierNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "id": @@ -227,16 +228,17 @@ namespace VersOne.Epub.Internal break; } } + result.Identifier = metadataIdentifierNode.Value; return result; } private static EpubMetadataMeta ReadMetadataMetaVersion2(XElement metadataMetaNode) { - EpubMetadataMeta result = new EpubMetadataMeta(); - foreach (XAttribute metadataMetaNodeAttribute in metadataMetaNode.Attributes()) + var result = new EpubMetadataMeta(); + foreach (var metadataMetaNodeAttribute in metadataMetaNode.Attributes()) { - string attributeValue = metadataMetaNodeAttribute.Value; + var attributeValue = metadataMetaNodeAttribute.Value; switch (metadataMetaNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "name": @@ -247,15 +249,16 @@ namespace VersOne.Epub.Internal break; } } + return result; } private static EpubMetadataMeta ReadMetadataMetaVersion3(XElement metadataMetaNode) { - EpubMetadataMeta result = new EpubMetadataMeta(); - foreach (XAttribute metadataMetaNodeAttribute in metadataMetaNode.Attributes()) + var result = new EpubMetadataMeta(); + foreach (var metadataMetaNodeAttribute in metadataMetaNode.Attributes()) { - string attributeValue = metadataMetaNodeAttribute.Value; + var attributeValue = metadataMetaNodeAttribute.Value; switch (metadataMetaNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "id": @@ -272,21 +275,21 @@ namespace VersOne.Epub.Internal break; } } + result.Content = metadataMetaNode.Value; return result; } private static EpubManifest ReadManifest(XElement manifestNode) { - EpubManifest result = new EpubManifest(); - foreach (XElement manifestItemNode in manifestNode.Elements()) - { - if (String.Compare(manifestItemNode.Name.LocalName, "item", StringComparison.OrdinalIgnoreCase) == 0) + var result = new EpubManifest(); + foreach (var manifestItemNode in manifestNode.Elements()) + if (string.Compare(manifestItemNode.Name.LocalName, "item", StringComparison.OrdinalIgnoreCase) == 0) { - EpubManifestItem manifestItem = new EpubManifestItem(); - foreach (XAttribute manifestItemNodeAttribute in manifestItemNode.Attributes()) + var manifestItem = new EpubManifestItem(); + foreach (var manifestItemNodeAttribute in manifestItemNode.Attributes()) { - string attributeValue = manifestItemNodeAttribute.Value; + var attributeValue = manifestItemNodeAttribute.Value; switch (manifestItemNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "id": @@ -312,63 +315,55 @@ namespace VersOne.Epub.Internal break; } } - if (String.IsNullOrWhiteSpace(manifestItem.Id)) - { + + if (string.IsNullOrWhiteSpace(manifestItem.Id)) throw new Exception("Incorrect EPUB manifest: item ID is missing"); - } - if (String.IsNullOrWhiteSpace(manifestItem.Href)) - { + if (string.IsNullOrWhiteSpace(manifestItem.Href)) throw new Exception("Incorrect EPUB manifest: item href is missing"); - } - if (String.IsNullOrWhiteSpace(manifestItem.MediaType)) - { + if (string.IsNullOrWhiteSpace(manifestItem.MediaType)) throw new Exception("Incorrect EPUB manifest: item media type is missing"); - } result.Add(manifestItem); } - } + return result; } private static EpubSpine ReadSpine(XElement spineNode) { - EpubSpine result = new EpubSpine(); - XAttribute tocAttribute = spineNode.Attribute("toc"); - if (tocAttribute == null || String.IsNullOrWhiteSpace(tocAttribute.Value)) - { + var result = new EpubSpine(); + var tocAttribute = spineNode.Attribute("toc"); + if (tocAttribute == null || string.IsNullOrWhiteSpace(tocAttribute.Value)) throw new Exception("Incorrect EPUB spine: TOC is missing"); - } result.Toc = tocAttribute.Value; - foreach (XElement spineItemNode in spineNode.Elements()) - { - if (String.Compare(spineItemNode.Name.LocalName, "itemref", StringComparison.OrdinalIgnoreCase) == 0) + foreach (var spineItemNode in spineNode.Elements()) + if (string.Compare(spineItemNode.Name.LocalName, "itemref", StringComparison.OrdinalIgnoreCase) == 0) { - EpubSpineItemRef spineItemRef = new EpubSpineItemRef(); - XAttribute idRefAttribute = spineItemNode.Attribute("idref"); - if (idRefAttribute == null || String.IsNullOrWhiteSpace(idRefAttribute.Value)) - { + var spineItemRef = new EpubSpineItemRef(); + var idRefAttribute = spineItemNode.Attribute("idref"); + if (idRefAttribute == null || string.IsNullOrWhiteSpace(idRefAttribute.Value)) throw new Exception("Incorrect EPUB spine: item ID ref is missing"); - } spineItemRef.IdRef = idRefAttribute.Value; - XAttribute linearAttribute = spineItemNode.Attribute("linear"); - spineItemRef.IsLinear = linearAttribute == null || String.Compare(linearAttribute.Value, "no", StringComparison.OrdinalIgnoreCase) != 0; + var linearAttribute = spineItemNode.Attribute("linear"); + spineItemRef.IsLinear = linearAttribute == null || + string.Compare(linearAttribute.Value, "no", + StringComparison.OrdinalIgnoreCase) != 0; result.Add(spineItemRef); } - } + return result; } private static EpubGuide ReadGuide(XElement guideNode) { - EpubGuide result = new EpubGuide(); - foreach (XElement guideReferenceNode in guideNode.Elements()) - { - if (String.Compare(guideReferenceNode.Name.LocalName, "reference", StringComparison.OrdinalIgnoreCase) == 0) + var result = new EpubGuide(); + foreach (var guideReferenceNode in guideNode.Elements()) + if (string.Compare(guideReferenceNode.Name.LocalName, "reference", + StringComparison.OrdinalIgnoreCase) == 0) { - EpubGuideReference guideReference = new EpubGuideReference(); - foreach (XAttribute guideReferenceNodeAttribute in guideReferenceNode.Attributes()) + var guideReference = new EpubGuideReference(); + foreach (var guideReferenceNodeAttribute in guideReferenceNode.Attributes()) { - string attributeValue = guideReferenceNodeAttribute.Value; + var attributeValue = guideReferenceNodeAttribute.Value; switch (guideReferenceNodeAttribute.Name.LocalName.ToLowerInvariant()) { case "type": @@ -382,18 +377,15 @@ namespace VersOne.Epub.Internal break; } } - if (String.IsNullOrWhiteSpace(guideReference.Type)) - { + + if (string.IsNullOrWhiteSpace(guideReference.Type)) throw new Exception("Incorrect EPUB guide: item type is missing"); - } - if (String.IsNullOrWhiteSpace(guideReference.Href)) - { + if (string.IsNullOrWhiteSpace(guideReference.Href)) throw new Exception("Incorrect EPUB guide: item href is missing"); - } result.Add(guideReference); } - } + return result; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/RootFilePathReader.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/RootFilePathReader.cs index 63c3487..16a24aa 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/RootFilePathReader.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/RootFilePathReader.cs @@ -1,5 +1,21 @@ -using System; -using System.IO; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; using System.IO.Compression; using System.Threading.Tasks; using System.Xml.Linq; @@ -11,23 +27,22 @@ namespace VersOne.Epub.Internal public static async Task GetRootFilePathAsync(ZipArchive epubArchive) { const string EPUB_CONTAINER_FILE_PATH = "META-INF/container.xml"; - ZipArchiveEntry containerFileEntry = epubArchive.GetEntry(EPUB_CONTAINER_FILE_PATH); + var containerFileEntry = epubArchive.GetEntry(EPUB_CONTAINER_FILE_PATH); if (containerFileEntry == null) - { - throw new Exception(String.Format("EPUB parsing error: {0} file not found in archive.", EPUB_CONTAINER_FILE_PATH)); - } + throw new Exception(string.Format("EPUB parsing error: {0} file not found in archive.", + EPUB_CONTAINER_FILE_PATH)); XDocument containerDocument; - using (Stream containerStream = containerFileEntry.Open()) + using (var containerStream = containerFileEntry.Open()) { containerDocument = await XmlUtils.LoadDocumentAsync(containerStream).ConfigureAwait(false); } + XNamespace cnsNamespace = "urn:oasis:names:tc:opendocument:xmlns:container"; - XAttribute fullPathAttribute = containerDocument.Element(cnsNamespace + "container")?.Element(cnsNamespace + "rootfiles")?.Element(cnsNamespace + "rootfile")?.Attribute("full-path"); + var fullPathAttribute = containerDocument.Element(cnsNamespace + "container") + ?.Element(cnsNamespace + "rootfiles")?.Element(cnsNamespace + "rootfile")?.Attribute("full-path"); if (fullPathAttribute == null) - { throw new Exception("EPUB parsing error: root file path not found in the EPUB container."); - } return fullPathAttribute.Value; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/SchemaReader.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/SchemaReader.cs index a4a00e9..f699f42 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/SchemaReader.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Readers/SchemaReader.cs @@ -1,6 +1,22 @@ -using System.IO.Compression; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.IO.Compression; using System.Threading.Tasks; -using VersOne.Epub.Schema; namespace VersOne.Epub.Internal { @@ -8,15 +24,16 @@ namespace VersOne.Epub.Internal { public static async Task ReadSchemaAsync(ZipArchive epubArchive) { - EpubSchema result = new EpubSchema(); - string rootFilePath = await RootFilePathReader.GetRootFilePathAsync(epubArchive).ConfigureAwait(false); - string contentDirectoryPath = ZipPathUtils.GetDirectoryPath(rootFilePath); + var result = new EpubSchema(); + var rootFilePath = await RootFilePathReader.GetRootFilePathAsync(epubArchive).ConfigureAwait(false); + var contentDirectoryPath = ZipPathUtils.GetDirectoryPath(rootFilePath); result.ContentDirectoryPath = contentDirectoryPath; - EpubPackage package = await PackageReader.ReadPackageAsync(epubArchive, rootFilePath).ConfigureAwait(false); + var package = await PackageReader.ReadPackageAsync(epubArchive, rootFilePath).ConfigureAwait(false); result.Package = package; - EpubNavigation navigation = await NavigationReader.ReadNavigationAsync(epubArchive, contentDirectoryPath, package).ConfigureAwait(false); + var navigation = await NavigationReader.ReadNavigationAsync(epubArchive, contentDirectoryPath, package) + .ConfigureAwait(false); result.Navigation = navigation; return result; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubBookRef.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubBookRef.cs index 95a6d88..41d998a 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubBookRef.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubBookRef.cs @@ -1,4 +1,21 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; using System.Collections.Generic; using System.IO.Compression; using System.Threading.Tasks; @@ -16,11 +33,6 @@ namespace VersOne.Epub isDisposed = false; } - ~EpubBookRef() - { - Dispose(false); - } - public string FilePath { get; set; } public string Title { get; set; } public string Author { get; set; } @@ -28,7 +40,18 @@ namespace VersOne.Epub public EpubSchema Schema { get; set; } public EpubContentRef Content { get; set; } - internal ZipArchive EpubArchive { get; private set; } + internal ZipArchive EpubArchive { get; } + + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } + + ~EpubBookRef() + { + Dispose(false); + } public byte[] ReadCover() { @@ -50,22 +73,13 @@ namespace VersOne.Epub return await Task.Run(() => ChapterReader.GetChapters(this)).ConfigureAwait(false); } - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - protected virtual void Dispose(bool disposing) { if (!isDisposed) { - if (disposing) - { - EpubArchive?.Dispose(); - } + if (disposing) EpubArchive?.Dispose(); isDisposed = true; } } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubByteContentFileRef.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubByteContentFileRef.cs index ed13eb4..2865d39 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubByteContentFileRef.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubByteContentFileRef.cs @@ -1,4 +1,21 @@ -using System.Threading.Tasks; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Threading.Tasks; namespace VersOne.Epub { @@ -19,4 +36,4 @@ namespace VersOne.Epub return ReadContentAsBytesAsync(); } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubChapterRef.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubChapterRef.cs index 1d06295..173e516 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubChapterRef.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubChapterRef.cs @@ -1,4 +1,20 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + using System.Collections.Generic; using System.Threading.Tasks; @@ -6,7 +22,7 @@ namespace VersOne.Epub { public class EpubChapterRef { - private readonly EpubTextContentFileRef epubTextContentFileRef; + private readonly EpubTextContentFileRef epubTextContentFileRef; public EpubChapterRef(EpubTextContentFileRef epubTextContentFileRef) { @@ -31,7 +47,7 @@ namespace VersOne.Epub public override string ToString() { - return String.Format("Title: {0}, Subchapter count: {1}", Title, SubChapters.Count); + return string.Format("Title: {0}, Subchapter count: {1}", Title, SubChapters.Count); } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubContentFileRef.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubContentFileRef.cs index 1e26637..5a08775 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubContentFileRef.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubContentFileRef.cs @@ -1,4 +1,21 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System; using System.IO; using System.IO.Compression; using System.Threading.Tasks; @@ -26,13 +43,14 @@ namespace VersOne.Epub public async Task ReadContentAsBytesAsync() { - ZipArchiveEntry contentFileEntry = GetContentFileEntry(); - byte[] content = new byte[(int)contentFileEntry.Length]; - using (Stream contentStream = OpenContentStream(contentFileEntry)) - using (MemoryStream memoryStream = new MemoryStream(content)) + var contentFileEntry = GetContentFileEntry(); + var content = new byte[(int) contentFileEntry.Length]; + using (var contentStream = OpenContentStream(contentFileEntry)) + using (var memoryStream = new MemoryStream(content)) { await contentStream.CopyToAsync(memoryStream).ConfigureAwait(false); } + return content; } @@ -43,8 +61,8 @@ namespace VersOne.Epub public async Task ReadContentAsTextAsync() { - using (Stream contentStream = GetContentStream()) - using (StreamReader streamReader = new StreamReader(contentStream)) + using (var contentStream = GetContentStream()) + using (var streamReader = new StreamReader(contentStream)) { return await streamReader.ReadToEndAsync().ConfigureAwait(false); } @@ -57,27 +75,24 @@ namespace VersOne.Epub private ZipArchiveEntry GetContentFileEntry() { - string contentFilePath = ZipPathUtils.Combine(epubBookRef.Schema.ContentDirectoryPath, FileName); - ZipArchiveEntry contentFileEntry = epubBookRef.EpubArchive.GetEntry(contentFilePath); + var contentFilePath = ZipPathUtils.Combine(epubBookRef.Schema.ContentDirectoryPath, FileName); + var contentFileEntry = epubBookRef.EpubArchive.GetEntry(contentFilePath); if (contentFileEntry == null) - { - throw new Exception(String.Format("EPUB parsing error: file {0} not found in archive.", contentFilePath)); - } - if (contentFileEntry.Length > Int32.MaxValue) - { - throw new Exception(String.Format("EPUB parsing error: file {0} is bigger than 2 Gb.", contentFilePath)); - } + throw new Exception( + string.Format("EPUB parsing error: file {0} not found in archive.", contentFilePath)); + if (contentFileEntry.Length > int.MaxValue) + throw new Exception(string.Format("EPUB parsing error: file {0} is bigger than 2 Gb.", + contentFilePath)); return contentFileEntry; } private Stream OpenContentStream(ZipArchiveEntry contentFileEntry) { - Stream contentStream = contentFileEntry.Open(); + var contentStream = contentFileEntry.Open(); if (contentStream == null) - { - throw new Exception(String.Format("Incorrect EPUB file: content file \"{0}\" specified in manifest is not found.", FileName)); - } + throw new Exception(string.Format( + "Incorrect EPUB file: content file \"{0}\" specified in manifest is not found.", FileName)); return contentStream; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubContentRef.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubContentRef.cs index 0ee82a1..aca3745 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubContentRef.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubContentRef.cs @@ -1,4 +1,21 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub { @@ -10,4 +27,4 @@ namespace VersOne.Epub public Dictionary Fonts { get; set; } public Dictionary AllFiles { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubTextContentFileRef.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubTextContentFileRef.cs index 4f6f269..39d3ff6 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubTextContentFileRef.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/RefEntities/EpubTextContentFileRef.cs @@ -1,4 +1,21 @@ -using System.Threading.Tasks; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Threading.Tasks; namespace VersOne.Epub { @@ -19,4 +36,4 @@ namespace VersOne.Epub return ReadContentAsTextAsync(); } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigation.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigation.cs index cd72147..40af42e 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigation.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigation.cs @@ -1,4 +1,21 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub.Schema { @@ -11,4 +28,4 @@ namespace VersOne.Epub.Schema public EpubNavigationPageList PageList { get; set; } public List NavLists { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationContent.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationContent.cs index d1fab6f..3772db5 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationContent.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationContent.cs @@ -1,4 +1,19 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . namespace VersOne.Epub.Schema { @@ -9,7 +24,7 @@ namespace VersOne.Epub.Schema public override string ToString() { - return String.Concat("Source: " + Source); + return string.Concat("Source: " + Source); } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationDocAuthor.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationDocAuthor.cs index 21b1fb4..0bb4102 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationDocAuthor.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationDocAuthor.cs @@ -1,8 +1,25 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub.Schema { public class EpubNavigationDocAuthor : List { } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationDocTitle.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationDocTitle.cs index 8a48fa0..56318d5 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationDocTitle.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationDocTitle.cs @@ -1,8 +1,25 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub.Schema { public class EpubNavigationDocTitle : List { } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationHead.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationHead.cs index fb00035..590f183 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationHead.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationHead.cs @@ -1,8 +1,25 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub.Schema { public class EpubNavigationHead : List { } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationHeadMeta.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationHeadMeta.cs index d6637b4..c869263 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationHeadMeta.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationHeadMeta.cs @@ -1,4 +1,21 @@ -namespace VersOne.Epub.Schema +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace VersOne.Epub.Schema { public class EpubNavigationHeadMeta { @@ -6,4 +23,4 @@ public string Content { get; set; } public string Scheme { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationLabel.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationLabel.cs index 97e5802..d2407c5 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationLabel.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationLabel.cs @@ -1,4 +1,21 @@ -namespace VersOne.Epub.Schema +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace VersOne.Epub.Schema { public class EpubNavigationLabel { @@ -9,4 +26,4 @@ return Text; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationList.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationList.cs index 325ce50..d68b76e 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationList.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationList.cs @@ -1,4 +1,21 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub.Schema { @@ -9,4 +26,4 @@ namespace VersOne.Epub.Schema public List NavigationLabels { get; set; } public List NavigationTargets { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationMap.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationMap.cs index dc01371..14f7a27 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationMap.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationMap.cs @@ -1,8 +1,25 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub.Schema { public class EpubNavigationMap : List { } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPageList.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPageList.cs index 8aae30e..3e59a3a 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPageList.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPageList.cs @@ -1,8 +1,25 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub.Schema { public class EpubNavigationPageList : List { } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPageTarget.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPageTarget.cs index bb0b395..19effb7 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPageTarget.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPageTarget.cs @@ -1,4 +1,21 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub.Schema { @@ -12,4 +29,4 @@ namespace VersOne.Epub.Schema public List NavigationLabels { get; set; } public EpubNavigationContent Content { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPageTargetType.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPageTargetType.cs index a930f71..2a31bb6 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPageTargetType.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPageTargetType.cs @@ -1,4 +1,21 @@ -namespace VersOne.Epub.Schema +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace VersOne.Epub.Schema { public enum EpubNavigationPageTargetType { @@ -6,4 +23,4 @@ NORMAL, SPECIAL } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPoint.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPoint.cs index 084e8f6..ab4115b 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPoint.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationPoint.cs @@ -1,4 +1,20 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + using System.Collections.Generic; namespace VersOne.Epub.Schema @@ -14,7 +30,7 @@ namespace VersOne.Epub.Schema public override string ToString() { - return String.Format("Id: {0}, Content.Source: {1}", Id, Content.Source); + return string.Format("Id: {0}, Content.Source: {1}", Id, Content.Source); } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationTarget.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationTarget.cs index ea5ac2a..a035020 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationTarget.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Navigation/EpubNavigationTarget.cs @@ -1,4 +1,21 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub.Schema { @@ -11,4 +28,4 @@ namespace VersOne.Epub.Schema public List NavigationLabels { get; set; } public EpubNavigationContent Content { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubGuide.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubGuide.cs index 8bb0f6e..cd505ce 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubGuide.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubGuide.cs @@ -1,8 +1,25 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub.Schema { public class EpubGuide : List { } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubGuideReference.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubGuideReference.cs index 69f488b..6a3fef1 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubGuideReference.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubGuideReference.cs @@ -1,4 +1,19 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . namespace VersOne.Epub.Schema { @@ -10,7 +25,7 @@ namespace VersOne.Epub.Schema public override string ToString() { - return String.Format("Type: {0}, Href: {1}", Type, Href); + return string.Format("Type: {0}, Href: {1}", Type, Href); } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubManifest.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubManifest.cs index d1464aa..e29d87b 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubManifest.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubManifest.cs @@ -1,8 +1,25 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub.Schema { public class EpubManifest : List { } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubManifestItem.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubManifestItem.cs index 4181589..b047810 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubManifestItem.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubManifestItem.cs @@ -1,4 +1,19 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . namespace VersOne.Epub.Schema { @@ -14,7 +29,7 @@ namespace VersOne.Epub.Schema public override string ToString() { - return String.Format("Id: {0}, Href = {1}, MediaType = {2}", Id, Href, MediaType); + return string.Format("Id: {0}, Href = {1}, MediaType = {2}", Id, Href, MediaType); } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadata.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadata.cs index e27f77a..98465e4 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadata.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadata.cs @@ -1,4 +1,21 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub.Schema { @@ -21,4 +38,4 @@ namespace VersOne.Epub.Schema public List Rights { get; set; } public List MetaItems { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataContributor.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataContributor.cs index 8a89819..1108fc2 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataContributor.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataContributor.cs @@ -1,4 +1,21 @@ -namespace VersOne.Epub.Schema +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace VersOne.Epub.Schema { public class EpubMetadataContributor { @@ -6,4 +23,4 @@ public string FileAs { get; set; } public string Role { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataCreator.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataCreator.cs index 015b840..c391578 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataCreator.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataCreator.cs @@ -1,4 +1,21 @@ -namespace VersOne.Epub.Schema +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace VersOne.Epub.Schema { public class EpubMetadataCreator { @@ -6,4 +23,4 @@ public string FileAs { get; set; } public string Role { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataDate.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataDate.cs index 7e882ec..816aed5 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataDate.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataDate.cs @@ -1,8 +1,25 @@ -namespace VersOne.Epub.Schema +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace VersOne.Epub.Schema { public class EpubMetadataDate { public string Date { get; set; } public string Event { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataIdentifier.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataIdentifier.cs index 61d3c2f..c46699f 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataIdentifier.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataIdentifier.cs @@ -1,4 +1,21 @@ -namespace VersOne.Epub.Schema +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace VersOne.Epub.Schema { public class EpubMetadataIdentifier { @@ -6,4 +23,4 @@ public string Scheme { get; set; } public string Identifier { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataMeta.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataMeta.cs index 133199d..6a3eda3 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataMeta.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubMetadataMeta.cs @@ -1,4 +1,21 @@ -namespace VersOne.Epub.Schema +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace VersOne.Epub.Schema { public class EpubMetadataMeta { @@ -9,4 +26,4 @@ public string Property { get; set; } public string Scheme { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubPackage.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubPackage.cs index 91efedd..75d1723 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubPackage.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubPackage.cs @@ -1,4 +1,21 @@ -namespace VersOne.Epub.Schema +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace VersOne.Epub.Schema { public class EpubPackage { @@ -8,4 +25,4 @@ public EpubSpine Spine { get; set; } public EpubGuide Guide { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubSpine.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubSpine.cs index 022db95..5a8502f 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubSpine.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubSpine.cs @@ -1,4 +1,21 @@ -using System.Collections.Generic; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.Collections.Generic; namespace VersOne.Epub.Schema { @@ -6,4 +23,4 @@ namespace VersOne.Epub.Schema { public string Toc { get; set; } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubSpineItemRef.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubSpineItemRef.cs index c239f95..5d87d77 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubSpineItemRef.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubSpineItemRef.cs @@ -1,4 +1,19 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . namespace VersOne.Epub.Schema { @@ -9,7 +24,7 @@ namespace VersOne.Epub.Schema public override string ToString() { - return String.Concat("IdRef: ", IdRef); + return string.Concat("IdRef: ", IdRef); } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubVersion.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubVersion.cs index b208e06..3b7b927 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubVersion.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Schema/Opf/EpubVersion.cs @@ -1,8 +1,25 @@ -namespace VersOne.Epub.Schema +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +namespace VersOne.Epub.Schema { public enum EpubVersion { EPUB_2 = 2, EPUB_3 } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Utils/XmlUtils.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Utils/XmlUtils.cs index 95b8bcd..0c5dade 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Utils/XmlUtils.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Utils/XmlUtils.cs @@ -1,4 +1,21 @@ -using System.IO; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + +using System.IO; using System.Threading.Tasks; using System.Xml; using System.Xml.Linq; @@ -9,20 +26,20 @@ namespace VersOne.Epub.Internal { public static async Task LoadDocumentAsync(Stream stream) { - using (MemoryStream memoryStream = new MemoryStream()) + using (var memoryStream = new MemoryStream()) { await stream.CopyToAsync(memoryStream).ConfigureAwait(false); memoryStream.Position = 0; - XmlReaderSettings xmlReaderSettings = new XmlReaderSettings + var xmlReaderSettings = new XmlReaderSettings { DtdProcessing = DtdProcessing.Ignore, Async = true }; - using (XmlReader xmlReader = XmlReader.Create(memoryStream, xmlReaderSettings)) + using (var xmlReader = XmlReader.Create(memoryStream, xmlReaderSettings)) { return await Task.Run(() => XDocument.Load(memoryStream)).ConfigureAwait(false); } } } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Utils/ZipPathUtils.cs b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Utils/ZipPathUtils.cs index e295dbb..1432750 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Utils/ZipPathUtils.cs +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubReader/Utils/ZipPathUtils.cs @@ -1,4 +1,19 @@ -using System; +// Copyright © 2018 Marco Gavelli and Paddy Xu +// +// This file is part of QuickLook program. +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . namespace VersOne.Epub.Internal { @@ -6,27 +21,17 @@ namespace VersOne.Epub.Internal { public static string GetDirectoryPath(string filePath) { - int lastSlashIndex = filePath.LastIndexOf('/'); + var lastSlashIndex = filePath.LastIndexOf('/'); if (lastSlashIndex == -1) - { - return String.Empty; - } - else - { - return filePath.Substring(0, lastSlashIndex); - } + return string.Empty; + return filePath.Substring(0, lastSlashIndex); } public static string Combine(string directory, string fileName) { - if (String.IsNullOrEmpty(directory)) - { + if (string.IsNullOrEmpty(directory)) return fileName; - } - else - { - return String.Concat(directory, "/", fileName); - } + return string.Concat(directory, "/", fileName); } } -} +} \ No newline at end of file diff --git a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubViewerControl.xaml b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubViewerControl.xaml index c3b9390..558096d 100644 --- a/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubViewerControl.xaml +++ b/QuickLook.Plugin/QuickLook.Plugin.EpubViewer/EpubViewerControl.xaml @@ -1,11 +1,10 @@  @@ -16,31 +15,14 @@ - - - - - - - -