mirror of
https://github.com/qbittorrent/qBittorrent
synced 2025-08-20 13:23:34 -07:00
Don't access libtorrent session directly from TorrentImpl
This commit is contained in:
parent
3691eb948e
commit
582dc99cae
4 changed files with 27 additions and 24 deletions
|
@ -5443,6 +5443,19 @@ bool SessionImpl::addMoveTorrentStorageJob(TorrentImpl *torrent, const Path &new
|
|||
return true;
|
||||
}
|
||||
|
||||
lt::torrent_handle SessionImpl::reloadTorrent(const lt::torrent_handle ¤tHandle, lt::add_torrent_params params)
|
||||
{
|
||||
m_nativeSession->remove_torrent(currentHandle, lt::session::delete_partfile);
|
||||
|
||||
auto *const extensionData = new ExtensionData;
|
||||
params.userdata = LTClientData(extensionData);
|
||||
#ifndef QBT_USES_LIBTORRENT2
|
||||
params.storage = customStorageConstructor;
|
||||
#endif
|
||||
|
||||
return m_nativeSession->add_torrent(std::move(params));
|
||||
}
|
||||
|
||||
void SessionImpl::moveTorrentStorage(const MoveStorageJob &job) const
|
||||
{
|
||||
const TorrentImpl *torrent = getTorrent(job.torrentHandle);
|
||||
|
@ -5971,7 +5984,7 @@ void SessionImpl::dispatchTorrentAlert(const lt::torrent_alert *alert)
|
|||
|
||||
TorrentImpl *SessionImpl::createTorrent(const lt::torrent_handle &nativeHandle, const LoadTorrentParams ¶ms)
|
||||
{
|
||||
auto *const torrent = new TorrentImpl(this, m_nativeSession, nativeHandle, params);
|
||||
auto *const torrent = new TorrentImpl(this, nativeHandle, params);
|
||||
m_torrents.insert(torrent->id(), torrent);
|
||||
if (const InfoHash infoHash = torrent->infoHash(); infoHash.isHybrid())
|
||||
m_hybridTorrentsByAltID.insert(TorrentID::fromSHA1Hash(infoHash.v1()), torrent);
|
||||
|
|
|
@ -482,6 +482,8 @@ namespace BitTorrent
|
|||
|
||||
bool addMoveTorrentStorageJob(TorrentImpl *torrent, const Path &newPath, MoveStorageMode mode, MoveStorageContext context);
|
||||
|
||||
lt::torrent_handle reloadTorrent(const lt::torrent_handle ¤tHandle, lt::add_torrent_params params);
|
||||
|
||||
QFuture<FileSearchResult> findIncompleteFiles(const Path &savePath, const Path &downloadPath, const PathList &filePaths = {}) const;
|
||||
|
||||
void enablePortMapping();
|
||||
|
|
|
@ -290,11 +290,9 @@ namespace
|
|||
|
||||
// TorrentImpl
|
||||
|
||||
TorrentImpl::TorrentImpl(SessionImpl *session, lt::session *nativeSession
|
||||
, const lt::torrent_handle &nativeHandle, const LoadTorrentParams ¶ms)
|
||||
TorrentImpl::TorrentImpl(SessionImpl *session, const lt::torrent_handle &nativeHandle, const LoadTorrentParams ¶ms)
|
||||
: Torrent(session)
|
||||
, m_session(session)
|
||||
, m_nativeSession(nativeSession)
|
||||
, m_nativeHandle(nativeHandle)
|
||||
#ifdef QBT_USES_LIBTORRENT2
|
||||
, m_infoHash(m_nativeHandle.info_hashes())
|
||||
|
@ -1836,16 +1834,6 @@ void TorrentImpl::reload()
|
|||
{
|
||||
try
|
||||
{
|
||||
m_completedFiles.fill(false);
|
||||
m_filesProgress.fill(0);
|
||||
m_pieces.fill(false);
|
||||
m_nativeStatus.pieces.clear_all();
|
||||
m_nativeStatus.num_pieces = 0;
|
||||
|
||||
const auto queuePos = m_nativeHandle.queue_position();
|
||||
|
||||
m_nativeSession->remove_torrent(m_nativeHandle, lt::session::delete_partfile);
|
||||
|
||||
lt::add_torrent_params p = m_ltAddTorrentParams;
|
||||
p.flags |= lt::torrent_flags::update_subscribe
|
||||
| lt::torrent_flags::override_trackers
|
||||
|
@ -1865,19 +1853,21 @@ void TorrentImpl::reload()
|
|||
p.flags &= ~(lt::torrent_flags::auto_managed | lt::torrent_flags::paused);
|
||||
}
|
||||
|
||||
auto *const extensionData = new ExtensionData;
|
||||
p.userdata = LTClientData(extensionData);
|
||||
#ifndef QBT_USES_LIBTORRENT2
|
||||
p.storage = customStorageConstructor;
|
||||
#endif
|
||||
m_nativeHandle = m_nativeSession->add_torrent(p);
|
||||
const auto queuePos = m_nativeHandle.queue_position();
|
||||
|
||||
m_nativeStatus = extensionData->status;
|
||||
m_nativeHandle = m_session->reloadTorrent(m_nativeHandle, std::move(p));
|
||||
m_nativeStatus = static_cast<ExtensionData *>(m_nativeHandle.userdata())->status;
|
||||
|
||||
if (queuePos >= lt::queue_position_t {})
|
||||
m_nativeHandle.queue_position_set(queuePos);
|
||||
m_nativeStatus.queue_position = queuePos;
|
||||
|
||||
m_completedFiles.fill(false);
|
||||
m_filesProgress.fill(0);
|
||||
m_pieces.fill(false);
|
||||
m_nativeStatus.pieces.clear_all();
|
||||
m_nativeStatus.num_pieces = 0;
|
||||
|
||||
updateState();
|
||||
}
|
||||
catch (const lt::system_error &err)
|
||||
|
|
|
@ -94,8 +94,7 @@ namespace BitTorrent
|
|||
Q_DISABLE_COPY_MOVE(TorrentImpl)
|
||||
|
||||
public:
|
||||
TorrentImpl(SessionImpl *session, lt::session *nativeSession
|
||||
, const lt::torrent_handle &nativeHandle, const LoadTorrentParams ¶ms);
|
||||
TorrentImpl(SessionImpl *session, const lt::torrent_handle &nativeHandle, const LoadTorrentParams ¶ms);
|
||||
~TorrentImpl() override;
|
||||
|
||||
bool isValid() const;
|
||||
|
@ -325,7 +324,6 @@ namespace BitTorrent
|
|||
QFuture<std::invoke_result_t<Func>> invokeAsync(Func &&func) const;
|
||||
|
||||
SessionImpl *const m_session = nullptr;
|
||||
lt::session *m_nativeSession = nullptr;
|
||||
lt::torrent_handle m_nativeHandle;
|
||||
mutable lt::torrent_status m_nativeStatus;
|
||||
TorrentState m_state = TorrentState::Unknown;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue