21 if (!file.open(QIODevice::ReadOnly)) {
22 result.
errorMessage = QCoreApplication::translate(
"LogFileParser",
"Failed to open file");
26 const qint64 fileSize = file.size();
28 result.
errorMessage = QCoreApplication::translate(
"LogFileParser",
"File is empty");
31 if (fileSize > std::numeric_limits<qsizetype>::max()) {
32 result.
errorMessage = QCoreApplication::translate(
"LogFileParser",
"File is too large to parse");
36 uchar *
const mappedData = file.map(0, fileSize);
37 if (mappedData ==
nullptr) {
38 result.
errorMessage = QCoreApplication::translate(
"LogFileParser",
"Failed to memory-map file");
44 uchar *data =
nullptr;
45 ~ScopedUnmap() {
if (data) { file.unmap(data); } }
46 } scopedUnmap{file, mappedData};
48 const char *
const raw =
reinterpret_cast<const char *
>(mappedData);
52 result.
errorMessage = QCoreApplication::translate(
"LogFileParser",
"File does not appear to be a ULog file (invalid header)");
56 auto handler = std::make_shared<ULogFullHandler>(result, progressCallback);
57 ulog_cpp::Reader reader(handler);
59 static constexpr qint64 kChunkSize = 64 * 1024;
61 while (offset < fileSize) {
62 const qint64 remaining = fileSize - offset;
63 const qint64 chunk = (remaining < kChunkSize) ? remaining : kChunkSize;
64 reader.readChunk(
reinterpret_cast<const uint8_t *
>(raw) + offset,
static_cast<size_t>(chunk));
66 if (cancelToken && cancelToken->load(std::memory_order_relaxed)) {
69 if (progressCallback) {
70 progressCallback(
static_cast<float>(offset) /
static_cast<float>(fileSize));
74 if (handler->hadFatalError()) {
76 result.
errorMessage = QCoreApplication::translate(
"LogFileParser",
"Fatal error while parsing ULog file");
81 if (!handler->isHeaderComplete()) {
82 result.
errorMessage = QCoreApplication::translate(
"LogFileParser",
"ULog file header is incomplete or corrupt");