Skip to content

Commit ee5fe42

Browse files
committed
Use single parameter to accept torrent source
1 parent 4bb3d13 commit ee5fe42

2 files changed

Lines changed: 8 additions & 5 deletions

File tree

src/base/bittorrent/session.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2039,14 +2039,14 @@ bool Session::addTorrent(const MagnetUri &magnetUri, const AddTorrentParams &par
20392039
{
20402040
if (!magnetUri.isValid()) return false;
20412041

2042-
return addTorrent_impl(params, magnetUri);
2042+
return addTorrent_impl(magnetUri, params);
20432043
}
20442044

20452045
bool Session::addTorrent(const TorrentInfo &torrentInfo, const AddTorrentParams &params)
20462046
{
20472047
if (!torrentInfo.isValid()) return false;
20482048

2049-
return addTorrent_impl(params, MagnetUri(), torrentInfo);
2049+
return addTorrent_impl(torrentInfo, params);
20502050
}
20512051

20522052
LoadTorrentParams Session::initLoadTorrentParams(const AddTorrentParams &addTorrentParams)
@@ -2087,9 +2087,11 @@ LoadTorrentParams Session::initLoadTorrentParams(const AddTorrentParams &addTorr
20872087
}
20882088

20892089
// Add a torrent to the BitTorrent session
2090-
bool Session::addTorrent_impl(const AddTorrentParams &addTorrentParams, const MagnetUri &magnetUri, TorrentInfo metadata)
2090+
bool Session::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source, const AddTorrentParams &addTorrentParams)
20912091
{
2092-
const bool hasMetadata = metadata.isValid();
2092+
const bool hasMetadata = std::holds_alternative<TorrentInfo>(source);
2093+
TorrentInfo metadata = (hasMetadata ? std::get<TorrentInfo>(source) : TorrentInfo {});
2094+
const MagnetUri &magnetUri = (hasMetadata ? MagnetUri {} : std::get<MagnetUri>(source));
20932095
const InfoHash hash = (hasMetadata ? metadata.hash() : magnetUri.hash());
20942096

20952097
// It looks illogical that we don't just use an existing handle,

src/base/bittorrent/session.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#pragma once
3131

3232
#include <memory>
33+
#include <variant>
3334
#include <vector>
3435

3536
#include <libtorrent/add_torrent_params.hpp>
@@ -600,7 +601,7 @@ namespace BitTorrent
600601
bool loadTorrentResumeData(const QByteArray &data, const TorrentInfo &metadata, LoadTorrentParams &torrentParams);
601602
bool loadTorrent(LoadTorrentParams params);
602603
LoadTorrentParams initLoadTorrentParams(const AddTorrentParams &addTorrentParams);
603-
bool addTorrent_impl(const AddTorrentParams &addTorrentParams, const MagnetUri &magnetUri, TorrentInfo torrentInfo = TorrentInfo());
604+
bool addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &source, const AddTorrentParams &addTorrentParams);
604605

605606
void updateSeedingLimitTimer();
606607
void exportTorrentFile(const TorrentHandle *torrent, TorrentExportFolder folder = TorrentExportFolder::Regular);

0 commit comments

Comments
 (0)