From f413e8b121d9eb015defbd0470d42011eb02e493 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Wed, 26 Nov 2014 00:31:22 +0200 Subject: [PATCH] Stop using internal libtorrent API. Closes #2202. --- src/misc.cpp | 33 ++++++++------------------------- src/torrentimportdlg.cpp | 9 ++------- 2 files changed, 10 insertions(+), 32 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index f3b1952ca..236188729 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -78,6 +78,7 @@ const int UNLEN = 256; #endif #include #include +#include using namespace libtorrent; @@ -410,31 +411,13 @@ QList misc::magnetUriToTrackers(const QString& magnet_uri) QString misc::magnetUriToHash(const QString& magnet_uri) { - QString hash = ""; - QRegExp regHex("urn:btih:([0-9A-Za-z]+)"); - // Hex - int pos = regHex.indexIn(magnet_uri); - if (pos > -1) { - const QString found = regHex.cap(1); - qDebug() << Q_FUNC_INFO << "regex found: " << found; - if (found.length() == 40) { - const sha1_hash sha1(QByteArray::fromHex(found.toLatin1()).constData()); - qDebug("magnetUriToHash (Hex): hash: %s", qPrintable(misc::toQString(sha1))); - return misc::toQString(sha1); - } - } - // Base 32 - QRegExp regBase32("urn:btih:([A-Za-z2-7=]+)"); - pos = regBase32.indexIn(magnet_uri); - if (pos > -1) { - const QString found = regBase32.cap(1); - if (found.length() > 20 && (found.length() * 5) % 40 == 0) { - const sha1_hash sha1(base32decode(regBase32.cap(1).toStdString())); - hash = misc::toQString(sha1); - } - } - qDebug("magnetUriToHash (base32): hash: %s", qPrintable(hash)); - return hash; + add_torrent_params p; + error_code ec; + parse_magnet_uri(magnet_uri.toUtf8().constData(), p, ec); + + if (ec) + return QString::null; + return toQString(p.info_hash); } // Take a number of seconds and return an user-friendly diff --git a/src/torrentimportdlg.cpp b/src/torrentimportdlg.cpp index 5b2820d5b..ed3a71993 100644 --- a/src/torrentimportdlg.cpp +++ b/src/torrentimportdlg.cpp @@ -74,15 +74,10 @@ void TorrentImportDlg::on_browseTorrentBtn_clicked() void TorrentImportDlg::on_browseContentBtn_clicked() { const QString default_dir = Preferences::instance()->getTorImportLastContentDir(); - // Test for multi-file taken from libtorrent/create_torrent.hpp -> create_torrent::create_torrent bool multifile = t->num_files() > 1; -#if LIBTORRENT_VERSION_NUM >= 1600 - if (!multifile && has_parent_path(t->files().file_path(*(t->files().begin())))) + if (!multifile && (fsutils::fromNativePath(misc::toQStringU(t->file_at(0).path)).indexOf('/') != -1)) multifile = true; -#else - if (!multifile && t->file_at(0).path.has_parent_path()) - multifile = true; -#endif + if (!multifile) { // Single file torrent const QString file_name = fsutils::fileName(misc::toQStringU(t->file_at(0).path));