fix macos book opening
This commit is contained in:
2 files changed
+16
-14
No files matched your search
@@ -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;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user