|
|
@ -29,7 +29,6 @@ |
|
|
|
#include "bencoderesumedatastorage.h" |
|
|
|
#include "bencoderesumedatastorage.h" |
|
|
|
|
|
|
|
|
|
|
|
#include <libtorrent/bdecode.hpp> |
|
|
|
#include <libtorrent/bdecode.hpp> |
|
|
|
#include <libtorrent/bencode.hpp> |
|
|
|
|
|
|
|
#include <libtorrent/entry.hpp> |
|
|
|
#include <libtorrent/entry.hpp> |
|
|
|
#include <libtorrent/read_resume_data.hpp> |
|
|
|
#include <libtorrent/read_resume_data.hpp> |
|
|
|
#include <libtorrent/torrent_info.hpp> |
|
|
|
#include <libtorrent/torrent_info.hpp> |
|
|
@ -37,7 +36,6 @@ |
|
|
|
|
|
|
|
|
|
|
|
#include <QByteArray> |
|
|
|
#include <QByteArray> |
|
|
|
#include <QRegularExpression> |
|
|
|
#include <QRegularExpression> |
|
|
|
#include <QSaveFile> |
|
|
|
|
|
|
|
#include <QThread> |
|
|
|
#include <QThread> |
|
|
|
|
|
|
|
|
|
|
|
#include "base/algorithm.h" |
|
|
|
#include "base/algorithm.h" |
|
|
@ -88,17 +86,6 @@ namespace |
|
|
|
entryList.emplace_back(setValue.toStdString()); |
|
|
|
entryList.emplace_back(setValue.toStdString()); |
|
|
|
return entryList; |
|
|
|
return entryList; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void writeEntryToFile(const QString &filepath, const lt::entry &data) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
QSaveFile file {filepath}; |
|
|
|
|
|
|
|
if (!file.open(QIODevice::WriteOnly)) |
|
|
|
|
|
|
|
throw RuntimeError(file.errorString()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
lt::bencode(Utils::IO::FileDeviceOutputIterator {file}, data); |
|
|
|
|
|
|
|
if (file.error() != QFileDevice::NoError || !file.commit()) |
|
|
|
|
|
|
|
throw RuntimeError(file.errorString()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
BitTorrent::BencodeResumeDataStorage::BencodeResumeDataStorage(const QString &path, QObject *parent) |
|
|
|
BitTorrent::BencodeResumeDataStorage::BencodeResumeDataStorage(const QString &path, QObject *parent) |
|
|
@ -355,14 +342,11 @@ void BitTorrent::BencodeResumeDataStorage::Worker::store(const TorrentID &id, co |
|
|
|
metadataDict.insert(dataDict.extract("comment")); |
|
|
|
metadataDict.insert(dataDict.extract("comment")); |
|
|
|
|
|
|
|
|
|
|
|
const QString torrentFilepath = m_resumeDataDir.absoluteFilePath(QString::fromLatin1("%1.torrent").arg(id.toString())); |
|
|
|
const QString torrentFilepath = m_resumeDataDir.absoluteFilePath(QString::fromLatin1("%1.torrent").arg(id.toString())); |
|
|
|
try |
|
|
|
const nonstd::expected<void, QString> result = Utils::IO::saveToFile(torrentFilepath, metadata); |
|
|
|
{ |
|
|
|
if (!result) |
|
|
|
writeEntryToFile(torrentFilepath, metadata); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (const RuntimeError &err) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
LogMsg(tr("Couldn't save torrent metadata to '%1'. Error: %2.") |
|
|
|
LogMsg(tr("Couldn't save torrent metadata to '%1'. Error: %2.") |
|
|
|
.arg(torrentFilepath, err.message()), Log::CRITICAL); |
|
|
|
.arg(torrentFilepath, result.error()), Log::CRITICAL); |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -378,14 +362,11 @@ void BitTorrent::BencodeResumeDataStorage::Worker::store(const TorrentID &id, co |
|
|
|
data["qBt-firstLastPiecePriority"] = resumeData.firstLastPiecePriority; |
|
|
|
data["qBt-firstLastPiecePriority"] = resumeData.firstLastPiecePriority; |
|
|
|
|
|
|
|
|
|
|
|
const QString resumeFilepath = m_resumeDataDir.absoluteFilePath(QString::fromLatin1("%1.fastresume").arg(id.toString())); |
|
|
|
const QString resumeFilepath = m_resumeDataDir.absoluteFilePath(QString::fromLatin1("%1.fastresume").arg(id.toString())); |
|
|
|
try |
|
|
|
const nonstd::expected<void, QString> result = Utils::IO::saveToFile(resumeFilepath, data); |
|
|
|
{ |
|
|
|
if (!result) |
|
|
|
writeEntryToFile(resumeFilepath, data); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
catch (const RuntimeError &err) |
|
|
|
|
|
|
|
{ |
|
|
|
{ |
|
|
|
LogMsg(tr("Couldn't save torrent resume data to '%1'. Error: %2.") |
|
|
|
LogMsg(tr("Couldn't save torrent resume data to '%1'. Error: %2.") |
|
|
|
.arg(resumeFilepath, err.message()), Log::CRITICAL); |
|
|
|
.arg(resumeFilepath, result.error()), Log::CRITICAL); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -406,10 +387,10 @@ void BitTorrent::BencodeResumeDataStorage::Worker::storeQueue(const QVector<Torr |
|
|
|
data += (torrentID.toString().toLatin1() + '\n'); |
|
|
|
data += (torrentID.toString().toLatin1() + '\n'); |
|
|
|
|
|
|
|
|
|
|
|
const QString filepath = m_resumeDataDir.absoluteFilePath(QLatin1String("queue")); |
|
|
|
const QString filepath = m_resumeDataDir.absoluteFilePath(QLatin1String("queue")); |
|
|
|
QSaveFile file {filepath}; |
|
|
|
const nonstd::expected<void, QString> result = Utils::IO::saveToFile(filepath, data); |
|
|
|
if (!file.open(QIODevice::WriteOnly) || (file.write(data) != data.size()) || !file.commit()) |
|
|
|
if (!result) |
|
|
|
{ |
|
|
|
{ |
|
|
|
LogMsg(tr("Couldn't save data to '%1'. Error: %2") |
|
|
|
LogMsg(tr("Couldn't save data to '%1'. Error: %2") |
|
|
|
.arg(filepath, file.errorString()), Log::CRITICAL); |
|
|
|
.arg(filepath, result.error()), Log::CRITICAL); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|