mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-25 08:51:21 -05:00
Add Tools::readAllFromDevice().
Make KeePass2XmlReader::readCompressedBinary() use the new function.
This commit is contained in:
parent
f8f52419c8
commit
f89ffa10e6
@ -17,6 +17,7 @@
|
||||
|
||||
#include "Tools.h"
|
||||
|
||||
#include <QtCore/QIODevice>
|
||||
#include <QtCore/QLocale>
|
||||
#include <QtCore/QStringList>
|
||||
|
||||
@ -51,4 +52,27 @@ bool hasChild(const QObject* parent, const QObject* child)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool readAllFromDevice(QIODevice* device, QByteArray& data)
|
||||
{
|
||||
QByteArray result;
|
||||
qint64 readBytes = 0;
|
||||
qint64 readResult;
|
||||
do {
|
||||
result.resize(result.size() + 16384);
|
||||
readResult = device->read(result.data() + readBytes, result.size() - readBytes);
|
||||
if (readResult > 0) {
|
||||
readBytes += readResult;
|
||||
}
|
||||
} while (readResult > 0);
|
||||
|
||||
if (readResult == -1) {
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
result.resize(static_cast<int>(readBytes));
|
||||
data = result;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace Tools
|
||||
|
@ -21,10 +21,13 @@
|
||||
#include <QtCore/QObject>
|
||||
#include <QtCore/QString>
|
||||
|
||||
class QIODevice;
|
||||
|
||||
namespace Tools {
|
||||
|
||||
QString humanReadableFileSize(qint64 bytes);
|
||||
bool hasChild(const QObject* parent, const QObject* child);
|
||||
bool readAllFromDevice(QIODevice* device, QByteArray& data);
|
||||
|
||||
} // namespace Tools
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "core/DatabaseIcons.h"
|
||||
#include "core/Group.h"
|
||||
#include "core/Metadata.h"
|
||||
#include "core/Tools.h"
|
||||
#include "format/KeePass2RandomStream.h"
|
||||
#include "streams/QtIOCompressor"
|
||||
|
||||
@ -873,24 +874,10 @@ QByteArray KeePass2XmlReader::readCompressedBinary()
|
||||
compressor.open(QIODevice::ReadOnly);
|
||||
|
||||
QByteArray result;
|
||||
qint64 readBytes = 0;
|
||||
qint64 readResult;
|
||||
do {
|
||||
result.resize(result.size() + 16384);
|
||||
readResult = compressor.read(result.data() + readBytes, result.size() - readBytes);
|
||||
if (readResult > 0) {
|
||||
readBytes += readResult;
|
||||
}
|
||||
} while (readResult > 0);
|
||||
|
||||
if (readResult == -1) {
|
||||
if (!Tools::readAllFromDevice(&compressor, result)) {
|
||||
raiseError(16);
|
||||
return QByteArray();
|
||||
}
|
||||
else {
|
||||
result.resize(static_cast<int>(readBytes));
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Group* KeePass2XmlReader::getGroup(const Uuid& uuid)
|
||||
|
Loading…
x
Reference in New Issue
Block a user