|
@@ -6,22 +6,28 @@
|
|
// Fb2TemporaryFile
|
|
// Fb2TemporaryFile
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|
|
|
|
|
|
-Fb2TemporaryFile::Fb2TemporaryFile(const QString &name)
|
|
|
|
|
|
+Fb2TemporaryFile::Fb2TemporaryFile(const QString &name, const QString &hash)
|
|
: QTemporaryFile()
|
|
: QTemporaryFile()
|
|
, m_name(name)
|
|
, m_name(name)
|
|
|
|
+ , m_hash(hash)
|
|
{
|
|
{
|
|
open();
|
|
open();
|
|
}
|
|
}
|
|
|
|
|
|
qint64 Fb2TemporaryFile::write(const QByteArray &data)
|
|
qint64 Fb2TemporaryFile::write(const QByteArray &data)
|
|
{
|
|
{
|
|
- m_hash = QCryptographicHash::hash(data, QCryptographicHash::Md5).toBase64();
|
|
|
|
|
|
+ if (m_hash.isEmpty()) m_hash = md5(data);
|
|
qint64 size = QTemporaryFile::write(data);
|
|
qint64 size = QTemporaryFile::write(data);
|
|
close();
|
|
close();
|
|
open();
|
|
open();
|
|
return size;
|
|
return size;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+QString Fb2TemporaryFile::md5(const QByteArray &data)
|
|
|
|
+{
|
|
|
|
+ return QCryptographicHash::hash(data, QCryptographicHash::Md5).toBase64();
|
|
|
|
+}
|
|
|
|
+
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|
|
// Fb2TemporaryList
|
|
// Fb2TemporaryList
|
|
//---------------------------------------------------------------------------
|
|
//---------------------------------------------------------------------------
|
|
@@ -36,21 +42,23 @@ Fb2TemporaryList::~Fb2TemporaryList()
|
|
while (it.hasNext()) delete it.next();
|
|
while (it.hasNext()) delete it.next();
|
|
}
|
|
}
|
|
|
|
|
|
-Fb2TemporaryFile & Fb2TemporaryList::get(const QString &name)
|
|
|
|
|
|
+Fb2TemporaryFile & Fb2TemporaryList::get(const QString &name, const QString &hash)
|
|
{
|
|
{
|
|
Fb2TemporaryIterator it(*this);
|
|
Fb2TemporaryIterator it(*this);
|
|
while (it.hasNext()) {
|
|
while (it.hasNext()) {
|
|
Fb2TemporaryFile *file = it.next();
|
|
Fb2TemporaryFile *file = it.next();
|
|
if (file->name() == name) return *file;
|
|
if (file->name() == name) return *file;
|
|
}
|
|
}
|
|
- Fb2TemporaryFile * file = new Fb2TemporaryFile(name);
|
|
|
|
|
|
+ Fb2TemporaryFile * file = new Fb2TemporaryFile(name, hash);
|
|
append(file);
|
|
append(file);
|
|
return *file;
|
|
return *file;
|
|
}
|
|
}
|
|
|
|
|
|
-void Fb2TemporaryList::set(const QString &name, const QByteArray &data)
|
|
|
|
|
|
+QString Fb2TemporaryList::set(const QString &name, const QByteArray &data, const QString &hash)
|
|
{
|
|
{
|
|
- get(name).write(data);
|
|
|
|
|
|
+ Fb2TemporaryFile & file = get(name, hash);
|
|
|
|
+ file.write(data);
|
|
|
|
+ return file.hash();
|
|
}
|
|
}
|
|
|
|
|
|
QString Fb2TemporaryList::hash(const QString &path) const
|
|
QString Fb2TemporaryList::hash(const QString &path) const
|
|
@@ -83,7 +91,7 @@ QString Fb2TemporaryList::data(const QString &name) const
|
|
return QString();
|
|
return QString();
|
|
}
|
|
}
|
|
|
|
|
|
-bool Fb2TemporaryList::exists(const QString &name)
|
|
|
|
|
|
+bool Fb2TemporaryList::exists(const QString &name) const
|
|
{
|
|
{
|
|
Fb2TemporaryIterator it(*this);
|
|
Fb2TemporaryIterator it(*this);
|
|
while (it.hasNext()) {
|
|
while (it.hasNext()) {
|