Browse Source

Expose 'max torrent file size' setting

adaptive-webui-19844
Chocobo1 1 year ago
parent
commit
66dfe8545d
No known key found for this signature in database
GPG Key ID: 210D9C873253A68C
  1. 6
      src/base/bittorrent/bencoderesumedatastorage.cpp
  2. 1
      src/base/bittorrent/common.h
  3. 6
      src/base/bittorrent/sessionimpl.cpp
  4. 4
      src/base/bittorrent/torrentinfo.cpp
  5. 13
      src/base/preferences.cpp
  6. 2
      src/base/preferences.h
  7. 6
      src/gui/addnewtorrentdialog.cpp
  8. 9
      src/gui/advancedsettings.cpp
  9. 5
      src/gui/advancedsettings.h
  10. 5
      src/webui/api/appcontroller.cpp
  11. 10
      src/webui/www/private/views/preferences.html

6
src/base/bittorrent/bencoderesumedatastorage.cpp

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

1
src/base/bittorrent/common.h

@ -34,6 +34,5 @@
inline const QString QB_EXT = u".!qB"_s; 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_DEPTH_LIMIT = 100;
inline const int BENCODE_TOKEN_LIMIT = 10'000'000; inline const int BENCODE_TOKEN_LIMIT = 10'000'000;

6
src/base/bittorrent/sessionimpl.cpp

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

4
src/base/bittorrent/torrentinfo.cpp

@ -42,6 +42,7 @@
#include "base/global.h" #include "base/global.h"
#include "base/path.h" #include "base/path.h"
#include "base/preferences.h"
#include "base/utils/fs.h" #include "base/utils/fs.h"
#include "base/utils/io.h" #include "base/utils/io.h"
#include "base/utils/misc.h" #include "base/utils/misc.h"
@ -104,7 +105,8 @@ nonstd::expected<TorrentInfo, QString> TorrentInfo::loadFromFile(const Path &pat
QByteArray data; QByteArray data;
try 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) if (!readResult)
return nonstd::make_unexpected(readResult.error().message); return nonstd::make_unexpected(readResult.error().message);
data = readResult.value(); data = readResult.value();

13
src/base/preferences.cpp

@ -304,6 +304,19 @@ void Preferences::setIconsInMenusEnabled(const bool enable)
} }
#endif // Q_OS_MACOS #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 bool Preferences::isToolbarDisplayed() const
{ {
return value(u"Preferences/General/ToolbarDisplayed"_s, true); return value(u"Preferences/General/ToolbarDisplayed"_s, true);

2
src/base/preferences.h

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

6
src/gui/addnewtorrentdialog.cpp

@ -43,7 +43,6 @@
#include <QUrl> #include <QUrl>
#include <QVector> #include <QVector>
#include "base/bittorrent/common.h"
#include "base/bittorrent/downloadpriority.h" #include "base/bittorrent/downloadpriority.h"
#include "base/bittorrent/infohash.h" #include "base/bittorrent/infohash.h"
#include "base/bittorrent/magneturi.h" #include "base/bittorrent/magneturi.h"
@ -489,10 +488,11 @@ void AddNewTorrentDialog::show(const QString &source, const BitTorrent::AddTorre
if (Net::DownloadManager::hasSupportedScheme(source)) if (Net::DownloadManager::hasSupportedScheme(source))
{ {
const auto *pref = Preferences::instance();
// Launch downloader // Launch downloader
Net::DownloadManager::instance()->download( Net::DownloadManager::instance()->download(
Net::DownloadRequest(source).limit(MAX_TORRENT_SIZE) Net::DownloadRequest(source).limit(pref->getTorrentFileSizeLimit())
, Preferences::instance()->useProxyForGeneralPurposes() , pref->useProxyForGeneralPurposes()
, dlg, &AddNewTorrentDialog::handleDownloadFinished); , dlg, &AddNewTorrentDialog::handleDownloadFinished);
return; return;
} }

9
src/gui/advancedsettings.cpp

@ -75,6 +75,7 @@ namespace
NETWORK_IFACE_ADDRESS, NETWORK_IFACE_ADDRESS,
// behavior // behavior
SAVE_RESUME_DATA_INTERVAL, SAVE_RESUME_DATA_INTERVAL,
TORRENT_FILE_SIZE_LIMIT,
CONFIRM_RECHECK_TORRENT, CONFIRM_RECHECK_TORRENT,
RECHECK_COMPLETED, RECHECK_COMPLETED,
// UI related // UI related
@ -244,6 +245,8 @@ void AdvancedSettings::saveAdvancedSettings() const
session->setSocketBacklogSize(m_spinBoxSocketBacklogSize.value()); session->setSocketBacklogSize(m_spinBoxSocketBacklogSize.value());
// Save resume data interval // Save resume data interval
session->setSaveResumeDataInterval(m_spinBoxSaveResumeDataInterval.value()); session->setSaveResumeDataInterval(m_spinBoxSaveResumeDataInterval.value());
// .torrent file size limit
pref->setTorrentFileSizeLimit(m_spinBoxTorrentFileSizeLimit.value() * 1024 * 1024);
// Outgoing ports // Outgoing ports
session->setOutgoingPortsMin(m_spinBoxOutgoingPortsMin.value()); session->setOutgoingPortsMin(m_spinBoxOutgoingPortsMin.value());
session->setOutgoingPortsMax(m_spinBoxOutgoingPortsMax.value()); session->setOutgoingPortsMax(m_spinBoxOutgoingPortsMax.value());
@ -619,6 +622,12 @@ void AdvancedSettings::loadAdvancedSettings()
m_spinBoxSaveResumeDataInterval.setSuffix(tr(" min", " minutes")); m_spinBoxSaveResumeDataInterval.setSuffix(tr(" min", " minutes"));
m_spinBoxSaveResumeDataInterval.setSpecialValueText(tr("0 (disabled)")); m_spinBoxSaveResumeDataInterval.setSpecialValueText(tr("0 (disabled)"));
addRow(SAVE_RESUME_DATA_INTERVAL, tr("Save resume data interval [0: disabled]", "How often the fastresume file is saved."), &m_spinBoxSaveResumeDataInterval); addRow(SAVE_RESUME_DATA_INTERVAL, tr("Save resume data interval [0: disabled]", "How often the fastresume file is saved."), &m_spinBoxSaveResumeDataInterval);
// .torrent file size limit
m_spinBoxTorrentFileSizeLimit.setMinimum(1);
m_spinBoxTorrentFileSizeLimit.setMaximum(std::numeric_limits<int>::max() / 1024 / 1024);
m_spinBoxTorrentFileSizeLimit.setValue(pref->getTorrentFileSizeLimit() / 1024 / 1024);
m_spinBoxTorrentFileSizeLimit.setSuffix(tr(" MiB"));
addRow(TORRENT_FILE_SIZE_LIMIT, tr(".torrent file size limit"), &m_spinBoxTorrentFileSizeLimit);
// Outgoing port Min // Outgoing port Min
m_spinBoxOutgoingPortsMin.setMinimum(0); m_spinBoxOutgoingPortsMin.setMinimum(0);
m_spinBoxOutgoingPortsMin.setMaximum(65535); m_spinBoxOutgoingPortsMin.setMaximum(65535);

5
src/gui/advancedsettings.h

@ -67,8 +67,9 @@ private:
void loadAdvancedSettings(); void loadAdvancedSettings();
template <typename T> void addRow(int row, const QString &text, T *widget); template <typename T> void addRow(int row, const QString &text, T *widget);
QSpinBox m_spinBoxAsyncIOThreads, m_spinBoxFilePoolSize, m_spinBoxCheckingMemUsage, m_spinBoxDiskQueueSize, QSpinBox m_spinBoxSaveResumeDataInterval, m_spinBoxTorrentFileSizeLimit,
m_spinBoxSaveResumeDataInterval, m_spinBoxOutgoingPortsMin, m_spinBoxOutgoingPortsMax, m_spinBoxUPnPLeaseDuration, m_spinBoxPeerToS, m_spinBoxAsyncIOThreads, m_spinBoxFilePoolSize, m_spinBoxCheckingMemUsage, m_spinBoxDiskQueueSize,
m_spinBoxOutgoingPortsMin, m_spinBoxOutgoingPortsMax, m_spinBoxUPnPLeaseDuration, m_spinBoxPeerToS,
m_spinBoxListRefresh, m_spinBoxTrackerPort, m_spinBoxSendBufferWatermark, m_spinBoxSendBufferLowWatermark, m_spinBoxListRefresh, m_spinBoxTrackerPort, m_spinBoxSendBufferWatermark, m_spinBoxSendBufferLowWatermark,
m_spinBoxSendBufferWatermarkFactor, m_spinBoxConnectionSpeed, m_spinBoxSocketSendBufferSize, m_spinBoxSocketReceiveBufferSize, m_spinBoxSocketBacklogSize, m_spinBoxSendBufferWatermarkFactor, m_spinBoxConnectionSpeed, m_spinBoxSocketSendBufferSize, m_spinBoxSocketReceiveBufferSize, m_spinBoxSocketBacklogSize,
m_spinBoxMaxConcurrentHTTPAnnounces, m_spinBoxStopTrackerTimeout, m_spinBoxMaxConcurrentHTTPAnnounces, m_spinBoxStopTrackerTimeout,

5
src/webui/api/appcontroller.cpp

@ -323,6 +323,8 @@ void AppController::preferencesAction()
data[u"current_interface_address"_s] = BitTorrent::Session::instance()->networkInterfaceAddress(); data[u"current_interface_address"_s] = BitTorrent::Session::instance()->networkInterfaceAddress();
// Save resume data interval // Save resume data interval
data[u"save_resume_data_interval"_s] = session->saveResumeDataInterval(); data[u"save_resume_data_interval"_s] = session->saveResumeDataInterval();
// .torrent file size limit
data[u"torrent_file_size_limit"_s] = pref->getTorrentFileSizeLimit();
// Recheck completed torrents // Recheck completed torrents
data[u"recheck_completed_torrents"_s] = pref->recheckTorrentsOnCompletion(); data[u"recheck_completed_torrents"_s] = pref->recheckTorrentsOnCompletion();
// Refresh interval // Refresh interval
@ -853,6 +855,9 @@ void AppController::setPreferencesAction()
// Save resume data interval // Save resume data interval
if (hasKey(u"save_resume_data_interval"_s)) if (hasKey(u"save_resume_data_interval"_s))
session->setSaveResumeDataInterval(it.value().toInt()); session->setSaveResumeDataInterval(it.value().toInt());
// .torrent file size limit
if (hasKey(u"torrent_file_size_limit"_s))
pref->setTorrentFileSizeLimit(it.value().toLongLong());
// Recheck completed torrents // Recheck completed torrents
if (hasKey(u"recheck_completed_torrents"_s)) if (hasKey(u"recheck_completed_torrents"_s))
pref->recheckTorrentsOnCompletion(it.value().toBool()); pref->recheckTorrentsOnCompletion(it.value().toBool());

10
src/webui/www/private/views/preferences.html

@ -977,6 +977,14 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
<input type="text" id="saveResumeDataInterval" style="width: 15em;">&nbsp;&nbsp;QBT_TR(min)QBT_TR[CONTEXT=OptionsDialog] <input type="text" id="saveResumeDataInterval" style="width: 15em;">&nbsp;&nbsp;QBT_TR(min)QBT_TR[CONTEXT=OptionsDialog]
</td> </td>
</tr> </tr>
<tr>
<td>
<label for="torrentFileSizeLimit">QBT_TR(.torrent file size limit:)QBT_TR[CONTEXT=OptionsDialog]</label>
</td>
<td>
<input type="text" id="torrentFileSizeLimit" style="width: 15em;">&nbsp;&nbsp;QBT_TR(MiB)QBT_TR[CONTEXT=OptionsDialog]
</td>
</tr>
<tr> <tr>
<td> <td>
<label for="recheckTorrentsOnCompletion">QBT_TR(Recheck torrents on completion:)QBT_TR[CONTEXT=OptionsDialog]</label> <label for="recheckTorrentsOnCompletion">QBT_TR(Recheck torrents on completion:)QBT_TR[CONTEXT=OptionsDialog]</label>
@ -2147,6 +2155,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
updateNetworkInterfaces(pref.current_network_interface); updateNetworkInterfaces(pref.current_network_interface);
updateInterfaceAddresses(pref.current_network_interface, pref.current_interface_address); updateInterfaceAddresses(pref.current_network_interface, pref.current_interface_address);
$('saveResumeDataInterval').setProperty('value', pref.save_resume_data_interval); $('saveResumeDataInterval').setProperty('value', pref.save_resume_data_interval);
$('torrentFileSizeLimit').setProperty('value', (pref.torrent_file_size_limit / 1024 / 1024));
$('recheckTorrentsOnCompletion').setProperty('checked', pref.recheck_completed_torrents); $('recheckTorrentsOnCompletion').setProperty('checked', pref.recheck_completed_torrents);
$('refreshInterval').setProperty('value', pref.refresh_interval); $('refreshInterval').setProperty('value', pref.refresh_interval);
$('resolvePeerCountries').setProperty('checked', pref.resolve_peer_countries); $('resolvePeerCountries').setProperty('checked', pref.resolve_peer_countries);
@ -2563,6 +2572,7 @@ Use ';' to split multiple entries. Can use wildcard '*'.)QBT_TR[CONTEXT=OptionsD
settings.set('current_network_interface', $('networkInterface').getProperty('value')); settings.set('current_network_interface', $('networkInterface').getProperty('value'));
settings.set('current_interface_address', $('optionalIPAddressToBind').getProperty('value')); settings.set('current_interface_address', $('optionalIPAddressToBind').getProperty('value'));
settings.set('save_resume_data_interval', $('saveResumeDataInterval').getProperty('value')); settings.set('save_resume_data_interval', $('saveResumeDataInterval').getProperty('value'));
settings.set('torrent_file_size_limit', ($('torrentFileSizeLimit').getProperty('value') * 1024 * 1024));
settings.set('recheck_completed_torrents', $('recheckTorrentsOnCompletion').getProperty('checked')); settings.set('recheck_completed_torrents', $('recheckTorrentsOnCompletion').getProperty('checked'));
settings.set('refresh_interval', $('refreshInterval').getProperty('value')); settings.set('refresh_interval', $('refreshInterval').getProperty('value'));
settings.set('resolve_peer_countries', $('resolvePeerCountries').getProperty('checked')); settings.set('resolve_peer_countries', $('resolvePeerCountries').getProperty('checked'));

Loading…
Cancel
Save