Cleanup code

Also remove redundant code, it is already handled correctly in subsequent function calls.
This commit is contained in:
Chocobo1 2018-12-28 13:38:08 +08:00
parent 19d6de795c
commit 6759446639
No known key found for this signature in database
GPG key ID: 210D9C873253A68C
5 changed files with 27 additions and 31 deletions

View file

@ -2090,12 +2090,9 @@ TorrentStatusReport Session::torrentStatusReport() const
return m_torrentStatusReport;
}
// source - .torrent file path/url or magnet uri
bool Session::addTorrent(QString source, const AddTorrentParams &params)
bool Session::addTorrent(const QString &source, const AddTorrentParams &params)
{
MagnetUri magnetUri(source);
if (magnetUri.isValid())
return addTorrent_impl(CreateTorrentParams(params), magnetUri);
// `source`: .torrent file path/url or magnet uri
if (Utils::Misc::isUrl(source)) {
LogMsg(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(source));
@ -2110,6 +2107,10 @@ bool Session::addTorrent(QString source, const AddTorrentParams &params)
return true;
}
const MagnetUri magnetUri {source};
if (magnetUri.isValid())
return addTorrent_impl(CreateTorrentParams(params), magnetUri);
TorrentFileGuard guard(source);
if (addTorrent_impl(CreateTorrentParams(params)
, MagnetUri(), TorrentInfo::loadFromFile(source))) {