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);
57 ulog_cpp::Reader reader(handler);
58 reader.readChunk(
reinterpret_cast<const uint8_t *
>(raw),
static_cast<size_t>(fileSize));
60 if (handler->hadFatalError()) {
62 result.
errorMessage = QCoreApplication::translate(
"LogFileParser",
"Fatal error while parsing ULog file");
67 if (!handler->isHeaderComplete()) {
68 result.
errorMessage = QCoreApplication::translate(
"LogFileParser",
"ULog file header is incomplete or corrupt");