Expose 'max torrent file size' setting

This commit is contained in:
Chocobo1
2023-07-04 00:46:42 +08:00
parent fff7b1dcbd
commit 66dfe8545d
11 changed files with 55 additions and 12 deletions

View File

@@ -44,6 +44,7 @@
#include "base/exceptions.h"
#include "base/global.h"
#include "base/logger.h"
#include "base/preferences.h"
#include "base/profile.h"
#include "base/tagset.h"
#include "base/utils/fs.h"
@@ -134,12 +135,13 @@ BitTorrent::LoadResumeDataResult BitTorrent::BencodeResumeDataStorage::load(cons
const QString idString = id.toString();
const Path fastresumePath = path() / Path(idString + u".fastresume");
const Path torrentFilePath = path() / Path(idString + u".torrent");
const qint64 torrentSizeLimit = Preferences::instance()->getTorrentFileSizeLimit();
const auto resumeDataReadResult = Utils::IO::readFile(fastresumePath, MAX_TORRENT_SIZE);
const auto resumeDataReadResult = Utils::IO::readFile(fastresumePath, torrentSizeLimit);
if (!resumeDataReadResult)
return nonstd::make_unexpected(resumeDataReadResult.error().message);
const auto metadataReadResult = Utils::IO::readFile(torrentFilePath, MAX_TORRENT_SIZE);
const auto metadataReadResult = Utils::IO::readFile(torrentFilePath, torrentSizeLimit);
if (!metadataReadResult)
{
if (metadataReadResult.error().status != Utils::IO::ReadError::NotExist)

View File

@@ -34,6 +34,5 @@
inline const QString QB_EXT = u".!qB"_s;
inline const int MAX_TORRENT_SIZE = 100 * 1024 * 1024; // 100 MiB
inline const int BENCODE_DEPTH_LIMIT = 100;
inline const int BENCODE_TOKEN_LIMIT = 10'000'000;

View File

@@ -96,7 +96,6 @@
#include "base/version.h"
#include "bandwidthscheduler.h"
#include "bencoderesumedatastorage.h"
#include "common.h"
#include "customstorage.h"
#include "dbresumedatastorage.h"
#include "downloadpriority.h"
@@ -2554,9 +2553,10 @@ bool SessionImpl::addTorrent(const QString &source, const AddTorrentParams &para
if (Net::DownloadManager::hasSupportedScheme(source))
{
LogMsg(tr("Downloading torrent, please wait... Source: \"%1\"").arg(source));
const auto *pref = Preferences::instance();
// Launch downloader
Net::DownloadManager::instance()->download(Net::DownloadRequest(source).limit(MAX_TORRENT_SIZE)
, Preferences::instance()->useProxyForGeneralPurposes(), this, &SessionImpl::handleDownloadFinished);
Net::DownloadManager::instance()->download(Net::DownloadRequest(source).limit(pref->getTorrentFileSizeLimit())
, pref->useProxyForGeneralPurposes(), this, &SessionImpl::handleDownloadFinished);
m_downloadedTorrents[source] = params;
return true;
}

View File

@@ -42,6 +42,7 @@
#include "base/global.h"
#include "base/path.h"
#include "base/preferences.h"
#include "base/utils/fs.h"
#include "base/utils/io.h"
#include "base/utils/misc.h"
@@ -104,7 +105,8 @@ nonstd::expected<TorrentInfo, QString> TorrentInfo::loadFromFile(const Path &pat
QByteArray data;
try
{
const auto readResult = Utils::IO::readFile(path, MAX_TORRENT_SIZE);
const qint64 torrentSizeLimit = Preferences::instance()->getTorrentFileSizeLimit();
const auto readResult = Utils::IO::readFile(path, torrentSizeLimit);
if (!readResult)
return nonstd::make_unexpected(readResult.error().message);
data = readResult.value();

View File

@@ -304,6 +304,19 @@ void Preferences::setIconsInMenusEnabled(const bool enable)
}
#endif // Q_OS_MACOS
qint64 Preferences::getTorrentFileSizeLimit() const
{
return value(u"BitTorrent/TorrentFileSizeLimit"_s, (100 * 1024 * 1024));
}
void Preferences::setTorrentFileSizeLimit(const qint64 value)
{
if (value == getTorrentFileSizeLimit())
return;
setValue(u"BitTorrent/TorrentFileSizeLimit"_s, value);
}
bool Preferences::isToolbarDisplayed() const
{
return value(u"Preferences/General/ToolbarDisplayed"_s, true);

View File

@@ -333,6 +333,8 @@ public:
bool iconsInMenusEnabled() const;
void setIconsInMenusEnabled(bool enable);
#endif // Q_OS_MACOS
qint64 getTorrentFileSizeLimit() const;
void setTorrentFileSizeLimit(qint64 value);
// Stuff that don't appear in the Options GUI but are saved
// in the same file.