QGroundControl
Ground Control Station for MAVLink Drones
Loading...
Searching...
No Matches
QGCDecompressDevice.cc
Go to the documentation of this file.
3
4#include <archive.h>
5#include <archive_entry.h>
6
7QGC_LOGGING_CATEGORY(QGCDecompressDeviceLog, "Utilities.QGCDecompressDevice")
8
9// ============================================================================
10// Constructors
11// ============================================================================
12
13QGCDecompressDevice::QGCDecompressDevice(QIODevice *source, QObject *parent)
14 : QGCArchiveDeviceBase(source, parent)
15{
16}
17
18QGCDecompressDevice::QGCDecompressDevice(const QString &filePath, QObject *parent)
19 : QGCArchiveDeviceBase(filePath, parent)
20{
21}
22
23// ============================================================================
24// QIODevice Interface
25// ============================================================================
26
27bool QGCDecompressDevice::open(OpenMode mode)
28{
29 if (mode != ReadOnly) {
30 _errorString = QStringLiteral("QGCDecompressDevice only supports ReadOnly mode");
31 return false;
32 }
33
34 // Handle file path constructor
35 if (!_filePath.isEmpty()) {
36 if (!initSourceFromPath()) {
37 return false;
38 }
39 }
40
41 if (!initArchive()) {
42 return false;
43 }
44
45 if (!prepareForReading()) {
46 return false;
47 }
48
49 return QIODevice::open(mode);
50}
51
52// ============================================================================
53// Protected Implementation
54// ============================================================================
55
57{
58 _archive = archive_read_new();
59 if (!_archive) {
60 _errorString = QStringLiteral("Failed to create archive reader");
61 return false;
62 }
63
64 // Raw format for single-file decompression
66
67 return openArchive();
68}
69
71{
72 // Read the first (and only) entry header for raw format
73 struct archive_entry *entry = nullptr;
74 if (archive_read_next_header(_archive, &entry) != ARCHIVE_OK) {
75 _errorString = QString::fromUtf8(archive_error_string(_archive));
76 archive_read_free(_archive);
77 _archive = nullptr;
78 return false;
79 }
80
81 _headerRead = true;
83
84 qCDebug(QGCDecompressDeviceLog) << "Opened compressed stream, format:" << _formatName
85 << "filter:" << _filterName;
86
87 return true;
88}
89
91{
93 _headerRead = false;
94}
QIODevice wrapper for streaming decompression.
#define QGC_LOGGING_CATEGORY(name, categoryStr)
Base class for QIODevice wrappers that use libarchive for decompression.
void captureFormatInfo()
Capture format info from the archive after first header read.
void configureArchiveFormats(bool allFormats)
virtual void resetState()
Reset all state (called by close())
QIODevice wrapper for streaming decompression of single-file formats.
bool prepareForReading() override
QGCDecompressDevice(QIODevice *source, QObject *parent=nullptr)
bool initArchive() override
void resetState() override
Reset all state (called by close())
bool open(OpenMode mode) override