From 3efba63e23391a3ae1fc6f308da7e8357e6f0577 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Wed, 23 Oct 2013 20:11:29 +0300 Subject: [PATCH] Revert "Don't use deprecated function when adding magnets." This reverts commit c74334669b495baeae2406d5af87a6b74eb3fb32. --- src/qtlibtorrent/qbtsession.cpp | 49 ++++++++++++++------------------- src/qtlibtorrent/qbtsession.h | 2 +- 2 files changed, 22 insertions(+), 29 deletions(-) diff --git a/src/qtlibtorrent/qbtsession.cpp b/src/qtlibtorrent/qbtsession.cpp index 2065b8682..1a37d9db9 100755 --- a/src/qtlibtorrent/qbtsession.cpp +++ b/src/qtlibtorrent/qbtsession.cpp @@ -921,15 +921,7 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f Q_UNUSED(filePath); Preferences pref; QTorrentHandle h; - add_torrent_params p; - libtorrent::error_code ec; - - libtorrent::parse_magnet_uri(magnet_uri.toUtf8().constData(), p, ec); - if (ec) { - addConsoleMessage(tr("Coudln't parse this magnet URI: '1%'").arg(magnet_uri)); - return h; - } - const QString hash(misc::toQString(p.info_hash)); + const QString hash(misc::magnetUriToHash(magnet_uri)); if (hash.isEmpty()) { addConsoleMessage(tr("'%1' is not a valid magnet URI.").arg(magnet_uri)); return h; @@ -944,21 +936,19 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f qDebug("Adding a magnet URI: %s", qPrintable(hash)); Q_ASSERT(magnet_uri.startsWith("magnet:", Qt::CaseInsensitive)); - // limit h_ex scope - { - // Check for duplicate torrent - QTorrentHandle h_ex = QTorrentHandle(s->find_torrent(p.info_hash)); - if (h_ex.is_valid()) { - qDebug("/!\\ Torrent is already in download list"); - addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(magnet_uri)); - // Check if the torrent contains trackers or url seeds we don't know about - // and add them - mergeTorrents(h_ex, magnet_uri); - return h; - } + // Check for duplicate torrent + if (s->find_torrent(QStringToSha1(hash)).is_valid()) { + qDebug("/!\\ Torrent is already in download list"); + addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(magnet_uri)); + // Check if the torrent contains trackers or url seeds we don't know about + // and add them + QTorrentHandle h_ex = getTorrentHandle(hash); + mergeTorrents(h_ex, magnet_uri); + + return h; } - initializeAddTorrentParams(hash, p); + add_torrent_params p = initializeAddTorrentParams(hash); // Get save path QString savePath; @@ -979,19 +969,19 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f // Check if save path exists, creating it otherwise if (!QDir(torrent_tmp_path).exists()) QDir().mkpath(torrent_tmp_path); - qDebug("addTorrent: using save_path: %s", qPrintable(torrent_tmp_path)); + qDebug("addMagnetURI: using save_path: %s", qPrintable(torrent_tmp_path)); } else { p.save_path = savePath.toUtf8().constData(); // Check if save path exists, creating it otherwise if (!QDir(savePath).exists()) QDir().mkpath(savePath); - qDebug("addTorrent: using save_path: %s", qPrintable(savePath)); + qDebug("addMagnetURI: using save_path: %s", qPrintable(savePath)); } qDebug("Adding magnet URI: %s", qPrintable(magnet_uri)); // Adding torrent to Bittorrent session try { - h = QTorrentHandle(s->add_torrent(p)); + h = QTorrentHandle(add_magnet_uri(*s, magnet_uri.toStdString(), p)); }catch(std::exception e) { qDebug("Error: %s", e.what()); } @@ -1131,8 +1121,7 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr } // Actually add the torrent - add_torrent_params p; - initializeAddTorrentParams(hash, p); + add_torrent_params p = initializeAddTorrentParams(hash); p.ti = t; // Get fast resume data if existing @@ -1264,7 +1253,9 @@ void QBtSession::exportTorrentFile(const QTorrentHandle& h, TorrentExportFolder } } -void QBtSession::initializeAddTorrentParams(const QString &hash, add_torrent_params &p) { +add_torrent_params QBtSession::initializeAddTorrentParams(const QString &hash) { + add_torrent_params p; + // Seeding mode // Skip checking and directly start seeding (new in libtorrent v0.15) if (TorrentTempData::isSeedingMode(hash)) @@ -1297,6 +1288,8 @@ void QBtSession::initializeAddTorrentParams(const QString &hash, add_torrent_par p.paused = true; p.duplicate_is_error = false; // Already checked p.auto_managed = false; // Because it is added in paused state + + return p; } void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool magnet) { diff --git a/src/qtlibtorrent/qbtsession.h b/src/qtlibtorrent/qbtsession.h index 0ce181c7b..019c0c0a1 100755 --- a/src/qtlibtorrent/qbtsession.h +++ b/src/qtlibtorrent/qbtsession.h @@ -182,7 +182,7 @@ private: bool loadFastResumeData(const QString &hash, std::vector &buf); void loadTorrentSettings(QTorrentHandle &h); void loadTorrentTempData(QTorrentHandle &h, QString savePath, bool magnet); - void initializeAddTorrentParams(const QString &hash, libtorrent::add_torrent_params &p); + libtorrent::add_torrent_params initializeAddTorrentParams(const QString &hash); libtorrent::entry generateFilePriorityResumeData(boost::intrusive_ptr &t, const std::vector &fp); void updateRatioTimer(); void recoverPersistentData(const QString &hash, const std::vector &buf);