|
|
@ -95,7 +95,7 @@ namespace libt = libtorrent; |
|
|
|
using namespace BitTorrent; |
|
|
|
using namespace BitTorrent; |
|
|
|
|
|
|
|
|
|
|
|
static bool readFile(const QString &path, QByteArray &buf); |
|
|
|
static bool readFile(const QString &path, QByteArray &buf); |
|
|
|
static bool loadTorrentResumeData(const QByteArray &data, AddTorrentData &out); |
|
|
|
static bool loadTorrentResumeData(const QByteArray &data, AddTorrentData &out, MagnetUri &magnetUri); |
|
|
|
|
|
|
|
|
|
|
|
static void torrentQueuePositionUp(const libt::torrent_handle &handle); |
|
|
|
static void torrentQueuePositionUp(const libt::torrent_handle &handle); |
|
|
|
static void torrentQueuePositionDown(const libt::torrent_handle &handle); |
|
|
|
static void torrentQueuePositionDown(const libt::torrent_handle &handle); |
|
|
@ -1086,14 +1086,16 @@ bool Session::addTorrent_impl(const AddTorrentData &addData, const MagnetUri &ma |
|
|
|
p = magnetUri.addTorrentParams(); |
|
|
|
p = magnetUri.addTorrentParams(); |
|
|
|
hash = magnetUri.hash(); |
|
|
|
hash = magnetUri.hash(); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else if (torrentInfo.isValid()) { |
|
|
|
if (!torrentInfo.isValid()) return false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Metadata
|
|
|
|
// Metadata
|
|
|
|
p.ti = torrentInfo.nativeInfo(); |
|
|
|
p.ti = torrentInfo.nativeInfo(); |
|
|
|
hash = torrentInfo.hash(); |
|
|
|
hash = torrentInfo.hash(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else { |
|
|
|
|
|
|
|
Q_ASSERT(false); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (addData.resumed) { |
|
|
|
if (addData.resumed && !fromMagnetUri) { |
|
|
|
// Set torrent fast resume data
|
|
|
|
// Set torrent fast resume data
|
|
|
|
#if LIBTORRENT_VERSION_NUM < 10000 |
|
|
|
#if LIBTORRENT_VERSION_NUM < 10000 |
|
|
|
p.resume_data = &buf; |
|
|
|
p.resume_data = &buf; |
|
|
@ -1113,7 +1115,6 @@ bool Session::addTorrent_impl(const AddTorrentData &addData, const MagnetUri &ma |
|
|
|
p.file_priorities = filePriorities; |
|
|
|
p.file_priorities = filePriorities; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// We should not add torrent if it already
|
|
|
|
// We should not add torrent if it already
|
|
|
|
// processed or adding to session
|
|
|
|
// processed or adding to session
|
|
|
@ -1929,24 +1930,17 @@ void Session::startUpTorrents() |
|
|
|
resumeDataDir.absoluteFilePath(QString("%1.fastresume.%2").arg(hash).arg(prio)); |
|
|
|
resumeDataDir.absoluteFilePath(QString("%1.fastresume.%2").arg(hash).arg(prio)); |
|
|
|
QByteArray data; |
|
|
|
QByteArray data; |
|
|
|
AddTorrentData resumeData; |
|
|
|
AddTorrentData resumeData; |
|
|
|
if (readFile(fastresumePath, data) && loadTorrentResumeData(data, resumeData)) { |
|
|
|
MagnetUri magnetUri; |
|
|
|
|
|
|
|
if (readFile(fastresumePath, data) && loadTorrentResumeData(data, resumeData, magnetUri)) { |
|
|
|
filePath = resumeDataDir.filePath(QString("%1.torrent").arg(hash)); |
|
|
|
filePath = resumeDataDir.filePath(QString("%1.torrent").arg(hash)); |
|
|
|
if (QFile(filePath).exists()) { |
|
|
|
|
|
|
|
qDebug("Starting up torrent %s ...", qPrintable(hash)); |
|
|
|
qDebug("Starting up torrent %s ...", qPrintable(hash)); |
|
|
|
if (!addTorrent_impl(resumeData, MagnetUri(), TorrentInfo::loadFromFile(filePath), data)) |
|
|
|
if (!addTorrent_impl(resumeData, magnetUri, TorrentInfo::loadFromFile(filePath), data)) |
|
|
|
logger->addMessage(tr("Unable to resume torrent '%1'.", "e.g: Unable to resume torrent 'hash'.") |
|
|
|
logger->addMessage(tr("Unable to resume torrent '%1'.", "e.g: Unable to resume torrent 'hash'.") |
|
|
|
.arg(Utils::Fs::toNativePath(hash)), Log::CRITICAL); |
|
|
|
.arg(Utils::Fs::toNativePath(hash)), Log::CRITICAL); |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
|
|
|
|
logger->addMessage(tr("Unable to resume torrent '%1': torrent file not found.", "e.g: Unable to resume torrent 'hash': torrent file not found.") |
|
|
|
|
|
|
|
.arg(Utils::Fs::toNativePath(hash)), Log::CRITICAL); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
qDebug("Unfinished torrents resumed."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
quint64 Session::getAlltimeDL() const |
|
|
|
quint64 Session::getAlltimeDL() const |
|
|
|
{ |
|
|
|
{ |
|
|
|
return m_statistics->getAlltimeDL(); |
|
|
|
return m_statistics->getAlltimeDL(); |
|
|
@ -2121,6 +2115,9 @@ void Session::handleAddTorrentAlert(libtorrent::add_torrent_alert *p) |
|
|
|
bool fromMagnetUri = !torrent->hasMetadata(); |
|
|
|
bool fromMagnetUri = !torrent->hasMetadata(); |
|
|
|
|
|
|
|
|
|
|
|
if (data.resumed) { |
|
|
|
if (data.resumed) { |
|
|
|
|
|
|
|
if (fromMagnetUri && !data.addPaused) |
|
|
|
|
|
|
|
torrent->resume(data.addForced); |
|
|
|
|
|
|
|
|
|
|
|
logger->addMessage(tr("'%1' resumed. (fast resume)", "'torrent name' was resumed. (fast resume)") |
|
|
|
logger->addMessage(tr("'%1' resumed. (fast resume)", "'torrent name' was resumed. (fast resume)") |
|
|
|
.arg(torrent->name())); |
|
|
|
.arg(torrent->name())); |
|
|
|
} |
|
|
|
} |
|
|
@ -2363,7 +2360,7 @@ bool readFile(const QString &path, QByteArray &buf) |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool loadTorrentResumeData(const QByteArray &data, AddTorrentData &out) |
|
|
|
bool loadTorrentResumeData(const QByteArray &data, AddTorrentData &out, MagnetUri &magnetUri) |
|
|
|
{ |
|
|
|
{ |
|
|
|
out = AddTorrentData(); |
|
|
|
out = AddTorrentData(); |
|
|
|
out.resumed = true; |
|
|
|
out.resumed = true; |
|
|
@ -2381,6 +2378,10 @@ bool loadTorrentResumeData(const QByteArray &data, AddTorrentData &out) |
|
|
|
out.hasSeedStatus = fast.dict_find_int_value("qBt-seedStatus"); |
|
|
|
out.hasSeedStatus = fast.dict_find_int_value("qBt-seedStatus"); |
|
|
|
out.disableTempPath = fast.dict_find_int_value("qBt-tempPathDisabled"); |
|
|
|
out.disableTempPath = fast.dict_find_int_value("qBt-tempPathDisabled"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
magnetUri = MagnetUri(Utils::String::fromStdString(fast.dict_find_string_value("qBt-magnetUri"))); |
|
|
|
|
|
|
|
out.addPaused = fast.dict_find_int_value("qBt-paused"); |
|
|
|
|
|
|
|
out.addForced = fast.dict_find_int_value("qBt-forced"); |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|