mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-01-06 15:04:34 +08:00
Stop using internal libtorrent API. Closes #2202.
This commit is contained in:
parent
cbbf14b0f8
commit
f413e8b121
33
src/misc.cpp
33
src/misc.cpp
@ -78,6 +78,7 @@ const int UNLEN = 256;
|
||||
#endif
|
||||
#include <libtorrent/escape_string.hpp>
|
||||
#include <libtorrent/lazy_entry.hpp>
|
||||
#include <libtorrent/magnet_uri.hpp>
|
||||
|
||||
using namespace libtorrent;
|
||||
|
||||
@ -410,31 +411,13 @@ QList<QUrl> 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
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user