Browse Source

Stop using internal libtorrent API. Closes #2202.

adaptive-webui-19844
sledgehammer999 10 years ago
parent
commit
f413e8b121
  1. 33
      src/misc.cpp
  2. 9
      src/torrentimportdlg.cpp

33
src/misc.cpp

@ -78,6 +78,7 @@ const int UNLEN = 256;
#endif #endif
#include <libtorrent/escape_string.hpp> #include <libtorrent/escape_string.hpp>
#include <libtorrent/lazy_entry.hpp> #include <libtorrent/lazy_entry.hpp>
#include <libtorrent/magnet_uri.hpp>
using namespace libtorrent; using namespace libtorrent;
@ -410,31 +411,13 @@ QList<QUrl> misc::magnetUriToTrackers(const QString& magnet_uri)
QString misc::magnetUriToHash(const QString& magnet_uri) QString misc::magnetUriToHash(const QString& magnet_uri)
{ {
QString hash = ""; add_torrent_params p;
QRegExp regHex("urn:btih:([0-9A-Za-z]+)"); error_code ec;
// Hex parse_magnet_uri(magnet_uri.toUtf8().constData(), p, ec);
int pos = regHex.indexIn(magnet_uri);
if (pos > -1) { if (ec)
const QString found = regHex.cap(1); return QString::null;
qDebug() << Q_FUNC_INFO << "regex found: " << found; return toQString(p.info_hash);
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;
} }
// Take a number of seconds and return an user-friendly // Take a number of seconds and return an user-friendly

9
src/torrentimportdlg.cpp

@ -74,15 +74,10 @@ void TorrentImportDlg::on_browseTorrentBtn_clicked()
void TorrentImportDlg::on_browseContentBtn_clicked() void TorrentImportDlg::on_browseContentBtn_clicked()
{ {
const QString default_dir = Preferences::instance()->getTorImportLastContentDir(); 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; bool multifile = t->num_files() > 1;
#if LIBTORRENT_VERSION_NUM >= 1600 if (!multifile && (fsutils::fromNativePath(misc::toQStringU(t->file_at(0).path)).indexOf('/') != -1))
if (!multifile && has_parent_path(t->files().file_path(*(t->files().begin()))))
multifile = true; multifile = true;
#else
if (!multifile && t->file_at(0).path.has_parent_path())
multifile = true;
#endif
if (!multifile) { if (!multifile) {
// Single file torrent // Single file torrent
const QString file_name = fsutils::fileName(misc::toQStringU(t->file_at(0).path)); const QString file_name = fsutils::fileName(misc::toQStringU(t->file_at(0).path));

Loading…
Cancel
Save