mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-06 03:50:19 +02:00
implemented OEBEncryptionReader; fixed container.xml search
This commit is contained in:
parent
60032f42ef
commit
480d3d1398
10 changed files with 139 additions and 16 deletions
|
@ -28,6 +28,7 @@
|
|||
|
||||
#include "OEBPlugin.h"
|
||||
#include "OEBMetaInfoReader.h"
|
||||
#include "OEBEncryptionReader.h"
|
||||
#include "OEBUidReader.h"
|
||||
#include "OEBBookReader.h"
|
||||
#include "OEBCoverReader.h"
|
||||
|
@ -77,6 +78,12 @@ const std::string OEBPlugin::supportedFileType() const {
|
|||
return "ePub";
|
||||
}
|
||||
|
||||
ZLFile OEBPlugin::epubFile(const ZLFile &oebFile) {
|
||||
const ZLFile epub = oebFile.extension() == OPF ? oebFile.getContainerArchive() : oebFile;
|
||||
epub.forceArchiveType(ZLFile::ZIP);
|
||||
return epub;
|
||||
}
|
||||
|
||||
ZLFile OEBPlugin::opfFile(const ZLFile &oebFile) {
|
||||
//ZLLogger::Instance().registerClass("epub");
|
||||
|
||||
|
@ -86,27 +93,25 @@ ZLFile OEBPlugin::opfFile(const ZLFile &oebFile) {
|
|||
|
||||
ZLLogger::Instance().println("epub", "Looking for opf file in " + oebFile.path());
|
||||
|
||||
shared_ptr<ZLDir> oebDir = oebFile.directory();
|
||||
if (!oebDir.isNull()) {
|
||||
const ZLFile containerInfoFile(oebDir->itemPath("META-INF/container.xml"));
|
||||
if (containerInfoFile.exists()) {
|
||||
ZLLogger::Instance().println("epub", "Found container file " + containerInfoFile.path());
|
||||
ContainerFileReader reader;
|
||||
reader.readDocument(containerInfoFile);
|
||||
const std::string &opfPath = reader.rootPath();
|
||||
ZLLogger::Instance().println("epub", "opf path = " + opfPath);
|
||||
if (!opfPath.empty()) {
|
||||
return ZLFile(oebDir->itemPath(opfPath));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
oebFile.forceArchiveType(ZLFile::ZIP);
|
||||
shared_ptr<ZLDir> zipDir = oebFile.directory(false);
|
||||
if (zipDir.isNull()) {
|
||||
ZLLogger::Instance().println("epub", "Couldn't open zip archive");
|
||||
return ZLFile::NO_FILE;
|
||||
}
|
||||
|
||||
const ZLFile containerInfoFile(zipDir->itemPath("META-INF/container.xml"));
|
||||
if (containerInfoFile.exists()) {
|
||||
ZLLogger::Instance().println("epub", "Found container file " + containerInfoFile.path());
|
||||
ContainerFileReader reader;
|
||||
reader.readDocument(containerInfoFile);
|
||||
const std::string &opfPath = reader.rootPath();
|
||||
ZLLogger::Instance().println("epub", "opf path = " + opfPath);
|
||||
if (!opfPath.empty()) {
|
||||
return ZLFile(zipDir->itemPath(opfPath));
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> fileNames;
|
||||
zipDir->collectFiles(fileNames, false);
|
||||
for (std::vector<std::string>::const_iterator it = fileNames.begin(); it != fileNames.end(); ++it) {
|
||||
|
@ -124,12 +129,18 @@ bool OEBPlugin::readMetaInfo(Book &book) const {
|
|||
return OEBMetaInfoReader(book).readMetaInfo(opfFile(file));
|
||||
}
|
||||
|
||||
std::string OEBPlugin::readEncryptionType(Book &book) const {
|
||||
return OEBEncryptionReader().readEncryptionInfo(epubFile(book.file()));
|
||||
}
|
||||
|
||||
bool OEBPlugin::readUids(Book &book) const {
|
||||
const ZLFile &file = book.file();
|
||||
return OEBUidReader(book).readUids(opfFile(file));
|
||||
}
|
||||
|
||||
bool OEBPlugin::readModel(BookModel &model) const {
|
||||
ZLLogger::Instance().registerClass("encryption");
|
||||
ZLLogger::Instance().println("encryption", "ENCRYPTION TYPE = " + readEncryptionType(*model.book()));
|
||||
const ZLFile &file = model.book()->file();
|
||||
return OEBBookReader(model).readBook(opfFile(file));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue