From 79f3c6439ca57e56a0b07d168f249bfb269747d7 Mon Sep 17 00:00:00 2001 From: sledgehammer999 Date: Wed, 26 Nov 2014 01:56:29 +0200 Subject: [PATCH] Stop using internal libtorrent API. Closes 2202. --- src/misc.cpp | 12 ++++++++++++ src/torrentimportdlg.cpp | 15 +++------------ 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/src/misc.cpp b/src/misc.cpp index 94219cf3f..1456075b8 100644 --- a/src/misc.cpp +++ b/src/misc.cpp @@ -70,6 +70,8 @@ const int UNLEN = 256; #endif #endif // DISABLE_GUI +#include + using namespace libtorrent; static struct { const char *source; const char *comment; } units[] = { @@ -372,6 +374,7 @@ QList misc::magnetUriToTrackers(const QString& magnet_uri) } QString misc::magnetUriToHash(const QString& magnet_uri) { +#if LIBTORRENT_VERSION_NUM < 1600 QString hash = ""; QRegExp regHex("urn:btih:([0-9A-Za-z]+)"); // Hex @@ -397,6 +400,15 @@ QString misc::magnetUriToHash(const QString& magnet_uri) { } qDebug("magnetUriToHash (base32): hash: %s", qPrintable(hash)); return hash; +#else + 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); +#endif } // Take a number of seconds and return an user-friendly diff --git a/src/torrentimportdlg.cpp b/src/torrentimportdlg.cpp index 0de839959..e5cee9ecc 100644 --- a/src/torrentimportdlg.cpp +++ b/src/torrentimportdlg.cpp @@ -77,22 +77,13 @@ void TorrentImportDlg::on_browseContentBtn_clicked() { QIniSettings settings; const QString default_dir = settings.value(QString::fromUtf8("TorrentImport/LastContentDir"), QDir::homePath()).toString(); - // 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())))) - multifile = true; -#else - if (!multifile && t->file_at(0).path.has_parent_path()) - multifile = true; -#endif + if (!multifile && (QDir::fromNativeSeparators(misc::toQStringU(t->file_at(0).path)).indexOf('/') != -1)) + multifile = true; + if (!multifile) { // Single file torrent -#if LIBTORRENT_VERSION_NUM >= 1600 const QString file_name = fsutils::fileName(misc::toQStringU(t->file_at(0).path)); -#else - const QString file_name = misc::toQStringU(t->file_at(0).path.filename()); -#endif qDebug("Torrent has only one file: %s", qPrintable(file_name)); QString extension = fsutils::fileExtension(file_name); qDebug("File extension is : %s", qPrintable(extension));