mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-08 21:04:26 +00:00
Don't use deprecated function when adding magnets.
This commit is contained in:
parent
8f955fe110
commit
1c128c65f0
@ -921,7 +921,15 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f
|
|||||||
Q_UNUSED(filePath);
|
Q_UNUSED(filePath);
|
||||||
Preferences pref;
|
Preferences pref;
|
||||||
QTorrentHandle h;
|
QTorrentHandle h;
|
||||||
const QString hash(misc::magnetUriToHash(magnet_uri));
|
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));
|
||||||
if (hash.isEmpty()) {
|
if (hash.isEmpty()) {
|
||||||
addConsoleMessage(tr("'%1' is not a valid magnet URI.").arg(magnet_uri));
|
addConsoleMessage(tr("'%1' is not a valid magnet URI.").arg(magnet_uri));
|
||||||
return h;
|
return h;
|
||||||
@ -936,19 +944,21 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f
|
|||||||
qDebug("Adding a magnet URI: %s", qPrintable(hash));
|
qDebug("Adding a magnet URI: %s", qPrintable(hash));
|
||||||
Q_ASSERT(magnet_uri.startsWith("magnet:", Qt::CaseInsensitive));
|
Q_ASSERT(magnet_uri.startsWith("magnet:", Qt::CaseInsensitive));
|
||||||
|
|
||||||
// Check for duplicate torrent
|
// limit h_ex scope
|
||||||
if (s->find_torrent(QStringToSha1(hash)).is_valid()) {
|
{
|
||||||
qDebug("/!\\ Torrent is already in download list");
|
// Check for duplicate torrent
|
||||||
addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(magnet_uri));
|
QTorrentHandle h_ex = QTorrentHandle(s->find_torrent(p.info_hash));
|
||||||
// Check if the torrent contains trackers or url seeds we don't know about
|
if (h_ex.is_valid()) {
|
||||||
// and add them
|
qDebug("/!\\ Torrent is already in download list");
|
||||||
QTorrentHandle h_ex = getTorrentHandle(hash);
|
addConsoleMessage(tr("'%1' is already in download list.", "e.g: 'xxx.avi' is already in download list.").arg(magnet_uri));
|
||||||
mergeTorrents(h_ex, magnet_uri);
|
// Check if the torrent contains trackers or url seeds we don't know about
|
||||||
|
// and add them
|
||||||
return h;
|
mergeTorrents(h_ex, magnet_uri);
|
||||||
|
return h;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add_torrent_params p = initializeAddTorrentParams(hash);
|
initializeAddTorrentParams(hash, p);
|
||||||
|
|
||||||
// Get save path
|
// Get save path
|
||||||
QString savePath;
|
QString savePath;
|
||||||
@ -969,19 +979,19 @@ QTorrentHandle QBtSession::addMagnetUri(QString magnet_uri, bool resumed, bool f
|
|||||||
// Check if save path exists, creating it otherwise
|
// Check if save path exists, creating it otherwise
|
||||||
if (!QDir(torrent_tmp_path).exists())
|
if (!QDir(torrent_tmp_path).exists())
|
||||||
QDir().mkpath(torrent_tmp_path);
|
QDir().mkpath(torrent_tmp_path);
|
||||||
qDebug("addMagnetURI: using save_path: %s", qPrintable(torrent_tmp_path));
|
qDebug("addTorrent: using save_path: %s", qPrintable(torrent_tmp_path));
|
||||||
} else {
|
} else {
|
||||||
p.save_path = savePath.toUtf8().constData();
|
p.save_path = savePath.toUtf8().constData();
|
||||||
// Check if save path exists, creating it otherwise
|
// Check if save path exists, creating it otherwise
|
||||||
if (!QDir(savePath).exists()) QDir().mkpath(savePath);
|
if (!QDir(savePath).exists()) QDir().mkpath(savePath);
|
||||||
qDebug("addMagnetURI: using save_path: %s", qPrintable(savePath));
|
qDebug("addTorrent: using save_path: %s", qPrintable(savePath));
|
||||||
}
|
}
|
||||||
|
|
||||||
qDebug("Adding magnet URI: %s", qPrintable(magnet_uri));
|
qDebug("Adding magnet URI: %s", qPrintable(magnet_uri));
|
||||||
|
|
||||||
// Adding torrent to Bittorrent session
|
// Adding torrent to Bittorrent session
|
||||||
try {
|
try {
|
||||||
h = QTorrentHandle(add_magnet_uri(*s, magnet_uri.toStdString(), p));
|
h = QTorrentHandle(s->add_torrent(p));
|
||||||
}catch(std::exception e) {
|
}catch(std::exception e) {
|
||||||
qDebug("Error: %s", e.what());
|
qDebug("Error: %s", e.what());
|
||||||
}
|
}
|
||||||
@ -1121,7 +1131,8 @@ QTorrentHandle QBtSession::addTorrent(QString path, bool fromScanDir, QString fr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Actually add the torrent
|
// Actually add the torrent
|
||||||
add_torrent_params p = initializeAddTorrentParams(hash);
|
add_torrent_params p;
|
||||||
|
initializeAddTorrentParams(hash, p);
|
||||||
p.ti = t;
|
p.ti = t;
|
||||||
|
|
||||||
// Get fast resume data if existing
|
// Get fast resume data if existing
|
||||||
@ -1253,9 +1264,7 @@ void QBtSession::exportTorrentFile(const QTorrentHandle& h, TorrentExportFolder
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
add_torrent_params QBtSession::initializeAddTorrentParams(const QString &hash) {
|
void QBtSession::initializeAddTorrentParams(const QString &hash, add_torrent_params &p) {
|
||||||
add_torrent_params p;
|
|
||||||
|
|
||||||
// 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 (TorrentTempData::isSeedingMode(hash))
|
if (TorrentTempData::isSeedingMode(hash))
|
||||||
@ -1288,8 +1297,6 @@ add_torrent_params QBtSession::initializeAddTorrentParams(const QString &hash) {
|
|||||||
p.paused = true;
|
p.paused = true;
|
||||||
p.duplicate_is_error = false; // Already checked
|
p.duplicate_is_error = false; // Already checked
|
||||||
p.auto_managed = false; // Because it is added in paused state
|
p.auto_managed = false; // Because it is added in paused state
|
||||||
|
|
||||||
return p;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool magnet) {
|
void QBtSession::loadTorrentTempData(QTorrentHandle &h, QString savePath, bool magnet) {
|
||||||
|
@ -182,7 +182,7 @@ private:
|
|||||||
bool loadFastResumeData(const QString &hash, std::vector<char> &buf);
|
bool loadFastResumeData(const QString &hash, std::vector<char> &buf);
|
||||||
void loadTorrentSettings(QTorrentHandle &h);
|
void loadTorrentSettings(QTorrentHandle &h);
|
||||||
void loadTorrentTempData(QTorrentHandle &h, QString savePath, bool magnet);
|
void loadTorrentTempData(QTorrentHandle &h, QString savePath, bool magnet);
|
||||||
libtorrent::add_torrent_params initializeAddTorrentParams(const QString &hash);
|
void initializeAddTorrentParams(const QString &hash, libtorrent::add_torrent_params &p);
|
||||||
libtorrent::entry generateFilePriorityResumeData(boost::intrusive_ptr<libtorrent::torrent_info> &t, const std::vector<int> &fp);
|
libtorrent::entry generateFilePriorityResumeData(boost::intrusive_ptr<libtorrent::torrent_info> &t, const std::vector<int> &fp);
|
||||||
void updateRatioTimer();
|
void updateRatioTimer();
|
||||||
void recoverPersistentData(const QString &hash, const std::vector<char> &buf);
|
void recoverPersistentData(const QString &hash, const std::vector<char> &buf);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user