Skip to content

Commit

Permalink
Change the feature concept
Browse files Browse the repository at this point in the history
  • Loading branch information
glassez committed Dec 17, 2024
1 parent 696854a commit 123065d
Show file tree
Hide file tree
Showing 11 changed files with 157 additions and 209 deletions.
6 changes: 3 additions & 3 deletions src/base/bittorrent/bencoderesumedatastorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,8 @@ BitTorrent::LoadResumeDataResult BitTorrent::BencodeResumeDataStorage::loadTorre
torrentParams.stopCondition = Utils::String::toEnum(
fromLTString(resumeDataRoot.dict_find_string_value("qBt-stopCondition")), Torrent::StopCondition::None);

torrentParams.torrentFileCopyPath = Profile::instance()->fromPortablePath(
Path(fromLTString(resumeDataRoot.dict_find_string_value("qBt-torrentFileCopyPath"))));
torrentParams.storedTorrentFilePath = Profile::instance()->fromPortablePath(
Path(fromLTString(resumeDataRoot.dict_find_string_value("qBt-storedTorrentFilePath"))));

torrentParams.sslParameters =
{
Expand Down Expand Up @@ -432,7 +432,7 @@ void BitTorrent::BencodeResumeDataStorage::Worker::store(const TorrentID &id, co
data["qBt-contentLayout"] = Utils::String::fromEnum(resumeData.contentLayout).toStdString();
data["qBt-firstLastPiecePriority"] = resumeData.firstLastPiecePriority;
data["qBt-stopCondition"] = Utils::String::fromEnum(resumeData.stopCondition).toStdString();
data["qBt-torrentFileCopyPath"] = Profile::instance()->toPortablePath(resumeData.torrentFileCopyPath).data().toStdString();
data["qBt-storedTorrentFilePath"] = Profile::instance()->toPortablePath(resumeData.storedTorrentFilePath).data().toStdString();

if (!resumeData.sslParameters.certificate.isNull())
data[KEY_SSL_CERTIFICATE] = resumeData.sslParameters.certificate.toPem().toStdString();
Expand Down
14 changes: 7 additions & 7 deletions src/base/bittorrent/dbresumedatastorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ namespace
const Column DB_COLUMN_OPERATING_MODE = makeColumn(u"operating_mode"_s);
const Column DB_COLUMN_STOPPED = makeColumn(u"stopped"_s);
const Column DB_COLUMN_STOP_CONDITION = makeColumn(u"stop_condition"_s);
const Column DB_COLUMN_TORRENT_FILE_COPY_PATH = makeColumn(u"torrent_file_copy_path"_s);
const Column DB_COLUMN_STORED_TORRENT_FILE_PATH = makeColumn(u"torrent_file_copy_path"_s);
const Column DB_COLUMN_SSL_CERTIFICATE = makeColumn(u"ssl_certificate"_s);
const Column DB_COLUMN_SSL_PRIVATE_KEY = makeColumn(u"ssl_private_key"_s);
const Column DB_COLUMN_SSL_DH_PARAMS = makeColumn(u"ssl_dh_params"_s);
Expand Down Expand Up @@ -244,8 +244,8 @@ namespace
resumeData.stopped = query.value(DB_COLUMN_STOPPED.name).toBool();
resumeData.stopCondition = Utils::String::toEnum(
query.value(DB_COLUMN_STOP_CONDITION.name).toString(), Torrent::StopCondition::None);
resumeData.torrentFileCopyPath = Profile::instance()->fromPortablePath(
Path(query.value(DB_COLUMN_TORRENT_FILE_COPY_PATH.name).toString()));
resumeData.storedTorrentFilePath = Profile::instance()->fromPortablePath(
Path(query.value(DB_COLUMN_STORED_TORRENT_FILE_PATH.name).toString()));
resumeData.sslParameters =
{
.certificate = QSslCertificate(query.value(DB_COLUMN_SSL_CERTIFICATE.name).toByteArray()),
Expand Down Expand Up @@ -550,7 +550,7 @@ void BitTorrent::DBResumeDataStorage::createDB() const
makeColumnDefinition(DB_COLUMN_OPERATING_MODE, u"TEXT NOT NULL"_s),
makeColumnDefinition(DB_COLUMN_STOPPED, u"INTEGER NOT NULL"_s),
makeColumnDefinition(DB_COLUMN_STOP_CONDITION, u"TEXT NOT NULL DEFAULT `None`"_s),
makeColumnDefinition(DB_COLUMN_TORRENT_FILE_COPY_PATH, u"TEXT"_s),
makeColumnDefinition(DB_COLUMN_STORED_TORRENT_FILE_PATH, u"TEXT"_s),
makeColumnDefinition(DB_COLUMN_SSL_CERTIFICATE, u"TEXT"_s),
makeColumnDefinition(DB_COLUMN_SSL_PRIVATE_KEY, u"TEXT"_s),
makeColumnDefinition(DB_COLUMN_SSL_DH_PARAMS, u"TEXT"_s),
Expand Down Expand Up @@ -657,7 +657,7 @@ void BitTorrent::DBResumeDataStorage::updateDB(const int fromVersion) const
}

if (fromVersion <= 8)
addColumn(DB_TABLE_TORRENTS, DB_COLUMN_TORRENT_FILE_COPY_PATH, "TEXT");
addColumn(DB_TABLE_TORRENTS, DB_COLUMN_STORED_TORRENT_FILE_PATH, u"TEXT"_s);

const QString updateMetaVersionQuery = makeUpdateStatement(DB_TABLE_META, {DB_COLUMN_NAME, DB_COLUMN_VALUE});
if (!query.prepare(updateMetaVersionQuery))
Expand Down Expand Up @@ -843,7 +843,7 @@ namespace
DB_COLUMN_OPERATING_MODE,
DB_COLUMN_STOPPED,
DB_COLUMN_STOP_CONDITION,
DB_COLUMN_TORRENT_FILE_COPY_PATH,
DB_COLUMN_STORED_TORRENT_FILE_PATH,
DB_COLUMN_SSL_CERTIFICATE,
DB_COLUMN_SSL_PRIVATE_KEY,
DB_COLUMN_SSL_DH_PARAMS,
Expand Down Expand Up @@ -907,7 +907,7 @@ namespace
query.bindValue(DB_COLUMN_OPERATING_MODE.placeholder, Utils::String::fromEnum(m_resumeData.operatingMode));
query.bindValue(DB_COLUMN_STOPPED.placeholder, m_resumeData.stopped);
query.bindValue(DB_COLUMN_STOP_CONDITION.placeholder, Utils::String::fromEnum(m_resumeData.stopCondition));
query.bindValue(DB_COLUMN_TORRENT_FILE_COPY_PATH.placeholder, Profile::instance()->toPortablePath(m_resumeData.torrentFileCopyPath).data());
query.bindValue(DB_COLUMN_STORED_TORRENT_FILE_PATH.placeholder, Profile::instance()->toPortablePath(m_resumeData.storedTorrentFilePath).data());
query.bindValue(DB_COLUMN_SSL_CERTIFICATE.placeholder, QString::fromLatin1(m_resumeData.sslParameters.certificate.toPem()));
query.bindValue(DB_COLUMN_SSL_PRIVATE_KEY.placeholder, QString::fromLatin1(m_resumeData.sslParameters.privateKey.toPem()));
query.bindValue(DB_COLUMN_SSL_DH_PARAMS.placeholder, QString::fromLatin1(m_resumeData.sslParameters.dhParams));
Expand Down
2 changes: 1 addition & 1 deletion src/base/bittorrent/loadtorrentparams.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ namespace BitTorrent
bool hasFinishedStatus = false;
bool stopped = false;
Torrent::StopCondition stopCondition = Torrent::StopCondition::None;
Path torrentFileCopyPath;
Path storedTorrentFilePath;

bool addToQueueTop = false; // only for new torrents

Expand Down
14 changes: 6 additions & 8 deletions src/base/bittorrent/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,14 +233,12 @@ namespace BitTorrent
virtual bool isPreallocationEnabled() const = 0;
virtual void setPreallocationEnabled(bool enabled) = 0;

virtual bool isCopyTorrentFileEnabled() const = 0;
virtual void setCopyTorrentFileEnabled(bool enabled) = 0;
virtual bool isCreateTorrentFileForMagnetEnabled() const = 0;
virtual void setCreateTorrentFileForMagnetEnabled(bool enabled) = 0;
virtual bool isDeleteTorrentFileCopyOnRemoveEnabled() const = 0;
virtual void setDeleteTorrentFileCopyOnRemoveEnabled(bool enabled) = 0;
virtual Path torrentFileCopyDirectory() const = 0;
virtual void setTorrentFileCopyDirectory(const Path &path) = 0;
virtual bool isStoreTorrentFileEnabled() const = 0;
virtual void setStoreTorrentFileEnabled(bool enabled) = 0;
virtual bool isDeleteStoredTorrentFileOnRemoveEnabled() const = 0;
virtual void setDeleteStoredTorrentFileOnRemoveEnabled(bool enabled) = 0;
virtual Path torrentFileStoreDirectory() const = 0;
virtual void setTorrentFileStoreDirectory(const Path &path) = 0;

virtual int globalDownloadSpeedLimit() const = 0;
virtual void setGlobalDownloadSpeedLimit(int limit) = 0;
Expand Down
72 changes: 30 additions & 42 deletions src/base/bittorrent/sessionimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,10 +492,9 @@ SessionImpl::SessionImpl(QObject *parent)
, m_isPreallocationEnabled(BITTORRENT_SESSION_KEY(u"Preallocation"_s), false)
, m_torrentExportDirectory(BITTORRENT_SESSION_KEY(u"TorrentExportDirectory"_s))
, m_finishedTorrentExportDirectory(BITTORRENT_SESSION_KEY(u"FinishedTorrentExportDirectory"_s))
, m_isCopyTorrentFileEnabled(BITTORRENT_SESSION_KEY(u"CopyTorrentFile"_s))
, m_isCreateTorrentFileForMagnetEnabled(BITTORRENT_SESSION_KEY(u"CreateTorrentFileForMagnet"_s))
, m_isDeleteTorrentFileCopyOnRemoveEnabled(BITTORRENT_SESSION_KEY(u"DeleteTorrentFileCopyOnRemove"_s))
, m_torrentFileCopyDirectory(BITTORRENT_SESSION_KEY(u"TorrentFileCopyDirectory"_s))
, m_isStoreTorrentFileEnabled(BITTORRENT_SESSION_KEY(u"StoreTorrentFile"_s))
, m_isDeleteStoredTorrentFileOnRemoveEnabled(BITTORRENT_SESSION_KEY(u"DeleteStoredTorrentFileOnRemove"_s))
, m_torrentFileStoreDirectory(BITTORRENT_SESSION_KEY(u"TorrentFileStoreDirectory"_s))
, m_globalDownloadSpeedLimit(BITTORRENT_SESSION_KEY(u"GlobalDLSpeedLimit"_s), 0, lowerLimited(0))
, m_globalUploadSpeedLimit(BITTORRENT_SESSION_KEY(u"GlobalUPSpeedLimit"_s), 0, lowerLimited(0))
, m_altGlobalDownloadSpeedLimit(BITTORRENT_SESSION_KEY(u"AlternativeGlobalDLSpeedLimit"_s), 10, lowerLimited(0))
Expand Down Expand Up @@ -823,48 +822,37 @@ void SessionImpl::setPreallocationEnabled(const bool enabled)
m_isPreallocationEnabled = enabled;
}

bool SessionImpl::isCopyTorrentFileEnabled() const
bool SessionImpl::isStoreTorrentFileEnabled() const
{
return m_isCopyTorrentFileEnabled;
return m_isStoreTorrentFileEnabled;
}

void SessionImpl::setCopyTorrentFileEnabled(const bool enabled)
void SessionImpl::setStoreTorrentFileEnabled(const bool enabled)
{
if (enabled != m_isCopyTorrentFileEnabled)
m_isCopyTorrentFileEnabled = enabled;
if (enabled != m_isStoreTorrentFileEnabled)
m_isStoreTorrentFileEnabled = enabled;
}

bool SessionImpl::isCreateTorrentFileForMagnetEnabled() const
bool SessionImpl::isDeleteStoredTorrentFileOnRemoveEnabled() const
{
return m_isCreateTorrentFileForMagnetEnabled;
return m_isDeleteStoredTorrentFileOnRemoveEnabled;
}

void SessionImpl::setCreateTorrentFileForMagnetEnabled(const bool enabled)
void SessionImpl::setDeleteStoredTorrentFileOnRemoveEnabled(const bool enabled)
{
if (enabled != m_isCreateTorrentFileForMagnetEnabled)
m_isCreateTorrentFileForMagnetEnabled = enabled;
if (enabled != m_isDeleteStoredTorrentFileOnRemoveEnabled)
m_isDeleteStoredTorrentFileOnRemoveEnabled = enabled;
}

bool SessionImpl::isDeleteTorrentFileCopyOnRemoveEnabled() const
Path SessionImpl::torrentFileStoreDirectory() const
{
return m_isDeleteTorrentFileCopyOnRemoveEnabled;
return m_torrentFileStoreDirectory;
}

void SessionImpl::setDeleteTorrentFileCopyOnRemoveEnabled(const bool enabled)
void SessionImpl::setTorrentFileStoreDirectory(const Path &path)
{
if (enabled != m_isDeleteTorrentFileCopyOnRemoveEnabled)
m_isDeleteTorrentFileCopyOnRemoveEnabled = enabled;
}

Path SessionImpl::torrentFileCopyDirectory() const
{
return m_torrentFileCopyDirectory;
}

void SessionImpl::setTorrentFileCopyDirectory(const Path &path)
{
if (path != torrentFileCopyDirectory())
m_torrentFileCopyDirectory = path;
if (path != torrentFileStoreDirectory())
m_torrentFileStoreDirectory = path;
}

Path SessionImpl::savePath() const
Expand Down Expand Up @@ -5143,13 +5131,13 @@ void SessionImpl::handleTorrentUrlSeedsRemoved(TorrentImpl *const torrent, const

void SessionImpl::handleTorrentMetadataReceived(TorrentImpl *const torrent)
{
if (const Path copyDir = torrentFileCopyDirectory();
isCopyTorrentFileEnabled() && isCreateTorrentFileForMagnetEnabled() && !copyDir.isEmpty())
if (const Path storeDir = torrentFileStoreDirectory();
isStoreTorrentFileEnabled() && !storeDir.isEmpty())
{
if (const auto result = createTorrentFile(torrent, copyDir))
if (const auto result = createTorrentFile(torrent, storeDir))
{
const Path torrentFilePath = result.value();
torrent->setTorrentFileCopyPath(torrentFilePath);
torrent->setStoredTorrentFilePath(torrentFilePath);
LogMsg(tr("Created .torrent file. Torrent: \"%1\". Destination: \"%2\".")
.arg(torrent->name(), torrentFilePath.toString()));
}
Expand Down Expand Up @@ -5330,19 +5318,19 @@ void SessionImpl::processPendingFinishedTorrents()
if (m_pendingFinishedTorrents.isEmpty())
return;

const Path copyDir = torrentFileCopyDirectory();
const bool needCreateTorrentFileForMagnet = isCopyTorrentFileEnabled() && isCreateTorrentFileForMagnetEnabled() && !copyDir.isEmpty();
const Path storeDir = torrentFileStoreDirectory();
const bool needStoreTorrentFile = isStoreTorrentFileEnabled() && !storeDir.isEmpty();
for (TorrentImpl *torrent : asConst(m_pendingFinishedTorrents))
{
LogMsg(tr("Torrent download finished. Torrent: \"%1\"").arg(torrent->name()));
emit torrentFinished(torrent);

if (needCreateTorrentFileForMagnet)
if (needStoreTorrentFile)
{
if (const auto result = createTorrentFile(torrent, copyDir))
if (const auto result = createTorrentFile(torrent, storeDir))
{
const Path torrentFilePath = result.value();
torrent->setTorrentFileCopyPath(torrentFilePath);
torrent->setStoredTorrentFilePath(torrentFilePath);
LogMsg(tr("Created .torrent file. Torrent: \"%1\". Destination: \"%2\".")
.arg(torrent->name(), torrentFilePath.toString()));
}
Expand Down Expand Up @@ -5851,15 +5839,15 @@ TorrentImpl *SessionImpl::createTorrent(const lt::torrent_handle &nativeHandle,
torrent->requestResumeData(lt::torrent_handle::save_info_dict);

const TorrentDescriptor torrentSource = m_addingTorrents.take(torrent->id());
const Path copyDir = torrentFileCopyDirectory();
const Path copyDir = torrentFileStoreDirectory();

// The following is useless for torrents added without metadata
if (torrentSource.info().has_value() && isCopyTorrentFileEnabled() && !copyDir.isEmpty())
if (torrentSource.info().has_value() && isStoreTorrentFileEnabled() && !copyDir.isEmpty())
{
if (const auto result = createTorrentFile(torrentSource, copyDir))
{
const Path torrentFilePath = result.value();
torrent->setTorrentFileCopyPath(torrentFilePath);
torrent->setStoredTorrentFilePath(torrentFilePath);
LogMsg(tr("Created copy of .torrent file. Torrent: \"%1\". Destination: \"%2\".")
.arg(torrent->name(), torrentFilePath.toString()));
}
Expand Down
21 changes: 9 additions & 12 deletions src/base/bittorrent/sessionimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,14 +208,12 @@ namespace BitTorrent
bool isPreallocationEnabled() const override;
void setPreallocationEnabled(bool enabled) override;

bool isCopyTorrentFileEnabled() const override;
void setCopyTorrentFileEnabled(bool enabled) override;
bool isCreateTorrentFileForMagnetEnabled() const override;
void setCreateTorrentFileForMagnetEnabled(bool enabled) override;
bool isDeleteTorrentFileCopyOnRemoveEnabled() const override;
void setDeleteTorrentFileCopyOnRemoveEnabled(bool enabled) override;
Path torrentFileCopyDirectory() const override;
void setTorrentFileCopyDirectory(const Path &path) override;
bool isStoreTorrentFileEnabled() const override;
void setStoreTorrentFileEnabled(bool enabled) override;
bool isDeleteStoredTorrentFileOnRemoveEnabled() const override;
void setDeleteStoredTorrentFileOnRemoveEnabled(bool enabled) override;
Path torrentFileStoreDirectory() const override;
void setTorrentFileStoreDirectory(const Path &path) override;

int globalDownloadSpeedLimit() const override;
void setGlobalDownloadSpeedLimit(int limit) override;
Expand Down Expand Up @@ -696,10 +694,9 @@ namespace BitTorrent
CachedSettingValue<bool> m_isPreallocationEnabled;
CachedSettingValue<Path> m_torrentExportDirectory;
CachedSettingValue<Path> m_finishedTorrentExportDirectory;
CachedSettingValue<bool> m_isCopyTorrentFileEnabled;
CachedSettingValue<bool> m_isCreateTorrentFileForMagnetEnabled;
CachedSettingValue<bool> m_isDeleteTorrentFileCopyOnRemoveEnabled;
CachedSettingValue<Path> m_torrentFileCopyDirectory;
CachedSettingValue<bool> m_isStoreTorrentFileEnabled;
CachedSettingValue<bool> m_isDeleteStoredTorrentFileOnRemoveEnabled;
CachedSettingValue<Path> m_torrentFileStoreDirectory;
CachedSettingValue<int> m_globalDownloadSpeedLimit;
CachedSettingValue<int> m_globalUploadSpeedLimit;
CachedSettingValue<int> m_altGlobalDownloadSpeedLimit;
Expand Down
14 changes: 7 additions & 7 deletions src/base/bittorrent/torrentimpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ TorrentImpl::TorrentImpl(SessionImpl *session, lt::session *nativeSession
, m_useAutoTMM(params.useAutoTMM)
, m_isStopped(params.stopped)
, m_sslParams(params.sslParameters)
, m_torrentFileCopyPath(params.torrentFileCopyPath)
, m_storedTorrentFilePath(params.storedTorrentFilePath)
, m_ltAddTorrentParams(params.ltAddTorrentParams)
, m_downloadLimit(cleanLimitValue(m_ltAddTorrentParams.download_limit))
, m_uploadLimit(cleanLimitValue(m_ltAddTorrentParams.upload_limit))
Expand Down Expand Up @@ -2253,7 +2253,7 @@ void TorrentImpl::prepareResumeData(const lt::add_torrent_params &params)
.hasFinishedStatus = m_hasFinishedStatus,
.stopped = m_isStopped,
.stopCondition = m_stopCondition,
.torrentFileCopyPath = m_torrentFileCopyPath,
.storedTorrentFilePath = m_storedTorrentFilePath,
.addToQueueTop = false,
.ratioLimit = m_ratioLimit,
.seedingTimeLimit = m_seedingTimeLimit,
Expand Down Expand Up @@ -2553,17 +2553,17 @@ lt::torrent_handle TorrentImpl::nativeHandle() const
return m_nativeHandle;
}

Path TorrentImpl::torrentFileCopyPath() const
Path TorrentImpl::storedTorrentFilePath() const
{
return m_torrentFileCopyPath;
return m_storedTorrentFilePath;
}

void TorrentImpl::setTorrentFileCopyPath(const Path &path)
void TorrentImpl::setStoredTorrentFilePath(const Path &path)
{
if (path == m_torrentFileCopyPath)
if (path == m_storedTorrentFilePath)
return;

m_torrentFileCopyPath = path;
m_storedTorrentFilePath = path;
deferredRequestResumeData();
}

Expand Down
6 changes: 3 additions & 3 deletions src/base/bittorrent/torrentimpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,8 @@ namespace BitTorrent
// Session interface
lt::torrent_handle nativeHandle() const;

Path torrentFileCopyPath() const;
void setTorrentFileCopyPath(const Path &path);
Path storedTorrentFilePath() const;
void setStoredTorrentFilePath(const Path &path);

void handleAlert(const lt::alert *a);
void handleStateUpdate(const lt::torrent_status &nativeStatus);
Expand Down Expand Up @@ -387,7 +387,7 @@ namespace BitTorrent
bool m_isStopped = false;
StopCondition m_stopCondition = StopCondition::None;
SSLParameters m_sslParams;
Path m_torrentFileCopyPath;
Path m_storedTorrentFilePath;

bool m_unchecked = false;

Expand Down
Loading

0 comments on commit 123065d

Please sign in to comment.