fix macos book opening
This commit is contained in:
2 files changed
+16
-14
No files matched your search
@@ -81,11 +81,12 @@ void Book::openImpl(const QString &filePath)
|
|||||||
m_openFuture = QtConcurrent::run([this, filePath, generation]() {
|
m_openFuture = QtConcurrent::run([this, filePath, generation]() {
|
||||||
auto reader = m_factory.create(filePath);
|
auto reader = m_factory.create(filePath);
|
||||||
if (!reader) {
|
if (!reader) {
|
||||||
QMetaObject::invokeMethod(this, [this, generation]() {
|
QMetaObject::invokeMethod(this, [this, generation, filePath]() {
|
||||||
if (generation != m_openGeneration) return;
|
if (generation != m_openGeneration) return;
|
||||||
m_loading = false;
|
m_loading = false;
|
||||||
emit loadingChanged();
|
emit loadingChanged();
|
||||||
m_errorMessage = QStringLiteral("No format reader available for this file type");
|
m_errorMessage = QStringLiteral("No format reader available for this file type");
|
||||||
|
qWarning() << "Book load failed:" << filePath << "—" << m_errorMessage;
|
||||||
emit errorMessageChanged();
|
emit errorMessageChanged();
|
||||||
}, Qt::QueuedConnection);
|
}, Qt::QueuedConnection);
|
||||||
return;
|
return;
|
||||||
@@ -93,11 +94,12 @@ void Book::openImpl(const QString &filePath)
|
|||||||
|
|
||||||
if (!reader->open(filePath)) {
|
if (!reader->open(filePath)) {
|
||||||
const QString err = reader->lastError();
|
const QString err = reader->lastError();
|
||||||
QMetaObject::invokeMethod(this, [this, generation, err]() {
|
QMetaObject::invokeMethod(this, [this, generation, filePath, err]() {
|
||||||
if (generation != m_openGeneration) return;
|
if (generation != m_openGeneration) return;
|
||||||
m_loading = false;
|
m_loading = false;
|
||||||
emit loadingChanged();
|
emit loadingChanged();
|
||||||
m_errorMessage = err;
|
m_errorMessage = err;
|
||||||
|
qWarning() << "Book load failed:" << filePath << "—" << m_errorMessage;
|
||||||
emit errorMessageChanged();
|
emit errorMessageChanged();
|
||||||
}, Qt::QueuedConnection);
|
}, Qt::QueuedConnection);
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -8,6 +8,8 @@
|
|||||||
#include <uchardet/uchardet.h>
|
#include <uchardet/uchardet.h>
|
||||||
#include <iconv.h>
|
#include <iconv.h>
|
||||||
|
|
||||||
|
#include <fstream>
|
||||||
|
|
||||||
static constexpr int kChunkSize = 4096;
|
static constexpr int kChunkSize = 4096;
|
||||||
|
|
||||||
static QString decodeWithIconv(const QByteArray &raw, const char *charset)
|
static QString decodeWithIconv(const QByteArray &raw, const char *charset)
|
||||||
@@ -98,18 +100,17 @@ static QStringList splitRawText(const QString &content)
|
|||||||
|
|
||||||
bool TxtReader::open(const QString &filePath)
|
bool TxtReader::open(const QString &filePath)
|
||||||
{
|
{
|
||||||
QFile file(filePath);
|
// Use std::ifstream to bypass Qt's CFStringGetFileSystemRepresentation() on macOS,
|
||||||
if (!file.exists()) {
|
// which re-normalizes paths to NFD and breaks NFC filenames on SMB/ZFS mounts.
|
||||||
m_error = QStringLiteral("File not found: ") + filePath;
|
std::ifstream f(filePath.toUtf8().constData(), std::ios::binary | std::ios::ate);
|
||||||
|
if (!f) {
|
||||||
|
m_error = QStringLiteral("Cannot open file: ") + filePath;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!file.open(QIODevice::ReadOnly)) {
|
const auto size = f.tellg();
|
||||||
m_error = QStringLiteral("Cannot open file: ") + file.errorString();
|
f.seekg(0);
|
||||||
return false;
|
QByteArray raw(static_cast<int>(size), '\0');
|
||||||
}
|
f.read(raw.data(), size);
|
||||||
|
|
||||||
QByteArray raw = file.readAll();
|
|
||||||
file.close();
|
|
||||||
|
|
||||||
m_contentHash = QCryptographicHash::hash(raw, QCryptographicHash::Md5);
|
m_contentHash = QCryptographicHash::hash(raw, QCryptographicHash::Md5);
|
||||||
|
|
||||||
@@ -145,8 +146,7 @@ bool TxtReader::open(const QString &filePath)
|
|||||||
|
|
||||||
bool TxtReader::loadMetadata(const QString &filePath)
|
bool TxtReader::loadMetadata(const QString &filePath)
|
||||||
{
|
{
|
||||||
QFile file(filePath);
|
if (!std::ifstream(filePath.toUtf8().constData())) {
|
||||||
if (!file.exists()) {
|
|
||||||
m_error = QStringLiteral("File not found: ") + filePath;
|
m_error = QStringLiteral("File not found: ") + filePath;
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user