Skip to content

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
yyhran committed Apr 2, 2022
1 parent aa88422 commit 7f9c2a3
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 15 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.9)

project(Reader LANGUAGES C CXX
VERSION 0.2.3
VERSION 0.2.4
DESCRIPTION "a simple epub-file reader"
HOMEPAGE_URL "https://github.com/ang-ao/epubreader"
)
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- 无法使用 `runOnRam` 模式,目前仅能将书解压至本地后读取(`v0.1.0` 以来)
- ~~打开一本书后再打开一本新书会崩溃(`v0.2.0` 更新后)~~`v0.2.2` 修复)
- ~~目录重名会导致打开文件路径被覆盖问题(`v0.2.2` 发现)~~`v0.2.3` 修复)
- 部分格式的 `epub` 文件无法打开

---
TODO:
Expand Down
35 changes: 25 additions & 10 deletions src/edocument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ namespace EPUB {
Document::Document(const QString& fileName, QObject* parent)
: QTextDocument(parent)
, _fileName(fileName)
, _baseRefDir("")
, _openedFile("")
, _runOnRam(false)
, _opened(false)
Expand Down Expand Up @@ -141,7 +142,7 @@ auto Document::getDomElementFromXml(const QByteArray& xml, bool usenamespace) ->
if(document.setContent(xml, usenamespace))
{
QDomElement node = document.documentElement();
EPUBDEBUG() << "sucess getDomElementFromXml first tagName: " << node.tagName();
EPUBDEBUG() << "sucess getDomElementFromXml first tagName: " << node.tagName() << __LINE__;
return node;
}

Expand All @@ -156,7 +157,7 @@ auto Document::metaReader(QByteArray& xml) -> bool
QDomNodeList der = root.elementsByTagName("rootfile");
if(0 == der.count())
{
EPUBWARNING() << "unable to get place from file content.opf, inside META-INF/container.xml";
EPUBWARNING() << "unable to get place from file content.opf, inside META-INF/container.xml" << __LINE__;
return ret;
}
this->_metaData.remove(containerFile);
Expand All @@ -166,14 +167,14 @@ auto Document::metaReader(QByteArray& xml) -> bool
{
QDomElement node = der.at(i).toElement();
contentFile = node.attribute("full-path"); // content.opf
if(0 == contentFile.size())
{
EPUBWARNING() << "unable to get place from file content.opf, inside META-INF/container.xml" << __LINE__;
return false;
}
EPUBDEBUG() << "Start on file:" << contentFile << __LINE__;
}

if(0 == contentFile.size())
{
EPUBWARNING() << "unable to get place from file content.opf, inside META-INF/container.xml";
return false;
}
if(contentFile.contains("/"))
{
this->_baseRefDir = contentFile.left(contentFile.lastIndexOf("/")) + "/";
Expand Down Expand Up @@ -202,6 +203,16 @@ auto Document::metaReader(QByteArray& xml) -> bool
tocFile = nodepager.attribute("href");
}
}
if(0 == tocFile.size())
{
EPUBDEBUG() << "unable to get place from file toc.ncx, inside content.opf" << __LINE__;
return false;
}
else
{
tocFile = this->_baseRefDir + tocFile;
}

EPUBDEBUG() << "get toc from " << tocFile << __LINE__;

QDomNodeList navitom = this->getPageName(tocFile, "navMap");
Expand All @@ -228,7 +239,7 @@ auto Document::readMenu(const QDomElement& element, const QString& text) -> bool
toc.order = child.attribute("playOrder").toInt();
QDomElement tmp = child.firstChildElement();
toc.text = tmp.firstChildElement().firstChild().toText().data();
toc.src = tmp.nextSiblingElement().attribute("src");
toc.src = this->_baseRefDir + tmp.nextSiblingElement().attribute("src");
this->_toc.append(toc);
this->readMenu(child, toc.text); // read submenu
}
Expand Down Expand Up @@ -308,7 +319,9 @@ auto Document::changePath(const QString& name, QByteArray& xml) -> void

auto Document::getPageName(const QString fileName, const QString tag) -> QDomNodeList
{
EPUBDEBUG() << "Request GetPageName: file_name/tag" << fileName << " : " << tag << " current actioncycle.";
EPUBDEBUG() << "Request GetPageName: file_name/tag" << fileName
<< " : " << tag
<< " current actioncycle." << __LINE__;

QDomNodeList defineterror;

Expand All @@ -322,7 +335,9 @@ auto Document::getPageName(const QString fileName, const QString tag) -> QDomNod
if(der.count() > 0) return der;
else if(dera.count() > 0) return dera;

EPUBDEBUG() << "Request Error: " << fileName << ":" << tag << " export FAIL!....";
EPUBDEBUG() << "Request Error: " << fileName
<< ":" << tag
<< " export FAIL!...." << __LINE__;
return defineterror;
}

Expand Down
4 changes: 0 additions & 4 deletions src/edocument.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
#include <QCoreApplication>
#include <QTextCursor>

#define refill QObject::tr
#define recit2 QString::toStdString

#if 0
#define EPUBDEBUG qDebug
#define EPUBWARNING qWarning
Expand All @@ -19,7 +16,6 @@
#endif

#define METAINFOCONTAINERFILE QLatin1String("META-INF/container.xml")
#define CONTENENTOPFFILE QLatin1String("content.opf")

namespace EPUB {

Expand Down

0 comments on commit 7f9c2a3

Please sign in to comment.