From ffc0982fe3d88e2ebe4c92345ad44894c3e7d6af Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Fri, 27 Dec 2024 22:03:13 +0300 Subject: [PATCH] Revamp deletion of source .torrent file --- src/base/bittorrent/session.h | 11 ++++++++ src/base/bittorrent/sessionimpl.cpp | 42 ++++++++++++++++++++++++----- src/base/bittorrent/sessionimpl.h | 3 +++ 3 files changed, 50 insertions(+), 6 deletions(-) diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index 9bcc520444d4..5e448685f640 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -137,6 +137,15 @@ namespace BitTorrent SQLite }; Q_ENUM_NS(ResumeDataStorageType) + + enum class DeleteTorrentFileOption : int + { + // Do not change these names: they are stored in config file + Never, + IfAdded, + Always + }; + Q_ENUM_NS(DeleteTorrentFileOption) } class Session : public QObject @@ -452,6 +461,8 @@ namespace BitTorrent virtual void setStartPaused(bool value) = 0; virtual TorrentContentRemoveOption torrentContentRemoveOption() const = 0; virtual void setTorrentContentRemoveOption(TorrentContentRemoveOption option) = 0; + virtual DeleteTorrentFileOption deleteTorrentFileOption() const = 0; + virtual void setDeleteTorrentFileOption(DeleteTorrentFileOption option) = 0; virtual bool isRestored() const = 0; diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index eaaa4a942b70..05a5627fb1af 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -562,6 +562,7 @@ SessionImpl::SessionImpl(QObject *parent) , m_I2PInboundLength {BITTORRENT_SESSION_KEY(u"I2P/InboundLength"_s), 3} , m_I2POutboundLength {BITTORRENT_SESSION_KEY(u"I2P/OutboundLength"_s), 3} , m_torrentContentRemoveOption {BITTORRENT_SESSION_KEY(u"TorrentContentRemoveOption"_s), TorrentContentRemoveOption::Delete} + , m_deleteTorrentFileOption {u"Core/AutoDeleteAddedTorrentFile"_s, DeleteTorrentFileOption::Never} , m_startPaused {BITTORRENT_SESSION_KEY(u"StartPaused"_s)} , m_seedingLimitTimer {new QTimer(this)} , m_resumeDataTimer {new QTimer(this)} @@ -4108,6 +4109,16 @@ void SessionImpl::setTorrentContentRemoveOption(const TorrentContentRemoveOption m_torrentContentRemoveOption = option; } +DeleteTorrentFileOption SessionImpl::deleteTorrentFileOption() const +{ + return m_deleteTorrentFileOption; +} + +void SessionImpl::setDeleteTorrentFileOption(const DeleteTorrentFileOption option) +{ + m_deleteTorrentFileOption = option; +} + QStringList SessionImpl::bannedIPs() const { return m_bannedIPs; @@ -5671,14 +5682,18 @@ void SessionImpl::handleAddTorrentAlert(const lt::add_torrent_alert *alert) #else const InfoHash infoHash {(hasMetadata ? params.ti->info_hash() : params.info_hash)}; #endif - if (const auto loadingTorrentsIter = m_loadingTorrents.find(TorrentID::fromInfoHash(infoHash)) + const auto torrentID = TorrentID::fromInfoHash(infoHash); + if (const auto loadingTorrentsIter = m_loadingTorrents.find(torrentID) ; loadingTorrentsIter != m_loadingTorrents.end()) { - emit addTorrentFailed(infoHash, msg); m_loadingTorrents.erase(loadingTorrentsIter); + m_addingTorrents.remove(torrentID); + // TODO: Delete .torrent file + + emit addTorrentFailed(infoHash, msg); } - else if (const auto downloadedMetadataIter = m_downloadedMetadata.find(TorrentID::fromInfoHash(infoHash)) - ; downloadedMetadataIter != m_downloadedMetadata.end()) + else if (const auto downloadedMetadataIter = m_downloadedMetadata.find(torrentID) + ; downloadedMetadataIter != m_downloadedMetadata.end()) { m_downloadedMetadata.erase(downloadedMetadataIter); if (infoHash.isHybrid()) @@ -5865,6 +5880,19 @@ void SessionImpl::dispatchTorrentAlert(const lt::torrent_alert *alert) } } +template