Some refactor
This commit is contained in:
37 files changed
+1599
-981
No files matched your search
@@ -1,7 +1,9 @@
|
||||
#include "EpubReader.h"
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QDir>
|
||||
#include <QDomDocument>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QTextStream>
|
||||
#include <QUrl>
|
||||
@@ -35,6 +37,14 @@ bool EpubReader::open(const QString &filePath)
|
||||
m_spineHrefs.clear();
|
||||
m_spineRawContent.clear();
|
||||
m_toc.clear();
|
||||
m_contentHash.clear();
|
||||
|
||||
// Compute content hash from raw file bytes before ZIP parsing
|
||||
{
|
||||
QFile f(filePath);
|
||||
if (f.open(QIODevice::ReadOnly))
|
||||
m_contentHash = QCryptographicHash::hash(f.readAll(), QCryptographicHash::Md5);
|
||||
}
|
||||
|
||||
unzFile zf = unzOpen(filePath.toUtf8().constData());
|
||||
if (!zf) {
|
||||
@@ -390,6 +400,11 @@ QString EpubReader::filePath()
|
||||
return m_filePath;
|
||||
}
|
||||
|
||||
QByteArray EpubReader::contentHash()
|
||||
{
|
||||
return m_contentHash;
|
||||
}
|
||||
|
||||
Chapter EpubReader::loadChapter(int index)
|
||||
{
|
||||
if (index < 0 || index >= m_spineRawContent.size())
|
||||
|
||||
@@ -18,9 +18,11 @@ public:
|
||||
QString title() override;
|
||||
QString author() override;
|
||||
QString coverImagePath() override;
|
||||
QByteArray contentHash() override;
|
||||
|
||||
private:
|
||||
QString m_filePath;
|
||||
QByteArray m_contentHash;
|
||||
QString m_title;
|
||||
QString m_author;
|
||||
QString m_error;
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "TxtReader.h"
|
||||
|
||||
#include <QCryptographicHash>
|
||||
#include <QFileInfo>
|
||||
#include <QRegularExpression>
|
||||
#include <QTextStream>
|
||||
@@ -110,6 +111,8 @@ bool TxtReader::open(const QString &filePath)
|
||||
QByteArray raw = file.readAll();
|
||||
file.close();
|
||||
|
||||
m_contentHash = QCryptographicHash::hash(raw, QCryptographicHash::Md5);
|
||||
|
||||
uchardet_t ud = uchardet_new();
|
||||
if (uchardet_handle_data(ud, raw.constData(), raw.size()) == 0) {
|
||||
uchardet_data_end(ud);
|
||||
@@ -206,3 +209,8 @@ QString TxtReader::coverImagePath()
|
||||
{
|
||||
return {};
|
||||
}
|
||||
|
||||
QByteArray TxtReader::contentHash()
|
||||
{
|
||||
return m_contentHash;
|
||||
}
|
||||
@@ -15,6 +15,7 @@ public:
|
||||
QString title() override;
|
||||
QString author() override;
|
||||
QString coverImagePath() override;
|
||||
QByteArray contentHash() override;
|
||||
|
||||
private:
|
||||
QString m_content;
|
||||
@@ -22,6 +23,7 @@ private:
|
||||
QString m_title;
|
||||
QString m_author;
|
||||
QString m_error;
|
||||
QByteArray m_contentHash;
|
||||
};
|
||||
|
||||
#endif // TXTREADER_H
|
||||
Reference in new issue
Block a user