|
|
@ -111,7 +111,7 @@ using namespace BitTorrent; |
|
|
|
namespace |
|
|
|
namespace |
|
|
|
{ |
|
|
|
{ |
|
|
|
bool readFile(const QString &path, QByteArray &buf); |
|
|
|
bool readFile(const QString &path, QByteArray &buf); |
|
|
|
bool loadTorrentResumeData(const QByteArray &data, AddTorrentData &torrentData, int &prio, MagnetUri &magnetUri); |
|
|
|
bool loadTorrentResumeData(const QByteArray &data, CreateTorrentParams &torrentParams, int &prio, MagnetUri &magnetUri); |
|
|
|
|
|
|
|
|
|
|
|
void torrentQueuePositionUp(const libt::torrent_handle &handle); |
|
|
|
void torrentQueuePositionUp(const libt::torrent_handle &handle); |
|
|
|
void torrentQueuePositionDown(const libt::torrent_handle &handle); |
|
|
|
void torrentQueuePositionDown(const libt::torrent_handle &handle); |
|
|
@ -2110,15 +2110,15 @@ bool Session::addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Add a torrent to the BitTorrent session
|
|
|
|
// Add a torrent to the BitTorrent session
|
|
|
|
bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri, |
|
|
|
bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magnetUri, |
|
|
|
TorrentInfo torrentInfo, const QByteArray &fastresumeData) |
|
|
|
TorrentInfo torrentInfo, const QByteArray &fastresumeData) |
|
|
|
{ |
|
|
|
{ |
|
|
|
addData.savePath = normalizeSavePath(addData.savePath, ""); |
|
|
|
params.savePath = normalizeSavePath(params.savePath, ""); |
|
|
|
|
|
|
|
|
|
|
|
if (!addData.category.isEmpty()) { |
|
|
|
if (!params.category.isEmpty()) { |
|
|
|
if (!m_categories.contains(addData.category) && !addCategory(addData.category)) { |
|
|
|
if (!m_categories.contains(params.category) && !addCategory(params.category)) { |
|
|
|
qWarning() << "Couldn't create category" << addData.category; |
|
|
|
qWarning() << "Couldn't create category" << params.category; |
|
|
|
addData.category = ""; |
|
|
|
params.category = ""; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2127,10 +2127,10 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri |
|
|
|
std::vector<boost::uint8_t> filePriorities; |
|
|
|
std::vector<boost::uint8_t> filePriorities; |
|
|
|
|
|
|
|
|
|
|
|
QString savePath; |
|
|
|
QString savePath; |
|
|
|
if (addData.savePath.isEmpty()) // using Automatic mode
|
|
|
|
if (params.savePath.isEmpty()) // using Automatic mode
|
|
|
|
savePath = categorySavePath(addData.category); |
|
|
|
savePath = categorySavePath(params.category); |
|
|
|
else // using Manual mode
|
|
|
|
else // using Manual mode
|
|
|
|
savePath = addData.savePath; |
|
|
|
savePath = params.savePath; |
|
|
|
|
|
|
|
|
|
|
|
bool fromMagnetUri = magnetUri.isValid(); |
|
|
|
bool fromMagnetUri = magnetUri.isValid(); |
|
|
|
if (fromMagnetUri) { |
|
|
|
if (fromMagnetUri) { |
|
|
@ -2151,7 +2151,7 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri |
|
|
|
adjustLimits(); |
|
|
|
adjustLimits(); |
|
|
|
|
|
|
|
|
|
|
|
// use common 2nd step of torrent addition
|
|
|
|
// use common 2nd step of torrent addition
|
|
|
|
m_addingTorrents.insert(hash, addData); |
|
|
|
m_addingTorrents.insert(hash, params); |
|
|
|
createTorrentHandle(handle); |
|
|
|
createTorrentHandle(handle); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
@ -2159,23 +2159,23 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri |
|
|
|
p = magnetUri.addTorrentParams(); |
|
|
|
p = magnetUri.addTorrentParams(); |
|
|
|
} |
|
|
|
} |
|
|
|
else if (torrentInfo.isValid()) { |
|
|
|
else if (torrentInfo.isValid()) { |
|
|
|
if (!addData.resumed) { |
|
|
|
if (!params.restored) { |
|
|
|
if (!addData.hasRootFolder) |
|
|
|
if (!params.hasRootFolder) |
|
|
|
torrentInfo.stripRootFolder(); |
|
|
|
torrentInfo.stripRootFolder(); |
|
|
|
|
|
|
|
|
|
|
|
// Metadata
|
|
|
|
// Metadata
|
|
|
|
if (!addData.hasSeedStatus) |
|
|
|
if (!params.hasSeedStatus) |
|
|
|
findIncompleteFiles(torrentInfo, savePath); |
|
|
|
findIncompleteFiles(torrentInfo, savePath); |
|
|
|
|
|
|
|
|
|
|
|
// if torrent name wasn't explicitly set we handle the case of
|
|
|
|
// if torrent name wasn't explicitly set we handle the case of
|
|
|
|
// initial renaming of torrent content and rename torrent accordingly
|
|
|
|
// initial renaming of torrent content and rename torrent accordingly
|
|
|
|
if (addData.name.isEmpty()) { |
|
|
|
if (params.name.isEmpty()) { |
|
|
|
QString contentName = torrentInfo.rootFolder(); |
|
|
|
QString contentName = torrentInfo.rootFolder(); |
|
|
|
if (contentName.isEmpty() && (torrentInfo.filesCount() == 1)) |
|
|
|
if (contentName.isEmpty() && (torrentInfo.filesCount() == 1)) |
|
|
|
contentName = torrentInfo.fileName(0); |
|
|
|
contentName = torrentInfo.fileName(0); |
|
|
|
|
|
|
|
|
|
|
|
if (!contentName.isEmpty() && (contentName != torrentInfo.name())) |
|
|
|
if (!contentName.isEmpty() && (contentName != torrentInfo.name())) |
|
|
|
addData.name = contentName; |
|
|
|
params.name = contentName; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -2189,13 +2189,13 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri |
|
|
|
return false; |
|
|
|
return false; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (addData.resumed && !fromMagnetUri) { |
|
|
|
if (params.restored && !fromMagnetUri) { |
|
|
|
// Set torrent fast resume data
|
|
|
|
// Set torrent fast resume data
|
|
|
|
p.resume_data = {fastresumeData.constData(), fastresumeData.constData() + fastresumeData.size()}; |
|
|
|
p.resume_data = {fastresumeData.constData(), fastresumeData.constData() + fastresumeData.size()}; |
|
|
|
p.flags |= libt::add_torrent_params::flag_use_resume_save_path; |
|
|
|
p.flags |= libt::add_torrent_params::flag_use_resume_save_path; |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
foreach (int prio, addData.filePriorities) |
|
|
|
foreach (int prio, params.filePriorities) |
|
|
|
filePriorities.push_back(prio); |
|
|
|
filePriorities.push_back(prio); |
|
|
|
p.file_priorities = filePriorities; |
|
|
|
p.file_priorities = filePriorities; |
|
|
|
} |
|
|
|
} |
|
|
@ -2228,7 +2228,7 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri |
|
|
|
|
|
|
|
|
|
|
|
// Seeding mode
|
|
|
|
// Seeding mode
|
|
|
|
// Skip checking and directly start seeding (new in libtorrent v0.15)
|
|
|
|
// Skip checking and directly start seeding (new in libtorrent v0.15)
|
|
|
|
if (addData.skipChecking) |
|
|
|
if (params.skipChecking) |
|
|
|
p.flags |= libt::add_torrent_params::flag_seed_mode; |
|
|
|
p.flags |= libt::add_torrent_params::flag_seed_mode; |
|
|
|
else |
|
|
|
else |
|
|
|
p.flags &= ~libt::add_torrent_params::flag_seed_mode; |
|
|
|
p.flags &= ~libt::add_torrent_params::flag_seed_mode; |
|
|
@ -2237,10 +2237,10 @@ bool Session::addTorrent_impl(AddTorrentData addData, const MagnetUri &magnetUri |
|
|
|
p.max_connections = maxConnectionsPerTorrent(); |
|
|
|
p.max_connections = maxConnectionsPerTorrent(); |
|
|
|
p.max_uploads = maxUploadsPerTorrent(); |
|
|
|
p.max_uploads = maxUploadsPerTorrent(); |
|
|
|
p.save_path = Utils::Fs::toNativePath(savePath).toStdString(); |
|
|
|
p.save_path = Utils::Fs::toNativePath(savePath).toStdString(); |
|
|
|
p.upload_limit = addData.uploadLimit; |
|
|
|
p.upload_limit = params.uploadLimit; |
|
|
|
p.download_limit = addData.downloadLimit; |
|
|
|
p.download_limit = params.downloadLimit; |
|
|
|
|
|
|
|
|
|
|
|
m_addingTorrents.insert(hash, addData); |
|
|
|
m_addingTorrents.insert(hash, params); |
|
|
|
// Adding torrent to BitTorrent session
|
|
|
|
// Adding torrent to BitTorrent session
|
|
|
|
m_nativeSession->async_add_torrent(p); |
|
|
|
m_nativeSession->async_add_torrent(p); |
|
|
|
return true; |
|
|
|
return true; |
|
|
@ -2362,7 +2362,6 @@ void Session::generateResumeData(bool final) |
|
|
|
if (!final && !torrent->needSaveResumeData()) continue; |
|
|
|
if (!final && !torrent->needSaveResumeData()) continue; |
|
|
|
|
|
|
|
|
|
|
|
saveTorrentResumeData(torrent, final); |
|
|
|
saveTorrentResumeData(torrent, final); |
|
|
|
qDebug("Saving fastresume data for %s", qUtf8Printable(torrent->name())); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -3529,45 +3528,58 @@ void Session::updateSeedingLimitTimer() |
|
|
|
|
|
|
|
|
|
|
|
void Session::handleTorrentShareLimitChanged(TorrentHandle *const torrent) |
|
|
|
void Session::handleTorrentShareLimitChanged(TorrentHandle *const torrent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
Q_UNUSED(torrent); |
|
|
|
saveTorrentResumeData(torrent); |
|
|
|
updateSeedingLimitTimer(); |
|
|
|
updateSeedingLimitTimer(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Session::saveTorrentResumeData(TorrentHandle *const torrent, bool finalSave) |
|
|
|
void Session::saveTorrentResumeData(TorrentHandle *const torrent, bool finalSave) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
qDebug("Saving fastresume data for %s", qUtf8Printable(torrent->name())); |
|
|
|
torrent->saveResumeData(finalSave); |
|
|
|
torrent->saveResumeData(finalSave); |
|
|
|
++m_numResumeData; |
|
|
|
++m_numResumeData; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Session::handleTorrentNameChanged(TorrentHandle *const torrent) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
saveTorrentResumeData(torrent); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Session::handleTorrentSavePathChanged(TorrentHandle *const torrent) |
|
|
|
void Session::handleTorrentSavePathChanged(TorrentHandle *const torrent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
saveTorrentResumeData(torrent); |
|
|
|
emit torrentSavePathChanged(torrent); |
|
|
|
emit torrentSavePathChanged(torrent); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Session::handleTorrentCategoryChanged(TorrentHandle *const torrent, const QString &oldCategory) |
|
|
|
void Session::handleTorrentCategoryChanged(TorrentHandle *const torrent, const QString &oldCategory) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
saveTorrentResumeData(torrent); |
|
|
|
emit torrentCategoryChanged(torrent, oldCategory); |
|
|
|
emit torrentCategoryChanged(torrent, oldCategory); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Session::handleTorrentTagAdded(TorrentHandle *const torrent, const QString &tag) |
|
|
|
void Session::handleTorrentTagAdded(TorrentHandle *const torrent, const QString &tag) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
saveTorrentResumeData(torrent); |
|
|
|
emit torrentTagAdded(torrent, tag); |
|
|
|
emit torrentTagAdded(torrent, tag); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Session::handleTorrentTagRemoved(TorrentHandle *const torrent, const QString &tag) |
|
|
|
void Session::handleTorrentTagRemoved(TorrentHandle *const torrent, const QString &tag) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
saveTorrentResumeData(torrent); |
|
|
|
emit torrentTagRemoved(torrent, tag); |
|
|
|
emit torrentTagRemoved(torrent, tag); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Session::handleTorrentSavingModeChanged(TorrentHandle *const torrent) |
|
|
|
void Session::handleTorrentSavingModeChanged(TorrentHandle *const torrent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
saveTorrentResumeData(torrent); |
|
|
|
emit torrentSavingModeChanged(torrent); |
|
|
|
emit torrentSavingModeChanged(torrent); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Session::handleTorrentTrackersAdded(TorrentHandle *const torrent, const QList<TrackerEntry> &newTrackers) |
|
|
|
void Session::handleTorrentTrackersAdded(TorrentHandle *const torrent, const QList<TrackerEntry> &newTrackers) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (const TrackerEntry &newTracker, newTrackers) |
|
|
|
saveTorrentResumeData(torrent); |
|
|
|
Logger::instance()->addMessage(tr("Tracker '%1' was added to torrent '%2'").arg(newTracker.url(), torrent->name())); |
|
|
|
|
|
|
|
|
|
|
|
for (const TrackerEntry &newTracker : newTrackers) |
|
|
|
|
|
|
|
LogMsg(tr("Tracker '%1' was added to torrent '%2'").arg(newTracker.url(), torrent->name())); |
|
|
|
emit trackersAdded(torrent, newTrackers); |
|
|
|
emit trackersAdded(torrent, newTrackers); |
|
|
|
if (torrent->trackers().size() == newTrackers.size()) |
|
|
|
if (torrent->trackers().size() == newTrackers.size()) |
|
|
|
emit trackerlessStateChanged(torrent, false); |
|
|
|
emit trackerlessStateChanged(torrent, false); |
|
|
@ -3576,8 +3588,10 @@ void Session::handleTorrentTrackersAdded(TorrentHandle *const torrent, const QLi |
|
|
|
|
|
|
|
|
|
|
|
void Session::handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QList<TrackerEntry> &deletedTrackers) |
|
|
|
void Session::handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QList<TrackerEntry> &deletedTrackers) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (const TrackerEntry &deletedTracker, deletedTrackers) |
|
|
|
saveTorrentResumeData(torrent); |
|
|
|
Logger::instance()->addMessage(tr("Tracker '%1' was deleted from torrent '%2'").arg(deletedTracker.url(), torrent->name())); |
|
|
|
|
|
|
|
|
|
|
|
for (const TrackerEntry &deletedTracker : deletedTrackers) |
|
|
|
|
|
|
|
LogMsg(tr("Tracker '%1' was deleted from torrent '%2'").arg(deletedTracker.url(), torrent->name())); |
|
|
|
emit trackersRemoved(torrent, deletedTrackers); |
|
|
|
emit trackersRemoved(torrent, deletedTrackers); |
|
|
|
if (torrent->trackers().size() == 0) |
|
|
|
if (torrent->trackers().size() == 0) |
|
|
|
emit trackerlessStateChanged(torrent, true); |
|
|
|
emit trackerlessStateChanged(torrent, true); |
|
|
@ -3586,19 +3600,22 @@ void Session::handleTorrentTrackersRemoved(TorrentHandle *const torrent, const Q |
|
|
|
|
|
|
|
|
|
|
|
void Session::handleTorrentTrackersChanged(TorrentHandle *const torrent) |
|
|
|
void Session::handleTorrentTrackersChanged(TorrentHandle *const torrent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
saveTorrentResumeData(torrent); |
|
|
|
emit trackersChanged(torrent); |
|
|
|
emit trackersChanged(torrent); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Session::handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList<QUrl> &newUrlSeeds) |
|
|
|
void Session::handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList<QUrl> &newUrlSeeds) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (const QUrl &newUrlSeed, newUrlSeeds) |
|
|
|
saveTorrentResumeData(torrent); |
|
|
|
Logger::instance()->addMessage(tr("URL seed '%1' was added to torrent '%2'").arg(newUrlSeed.toString(), torrent->name())); |
|
|
|
for (const QUrl &newUrlSeed : newUrlSeeds) |
|
|
|
|
|
|
|
LogMsg(tr("URL seed '%1' was added to torrent '%2'").arg(newUrlSeed.toString(), torrent->name())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Session::handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QList<QUrl> &urlSeeds) |
|
|
|
void Session::handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QList<QUrl> &urlSeeds) |
|
|
|
{ |
|
|
|
{ |
|
|
|
foreach (const QUrl &urlSeed, urlSeeds) |
|
|
|
saveTorrentResumeData(torrent); |
|
|
|
Logger::instance()->addMessage(tr("URL seed '%1' was removed from torrent '%2'").arg(urlSeed.toString(), torrent->name())); |
|
|
|
for (const QUrl &urlSeed : urlSeeds) |
|
|
|
|
|
|
|
LogMsg(tr("URL seed '%1' was removed from torrent '%2'").arg(urlSeed.toString(), torrent->name())); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
void Session::handleTorrentMetadataReceived(TorrentHandle *const torrent) |
|
|
|
void Session::handleTorrentMetadataReceived(TorrentHandle *const torrent) |
|
|
@ -3626,6 +3643,7 @@ void Session::handleTorrentPaused(TorrentHandle *const torrent) |
|
|
|
|
|
|
|
|
|
|
|
void Session::handleTorrentResumed(TorrentHandle *const torrent) |
|
|
|
void Session::handleTorrentResumed(TorrentHandle *const torrent) |
|
|
|
{ |
|
|
|
{ |
|
|
|
|
|
|
|
saveTorrentResumeData(torrent); |
|
|
|
emit torrentResumed(torrent); |
|
|
|
emit torrentResumed(torrent); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -3831,7 +3849,7 @@ void Session::startUpTorrents() |
|
|
|
{ |
|
|
|
{ |
|
|
|
QString hash; |
|
|
|
QString hash; |
|
|
|
MagnetUri magnetUri; |
|
|
|
MagnetUri magnetUri; |
|
|
|
AddTorrentData addTorrentData; |
|
|
|
CreateTorrentParams addTorrentData; |
|
|
|
QByteArray data; |
|
|
|
QByteArray data; |
|
|
|
} TorrentResumeData; |
|
|
|
} TorrentResumeData; |
|
|
|
|
|
|
|
|
|
|
@ -3864,12 +3882,12 @@ void Session::startUpTorrents() |
|
|
|
QString hash = rxMatch.captured(1); |
|
|
|
QString hash = rxMatch.captured(1); |
|
|
|
QString fastresumePath = resumeDataDir.absoluteFilePath(fastresumeName); |
|
|
|
QString fastresumePath = resumeDataDir.absoluteFilePath(fastresumeName); |
|
|
|
QByteArray data; |
|
|
|
QByteArray data; |
|
|
|
AddTorrentData resumeData; |
|
|
|
CreateTorrentParams torrentParams; |
|
|
|
MagnetUri magnetUri; |
|
|
|
MagnetUri magnetUri; |
|
|
|
int queuePosition; |
|
|
|
int queuePosition; |
|
|
|
if (readFile(fastresumePath, data) && loadTorrentResumeData(data, resumeData, queuePosition, magnetUri)) { |
|
|
|
if (readFile(fastresumePath, data) && loadTorrentResumeData(data, torrentParams, queuePosition, magnetUri)) { |
|
|
|
if (queuePosition <= nextQueuePosition) { |
|
|
|
if (queuePosition <= nextQueuePosition) { |
|
|
|
startupTorrent({ hash, magnetUri, resumeData, data }); |
|
|
|
startupTorrent({ hash, magnetUri, torrentParams, data }); |
|
|
|
|
|
|
|
|
|
|
|
if (queuePosition == nextQueuePosition) { |
|
|
|
if (queuePosition == nextQueuePosition) { |
|
|
|
++nextQueuePosition; |
|
|
|
++nextQueuePosition; |
|
|
@ -3886,7 +3904,7 @@ void Session::startUpTorrents() |
|
|
|
if (q != queuePosition) { |
|
|
|
if (q != queuePosition) { |
|
|
|
++numOfRemappedFiles; |
|
|
|
++numOfRemappedFiles; |
|
|
|
} |
|
|
|
} |
|
|
|
queuedResumeData[q] = {hash, magnetUri, resumeData, data}; |
|
|
|
queuedResumeData[q] = {hash, magnetUri, torrentParams, data}; |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -4012,6 +4030,7 @@ void Session::handleAlert(libt::alert *a) |
|
|
|
case libt::storage_moved_alert::alert_type: |
|
|
|
case libt::storage_moved_alert::alert_type: |
|
|
|
case libt::storage_moved_failed_alert::alert_type: |
|
|
|
case libt::storage_moved_failed_alert::alert_type: |
|
|
|
case libt::torrent_paused_alert::alert_type: |
|
|
|
case libt::torrent_paused_alert::alert_type: |
|
|
|
|
|
|
|
case libt::torrent_resumed_alert::alert_type: |
|
|
|
case libt::tracker_error_alert::alert_type: |
|
|
|
case libt::tracker_error_alert::alert_type: |
|
|
|
case libt::tracker_reply_alert::alert_type: |
|
|
|
case libt::tracker_reply_alert::alert_type: |
|
|
|
case libt::tracker_warning_alert::alert_type: |
|
|
|
case libt::tracker_warning_alert::alert_type: |
|
|
@ -4089,25 +4108,19 @@ void Session::createTorrentHandle(const libt::torrent_handle &nativeHandle) |
|
|
|
// Magnet added for preload its metadata
|
|
|
|
// Magnet added for preload its metadata
|
|
|
|
if (!m_addingTorrents.contains(nativeHandle.info_hash())) return; |
|
|
|
if (!m_addingTorrents.contains(nativeHandle.info_hash())) return; |
|
|
|
|
|
|
|
|
|
|
|
AddTorrentData data = m_addingTorrents.take(nativeHandle.info_hash()); |
|
|
|
CreateTorrentParams params = m_addingTorrents.take(nativeHandle.info_hash()); |
|
|
|
|
|
|
|
|
|
|
|
TorrentHandle *const torrent = new TorrentHandle(this, nativeHandle, data); |
|
|
|
TorrentHandle *const torrent = new TorrentHandle(this, nativeHandle, params); |
|
|
|
m_torrents.insert(torrent->hash(), torrent); |
|
|
|
m_torrents.insert(torrent->hash(), torrent); |
|
|
|
|
|
|
|
|
|
|
|
Logger *const logger = Logger::instance(); |
|
|
|
Logger *const logger = Logger::instance(); |
|
|
|
|
|
|
|
|
|
|
|
bool fromMagnetUri = !torrent->hasMetadata(); |
|
|
|
bool fromMagnetUri = !torrent->hasMetadata(); |
|
|
|
|
|
|
|
|
|
|
|
if (data.resumed) { |
|
|
|
if (params.restored) { |
|
|
|
if (fromMagnetUri && !data.addPaused) |
|
|
|
logger->addMessage(tr("'%1' restored.", "'torrent name' restored.").arg(torrent->name())); |
|
|
|
torrent->resume(data.addForced); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
logger->addMessage(tr("'%1' resumed. (fast resume)", "'torrent name' was resumed. (fast resume)") |
|
|
|
|
|
|
|
.arg(torrent->name())); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
qDebug("This is a NEW torrent (first time)..."); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// The following is useless for newly added magnet
|
|
|
|
// The following is useless for newly added magnet
|
|
|
|
if (!fromMagnetUri) { |
|
|
|
if (!fromMagnetUri) { |
|
|
|
// Backup torrent file
|
|
|
|
// Backup torrent file
|
|
|
@ -4126,9 +4139,6 @@ void Session::createTorrentHandle(const libt::torrent_handle &nativeHandle) |
|
|
|
if (isAddTrackersEnabled() && !torrent->isPrivate()) |
|
|
|
if (isAddTrackersEnabled() && !torrent->isPrivate()) |
|
|
|
torrent->addTrackers(m_additionalTrackerList); |
|
|
|
torrent->addTrackers(m_additionalTrackerList); |
|
|
|
|
|
|
|
|
|
|
|
// Start torrent because it was added in paused state
|
|
|
|
|
|
|
|
if (!data.addPaused) |
|
|
|
|
|
|
|
torrent->resume(); |
|
|
|
|
|
|
|
logger->addMessage(tr("'%1' added to download list.", "'torrent name' was added to download list.") |
|
|
|
logger->addMessage(tr("'%1' added to download list.", "'torrent name' was added to download list.") |
|
|
|
.arg(torrent->name())); |
|
|
|
.arg(torrent->name())); |
|
|
|
|
|
|
|
|
|
|
@ -4144,7 +4154,7 @@ void Session::createTorrentHandle(const libt::torrent_handle &nativeHandle) |
|
|
|
// Send torrent addition signal
|
|
|
|
// Send torrent addition signal
|
|
|
|
emit torrentAdded(torrent); |
|
|
|
emit torrentAdded(torrent); |
|
|
|
// Send new torrent signal
|
|
|
|
// Send new torrent signal
|
|
|
|
if (!data.resumed) |
|
|
|
if (!params.restored) |
|
|
|
emit torrentNew(torrent); |
|
|
|
emit torrentNew(torrent); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -4494,11 +4504,11 @@ namespace |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
bool loadTorrentResumeData(const QByteArray &data, AddTorrentData &torrentData, int &prio, MagnetUri &magnetUri) |
|
|
|
bool loadTorrentResumeData(const QByteArray &data, CreateTorrentParams &torrentParams, int &prio, MagnetUri &magnetUri) |
|
|
|
{ |
|
|
|
{ |
|
|
|
torrentData = AddTorrentData(); |
|
|
|
torrentParams = CreateTorrentParams(); |
|
|
|
torrentData.resumed = true; |
|
|
|
torrentParams.restored = true; |
|
|
|
torrentData.skipChecking = false; |
|
|
|
torrentParams.skipChecking = false; |
|
|
|
|
|
|
|
|
|
|
|
libt::error_code ec; |
|
|
|
libt::error_code ec; |
|
|
|
#if LIBTORRENT_VERSION_NUM < 10100 |
|
|
|
#if LIBTORRENT_VERSION_NUM < 10100 |
|
|
@ -4511,36 +4521,36 @@ namespace |
|
|
|
if (ec || (fast.type() != libt::bdecode_node::dict_t)) return false; |
|
|
|
if (ec || (fast.type() != libt::bdecode_node::dict_t)) return false; |
|
|
|
#endif |
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
|
|
torrentData.savePath = Profile::instance().fromPortablePath( |
|
|
|
torrentParams.savePath = Profile::instance().fromPortablePath( |
|
|
|
Utils::Fs::fromNativePath(QString::fromStdString(fast.dict_find_string_value("qBt-savePath")))); |
|
|
|
Utils::Fs::fromNativePath(QString::fromStdString(fast.dict_find_string_value("qBt-savePath")))); |
|
|
|
|
|
|
|
|
|
|
|
std::string ratioLimitString = fast.dict_find_string_value("qBt-ratioLimit"); |
|
|
|
std::string ratioLimitString = fast.dict_find_string_value("qBt-ratioLimit"); |
|
|
|
if (ratioLimitString.empty()) |
|
|
|
if (ratioLimitString.empty()) |
|
|
|
torrentData.ratioLimit = fast.dict_find_int_value("qBt-ratioLimit", TorrentHandle::USE_GLOBAL_RATIO * 1000) / 1000.0; |
|
|
|
torrentParams.ratioLimit = fast.dict_find_int_value("qBt-ratioLimit", TorrentHandle::USE_GLOBAL_RATIO * 1000) / 1000.0; |
|
|
|
else |
|
|
|
else |
|
|
|
torrentData.ratioLimit = QString::fromStdString(ratioLimitString).toDouble(); |
|
|
|
torrentParams.ratioLimit = QString::fromStdString(ratioLimitString).toDouble(); |
|
|
|
torrentData.seedingTimeLimit = fast.dict_find_int_value("qBt-seedingTimeLimit", TorrentHandle::USE_GLOBAL_SEEDING_TIME); |
|
|
|
torrentParams.seedingTimeLimit = fast.dict_find_int_value("qBt-seedingTimeLimit", TorrentHandle::USE_GLOBAL_SEEDING_TIME); |
|
|
|
// **************************************************************************************
|
|
|
|
// **************************************************************************************
|
|
|
|
// Workaround to convert legacy label to category
|
|
|
|
// Workaround to convert legacy label to category
|
|
|
|
// TODO: Should be removed in future
|
|
|
|
// TODO: Should be removed in future
|
|
|
|
torrentData.category = QString::fromStdString(fast.dict_find_string_value("qBt-label")); |
|
|
|
torrentParams.category = QString::fromStdString(fast.dict_find_string_value("qBt-label")); |
|
|
|
if (torrentData.category.isEmpty()) |
|
|
|
if (torrentParams.category.isEmpty()) |
|
|
|
// **************************************************************************************
|
|
|
|
// **************************************************************************************
|
|
|
|
torrentData.category = QString::fromStdString(fast.dict_find_string_value("qBt-category")); |
|
|
|
torrentParams.category = QString::fromStdString(fast.dict_find_string_value("qBt-category")); |
|
|
|
// auto because the return type depends on the #if above.
|
|
|
|
// auto because the return type depends on the #if above.
|
|
|
|
const auto tagsEntry = fast.dict_find_list("qBt-tags"); |
|
|
|
const auto tagsEntry = fast.dict_find_list("qBt-tags"); |
|
|
|
if (isList(tagsEntry)) |
|
|
|
if (isList(tagsEntry)) |
|
|
|
torrentData.tags = entryListToSet(tagsEntry); |
|
|
|
torrentParams.tags = entryListToSet(tagsEntry); |
|
|
|
torrentData.name = QString::fromStdString(fast.dict_find_string_value("qBt-name")); |
|
|
|
torrentParams.name = QString::fromStdString(fast.dict_find_string_value("qBt-name")); |
|
|
|
torrentData.hasSeedStatus = fast.dict_find_int_value("qBt-seedStatus"); |
|
|
|
torrentParams.hasSeedStatus = fast.dict_find_int_value("qBt-seedStatus"); |
|
|
|
torrentData.disableTempPath = fast.dict_find_int_value("qBt-tempPathDisabled"); |
|
|
|
torrentParams.disableTempPath = fast.dict_find_int_value("qBt-tempPathDisabled"); |
|
|
|
torrentData.hasRootFolder = fast.dict_find_int_value("qBt-hasRootFolder"); |
|
|
|
torrentParams.hasRootFolder = fast.dict_find_int_value("qBt-hasRootFolder"); |
|
|
|
|
|
|
|
|
|
|
|
magnetUri = MagnetUri(QString::fromStdString(fast.dict_find_string_value("qBt-magnetUri"))); |
|
|
|
magnetUri = MagnetUri(QString::fromStdString(fast.dict_find_string_value("qBt-magnetUri"))); |
|
|
|
torrentData.addPaused = fast.dict_find_int_value("qBt-paused"); |
|
|
|
torrentParams.paused = fast.dict_find_int_value("qBt-paused"); |
|
|
|
torrentData.addForced = fast.dict_find_int_value("qBt-forced"); |
|
|
|
torrentParams.forced = fast.dict_find_int_value("qBt-forced"); |
|
|
|
torrentData.firstLastPiecePriority = fast.dict_find_int_value("qBt-firstLastPiecePriority"); |
|
|
|
torrentParams.firstLastPiecePriority = fast.dict_find_int_value("qBt-firstLastPiecePriority"); |
|
|
|
torrentData.sequential = fast.dict_find_int_value("qBt-sequential"); |
|
|
|
torrentParams.sequential = fast.dict_find_int_value("qBt-sequential"); |
|
|
|
|
|
|
|
|
|
|
|
prio = fast.dict_find_int_value("qBt-queuePosition"); |
|
|
|
prio = fast.dict_find_int_value("qBt-queuePosition"); |
|
|
|
|
|
|
|
|
|
|
|