|
|
@ -1728,18 +1728,9 @@ bool Session::cancelLoadMetadata(const InfoHash &hash) |
|
|
|
if (loadedMetadataIter == m_loadedMetadata.end()) return false; |
|
|
|
if (loadedMetadataIter == m_loadedMetadata.end()) return false; |
|
|
|
|
|
|
|
|
|
|
|
m_loadedMetadata.erase(loadedMetadataIter); |
|
|
|
m_loadedMetadata.erase(loadedMetadataIter); |
|
|
|
const lt::torrent_handle torrent = m_nativeSession->find_torrent(hash); |
|
|
|
--m_extraLimit; |
|
|
|
if (!torrent.is_valid()) return false; |
|
|
|
adjustLimits(); |
|
|
|
|
|
|
|
m_nativeSession->remove_torrent(m_nativeSession->find_torrent(hash), lt::session::delete_files); |
|
|
|
if (!torrent.status(lt::status_flags_t {0}).has_metadata) { |
|
|
|
|
|
|
|
// if hidden torrent is still loading metadata...
|
|
|
|
|
|
|
|
--m_extraLimit; |
|
|
|
|
|
|
|
adjustLimits(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Remove it from session
|
|
|
|
|
|
|
|
m_nativeSession->remove_torrent(torrent, lt::session::delete_files); |
|
|
|
|
|
|
|
qDebug("Preloaded torrent deleted."); |
|
|
|
|
|
|
|
return true; |
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -1787,7 +1778,7 @@ void Session::decreaseTorrentsQueuePos(const QVector<InfoHash> &hashes) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (auto i = m_loadedMetadata.cbegin(); i != m_loadedMetadata.cend(); ++i) |
|
|
|
for (auto i = m_loadedMetadata.cbegin(); i != m_loadedMetadata.cend(); ++i) |
|
|
|
torrentQueuePositionBottom(m_nativeSession->find_torrent(i.key())); |
|
|
|
torrentQueuePositionBottom(m_nativeSession->find_torrent(*i)); |
|
|
|
|
|
|
|
|
|
|
|
saveTorrentsQueue(); |
|
|
|
saveTorrentsQueue(); |
|
|
|
} |
|
|
|
} |
|
|
@ -1836,7 +1827,7 @@ void Session::bottomTorrentsQueuePos(const QVector<InfoHash> &hashes) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
for (auto i = m_loadedMetadata.cbegin(); i != m_loadedMetadata.cend(); ++i) |
|
|
|
for (auto i = m_loadedMetadata.cbegin(); i != m_loadedMetadata.cend(); ++i) |
|
|
|
torrentQueuePositionBottom(m_nativeSession->find_torrent(i.key())); |
|
|
|
torrentQueuePositionBottom(m_nativeSession->find_torrent(*i)); |
|
|
|
|
|
|
|
|
|
|
|
saveTorrentsQueue(); |
|
|
|
saveTorrentsQueue(); |
|
|
|
} |
|
|
|
} |
|
|
@ -1891,42 +1882,14 @@ bool Session::addTorrent(const MagnetUri &magnetUri, const AddTorrentParams &par |
|
|
|
|
|
|
|
|
|
|
|
const auto it = m_loadedMetadata.constFind(hash); |
|
|
|
const auto it = m_loadedMetadata.constFind(hash); |
|
|
|
if (it != m_loadedMetadata.constEnd()) { |
|
|
|
if (it != m_loadedMetadata.constEnd()) { |
|
|
|
// Adding preloaded torrent...
|
|
|
|
// It looks illogical that we don't just use an existing handle,
|
|
|
|
const TorrentInfo metadata = it->metadata; |
|
|
|
// but as previous experience has shown, it actually creates unnecessary
|
|
|
|
if (metadata.isValid()) { |
|
|
|
// problems and unwanted behavior due to the fact that it was originally
|
|
|
|
// Metadata is received and torrent_handle is being deleted
|
|
|
|
// added with parameters other than those provided by the user.
|
|
|
|
// so we can't reuse it. Just add torrent using its metadata.
|
|
|
|
m_loadedMetadata.erase(it); |
|
|
|
return addTorrent(metadata, params); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Reuse existing torrent_handle
|
|
|
|
|
|
|
|
lt::torrent_handle handle = m_nativeSession->find_torrent(hash); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Preloaded torrent is in "Upload mode" so we need to disable it
|
|
|
|
|
|
|
|
// otherwise the torrent never be downloaded (until application restart)
|
|
|
|
|
|
|
|
handle.unset_flags(lt::torrent_flags::upload_mode); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
LoadTorrentParams createTorrentParams = initLoadTorrentParams(params); |
|
|
|
|
|
|
|
createTorrentParams.ltAddTorrentParams = it->ltAddTorrentParams; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (createTorrentParams.paused) { |
|
|
|
|
|
|
|
// Preloaded torrent isn't auto managed already
|
|
|
|
|
|
|
|
handle.pause(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (!createTorrentParams.forced) { |
|
|
|
|
|
|
|
handle.set_flags(lt::torrent_flags::auto_managed); |
|
|
|
|
|
|
|
handle.pause(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_loadedMetadata.remove(hash); |
|
|
|
|
|
|
|
m_loadingTorrents.insert(hash, createTorrentParams); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
--m_extraLimit; |
|
|
|
--m_extraLimit; |
|
|
|
adjustLimits(); |
|
|
|
adjustLimits(); |
|
|
|
|
|
|
|
m_nativeSession->remove_torrent(m_nativeSession->find_torrent(hash), lt::session::delete_files); |
|
|
|
// use common last step of torrent loading
|
|
|
|
|
|
|
|
createTorrentHandle(handle); |
|
|
|
|
|
|
|
return true; |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return addTorrent_impl(params, magnetUri); |
|
|
|
return addTorrent_impl(params, magnetUri); |
|
|
@ -2034,6 +1997,10 @@ bool Session::addTorrent_impl(const AddTorrentParams &addTorrentParams, const Ma |
|
|
|
} |
|
|
|
} |
|
|
|
else { |
|
|
|
else { |
|
|
|
p = magnetUri.addTorrentParams(); |
|
|
|
p = magnetUri.addTorrentParams(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (loadTorrentParams.name.isEmpty() && !p.name.empty()) |
|
|
|
|
|
|
|
loadTorrentParams.name = QString::fromStdString(p.name); |
|
|
|
|
|
|
|
|
|
|
|
if (isTempPathEnabled()) |
|
|
|
if (isTempPathEnabled()) |
|
|
|
actualSavePath = tempPath(); |
|
|
|
actualSavePath = tempPath(); |
|
|
|
} |
|
|
|
} |
|
|
@ -2164,7 +2131,7 @@ bool Session::loadMetadata(const MagnetUri &magnetUri) |
|
|
|
if (ec) return false; |
|
|
|
if (ec) return false; |
|
|
|
|
|
|
|
|
|
|
|
// waiting for metadata...
|
|
|
|
// waiting for metadata...
|
|
|
|
m_loadedMetadata.insert(h.info_hash(), {p, TorrentInfo {}}); |
|
|
|
m_loadedMetadata.insert(h.info_hash()); |
|
|
|
++m_extraLimit; |
|
|
|
++m_extraLimit; |
|
|
|
adjustLimits(); |
|
|
|
adjustLimits(); |
|
|
|
|
|
|
|
|
|
|
@ -3953,6 +3920,10 @@ bool Session::loadTorrentResumeData(const QByteArray &data, const TorrentInfo &m |
|
|
|
const lt::bdecode_node addedTimeNode = root.dict_find("qBt-addedTime"); |
|
|
|
const lt::bdecode_node addedTimeNode = root.dict_find("qBt-addedTime"); |
|
|
|
if (addedTimeNode.type() == lt::bdecode_node::int_t) |
|
|
|
if (addedTimeNode.type() == lt::bdecode_node::int_t) |
|
|
|
p.added_time = addedTimeNode.int_value(); |
|
|
|
p.added_time = addedTimeNode.int_value(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (torrentParams.name.isEmpty() && !p.name.empty()) |
|
|
|
|
|
|
|
torrentParams.name = QString::fromStdString(p.name); |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
// === END DEPRECATED CODE === //
|
|
|
|
// === END DEPRECATED CODE === //
|
|
|
|
else { |
|
|
|
else { |
|
|
@ -4291,12 +4262,6 @@ void Session::handleTorrentRemovedAlert(const lt::torrent_removed_alert *p) |
|
|
|
{ |
|
|
|
{ |
|
|
|
const InfoHash infoHash {p->info_hash}; |
|
|
|
const InfoHash infoHash {p->info_hash}; |
|
|
|
|
|
|
|
|
|
|
|
const auto loadedMetadataIter = m_loadedMetadata.find(infoHash); |
|
|
|
|
|
|
|
if (loadedMetadataIter != m_loadedMetadata.end()) { |
|
|
|
|
|
|
|
emit metadataLoaded(loadedMetadataIter->metadata); |
|
|
|
|
|
|
|
m_loadedMetadata.erase(loadedMetadataIter); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const auto removingTorrentDataIter = m_removingTorrents.find(infoHash); |
|
|
|
const auto removingTorrentDataIter = m_removingTorrents.find(infoHash); |
|
|
|
if (removingTorrentDataIter != m_removingTorrents.end()) { |
|
|
|
if (removingTorrentDataIter != m_removingTorrents.end()) { |
|
|
|
if (removingTorrentDataIter->deleteOption == Torrent) { |
|
|
|
if (removingTorrentDataIter->deleteOption == Torrent) { |
|
|
@ -4348,10 +4313,14 @@ void Session::handleMetadataReceivedAlert(const lt::metadata_received_alert *p) |
|
|
|
const auto loadedMetadataIter = m_loadedMetadata.find(hash); |
|
|
|
const auto loadedMetadataIter = m_loadedMetadata.find(hash); |
|
|
|
|
|
|
|
|
|
|
|
if (loadedMetadataIter != m_loadedMetadata.end()) { |
|
|
|
if (loadedMetadataIter != m_loadedMetadata.end()) { |
|
|
|
|
|
|
|
TorrentInfo metadata {p->handle.torrent_file()}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
m_loadedMetadata.erase(loadedMetadataIter); |
|
|
|
--m_extraLimit; |
|
|
|
--m_extraLimit; |
|
|
|
adjustLimits(); |
|
|
|
adjustLimits(); |
|
|
|
loadedMetadataIter->metadata = TorrentInfo {p->handle.torrent_file()}; |
|
|
|
|
|
|
|
m_nativeSession->remove_torrent(p->handle, lt::session::delete_files); |
|
|
|
m_nativeSession->remove_torrent(p->handle, lt::session::delete_files); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
emit metadataLoaded(metadata); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|