diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 08ef4ec60..2594d9b3c 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -2100,7 +2100,7 @@ bool Session::addTorrent(QString source, const AddTorrentParams ¶ms) LogMsg(tr("Downloading '%1', please wait...", "e.g: Downloading 'xxx.torrent', please wait...").arg(source)); // Launch downloader Net::DownloadHandler *handler = - Net::DownloadManager::instance()->download(Net::DownloadRequest(source).limit(10485760 /* 10MB */).handleRedirectToMagnet(true)); + Net::DownloadManager::instance()->download(Net::DownloadRequest(source).limit(MAX_TORRENT_SIZE).handleRedirectToMagnet(true)); connect(handler, static_cast(&Net::DownloadHandler::downloadFinished) , this, &Session::handleDownloadFinished); connect(handler, &Net::DownloadHandler::downloadFailed, this, &Session::handleDownloadFailed); diff --git a/src/base/bittorrent/torrentinfo.cpp b/src/base/bittorrent/torrentinfo.cpp index d2ad0255f..ca121ab20 100644 --- a/src/base/bittorrent/torrentinfo.cpp +++ b/src/base/bittorrent/torrentinfo.cpp @@ -35,6 +35,7 @@ #include #include +#include "base/global.h" #include "base/utils/fs.h" #include "base/utils/misc.h" #include "base/utils/string.h" @@ -105,10 +106,9 @@ TorrentInfo TorrentInfo::loadFromFile(const QString &path, QString *error) noexc return TorrentInfo(); } - const qint64 fileSizeLimit = 100 * 1024 * 1024; // 100 MB - if (file.size() > fileSizeLimit) { + if (file.size() > MAX_TORRENT_SIZE) { if (error) - *error = tr("File size exceeds max limit %1").arg(fileSizeLimit); + *error = tr("File size exceeds max limit %1").arg(Utils::Misc::friendlyUnit(MAX_TORRENT_SIZE)); return TorrentInfo(); } diff --git a/src/base/global.h b/src/base/global.h index 6e0e0370d..595d70bc3 100644 --- a/src/base/global.h +++ b/src/base/global.h @@ -32,6 +32,7 @@ #include const char C_TORRENT_FILE_EXTENSION[] = ".torrent"; +const int MAX_TORRENT_SIZE = 100 * 1024 * 1024; // 100 MiB template constexpr typename std::add_const::type &asConst(T &t) noexcept { return t; } diff --git a/src/gui/addnewtorrentdialog.cpp b/src/gui/addnewtorrentdialog.cpp index 132207714..7283c5a4c 100644 --- a/src/gui/addnewtorrentdialog.cpp +++ b/src/gui/addnewtorrentdialog.cpp @@ -235,7 +235,7 @@ void AddNewTorrentDialog::show(QString source, const BitTorrent::AddTorrentParam // Launch downloader // TODO: Don't save loaded torrent to file, just use downloaded data! Net::DownloadHandler *handler = Net::DownloadManager::instance()->download( - Net::DownloadRequest(source).limit(10485760 /* 10MB */).handleRedirectToMagnet(true).saveToFile(true)); + Net::DownloadRequest(source).limit(MAX_TORRENT_SIZE).handleRedirectToMagnet(true).saveToFile(true)); connect(handler, static_cast(&Net::DownloadHandler::downloadFinished) , dlg, &AddNewTorrentDialog::handleDownloadFinished); connect(handler, &Net::DownloadHandler::downloadFailed, dlg, &AddNewTorrentDialog::handleDownloadFailed);