Qt6 migration: LtsWidgets API fixes, LtsWebSocket logger init, RTI Docker install
- LtsWidgets: Fixed Qt6 API compatibility issues - QWheelEvent::delta() → angleDelta().y() - QStyleOption::init() → initFrom() - QComboBox activated signal signature change - QTextCodec removal (UTF-8 default in Qt6) - Missing widget includes added - LtsWebSocket: Fixed m_logger reference initialization - Added NGLLoggerBootstrap includes - Proper initialization in constructor initializer lists - CMake: Added BUILD_LTSWEBSOCKET option for temporary exclusion - Docker: RTI Connext permanent installation script added - ci/install-rti-in-docker.sh for persistent RTI setup - Removes need for volume mounting RTI into container - BUILD options: FilterManagement, RTI, Codification, Grantlee, LtsWebSocket can be disabled for partial builds during migration Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
69 files changed
+12765
-14202
No files matched your search
Executable → Regular
+242
-261
@@ -1,360 +1,341 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include "nglcomp_bzip2iodevice.h"
|
||||
|
||||
#include <QIODevice>
|
||||
#include <QString>
|
||||
|
||||
#include <bzlib.h>
|
||||
|
||||
|
||||
|
||||
|
||||
class BZip2IODevice::Private
|
||||
{
|
||||
public:
|
||||
Private(BZip2IODevice *parent_, QIODevice *dev, int bs)
|
||||
: parent(parent_)
|
||||
, device(dev)
|
||||
, iCurPos(0)
|
||||
, iMaxBufSize(1024 * 1024)
|
||||
, blocksize(bs)
|
||||
, initialized(false)
|
||||
, decomressStreamEnd(false)
|
||||
{
|
||||
buffer.resize(iMaxBufSize);
|
||||
}
|
||||
public:
|
||||
Private(BZip2IODevice* parent_, QIODevice* dev, int bs)
|
||||
: parent(parent_), device(dev), iCurPos(0), iMaxBufSize(1024 * 1024), blocksize(bs), initialized(false),
|
||||
decomressStreamEnd(false)
|
||||
{
|
||||
buffer.resize(iMaxBufSize);
|
||||
}
|
||||
|
||||
bool initializeCompress();
|
||||
qint64 doCompress(const char *in, qint64 iMaxLen);
|
||||
bool finishCompress();
|
||||
bool initializeDecompress();
|
||||
qint64 doDecompress(char *out, qint64 iMaxLen);
|
||||
bool finishDecompress();
|
||||
static QString bzipError2String(int errCode);
|
||||
bool initializeCompress();
|
||||
qint64 doCompress(const char* in, qint64 iMaxLen);
|
||||
bool finishCompress();
|
||||
bool initializeDecompress();
|
||||
qint64 doDecompress(char* out, qint64 iMaxLen);
|
||||
bool finishDecompress();
|
||||
static QString bzipError2String(int errCode);
|
||||
|
||||
QAtomicInt aborted { 0 };
|
||||
BZip2IODevice *parent;
|
||||
QIODevice *device;
|
||||
unsigned int iCurPos;
|
||||
unsigned int iMaxBufSize;
|
||||
unsigned int blocksize;
|
||||
bool initialized;
|
||||
bool decomressStreamEnd;
|
||||
QByteArray buffer;
|
||||
bz_stream stream;
|
||||
QAtomicInt aborted{0};
|
||||
BZip2IODevice* parent;
|
||||
QIODevice* device;
|
||||
unsigned int iCurPos;
|
||||
unsigned int iMaxBufSize;
|
||||
unsigned int blocksize;
|
||||
bool initialized;
|
||||
bool decomressStreamEnd;
|
||||
QByteArray buffer;
|
||||
bz_stream stream;
|
||||
};
|
||||
|
||||
bool BZip2IODevice::Private::initializeCompress()
|
||||
{
|
||||
if (initialized)
|
||||
return true;
|
||||
memset(&stream, 0, sizeof(stream));
|
||||
int blockSize = (blocksize > 0 && blocksize < 10) ? blocksize : 10;
|
||||
int ret = BZ2_bzCompressInit(&stream, blockSize, 0, 0);
|
||||
if (ret != BZ_OK)
|
||||
{
|
||||
parent->setErrorString(QStringLiteral("Error initializing bzip2 %1").arg(bzipError2String(ret)));
|
||||
initialized = false;
|
||||
}
|
||||
else
|
||||
initialized = true;
|
||||
if (initialized)
|
||||
return true;
|
||||
memset(&stream, 0, sizeof(stream));
|
||||
int blockSize = (blocksize > 0 && blocksize < 10) ? blocksize : 10;
|
||||
int ret = BZ2_bzCompressInit(&stream, blockSize, 0, 0);
|
||||
if (ret != BZ_OK)
|
||||
{
|
||||
parent->setErrorString(QStringLiteral("Error initializing bzip2 %1").arg(bzipError2String(ret)));
|
||||
initialized = false;
|
||||
}
|
||||
else
|
||||
initialized = true;
|
||||
|
||||
return initialized;
|
||||
return initialized;
|
||||
}
|
||||
|
||||
qint64 BZip2IODevice::Private::doCompress(const char *in, qint64 iMaxLen)
|
||||
qint64 BZip2IODevice::Private::doCompress(const char* in, qint64 iMaxLen)
|
||||
{
|
||||
if (!initialized)
|
||||
{
|
||||
if (parent->errorString().isEmpty())
|
||||
parent->setErrorString(QLatin1String("Internal Error - bzip not initialized"));
|
||||
finishCompress();
|
||||
return -1;
|
||||
}
|
||||
if (iMaxLen > 2 * 1024 * 1024 * 1024LL)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Currently can't handle more than 2GB!"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
stream.next_in = const_cast<char *>(in);
|
||||
stream.avail_in = iMaxLen;
|
||||
|
||||
do
|
||||
{
|
||||
if (aborted) return 0;
|
||||
|
||||
stream.next_out = buffer.data();
|
||||
stream.avail_out = buffer.size();
|
||||
|
||||
const int ret = BZ2_bzCompress(&stream, BZ_RUN);
|
||||
if (ret != BZ_RUN_OK)
|
||||
if (!initialized)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QStringLiteral("Error executing BZ2_bzCompress: %1").arg(bzipError2String(ret)));
|
||||
return -1;
|
||||
}
|
||||
int iBytesToWrite = buffer.size() - stream.avail_out;
|
||||
if (iBytesToWrite)
|
||||
{
|
||||
if (device->write(buffer.constData(), iBytesToWrite) != iBytesToWrite)
|
||||
{
|
||||
if (parent->errorString().isEmpty())
|
||||
parent->setErrorString(QLatin1String("Internal Error - bzip not initialized"));
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Error writing to QIODevice"));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
while (stream.avail_in != 0);
|
||||
if (iMaxLen > 2 * 1024 * 1024 * 1024LL)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Currently can't handle more than 2GB!"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
return stream.next_in - in;
|
||||
stream.next_in = const_cast<char*>(in);
|
||||
stream.avail_in = iMaxLen;
|
||||
|
||||
do
|
||||
{
|
||||
if (aborted)
|
||||
return 0;
|
||||
|
||||
stream.next_out = buffer.data();
|
||||
stream.avail_out = buffer.size();
|
||||
|
||||
const int ret = BZ2_bzCompress(&stream, BZ_RUN);
|
||||
if (ret != BZ_RUN_OK)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QStringLiteral("Error executing BZ2_bzCompress: %1").arg(bzipError2String(ret)));
|
||||
return -1;
|
||||
}
|
||||
int iBytesToWrite = buffer.size() - stream.avail_out;
|
||||
if (iBytesToWrite)
|
||||
{
|
||||
if (device->write(buffer.constData(), iBytesToWrite) != iBytesToWrite)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Error writing to QIODevice"));
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
} while (stream.avail_in != 0);
|
||||
|
||||
return stream.next_in - in;
|
||||
}
|
||||
|
||||
bool BZip2IODevice::Private::finishCompress()
|
||||
{
|
||||
if (!initialized || aborted)
|
||||
if (!initialized || aborted)
|
||||
return true;
|
||||
|
||||
int ret = -1;
|
||||
|
||||
do
|
||||
{
|
||||
stream.next_out = buffer.data();
|
||||
stream.avail_out = buffer.size();
|
||||
ret = BZ2_bzCompress(&stream, BZ_FINISH);
|
||||
if (ret != BZ_FINISH_OK && ret != BZ_STREAM_END)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QStringLiteral("Error executing BZ2_bzCompress: %1").arg(bzipError2String(ret)));
|
||||
return false;
|
||||
}
|
||||
int iBytesToWrite = buffer.size() - stream.avail_out;
|
||||
if (device->write(buffer.constData(), iBytesToWrite) != iBytesToWrite)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Error writing to QIODevice"));
|
||||
return false;
|
||||
}
|
||||
} while (ret != BZ_STREAM_END);
|
||||
BZ2_bzCompressEnd(&stream);
|
||||
|
||||
initialized = false;
|
||||
return true;
|
||||
|
||||
int ret = -1;
|
||||
|
||||
do
|
||||
{
|
||||
stream.next_out = buffer.data();
|
||||
stream.avail_out = buffer.size();
|
||||
ret = BZ2_bzCompress(&stream, BZ_FINISH);
|
||||
if (ret != BZ_FINISH_OK && ret != BZ_STREAM_END)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QStringLiteral("Error executing BZ2_bzCompress: %1").arg(bzipError2String(ret)));
|
||||
return false;
|
||||
}
|
||||
int iBytesToWrite = buffer.size() - stream.avail_out;
|
||||
if (device->write(buffer.constData(), iBytesToWrite) != iBytesToWrite)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Error writing to QIODevice"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
while (ret != BZ_STREAM_END);
|
||||
BZ2_bzCompressEnd(&stream);
|
||||
|
||||
initialized = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BZip2IODevice::Private::initializeDecompress()
|
||||
{
|
||||
if (initialized)
|
||||
return true;
|
||||
memset(&stream, 0, sizeof(stream));
|
||||
int ret = BZ2_bzDecompressInit(&stream, 0, 0);
|
||||
if (ret != BZ_OK)
|
||||
{
|
||||
parent->setErrorString(QStringLiteral("Error initializing bzip2: %1").arg(bzipError2String(ret)));
|
||||
initialized = false;
|
||||
}
|
||||
else
|
||||
initialized = true;
|
||||
decomressStreamEnd = false;
|
||||
return initialized;
|
||||
if (initialized)
|
||||
return true;
|
||||
memset(&stream, 0, sizeof(stream));
|
||||
int ret = BZ2_bzDecompressInit(&stream, 0, 0);
|
||||
if (ret != BZ_OK)
|
||||
{
|
||||
parent->setErrorString(QStringLiteral("Error initializing bzip2: %1").arg(bzipError2String(ret)));
|
||||
initialized = false;
|
||||
}
|
||||
else
|
||||
initialized = true;
|
||||
decomressStreamEnd = false;
|
||||
return initialized;
|
||||
}
|
||||
|
||||
qint64 BZip2IODevice::Private::doDecompress(char *out, qint64 iMaxLen)
|
||||
qint64 BZip2IODevice::Private::doDecompress(char* out, qint64 iMaxLen)
|
||||
{
|
||||
int ret = -1;
|
||||
if (!initialized)
|
||||
{
|
||||
if (parent->errorString().isEmpty())
|
||||
parent->setErrorString(QLatin1String("Internal Error - bzip not initialized"));
|
||||
finishDecompress();
|
||||
return -1;
|
||||
}
|
||||
if (decomressStreamEnd)
|
||||
return 0;
|
||||
|
||||
if (iMaxLen > 2 * 1024 * 1024 * 1024LL)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Currently can't handle more than 2GB!"));
|
||||
return -1;
|
||||
}
|
||||
|
||||
stream.next_out = out;
|
||||
stream.avail_out = iMaxLen;
|
||||
|
||||
do
|
||||
{
|
||||
if (ret != BZ_STREAM_END && stream.avail_in == 0)
|
||||
int ret = -1;
|
||||
if (!initialized)
|
||||
{
|
||||
qint64 iReadCnt = device->read(buffer.data(), buffer.size());
|
||||
if (iReadCnt <= 0)
|
||||
if (parent->errorString().isEmpty())
|
||||
parent->setErrorString(QLatin1String("Internal Error - bzip not initialized"));
|
||||
finishDecompress();
|
||||
return -1;
|
||||
}
|
||||
if (decomressStreamEnd)
|
||||
return 0;
|
||||
|
||||
if (iMaxLen > 2 * 1024 * 1024 * 1024LL)
|
||||
{
|
||||
finishCompress();
|
||||
parent->setErrorString(QLatin1String("Currently can't handle more than 2GB!"));
|
||||
return -1;
|
||||
stream.next_in = buffer.data();
|
||||
stream.avail_in = iReadCnt;
|
||||
}
|
||||
|
||||
ret = BZ2_bzDecompress(&stream);
|
||||
if (ret != BZ_OK && ret != BZ_STREAM_END)
|
||||
stream.next_out = out;
|
||||
stream.avail_out = iMaxLen;
|
||||
|
||||
do
|
||||
{
|
||||
parent->setErrorString(QStringLiteral("Error executing BZ2_bzCompress: %1").arg(bzipError2String(ret)));
|
||||
finishDecompress();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
while (stream.avail_out != 0 && ret != BZ_STREAM_END);
|
||||
decomressStreamEnd = (ret == BZ_STREAM_END);
|
||||
return stream.next_out - out;
|
||||
if (ret != BZ_STREAM_END && stream.avail_in == 0)
|
||||
{
|
||||
qint64 iReadCnt = device->read(buffer.data(), buffer.size());
|
||||
if (iReadCnt <= 0)
|
||||
return -1;
|
||||
stream.next_in = buffer.data();
|
||||
stream.avail_in = iReadCnt;
|
||||
}
|
||||
|
||||
ret = BZ2_bzDecompress(&stream);
|
||||
if (ret != BZ_OK && ret != BZ_STREAM_END)
|
||||
{
|
||||
parent->setErrorString(QStringLiteral("Error executing BZ2_bzCompress: %1").arg(bzipError2String(ret)));
|
||||
finishDecompress();
|
||||
return -1;
|
||||
}
|
||||
} while (stream.avail_out != 0 && ret != BZ_STREAM_END);
|
||||
decomressStreamEnd = (ret == BZ_STREAM_END);
|
||||
return stream.next_out - out;
|
||||
}
|
||||
|
||||
bool BZip2IODevice::Private::finishDecompress()
|
||||
{
|
||||
if (!initialized)
|
||||
return true;
|
||||
BZ2_bzDecompressEnd(&stream);
|
||||
if (!initialized)
|
||||
return true;
|
||||
BZ2_bzDecompressEnd(&stream);
|
||||
|
||||
initialized = false;
|
||||
return true;
|
||||
initialized = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
QString BZip2IODevice::Private::bzipError2String(int errCode)
|
||||
{
|
||||
switch (errCode)
|
||||
{
|
||||
case BZ_SEQUENCE_ERROR:
|
||||
return QLatin1String("Sequence error");
|
||||
case BZ_PARAM_ERROR:
|
||||
return QLatin1String("Parameter not correct");
|
||||
case BZ_MEM_ERROR:
|
||||
return QLatin1String("Memory allocation error");
|
||||
case BZ_DATA_ERROR:
|
||||
return QLatin1String("Invalid input data");
|
||||
case BZ_DATA_ERROR_MAGIC:
|
||||
return QLatin1String("Not a bzip2 file");
|
||||
case BZ_IO_ERROR:
|
||||
return QLatin1String("I/O error");
|
||||
case BZ_UNEXPECTED_EOF:
|
||||
return QLatin1String("Unexpected end of file");
|
||||
case BZ_OUTBUFF_FULL:
|
||||
return QLatin1String("Output buffer full");
|
||||
case BZ_CONFIG_ERROR:
|
||||
return QLatin1String("Wrong config parameter");
|
||||
};
|
||||
return QString::number(errCode);
|
||||
switch (errCode)
|
||||
{
|
||||
case BZ_SEQUENCE_ERROR:
|
||||
return QLatin1String("Sequence error");
|
||||
case BZ_PARAM_ERROR:
|
||||
return QLatin1String("Parameter not correct");
|
||||
case BZ_MEM_ERROR:
|
||||
return QLatin1String("Memory allocation error");
|
||||
case BZ_DATA_ERROR:
|
||||
return QLatin1String("Invalid input data");
|
||||
case BZ_DATA_ERROR_MAGIC:
|
||||
return QLatin1String("Not a bzip2 file");
|
||||
case BZ_IO_ERROR:
|
||||
return QLatin1String("I/O error");
|
||||
case BZ_UNEXPECTED_EOF:
|
||||
return QLatin1String("Unexpected end of file");
|
||||
case BZ_OUTBUFF_FULL:
|
||||
return QLatin1String("Output buffer full");
|
||||
case BZ_CONFIG_ERROR:
|
||||
return QLatin1String("Wrong config parameter");
|
||||
};
|
||||
return QString::number(errCode);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
BZip2IODevice::BZip2IODevice(QIODevice *dev, int blocksize)
|
||||
: d(new Private(this, dev, blocksize))
|
||||
{}
|
||||
BZip2IODevice::BZip2IODevice(QIODevice* dev, int blocksize) : d(new Private(this, dev, blocksize)) {}
|
||||
|
||||
BZip2IODevice::~BZip2IODevice()
|
||||
{
|
||||
close();
|
||||
delete d;
|
||||
close();
|
||||
delete d;
|
||||
}
|
||||
|
||||
void BZip2IODevice::setBufferSize(unsigned int size)
|
||||
{
|
||||
d->iMaxBufSize = size > 1024 ? size : 1024;
|
||||
d->buffer.resize(d->iMaxBufSize);
|
||||
d->iMaxBufSize = size > 1024 ? size : 1024;
|
||||
d->buffer.resize(d->iMaxBufSize);
|
||||
}
|
||||
|
||||
void BZip2IODevice::setBlockSize(unsigned int size)
|
||||
{
|
||||
if (isOpen())
|
||||
return;
|
||||
d->blocksize = size;
|
||||
if (isOpen())
|
||||
return;
|
||||
d->blocksize = size;
|
||||
}
|
||||
|
||||
bool BZip2IODevice::isSequential() const
|
||||
{
|
||||
return true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BZip2IODevice::open(OpenMode mode)
|
||||
{
|
||||
if ((mode & QIODevice::ReadWrite) == 0)
|
||||
{
|
||||
setErrorString(QStringLiteral("Unsupported OpenMode %1").arg(mode));
|
||||
return false;
|
||||
}
|
||||
if ((mode & QIODevice::ReadWrite) == QIODevice::ReadWrite)
|
||||
{
|
||||
setErrorString(QLatin1String("Can't read and write simultaniously"));
|
||||
return false;
|
||||
}
|
||||
if ((mode & QIODevice::ReadOnly) == QIODevice::ReadOnly)
|
||||
{
|
||||
if (!d->device)
|
||||
if ((mode & QIODevice::ReadWrite) == 0)
|
||||
{
|
||||
setErrorString(QLatin1String("No QIODevice for reading available"));
|
||||
return false;
|
||||
setErrorString(QStringLiteral("Unsupported OpenMode %1").arg(static_cast<int>(mode)));
|
||||
return false;
|
||||
}
|
||||
if ((d->device->openMode() & QIODevice::ReadOnly) == 0)
|
||||
if ((mode & QIODevice::ReadWrite) == QIODevice::ReadWrite)
|
||||
{
|
||||
setErrorString(QLatin1String("QIODevice not opened for reading"));
|
||||
return false;
|
||||
setErrorString(QLatin1String("Can't read and write simultaniously"));
|
||||
return false;
|
||||
}
|
||||
if (!d->initializeDecompress())
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!d->device)
|
||||
if ((mode & QIODevice::ReadOnly) == QIODevice::ReadOnly)
|
||||
{
|
||||
setErrorString(QLatin1String("No QIODevice for writing available"));
|
||||
return false;
|
||||
if (!d->device)
|
||||
{
|
||||
setErrorString(QLatin1String("No QIODevice for reading available"));
|
||||
return false;
|
||||
}
|
||||
if ((d->device->openMode() & QIODevice::ReadOnly) == 0)
|
||||
{
|
||||
setErrorString(QLatin1String("QIODevice not opened for reading"));
|
||||
return false;
|
||||
}
|
||||
if (!d->initializeDecompress())
|
||||
return false;
|
||||
}
|
||||
if ((d->device->openMode() & QIODevice::WriteOnly) == 0)
|
||||
else
|
||||
{
|
||||
setErrorString(QLatin1String("QIODevice not opened for writing"));
|
||||
return false;
|
||||
if (!d->device)
|
||||
{
|
||||
setErrorString(QLatin1String("No QIODevice for writing available"));
|
||||
return false;
|
||||
}
|
||||
if ((d->device->openMode() & QIODevice::WriteOnly) == 0)
|
||||
{
|
||||
setErrorString(QLatin1String("QIODevice not opened for writing"));
|
||||
return false;
|
||||
}
|
||||
if (!d->initializeCompress())
|
||||
return false;
|
||||
}
|
||||
if (!d->initializeCompress())
|
||||
return false;
|
||||
}
|
||||
setErrorString(QString());
|
||||
setOpenMode(mode);
|
||||
return QIODevice::open(mode);
|
||||
setErrorString(QString());
|
||||
setOpenMode(mode);
|
||||
return QIODevice::open(mode);
|
||||
}
|
||||
|
||||
void BZip2IODevice::abort()
|
||||
{
|
||||
d->aborted = 1;
|
||||
d->aborted = 1;
|
||||
}
|
||||
|
||||
void BZip2IODevice::close()
|
||||
{
|
||||
if (!isOpen())
|
||||
return;
|
||||
if ((openMode() & QIODevice::ReadOnly) == QIODevice::ReadOnly)
|
||||
d->finishDecompress();
|
||||
else
|
||||
d->finishCompress();
|
||||
QIODevice::close();
|
||||
if (!isOpen())
|
||||
return;
|
||||
if ((openMode() & QIODevice::ReadOnly) == QIODevice::ReadOnly)
|
||||
d->finishDecompress();
|
||||
else
|
||||
d->finishCompress();
|
||||
QIODevice::close();
|
||||
}
|
||||
|
||||
bool BZip2IODevice::atEnd() const
|
||||
{
|
||||
if (!d->device)
|
||||
return true;
|
||||
return d->device->atEnd() && d->decomressStreamEnd && QIODevice::atEnd();
|
||||
if (!d->device)
|
||||
return true;
|
||||
return d->device->atEnd() && d->decomressStreamEnd && QIODevice::atEnd();
|
||||
}
|
||||
|
||||
qint64 BZip2IODevice::readData(char *data, qint64 maxSize)
|
||||
qint64 BZip2IODevice::readData(char* data, qint64 maxSize)
|
||||
{
|
||||
return d->doDecompress(data, maxSize);
|
||||
return d->doDecompress(data, maxSize);
|
||||
}
|
||||
|
||||
qint64 BZip2IODevice::writeData(const char *data, qint64 maxSize)
|
||||
qint64 BZip2IODevice::writeData(const char* data, qint64 maxSize)
|
||||
{
|
||||
return d->doCompress(data, maxSize);
|
||||
return d->doCompress(data, maxSize);
|
||||
}
|
||||
Executable → Regular
+405
-445
@@ -1,569 +1,529 @@
|
||||
|
||||
|
||||
#include "nglcomp_compress.h"
|
||||
|
||||
#include "nglcomp_bzip2iodevice.h"
|
||||
#include "nglcomp_tarfilter.h"
|
||||
|
||||
#include <NGLLogger/NGLLoggerBootstrap.h>
|
||||
|
||||
#include <QBuffer>
|
||||
#include <QtConcurrent>
|
||||
#include <QCoreApplication>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFileInfo>
|
||||
#include <QFutureWatcher>
|
||||
#include <QIODevice>
|
||||
#include <QStringList>
|
||||
#include <QtConcurrent>
|
||||
#include <memory>
|
||||
#include <utility>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
namespace NGL
|
||||
{
|
||||
|
||||
Compress::Compress(QObject *parent)
|
||||
: QObject(parent)
|
||||
, m_u2_memFiles()
|
||||
, m_aborted(0)
|
||||
Compress::Compress(QObject* parent)
|
||||
: QObject(parent), m_u2_memFiles(), m_aborted(0),
|
||||
m_logger(NGL::NGLLoggerBootstrap::getNGLRootLogger().getNGLLogger("nglcompress"))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "c_tor";
|
||||
DEBUG_LOG(m_logger) << "c_tor";
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
QTimer *t = new QTimer(this);
|
||||
t->setInterval(1000);
|
||||
connect(t, &QTimer::timeout, this, [](){qWarning() << "still alive ...";});
|
||||
t->start();
|
||||
QTimer* t = new QTimer(this);
|
||||
t->setInterval(1000);
|
||||
connect(t, &QTimer::timeout, this, []() { qWarning() << "still alive ..."; });
|
||||
t->start();
|
||||
}
|
||||
|
||||
Compress::~Compress()
|
||||
{
|
||||
qWarning() << "## COMPRESS DTOR!!!!";
|
||||
qWarning() << "## COMPRESS DTOR!!!!";
|
||||
|
||||
|
||||
DEBUG_LOG(m_logger) << "~";
|
||||
DEBUG_LOG(m_logger) << "~";
|
||||
|
||||
abort();
|
||||
m_future.waitForFinished();
|
||||
DEBUG_LOG(m_logger) << "~ finished";
|
||||
abort();
|
||||
m_future.waitForFinished();
|
||||
DEBUG_LOG(m_logger) << "~ finished";
|
||||
}
|
||||
|
||||
void Compress::abort()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "ABORT";
|
||||
DEBUG_LOG(m_logger) << "ABORT";
|
||||
|
||||
m_aborted = 1;
|
||||
m_lastError = tr("Aborted");
|
||||
m_aborted = 1;
|
||||
m_lastError = tr("Aborted");
|
||||
|
||||
if (m_currentTarFilter != nullptr)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "aborting tar";
|
||||
m_currentTarFilter->abort();
|
||||
}
|
||||
if (m_currentTarFilter != nullptr)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "aborting tar";
|
||||
m_currentTarFilter->abort();
|
||||
}
|
||||
|
||||
if (m_currentBzipDevice != nullptr)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "aborting bzip";
|
||||
m_currentBzipDevice->abort();
|
||||
}
|
||||
if (m_currentBzipDevice != nullptr)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "aborting bzip";
|
||||
m_currentBzipDevice->abort();
|
||||
}
|
||||
}
|
||||
|
||||
void Compress::compress(QIODevice *out,
|
||||
const QString &filesRootDir,
|
||||
const QVector<FileInformations> &files,
|
||||
const QVector<FileInformations> &memFiles,
|
||||
const QString &destRootDir)
|
||||
void Compress::compress(QIODevice* out, const QString& filesRootDir, const QVector<FileInformations>& files,
|
||||
const QVector<FileInformations>& memFiles, const QString& destRootDir)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "compress #2";
|
||||
reset();
|
||||
setupFutureWatcher(QtConcurrent::run([this, out, filesRootDir, files, memFiles, destRootDir]() {
|
||||
return this->_compress(out, filesRootDir, files, memFiles, destRootDir);
|
||||
}));
|
||||
DEBUG_LOG(m_logger) << "compress #2";
|
||||
reset();
|
||||
setupFutureWatcher(QtConcurrent::run([this, out, filesRootDir, files, memFiles, destRootDir]() {
|
||||
return this->_compress(out, filesRootDir, files, memFiles, destRootDir);
|
||||
}));
|
||||
}
|
||||
|
||||
void Compress::compress(QIODevice *out, const QString &sourceDir, const QString &destRootDir)
|
||||
void Compress::compress(QIODevice* out, const QString& sourceDir, const QString& destRootDir)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "compress #1 source dir: " << sourceDir << ", destRootDir: " << destRootDir;
|
||||
reset();
|
||||
DEBUG_LOG(m_logger) << "compress #1 source dir: " << sourceDir << ", destRootDir: " << destRootDir;
|
||||
reset();
|
||||
|
||||
QVector<Compress::FileInformations> inFiles = directoryFileList(sourceDir, true);
|
||||
QVector<Compress::FileInformations> inFiles = directoryFileList(sourceDir, true);
|
||||
|
||||
|
||||
int len = sourceDir.length();
|
||||
if (!sourceDir.endsWith(QLatin1Char('/')))
|
||||
len += 1;
|
||||
for (auto &fi : inFiles)
|
||||
{
|
||||
fi.inputFileName = fi.inputFileName.mid(len);
|
||||
fi.bAbsInputPath = false;
|
||||
DEBUG_LOG(m_logger) << "fi: ifm = " << fi.inputFileName << ", abs = " << fi.bAbsInputPath;
|
||||
}
|
||||
int len = sourceDir.length();
|
||||
if (!sourceDir.endsWith(QLatin1Char('/')))
|
||||
len += 1;
|
||||
for (auto& fi : inFiles)
|
||||
{
|
||||
fi.inputFileName = fi.inputFileName.mid(len);
|
||||
fi.bAbsInputPath = false;
|
||||
DEBUG_LOG(m_logger) << "fi: ifm = " << fi.inputFileName << ", abs = " << fi.bAbsInputPath;
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "FI list size: " << inFiles.count();
|
||||
DEBUG_LOG(m_logger) << "FI list size: " << inFiles.count();
|
||||
|
||||
compress(out, sourceDir, inFiles, {}, destRootDir);
|
||||
compress(out, sourceDir, inFiles, {}, destRootDir);
|
||||
}
|
||||
|
||||
bool Compress::_compress(QIODevice *output,
|
||||
const QString &filesRootDir,
|
||||
const QVector<FileInformations> &files,
|
||||
const QVector<FileInformations> &memFiles,
|
||||
const QString &_destRootDir)
|
||||
bool Compress::_compress(QIODevice* output, const QString& filesRootDir, const QVector<FileInformations>& files,
|
||||
const QVector<FileInformations>& memFiles, const QString& _destRootDir)
|
||||
{
|
||||
std::shared_ptr<int> invalidatePointersOnScopeLeave(nullptr, [this](int *)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "invalidatePointersOnScopeLeave #1";
|
||||
m_currentTarFilter = nullptr;
|
||||
m_currentBzipDevice = nullptr;
|
||||
});
|
||||
(void)invalidatePointersOnScopeLeave;
|
||||
std::shared_ptr<int> invalidatePointersOnScopeLeave(nullptr, [this](int*) {
|
||||
DEBUG_LOG(m_logger) << "invalidatePointersOnScopeLeave #1";
|
||||
m_currentTarFilter = nullptr;
|
||||
m_currentBzipDevice = nullptr;
|
||||
});
|
||||
(void)invalidatePointersOnScopeLeave;
|
||||
|
||||
|
||||
if (!output || !output->isWritable())
|
||||
{
|
||||
m_lastError = tr("Device is not writeable");
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
const QString destRootDir = _destRootDir.endsWith(QLatin1Char('/')) ?
|
||||
_destRootDir : _destRootDir + QLatin1Char('/');
|
||||
|
||||
const qint64 maxCount = files.count() + memFiles.count();
|
||||
qint64 count = 0;
|
||||
|
||||
DEBUG_LOG(m_logger) << "destRootDir = " << destRootDir << ", maxCount = " << maxCount << ", count = " << count;
|
||||
|
||||
BZip2IODevice bzip2(output, 9);
|
||||
m_currentBzipDevice = &bzip2;
|
||||
|
||||
if (!bzip2.open(QIODevice::WriteOnly))
|
||||
{
|
||||
m_lastError = bzip2.errorString();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
qint64 bytesTotal = 0;
|
||||
for (const FileInformations &file : std::as_const(files))
|
||||
{
|
||||
if (m_aborted) return false;
|
||||
|
||||
const QString in = file.bAbsInputPath ? file.inputFileName : filesRootDir + QLatin1Char('/') + file.inputFileName;
|
||||
const QFileInfo fi(in);
|
||||
|
||||
bytesTotal += fi.size();
|
||||
}
|
||||
|
||||
|
||||
qint64 currentFileSize = 0;
|
||||
QString currentFileName;
|
||||
auto readCallback = [this, &maxCount, &count, ¤tFileSize, ¤tFileName, &bytesTotal](const qint64 iSize)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "readCallback: maxCount = " << maxCount << ", count = " << count
|
||||
<< ", currentFileSize = " << currentFileSize << ", currentFileName = " << currentFileName << ", iSize = " << iSize;
|
||||
emit compressInfoEx(maxCount, count, currentFileSize, (currentFileSize - iSize), currentFileName, bytesTotal);
|
||||
};
|
||||
|
||||
|
||||
TarFilter tf(&bzip2, readCallback);
|
||||
m_currentTarFilter = &tf;
|
||||
const QStringList paths = destRootDir.split(QLatin1Char('/'), Qt::SkipEmptyParts);
|
||||
QString curPath;
|
||||
|
||||
|
||||
DEBUG_LOG(m_logger) << "prepairing tar filter";
|
||||
for (const QString &path : paths)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "path = " << path;
|
||||
if (m_aborted) return false;
|
||||
|
||||
if (curPath.isEmpty())
|
||||
curPath = path + QLatin1Char('/');
|
||||
else
|
||||
curPath += path + QLatin1Char('/');
|
||||
|
||||
DEBUG_LOG(m_logger) << "curPath = " << curPath << ", filesRootDir.isEmpty() = " << filesRootDir.isEmpty();
|
||||
|
||||
if (filesRootDir.isEmpty())
|
||||
if (!output || !output->isWritable())
|
||||
{
|
||||
if (!tf.addData(curPath, QByteArray(), true))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
m_lastError = tr("Device is not writeable");
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
|
||||
const QString destRootDir =
|
||||
_destRootDir.endsWith(QLatin1Char('/')) ? _destRootDir : _destRootDir + QLatin1Char('/');
|
||||
|
||||
const qint64 maxCount = files.count() + memFiles.count();
|
||||
qint64 count = 0;
|
||||
|
||||
DEBUG_LOG(m_logger) << "destRootDir = " << destRootDir << ", maxCount = " << maxCount << ", count = " << count;
|
||||
|
||||
BZip2IODevice bzip2(output, 9);
|
||||
m_currentBzipDevice = &bzip2;
|
||||
|
||||
if (!bzip2.open(QIODevice::WriteOnly))
|
||||
{
|
||||
if (!tf.addFile(filesRootDir, curPath))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
m_lastError = bzip2.errorString();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_c_sizeInfo.realSize = 0;
|
||||
for (const FileInformations &file : std::as_const(files))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "file = " << file.inputFileName;
|
||||
emit compressInfo(maxCount, ++count, file.inputFileName);
|
||||
|
||||
if (m_aborted) return false;
|
||||
|
||||
QString in = file.bAbsInputPath ? file.inputFileName : filesRootDir + QLatin1Char('/') + file.inputFileName;
|
||||
QString out = destRootDir + (file.outputFileName.isEmpty() ? file.inputFileName : file.outputFileName);
|
||||
|
||||
DEBUG_LOG(m_logger) << "in = " << in << ", out = " << out;
|
||||
|
||||
QFileInfo fi(in);
|
||||
|
||||
currentFileName = fi.fileName();
|
||||
currentFileSize = fi.size();
|
||||
m_c_sizeInfo.realSize += currentFileSize;
|
||||
|
||||
DEBUG_LOG(m_logger) << "currentFileName = " << currentFileName << ", currentFileSize = " << currentFileSize << "m_c_sizeInfo.realSize" << m_c_sizeInfo.realSize;
|
||||
|
||||
if (!tf.addFile(in, out))
|
||||
qint64 bytesTotal = 0;
|
||||
for (const FileInformations& file : std::as_const(files))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
if (m_aborted)
|
||||
return false;
|
||||
|
||||
const QString in =
|
||||
file.bAbsInputPath ? file.inputFileName : filesRootDir + QLatin1Char('/') + file.inputFileName;
|
||||
const QFileInfo fi(in);
|
||||
|
||||
bytesTotal += fi.size();
|
||||
}
|
||||
}
|
||||
|
||||
for (const FileInformations &file : std::as_const(memFiles))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "(mem) file = " << file.inputFileName;
|
||||
emit compressInfo(maxCount, ++count, file.inputFileName);
|
||||
|
||||
if (m_aborted) return false;
|
||||
qint64 currentFileSize = 0;
|
||||
QString currentFileName;
|
||||
auto readCallback = [this, &maxCount, &count, ¤tFileSize, ¤tFileName, &bytesTotal](const qint64 iSize) {
|
||||
DEBUG_LOG(m_logger) << "readCallback: maxCount = " << maxCount << ", count = " << count
|
||||
<< ", currentFileSize = " << currentFileSize << ", currentFileName = " << currentFileName
|
||||
<< ", iSize = " << iSize;
|
||||
emit compressInfoEx(maxCount, count, currentFileSize, (currentFileSize - iSize), currentFileName, bytesTotal);
|
||||
};
|
||||
|
||||
currentFileName = file.inputFileName;
|
||||
currentFileSize = file.fileData.size();
|
||||
m_c_sizeInfo.compressedSize += currentFileSize;
|
||||
TarFilter tf(&bzip2, readCallback);
|
||||
m_currentTarFilter = &tf;
|
||||
const QStringList paths = destRootDir.split(QLatin1Char('/'), Qt::SkipEmptyParts);
|
||||
QString curPath;
|
||||
|
||||
DEBUG_LOG(m_logger) << "(mem) currentFileName = " << currentFileName << ", currentFileSize = " << currentFileSize << "m_c_sizeInfo.realSize" << m_c_sizeInfo.realSize;
|
||||
|
||||
if (!tf.addData(file.inputFileName, file.fileData))
|
||||
DEBUG_LOG(m_logger) << "prepairing tar filter";
|
||||
for (const QString& path : paths)
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
DEBUG_LOG(m_logger) << "path = " << path;
|
||||
if (m_aborted)
|
||||
return false;
|
||||
|
||||
if (curPath.isEmpty())
|
||||
curPath = path + QLatin1Char('/');
|
||||
else
|
||||
curPath += path + QLatin1Char('/');
|
||||
|
||||
DEBUG_LOG(m_logger) << "curPath = " << curPath << ", filesRootDir.isEmpty() = " << filesRootDir.isEmpty();
|
||||
|
||||
if (filesRootDir.isEmpty())
|
||||
{
|
||||
if (!tf.addData(curPath, QByteArray(), true))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (!tf.addFile(filesRootDir, curPath))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_c_sizeInfo.realSize = 0;
|
||||
for (const FileInformations& file : std::as_const(files))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "file = " << file.inputFileName;
|
||||
emit compressInfo(maxCount, ++count, file.inputFileName);
|
||||
|
||||
DEBUG_LOG(m_logger) << "writing eos";
|
||||
tf.writeEOS();
|
||||
if (m_aborted)
|
||||
return false;
|
||||
|
||||
DEBUG_LOG(m_logger) << "closing bzip";
|
||||
bzip2.close();
|
||||
QString in = file.bAbsInputPath ? file.inputFileName : filesRootDir + QLatin1Char('/') + file.inputFileName;
|
||||
QString out = destRootDir + (file.outputFileName.isEmpty() ? file.inputFileName : file.outputFileName);
|
||||
|
||||
m_c_sizeInfo.compressedSize = output->size();
|
||||
DEBUG_LOG(m_logger) << "m_c_sizeInfo.compressedSize = " << m_c_sizeInfo.compressedSize;
|
||||
DEBUG_LOG(m_logger) << "in = " << in << ", out = " << out;
|
||||
|
||||
m_success = true;
|
||||
QFileInfo fi(in);
|
||||
|
||||
DEBUG_LOG(m_logger) << "DONE!";
|
||||
currentFileName = fi.fileName();
|
||||
currentFileSize = fi.size();
|
||||
m_c_sizeInfo.realSize += currentFileSize;
|
||||
|
||||
return true;
|
||||
DEBUG_LOG(m_logger) << "currentFileName = " << currentFileName << ", currentFileSize = " << currentFileSize
|
||||
<< "m_c_sizeInfo.realSize" << m_c_sizeInfo.realSize;
|
||||
|
||||
if (!tf.addFile(in, out))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (const FileInformations& file : std::as_const(memFiles))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "(mem) file = " << file.inputFileName;
|
||||
emit compressInfo(maxCount, ++count, file.inputFileName);
|
||||
|
||||
if (m_aborted)
|
||||
return false;
|
||||
|
||||
currentFileName = file.inputFileName;
|
||||
currentFileSize = file.fileData.size();
|
||||
m_c_sizeInfo.compressedSize += currentFileSize;
|
||||
|
||||
DEBUG_LOG(m_logger) << "(mem) currentFileName = " << currentFileName
|
||||
<< ", currentFileSize = " << currentFileSize << "m_c_sizeInfo.realSize"
|
||||
<< m_c_sizeInfo.realSize;
|
||||
|
||||
if (!tf.addData(file.inputFileName, file.fileData))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "writing eos";
|
||||
tf.writeEOS();
|
||||
|
||||
DEBUG_LOG(m_logger) << "closing bzip";
|
||||
bzip2.close();
|
||||
|
||||
m_c_sizeInfo.compressedSize = output->size();
|
||||
DEBUG_LOG(m_logger) << "m_c_sizeInfo.compressedSize = " << m_c_sizeInfo.compressedSize;
|
||||
|
||||
m_success = true;
|
||||
|
||||
DEBUG_LOG(m_logger) << "DONE!";
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Compress::uncompress(QIODevice *in, const QString &outDir)
|
||||
void Compress::uncompress(QIODevice* in, const QString& outDir)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "uncompress #1";
|
||||
reset();
|
||||
setupFutureWatcher(QtConcurrent::run([this, in, outDir](){ return this->_uncompressDirectory(in, outDir); }));
|
||||
DEBUG_LOG(m_logger) << "uncompress #1";
|
||||
reset();
|
||||
setupFutureWatcher(QtConcurrent::run([this, in, outDir]() { return this->_uncompressDirectory(in, outDir); }));
|
||||
}
|
||||
|
||||
bool Compress::_uncompressDirectory(QIODevice *input, const QString &outDir)
|
||||
bool Compress::_uncompressDirectory(QIODevice* input, const QString& outDir)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "_uncompressDirectory";
|
||||
DEBUG_LOG(m_logger) << "_uncompressDirectory";
|
||||
|
||||
std::shared_ptr<int> invalidatePointersOnScopeLeave(nullptr, [this](int *)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "invalidatePointersOnScopeLeave #2";
|
||||
m_currentTarFilter = nullptr;
|
||||
m_currentBzipDevice = nullptr;
|
||||
});
|
||||
(void)invalidatePointersOnScopeLeave;
|
||||
std::shared_ptr<int> invalidatePointersOnScopeLeave(nullptr, [this](int*) {
|
||||
DEBUG_LOG(m_logger) << "invalidatePointersOnScopeLeave #2";
|
||||
m_currentTarFilter = nullptr;
|
||||
m_currentBzipDevice = nullptr;
|
||||
});
|
||||
(void)invalidatePointersOnScopeLeave;
|
||||
|
||||
|
||||
if (!input || !input->isReadable())
|
||||
{
|
||||
m_lastError = tr("Device is not readable");
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
BZip2IODevice bzip2(input, 9);
|
||||
m_currentBzipDevice = &bzip2;
|
||||
if (!bzip2.open(QIODevice::ReadOnly))
|
||||
{
|
||||
m_lastError = bzip2.errorString();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
TarFilter tf(&bzip2);
|
||||
m_currentTarFilter = &tf;
|
||||
TarFilter::FileInformations tfi;
|
||||
QDir dir(outDir);
|
||||
|
||||
DEBUG_LOG(m_logger) << "dir = " << dir.path();
|
||||
|
||||
while (tf.getData(tfi))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "tfi.fileName = " << tfi.fileName;
|
||||
emit uncompressInfo(input->size(), input->pos(), tfi.fileName);
|
||||
if (m_aborted) return false;
|
||||
|
||||
QString path = outDir + QLatin1Char('/') + tfi.fileName;
|
||||
DEBUG_LOG(m_logger) << "path = " << path;
|
||||
if (tfi.fileType == TarFilter::directory)
|
||||
if (!input || !input->isReadable())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "tfi.fileType == TarFilter::directory";
|
||||
if (!dir.exists(path) && !dir.mkpath(path))
|
||||
{
|
||||
m_lastError = tr("Error creating directory %1").arg(outDir);
|
||||
m_lastError = tr("Device is not readable");
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
QString pathName = QFileInfo(path).absolutePath();
|
||||
if (!dir.exists(pathName) && !dir.mkpath(pathName))
|
||||
{
|
||||
m_lastError = tr("Error creating directory %1").arg(pathName);
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
QFile f(path);
|
||||
if (!f.open(QIODevice::WriteOnly))
|
||||
{
|
||||
m_lastError = tr("Error opening %1 for writing (%2)").arg(path, f.errorString());
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!tf.getData(&f))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "uncompress done!";
|
||||
m_success = true;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
BZip2IODevice bzip2(input, 9);
|
||||
m_currentBzipDevice = &bzip2;
|
||||
if (!bzip2.open(QIODevice::ReadOnly))
|
||||
{
|
||||
m_lastError = bzip2.errorString();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
TarFilter tf(&bzip2);
|
||||
m_currentTarFilter = &tf;
|
||||
TarFilter::FileInformations tfi;
|
||||
QDir dir(outDir);
|
||||
|
||||
DEBUG_LOG(m_logger) << "dir = " << dir.path();
|
||||
|
||||
while (tf.getData(tfi))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "tfi.fileName = " << tfi.fileName;
|
||||
emit uncompressInfo(input->size(), input->pos(), tfi.fileName);
|
||||
if (m_aborted)
|
||||
return false;
|
||||
|
||||
QString path = outDir + QLatin1Char('/') + tfi.fileName;
|
||||
DEBUG_LOG(m_logger) << "path = " << path;
|
||||
if (tfi.fileType == TarFilter::directory)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "tfi.fileType == TarFilter::directory";
|
||||
if (!dir.exists(path) && !dir.mkpath(path))
|
||||
{
|
||||
m_lastError = tr("Error creating directory %1").arg(outDir);
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
QString pathName = QFileInfo(path).absolutePath();
|
||||
if (!dir.exists(pathName) && !dir.mkpath(pathName))
|
||||
{
|
||||
m_lastError = tr("Error creating directory %1").arg(pathName);
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
QFile f(path);
|
||||
if (!f.open(QIODevice::WriteOnly))
|
||||
{
|
||||
m_lastError = tr("Error opening %1 for writing (%2)").arg(path, f.errorString());
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!tf.getData(&f))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "uncompress done!";
|
||||
m_success = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
void Compress::uncompress(QIODevice *in)
|
||||
void Compress::uncompress(QIODevice* in)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "uncompress #2!";
|
||||
reset();
|
||||
setupFutureWatcher(QtConcurrent::run([this, in](){ return this->_uncompressBuffer(in); }));
|
||||
DEBUG_LOG(m_logger) << "uncompress #2!";
|
||||
reset();
|
||||
setupFutureWatcher(QtConcurrent::run([this, in]() { return this->_uncompressBuffer(in); }));
|
||||
}
|
||||
|
||||
bool Compress::_uncompressBuffer(QIODevice *input)
|
||||
bool Compress::_uncompressBuffer(QIODevice* input)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "uncompressBuffer";
|
||||
DEBUG_LOG(m_logger) << "uncompressBuffer";
|
||||
|
||||
std::shared_ptr<int> invalidatePointersOnScopeLeave(nullptr, [this](int *)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "invalidatePointersOnScopeLeave #2";
|
||||
m_currentTarFilter = nullptr;
|
||||
m_currentBzipDevice = nullptr;
|
||||
});
|
||||
(void)invalidatePointersOnScopeLeave;
|
||||
std::shared_ptr<int> invalidatePointersOnScopeLeave(nullptr, [this](int*) {
|
||||
DEBUG_LOG(m_logger) << "invalidatePointersOnScopeLeave #2";
|
||||
m_currentTarFilter = nullptr;
|
||||
m_currentBzipDevice = nullptr;
|
||||
});
|
||||
(void)invalidatePointersOnScopeLeave;
|
||||
|
||||
|
||||
if (!input->isReadable())
|
||||
{
|
||||
m_lastError = tr("Device is not readable");
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
BZip2IODevice bzip2(input, 9);
|
||||
m_currentBzipDevice = &bzip2;
|
||||
if (!bzip2.open(QIODevice::ReadOnly))
|
||||
{
|
||||
m_lastError = bzip2.errorString();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
TarFilter tf(&bzip2);
|
||||
m_currentTarFilter = &tf;
|
||||
TarFilter::FileInformations tfi;
|
||||
while (tf.getData(tfi))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "tfi.fileName = " << tfi.fileName;
|
||||
emit uncompressInfo(input->size(), input->pos(), tfi.fileName);
|
||||
if (m_aborted) return false;
|
||||
|
||||
FileInformations fi;
|
||||
fi.outputFileName = tfi.fileName;
|
||||
|
||||
DEBUG_LOG(m_logger) << "fi.outputFileName = " << fi.outputFileName;
|
||||
|
||||
if (tfi.fileType == TarFilter::directory)
|
||||
if (!input->isReadable())
|
||||
{
|
||||
fi.outputFileName += QLatin1Char('/');
|
||||
DEBUG_LOG(m_logger) << "> fi.outputFileName = " << fi.outputFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "stuff";
|
||||
m_lastError = tr("Device is not readable");
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
QBuffer buf(&fi.fileData);
|
||||
if (!buf.open(QIODevice::WriteOnly))
|
||||
{
|
||||
m_lastError = tr("Error opening buffer for writing (%1)").arg(buf.errorString());
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!tf.getData(&buf))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
fi.bAbsInputPath = fi.outputFileName.startsWith(QLatin1Char('/'));
|
||||
DEBUG_LOG(m_logger) << "added fi.bAbsInputPath = " << fi.bAbsInputPath;
|
||||
m_u2_memFiles += fi;
|
||||
}
|
||||
BZip2IODevice bzip2(input, 9);
|
||||
m_currentBzipDevice = &bzip2;
|
||||
if (!bzip2.open(QIODevice::ReadOnly))
|
||||
{
|
||||
m_lastError = bzip2.errorString();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
m_success = true;
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
TarFilter tf(&bzip2);
|
||||
m_currentTarFilter = &tf;
|
||||
TarFilter::FileInformations tfi;
|
||||
while (tf.getData(tfi))
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "tfi.fileName = " << tfi.fileName;
|
||||
emit uncompressInfo(input->size(), input->pos(), tfi.fileName);
|
||||
if (m_aborted)
|
||||
return false;
|
||||
|
||||
FileInformations fi;
|
||||
fi.outputFileName = tfi.fileName;
|
||||
|
||||
DEBUG_LOG(m_logger) << "fi.outputFileName = " << fi.outputFileName;
|
||||
|
||||
if (tfi.fileType == TarFilter::directory)
|
||||
{
|
||||
fi.outputFileName += QLatin1Char('/');
|
||||
DEBUG_LOG(m_logger) << "> fi.outputFileName = " << fi.outputFileName;
|
||||
}
|
||||
else
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "stuff";
|
||||
|
||||
QBuffer buf(&fi.fileData);
|
||||
if (!buf.open(QIODevice::WriteOnly))
|
||||
{
|
||||
m_lastError = tr("Error opening buffer for writing (%1)").arg(buf.errorString());
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
if (!tf.getData(&buf))
|
||||
{
|
||||
m_lastError = tf.lastError();
|
||||
ERROR_LOG(m_logger) << "compress failed: " << m_lastError;
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
fi.bAbsInputPath = fi.outputFileName.startsWith(QLatin1Char('/'));
|
||||
DEBUG_LOG(m_logger) << "added fi.bAbsInputPath = " << fi.bAbsInputPath;
|
||||
m_u2_memFiles += fi;
|
||||
}
|
||||
|
||||
m_success = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Compress::success() const
|
||||
{
|
||||
|
||||
ERROR_LOG(m_logger) << "success? " << (m_future.isFinished() && !m_future.isCanceled() && m_success);
|
||||
ERROR_LOG(m_logger) << "success details: "
|
||||
<< "success m_future.isFinished() = " << (m_future.isFinished())
|
||||
<< " !m_future.isCanceled() = " << !m_future.isCanceled()
|
||||
<< " m_success = " << m_success;
|
||||
return (m_future.isFinished() && !m_future.isCanceled() && m_success);
|
||||
|
||||
ERROR_LOG(m_logger) << "success? " << (m_future.isFinished() && !m_future.isCanceled() && m_success);
|
||||
ERROR_LOG(m_logger) << "success details: "
|
||||
<< "success m_future.isFinished() = " << (m_future.isFinished())
|
||||
<< " !m_future.isCanceled() = " << !m_future.isCanceled() << " m_success = " << m_success;
|
||||
return (m_future.isFinished() && !m_future.isCanceled() && m_success);
|
||||
}
|
||||
|
||||
bool Compress::waitForFinished()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "waitForFinished...";
|
||||
m_future.waitForFinished();
|
||||
DEBUG_LOG(m_logger) << "waitForFinished... done!";
|
||||
return success();
|
||||
DEBUG_LOG(m_logger) << "waitForFinished...";
|
||||
m_future.waitForFinished();
|
||||
DEBUG_LOG(m_logger) << "waitForFinished... done!";
|
||||
return success();
|
||||
}
|
||||
|
||||
QVector<Compress::FileInformations> Compress::directoryFileList(const QString &dir, bool recursive)
|
||||
QVector<Compress::FileInformations> Compress::directoryFileList(const QString& dir, bool recursive)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "directoryFileList";
|
||||
DEBUG_LOG(m_logger) << "directoryFileList";
|
||||
|
||||
QVector<FileInformations> sl_absolute;
|
||||
QDir d(dir);
|
||||
QVector<FileInformations> sl_absolute;
|
||||
QDir d(dir);
|
||||
|
||||
if (d.exists())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "exists";
|
||||
const auto entries = d.entryList(QDir::Files);
|
||||
sl_absolute.reserve(sl_absolute.size() + entries.size());
|
||||
for (const QString &entry : entries)
|
||||
sl_absolute << FileInformations(QFileInfo(d, entry).absoluteFilePath(), true);
|
||||
}
|
||||
if (d.exists())
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "exists";
|
||||
const auto entries = d.entryList(QDir::Files);
|
||||
sl_absolute.reserve(sl_absolute.size() + entries.size());
|
||||
for (const QString& entry : entries)
|
||||
sl_absolute << FileInformations(QFileInfo(d, entry).absoluteFilePath(), true);
|
||||
}
|
||||
|
||||
if (recursive)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "recursive";
|
||||
const auto entries = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
sl_absolute.reserve(sl_absolute.size() + entries.size());
|
||||
for (const QString &s : entries)
|
||||
sl_absolute << directoryFileList(dir + QLatin1Char('/') + s, true);
|
||||
}
|
||||
if (recursive)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "recursive";
|
||||
const auto entries = d.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
|
||||
sl_absolute.reserve(sl_absolute.size() + entries.size());
|
||||
for (const QString& s : entries)
|
||||
sl_absolute << directoryFileList(dir + QLatin1Char('/') + s, true);
|
||||
}
|
||||
|
||||
DEBUG_LOG(m_logger) << "done";
|
||||
return sl_absolute;
|
||||
DEBUG_LOG(m_logger) << "done";
|
||||
return sl_absolute;
|
||||
}
|
||||
|
||||
void Compress::reset()
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "reset";
|
||||
m_u2_memFiles.clear();
|
||||
DEBUG_LOG(m_logger) << "reset";
|
||||
m_u2_memFiles.clear();
|
||||
|
||||
m_lastError.clear();
|
||||
m_lastError.clear();
|
||||
|
||||
m_c_sizeInfo.realSize = 0;
|
||||
m_c_sizeInfo.compressedSize = 0;
|
||||
m_c_sizeInfo.realSize = 0;
|
||||
m_c_sizeInfo.compressedSize = 0;
|
||||
|
||||
m_success = false;
|
||||
m_success = false;
|
||||
}
|
||||
|
||||
void Compress::setupFutureWatcher(const QFuture<bool> &future)
|
||||
void Compress::setupFutureWatcher(const QFuture<bool>& future)
|
||||
{
|
||||
DEBUG_LOG(m_logger) << "setupFutureWatcher";
|
||||
m_future = future;
|
||||
QFutureWatcher<bool> *fw = new QFutureWatcher<bool>(this);
|
||||
QObject::connect(fw, &QObject::destroyed, this, [this]() { DEBUG_LOG(m_logger) << "Future Watcher destroyed"; });
|
||||
QObject::connect(fw, &QFutureWatcher<bool>::finished, this, &Compress::finished);
|
||||
QObject::connect(fw, &QFutureWatcher<bool>::finished, fw, &QObject::deleteLater);
|
||||
QObject::connect(fw, &QFutureWatcher<bool>::finished, fw, [this]() { DEBUG_LOG(m_logger) << "Future Watcher about to be deleted"; });
|
||||
fw->setFuture(m_future);
|
||||
DEBUG_LOG(m_logger) << "setupFutureWatcher";
|
||||
m_future = future;
|
||||
QFutureWatcher<bool>* fw = new QFutureWatcher<bool>(this);
|
||||
QObject::connect(fw, &QObject::destroyed, this, [this]() { DEBUG_LOG(m_logger) << "Future Watcher destroyed"; });
|
||||
QObject::connect(fw, &QFutureWatcher<bool>::finished, this, &Compress::finished);
|
||||
QObject::connect(fw, &QFutureWatcher<bool>::finished, fw, &QObject::deleteLater);
|
||||
QObject::connect(fw, &QFutureWatcher<bool>::finished, fw,
|
||||
[this]() { DEBUG_LOG(m_logger) << "Future Watcher about to be deleted"; });
|
||||
fw->setFuture(m_future);
|
||||
}
|
||||
|
||||
}
|
||||
} // namespace NGL
|
||||
Reference in new issue
Block a user