Code reformat and UI tweaks

This commit is contained in:
Paddy Xu
2018-07-24 22:06:06 +03:00
parent c1733a39fd
commit e7aee219b3
59 changed files with 1490 additions and 703 deletions

View File

@@ -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 <http://www.gnu.org/licenses/>.
using System;
using System.IO;
using System.IO.Compression;
using System.Threading.Tasks;
@@ -26,13 +43,14 @@ namespace VersOne.Epub
public async Task<byte[]> 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<string> 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;
}
}
}
}