mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-19 23:17:21 -06:00
committed by
sledgehammer999
parent
18b56f4d0a
commit
ee5a72c570
@@ -43,6 +43,7 @@ using namespace BitTorrent;
|
||||
#include <QTimer>
|
||||
#include <QProcess>
|
||||
#include <QCoreApplication>
|
||||
#include <QThread>
|
||||
|
||||
#include <queue>
|
||||
#include <vector>
|
||||
@@ -78,6 +79,7 @@ using namespace BitTorrent;
|
||||
#include "private/filterparserthread.h"
|
||||
#include "private/statistics.h"
|
||||
#include "private/bandwidthscheduler.h"
|
||||
#include "private/resumedatasavingmanager.h"
|
||||
#include "trackerentry.h"
|
||||
#include "tracker.h"
|
||||
#include "magneturi.h"
|
||||
@@ -193,6 +195,11 @@ Session::Session(QObject *parent)
|
||||
connect(&m_networkManager, SIGNAL(configurationRemoved(const QNetworkConfiguration&)), SLOT(networkConfigurationChange(const QNetworkConfiguration&)));
|
||||
connect(&m_networkManager, SIGNAL(configurationChanged(const QNetworkConfiguration&)), SLOT(networkConfigurationChange(const QNetworkConfiguration&)));
|
||||
|
||||
m_ioThread = new QThread(this);
|
||||
m_resumeDataSavingManager = new ResumeDataSavingManager(m_resumeFolderPath);
|
||||
m_resumeDataSavingManager->moveToThread(m_ioThread);
|
||||
connect(m_ioThread, SIGNAL(finished()), m_resumeDataSavingManager, SLOT(deleteLater()));
|
||||
m_ioThread->start();
|
||||
m_resumeDataTimer->start();
|
||||
|
||||
// initialize PortForwarder instance
|
||||
@@ -270,6 +277,9 @@ Session::~Session()
|
||||
qDebug("Deleting the session");
|
||||
delete m_nativeSession;
|
||||
|
||||
m_ioThread->quit();
|
||||
m_ioThread->wait();
|
||||
|
||||
m_resumeFolderLock.close();
|
||||
m_resumeFolderLock.remove();
|
||||
}
|
||||
@@ -1701,7 +1711,17 @@ void Session::handleTorrentFinished(TorrentHandle *const torrent)
|
||||
void Session::handleTorrentResumeDataReady(TorrentHandle *const torrent, const libtorrent::entry &data)
|
||||
{
|
||||
--m_numResumeData;
|
||||
writeResumeDataFile(torrent, data);
|
||||
|
||||
// Separated thread is used for the blocking IO which results in slow processing of many torrents.
|
||||
// Encoding data in parallel while doing IO saves time. Copying libtorrent::entry objects around
|
||||
// isn't cheap too.
|
||||
|
||||
QByteArray out;
|
||||
libt::bencode(std::back_inserter(out), data);
|
||||
|
||||
QMetaObject::invokeMethod(m_resumeDataSavingManager, "saveResumeData",
|
||||
Q_ARG(QString, torrent->hash()), Q_ARG(QByteArray, out),
|
||||
Q_ARG(int, torrent->queuePosition()));
|
||||
}
|
||||
|
||||
void Session::handleTorrentResumeDataFailed(TorrentHandle *const torrent)
|
||||
@@ -2368,28 +2388,6 @@ bool loadTorrentResumeData(const QByteArray &data, AddTorrentData &out, MagnetUr
|
||||
return true;
|
||||
}
|
||||
|
||||
bool Session::writeResumeDataFile(TorrentHandle *const torrent, const libt::entry &data)
|
||||
{
|
||||
const QDir resumeDataDir(m_resumeFolderPath);
|
||||
|
||||
QStringList filters(QString("%1.fastresume.*").arg(torrent->hash()));
|
||||
const QStringList files = resumeDataDir.entryList(filters, QDir::Files, QDir::Unsorted);
|
||||
foreach (const QString &file, files)
|
||||
Utils::Fs::forceRemove(resumeDataDir.absoluteFilePath(file));
|
||||
|
||||
QString filename = QString("%1.fastresume.%2").arg(torrent->hash()).arg(torrent->queuePosition());
|
||||
QString filepath = resumeDataDir.absoluteFilePath(filename);
|
||||
|
||||
qDebug("Saving resume data in %s", qPrintable(filepath));
|
||||
QFile resumeFile(filepath);
|
||||
QVector<char> out;
|
||||
libt::bencode(std::back_inserter(out), data);
|
||||
if (resumeFile.open(QIODevice::WriteOnly))
|
||||
return (resumeFile.write(&out[0], out.size()) == out.size());
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void torrentQueuePositionUp(const libt::torrent_handle &handle)
|
||||
{
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user