Revert "Don't use deprecated function when adding magnets."

This reverts commit c74334669b.
This commit is contained in:
sledgehammer999 2013-10-23 20:11:29 +03:00
parent 8f29befc65
commit 3efba63e23
2 changed files with 22 additions and 29 deletions

View file

@ -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) {

View file

@ -182,7 +182,7 @@ private:
bool loadFastResumeData(const QString &hash, std::vector<char> &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<libtorrent::torrent_info> &t, const std::vector<int> &fp);
void updateRatioTimer();
void recoverPersistentData(const QString &hash, const std::vector<char> &buf);