fix macos book opening

This commit is contained in:
Agel committed 2026-04-17 11:14:52 +02:00
1 parent 0c17c7d351
commit f80fefa34f
2 files changed
+16 -14

No files matched your search

+4 -2
View File
@@ -81,11 +81,12 @@ void Book::openImpl(const QString &filePath)
m_openFuture = QtConcurrent::run([this, filePath, generation]() {
auto reader = m_factory.create(filePath);
if (!reader) {
QMetaObject::invokeMethod(this, [this, generation]() {
QMetaObject::invokeMethod(this, [this, generation, filePath]() {
if (generation != m_openGeneration) return;
m_loading = false;
emit loadingChanged();
m_errorMessage = QStringLiteral("No format reader available for this file type");
qWarning() << "Book load failed:" << filePath << "—" << m_errorMessage;
emit errorMessageChanged();
}, Qt::QueuedConnection);
return;
@@ -93,11 +94,12 @@ void Book::openImpl(const QString &filePath)
if (!reader->open(filePath)) {
const QString err = reader->lastError();
QMetaObject::invokeMethod(this, [this, generation, err]() {
QMetaObject::invokeMethod(this, [this, generation, filePath, err]() {
if (generation != m_openGeneration) return;
m_loading = false;
emit loadingChanged();
m_errorMessage = err;
qWarning() << "Book load failed:" << filePath << "—" << m_errorMessage;
emit errorMessageChanged();
}, Qt::QueuedConnection);
return;
+12 -12
View File
@@ -8,6 +8,8 @@
#include <uchardet/uchardet.h>
#include <iconv.h>
#include <fstream>
static constexpr int kChunkSize = 4096;
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)
{
QFile file(filePath);
if (!file.exists()) {
m_error = QStringLiteral("File not found: ") + filePath;
// Use std::ifstream to bypass Qt's CFStringGetFileSystemRepresentation() on macOS,
// which re-normalizes paths to NFD and breaks NFC filenames on SMB/ZFS mounts.
std::ifstream f(filePath.toUtf8().constData(), std::ios::binary | std::ios::ate);
if (!f) {
m_error = QStringLiteral("Cannot open file: ") + filePath;
return false;
}
if (!file.open(QIODevice::ReadOnly)) {
m_error = QStringLiteral("Cannot open file: ") + file.errorString();
return false;
}
QByteArray raw = file.readAll();
file.close();
const auto size = f.tellg();
f.seekg(0);
QByteArray raw(static_cast<int>(size), '\0');
f.read(raw.data(), size);
m_contentHash = QCryptographicHash::hash(raw, QCryptographicHash::Md5);
@@ -145,8 +146,7 @@ bool TxtReader::open(const QString &filePath)
bool TxtReader::loadMetadata(const QString &filePath)
{
QFile file(filePath);
if (!file.exists()) {
if (!std::ifstream(filePath.toUtf8().constData())) {
m_error = QStringLiteral("File not found: ") + filePath;
return false;
}