mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-30 16:34:16 +00:00
Allow to load TorrentInfo from data buffer
This commit is contained in:
parent
56ccf28000
commit
69df8174b9
@ -60,23 +60,32 @@ TorrentInfo &TorrentInfo::operator=(const TorrentInfo &other)
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentInfo TorrentInfo::loadFromFile(const QString &path, QString &error)
|
TorrentInfo TorrentInfo::load(const QByteArray &data, QString *error) noexcept
|
||||||
{
|
{
|
||||||
error.clear();
|
|
||||||
libt::error_code ec;
|
libt::error_code ec;
|
||||||
TorrentInfo info(NativePtr(new libt::torrent_info(Utils::Fs::toNativePath(path).toStdString(), ec)));
|
TorrentInfo info(NativePtr(new libt::torrent_info(data.constData(), data.size(), ec)));
|
||||||
if (ec) {
|
if (error) {
|
||||||
error = QString::fromUtf8(ec.message().c_str());
|
if (ec)
|
||||||
qDebug("Cannot load .torrent file: %s", qUtf8Printable(error));
|
*error = QString::fromStdString(ec.message());
|
||||||
|
else
|
||||||
|
error->clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
return info;
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
TorrentInfo TorrentInfo::loadFromFile(const QString &path)
|
TorrentInfo TorrentInfo::loadFromFile(const QString &path, QString *error) noexcept
|
||||||
{
|
{
|
||||||
QString error;
|
libt::error_code ec;
|
||||||
return loadFromFile(path, error);
|
TorrentInfo info(NativePtr(new libt::torrent_info(Utils::Fs::toNativePath(path).toStdString(), ec)));
|
||||||
|
if (error) {
|
||||||
|
if (ec)
|
||||||
|
*error = QString::fromStdString(ec.message());
|
||||||
|
else
|
||||||
|
error->clear();
|
||||||
|
}
|
||||||
|
|
||||||
|
return info;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool TorrentInfo::isValid() const
|
bool TorrentInfo::isValid() const
|
||||||
|
@ -63,8 +63,8 @@ namespace BitTorrent
|
|||||||
explicit TorrentInfo(NativeConstPtr nativeInfo = NativeConstPtr());
|
explicit TorrentInfo(NativeConstPtr nativeInfo = NativeConstPtr());
|
||||||
TorrentInfo(const TorrentInfo &other);
|
TorrentInfo(const TorrentInfo &other);
|
||||||
|
|
||||||
static TorrentInfo loadFromFile(const QString &path, QString &error);
|
static TorrentInfo load(const QByteArray &data, QString *error = nullptr) noexcept;
|
||||||
static TorrentInfo loadFromFile(const QString &path);
|
static TorrentInfo loadFromFile(const QString &path, QString *error = nullptr) noexcept;
|
||||||
|
|
||||||
TorrentInfo &operator=(const TorrentInfo &other);
|
TorrentInfo &operator=(const TorrentInfo &other);
|
||||||
|
|
||||||
|
@ -286,7 +286,7 @@ bool AddNewTorrentDialog::loadTorrent(const QString &torrentPath)
|
|||||||
|
|
||||||
m_hasMetadata = true;
|
m_hasMetadata = true;
|
||||||
QString error;
|
QString error;
|
||||||
m_torrentInfo = BitTorrent::TorrentInfo::loadFromFile(m_filePath, error);
|
m_torrentInfo = BitTorrent::TorrentInfo::loadFromFile(m_filePath, &error);
|
||||||
if (!m_torrentInfo.isValid()) {
|
if (!m_torrentInfo.isValid()) {
|
||||||
MessageBoxRaised::critical(this, tr("Invalid torrent"), tr("Failed to load the torrent: %1.\nError: %2", "Don't remove the '\n' characters. They insert a newline.").arg(Utils::Fs::toNativePath(m_filePath)).arg(error));
|
MessageBoxRaised::critical(this, tr("Invalid torrent"), tr("Failed to load the torrent: %1.\nError: %2", "Don't remove the '\n' characters. They insert a newline.").arg(Utils::Fs::toNativePath(m_filePath)).arg(error));
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user