Browse Source

When duplicate torrent is added set metadata to existing one

PR #17454. 
Closes #907.
adaptive-webui-19844
Vladimir Golovnev 2 years ago committed by GitHub
parent
commit
1c0479a795
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 8
      src/base/bittorrent/session.cpp
  2. 1
      src/base/bittorrent/torrent.h
  3. 13
      src/base/bittorrent/torrentimpl.cpp
  4. 1
      src/base/bittorrent/torrentimpl.h
  5. 3
      src/gui/addnewtorrentdialog.cpp

8
src/base/bittorrent/session.cpp

@ -2502,7 +2502,15 @@ bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source @@ -2502,7 +2502,15 @@ bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source
TorrentImpl *const torrent = m_torrents.value(id);
if (torrent)
{
if (hasMetadata)
{
// Trying to set metadata to existing torrent in case if it has none
torrent->setMetadata(std::get<TorrentInfo>(source));
}
return false;
}
LoadTorrentParams loadTorrentParams = initLoadTorrentParams(addTorrentParams);
lt::add_torrent_params &p = loadTorrentParams.ltAddTorrentParams;

1
src/base/bittorrent/torrent.h

@ -298,6 +298,7 @@ namespace BitTorrent @@ -298,6 +298,7 @@ namespace BitTorrent
virtual void removeUrlSeeds(const QVector<QUrl> &urlSeeds) = 0;
virtual bool connectPeer(const PeerAddress &peerAddress) = 0;
virtual void clearPeers() = 0;
virtual bool setMetadata(const TorrentInfo &torrentInfo) = 0;
virtual QString createMagnetURI() const = 0;
virtual nonstd::expected<QByteArray, QString> exportToBuffer() const = 0;

13
src/base/bittorrent/torrentimpl.cpp

@ -2126,6 +2126,19 @@ lt::torrent_handle TorrentImpl::nativeHandle() const @@ -2126,6 +2126,19 @@ lt::torrent_handle TorrentImpl::nativeHandle() const
return m_nativeHandle;
}
bool TorrentImpl::setMetadata(const TorrentInfo &torrentInfo)
{
if (hasMetadata())
return false;
#ifdef QBT_USES_LIBTORRENT2
return m_nativeHandle.set_metadata(torrentInfo.nativeInfo()->info_section());
#else
const std::shared_ptr<lt::torrent_info> nativeInfo = torrentInfo.nativeInfo();
return m_nativeHandle.set_metadata(lt::span<const char>(nativeInfo->metadata().get(), nativeInfo->metadata_size()));
#endif
}
bool TorrentImpl::isMoveInProgress() const
{
return m_storageIsMoving;

1
src/base/bittorrent/torrentimpl.h

@ -225,6 +225,7 @@ namespace BitTorrent @@ -225,6 +225,7 @@ namespace BitTorrent
void removeUrlSeeds(const QVector<QUrl> &urlSeeds) override;
bool connectPeer(const PeerAddress &peerAddress) override;
void clearPeers() override;
bool setMetadata(const TorrentInfo &torrentInfo) override;
QString createMagnetURI() const override;
nonstd::expected<QByteArray, QString> exportToBuffer() const override;

3
src/gui/addnewtorrentdialog.cpp

@ -435,6 +435,9 @@ bool AddNewTorrentDialog::loadTorrentImpl() @@ -435,6 +435,9 @@ bool AddNewTorrentDialog::loadTorrentImpl()
BitTorrent::Torrent *const torrent = BitTorrent::Session::instance()->findTorrent(torrentID);
if (torrent)
{
// Trying to set metadata to existing torrent in case if it has none
torrent->setMetadata(m_torrentInfo);
if (torrent->isPrivate() || m_torrentInfo.isPrivate())
{
RaisedMessageBox::warning(this, tr("Torrent is already present"), tr("Torrent '%1' is already in the transfer list. Trackers cannot be merged because it is a private torrent.").arg(torrent->name()), QMessageBox::Ok);

Loading…
Cancel
Save