Browse Source

Fix import of new trackers when adding a torrent with same hash (Closes #747000)

adaptive-webui-19844
Christophe Dumez 13 years ago
parent
commit
d53ca1d096
  1. 33
      src/qtlibtorrent/qbtsession.cpp

33
src/qtlibtorrent/qbtsession.cpp

@ -1307,35 +1307,37 @@ void QBtSession::mergeTorrents(QTorrentHandle &h_ex, boost::intrusive_ptr<torren
// Check if the torrent contains trackers or url seeds we don't know about // Check if the torrent contains trackers or url seeds we don't know about
// and add them // and add them
if(!h_ex.is_valid()) return; if(!h_ex.is_valid()) return;
std::vector<announce_entry> old_trackers = h_ex.trackers(); std::vector<announce_entry> existing_trackers = h_ex.trackers();
std::vector<announce_entry> new_trackers = t->trackers(); std::vector<announce_entry> new_trackers = t->trackers();
bool trackers_added = false; bool trackers_added = false;
for(std::vector<announce_entry>::iterator it=new_trackers.begin();it!=new_trackers.end();it++) { foreach (const announce_entry& new_tracker, new_trackers) {
std::string tracker_url = it->url; std::string new_tracker_url = new_tracker.url;
// Check if existing torrent has this tracker
bool found = false; bool found = false;
for(std::vector<announce_entry>::iterator itold=old_trackers.begin();itold!=old_trackers.end();itold++) { foreach (const announce_entry& existing_tracker, existing_trackers) {
if(tracker_url == itold->url) { if(QUrl(new_tracker_url.c_str()) == QUrl(existing_tracker.url.c_str())) {
found = true; found = true;
break; break;
} }
} }
if(found) {
if (!found) {
h_ex.add_tracker(announce_entry(new_tracker_url));
trackers_added = true; trackers_added = true;
announce_entry entry(tracker_url);
h_ex.add_tracker(entry);
} }
} }
if(trackers_added) {
if (trackers_added)
addConsoleMessage(tr("Note: new trackers were added to the existing torrent.")); addConsoleMessage(tr("Note: new trackers were added to the existing torrent."));
}
bool urlseeds_added = false; bool urlseeds_added = false;
const QStringList old_urlseeds = h_ex.url_seeds(); const QStringList old_urlseeds = h_ex.url_seeds();
#if LIBTORRENT_VERSION_MINOR > 15 #if LIBTORRENT_VERSION_MINOR > 15
std::vector<web_seed_entry> new_urlseeds = t->web_seeds(); std::vector<web_seed_entry> new_urlseeds = t->web_seeds();
std::vector<web_seed_entry>::iterator it; std::vector<web_seed_entry>::iterator it;
for(it = new_urlseeds.begin(); it != new_urlseeds.end(); it++) { for (it = new_urlseeds.begin(); it != new_urlseeds.end(); it++) {
const QString new_url = misc::toQString(it->url.c_str()); const QString new_url = misc::toQString(it->url.c_str());
if(!old_urlseeds.contains(new_url)) { if (!old_urlseeds.contains(new_url)) {
urlseeds_added = true; urlseeds_added = true;
h_ex.add_url_seed(new_url); h_ex.add_url_seed(new_url);
} }
@ -1343,17 +1345,16 @@ void QBtSession::mergeTorrents(QTorrentHandle &h_ex, boost::intrusive_ptr<torren
#else #else
std::vector<std::string> new_urlseeds = t->url_seeds(); std::vector<std::string> new_urlseeds = t->url_seeds();
std::vector<std::string>::iterator it; std::vector<std::string>::iterator it;
for(it = new_urlseeds.begin(); it != new_urlseeds.end(); it++) { for (it = new_urlseeds.begin(); it != new_urlseeds.end(); it++) {
const QString new_url = misc::toQString(it->c_str()); const QString new_url = misc::toQString(it->c_str());
if(!old_urlseeds.contains(new_url)) { if (!old_urlseeds.contains(new_url)) {
urlseeds_added = true; urlseeds_added = true;
h_ex.add_url_seed(new_url); h_ex.add_url_seed(new_url);
} }
} }
#endif #endif
if(urlseeds_added) { if(urlseeds_added)
addConsoleMessage(tr("Note: new URL seeds were added to the existing torrent.")); addConsoleMessage(tr("Note: new URL seeds were added to the existing torrent."));
}
} }
void QBtSession::exportTorrentFiles(QString path) { void QBtSession::exportTorrentFiles(QString path) {

Loading…
Cancel
Save