diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt index 6188f4706..4467c9bf8 100644 --- a/src/base/CMakeLists.txt +++ b/src/base/CMakeLists.txt @@ -12,6 +12,8 @@ bittorrent/peerinfo.h bittorrent/private/bandwidthscheduler.h bittorrent/private/filterparserthread.h bittorrent/private/ltunderlyingtype.h +bittorrent/private/nativesessionextension.h +bittorrent/private/nativetorrentextension.h bittorrent/private/portforwarderimpl.h bittorrent/private/resumedatasavingmanager.h bittorrent/private/speedmonitor.h @@ -88,6 +90,8 @@ bittorrent/peeraddress.cpp bittorrent/peerinfo.cpp bittorrent/private/bandwidthscheduler.cpp bittorrent/private/filterparserthread.cpp +bittorrent/private/nativesessionextension.cpp +bittorrent/private/nativetorrentextension.cpp bittorrent/private/portforwarderimpl.cpp bittorrent/private/resumedatasavingmanager.cpp bittorrent/private/speedmonitor.cpp diff --git a/src/base/base.pri b/src/base/base.pri index 68df7315a..1847d33f4 100644 --- a/src/base/base.pri +++ b/src/base/base.pri @@ -11,6 +11,8 @@ HEADERS += \ $$PWD/bittorrent/private/bandwidthscheduler.h \ $$PWD/bittorrent/private/filterparserthread.h \ $$PWD/bittorrent/private/ltunderlyingtype.h \ + $$PWD/bittorrent/private/nativesessionextension.h \ + $$PWD/bittorrent/private/nativetorrentextension.h \ $$PWD/bittorrent/private/portforwarderimpl.h \ $$PWD/bittorrent/private/resumedatasavingmanager.h \ $$PWD/bittorrent/private/speedmonitor.h \ @@ -87,6 +89,8 @@ SOURCES += \ $$PWD/bittorrent/peerinfo.cpp \ $$PWD/bittorrent/private/bandwidthscheduler.cpp \ $$PWD/bittorrent/private/filterparserthread.cpp \ + $$PWD/bittorrent/private/nativesessionextension.cpp \ + $$PWD/bittorrent/private/nativetorrentextension.cpp \ $$PWD/bittorrent/private/portforwarderimpl.cpp \ $$PWD/bittorrent/private/resumedatasavingmanager.cpp \ $$PWD/bittorrent/private/speedmonitor.cpp \ diff --git a/src/base/bittorrent/private/nativesessionextension.cpp b/src/base/bittorrent/private/nativesessionextension.cpp new file mode 100644 index 000000000..f1bf0d55b --- /dev/null +++ b/src/base/bittorrent/private/nativesessionextension.cpp @@ -0,0 +1,74 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2020 Vladimir Golovnev + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#include "nativesessionextension.h" + +#include + +#include "nativetorrentextension.h" + +namespace +{ + void handleFastresumeRejectedAlert(const lt::fastresume_rejected_alert *alert) + { + if (alert->error.value() == lt::errors::mismatching_file_size) { +#if (LIBTORRENT_VERSION_NUM < 10200) + alert->handle.auto_managed(false); +#else + alert->handle.unset_flags(lt::torrent_flags::auto_managed); +#endif + alert->handle.pause(); + } + } +} + +#if (LIBTORRENT_VERSION_NUM >= 10200) +lt::feature_flags_t NativeSessionExtension::implemented_features() +{ + return alert_feature; +} + +std::shared_ptr NativeSessionExtension::new_torrent(const lt::torrent_handle &torrentHandle, void *) +{ + return std::make_shared(torrentHandle); +} +#else +boost::shared_ptr NativeSessionExtension::new_torrent(const lt::torrent_handle &torrentHandle, void *) +{ + return boost::shared_ptr {new NativeTorrentExtension {torrentHandle}}; +} +#endif + +void NativeSessionExtension::on_alert(const lt::alert *alert) +{ + switch (alert->type()) { + case lt::fastresume_rejected_alert::alert_type: + handleFastresumeRejectedAlert(static_cast(alert)); + break; + } +} diff --git a/src/base/bittorrent/private/nativesessionextension.h b/src/base/bittorrent/private/nativesessionextension.h new file mode 100644 index 000000000..0e0aa4c7c --- /dev/null +++ b/src/base/bittorrent/private/nativesessionextension.h @@ -0,0 +1,43 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2020 Vladimir Golovnev + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#pragma once + +#include +#include + +class NativeSessionExtension : public lt::plugin +{ +#if (LIBTORRENT_VERSION_NUM >= 10200) + lt::feature_flags_t implemented_features() override; + std::shared_ptr new_torrent(const lt::torrent_handle &torrentHandle, void *userData) override; +#else + boost::shared_ptr new_torrent(const lt::torrent_handle &torrentHandle, void *userData) override; +#endif + void on_alert(const lt::alert *alert) override; +}; diff --git a/src/base/bittorrent/private/nativetorrentextension.cpp b/src/base/bittorrent/private/nativetorrentextension.cpp new file mode 100644 index 000000000..62071fec6 --- /dev/null +++ b/src/base/bittorrent/private/nativetorrentextension.cpp @@ -0,0 +1,94 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2020 Vladimir Golovnev + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#include "nativetorrentextension.h" + +#include + +namespace +{ + bool isPaused(const lt::torrent_status &torrentStatus) + { +#if (LIBTORRENT_VERSION_NUM < 10200) + return (torrentStatus.paused && !torrentStatus.auto_managed); +#else + return ((torrentStatus.flags & lt::torrent_flags::paused) + && !(torrentStatus.flags & lt::torrent_flags::auto_managed)); +#endif + } + + bool isAutoManaged(const lt::torrent_status &torrentStatus) + { +#if (LIBTORRENT_VERSION_NUM < 10200) + return torrentStatus.auto_managed; +#else + return bool {torrentStatus.flags & lt::torrent_flags::auto_managed}; +#endif + } +} + +NativeTorrentExtension::NativeTorrentExtension(const lt::torrent_handle &torrentHandle) + : m_torrentHandle {torrentHandle} +{ +} + +// This method is called when state of torrent is changed +#if (LIBTORRENT_VERSION_NUM < 10200) +void NativeTorrentExtension::on_state(const int state) +#else +void NativeTorrentExtension::on_state(const lt::torrent_status::state_t state) +#endif +{ + // When a torrent enters "checking files" state while paused, we temporarily resume it + // (really we just allow libtorrent to resume it by enabling auto management for it). + if (state == lt::torrent_status::checking_files) { + if (isPaused(m_torrentHandle.status({}))) { +#if (LIBTORRENT_VERSION_NUM < 10200) + m_torrentHandle.stop_when_ready(true); + m_torrentHandle.auto_managed(true); +#else + m_torrentHandle.set_flags(lt::torrent_flags::stop_when_ready | lt::torrent_flags::auto_managed); +#endif + } + } +} + +bool NativeTorrentExtension::on_pause() +{ + if (!isAutoManaged(m_torrentHandle.status({}))) { +#if (LIBTORRENT_VERSION_NUM < 10200) + m_torrentHandle.stop_when_ready(false); +#else + m_torrentHandle.unset_flags(lt::torrent_flags::stop_when_ready); +#endif + } + + // return `false` to allow standard handler + // and other extensions to be also invoked. + return false; +} diff --git a/src/base/bittorrent/private/nativetorrentextension.h b/src/base/bittorrent/private/nativetorrentextension.h new file mode 100644 index 000000000..46a7759ca --- /dev/null +++ b/src/base/bittorrent/private/nativetorrentextension.h @@ -0,0 +1,49 @@ +/* + * Bittorrent Client using Qt and libtorrent. + * Copyright (C) 2020 Vladimir Golovnev + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * In addition, as a special exception, the copyright holders give permission to + * link this program with the OpenSSL project's "OpenSSL" library (or with + * modified versions of it that use the same license as the "OpenSSL" library), + * and distribute the linked executables. You must obey the GNU General Public + * License in all respects for all of the code used other than "OpenSSL". If you + * modify file(s), you may extend this exception to your version of the file(s), + * but you are not obligated to do so. If you do not wish to do so, delete this + * exception statement from your version. + */ + +#pragma once + +#include +#include +#include + +class NativeTorrentExtension : public lt::torrent_plugin +{ +public: + explicit NativeTorrentExtension(const lt::torrent_handle &torrentHandle); + +private: +#if (LIBTORRENT_VERSION_NUM < 10200) + void on_state(int state) override; +#else + void on_state(lt::torrent_status::state_t state) override; +#endif + bool on_pause() override; + + lt::torrent_handle m_torrentHandle; +}; diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index ae509b9c9..0000dc029 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -90,6 +90,7 @@ #include "private/bandwidthscheduler.h" #include "private/filterparserthread.h" #include "private/ltunderlyingtype.h" +#include "private/nativesessionextension.h" #include "private/portforwarderimpl.h" #include "private/resumedatasavingmanager.h" #include "private/statistics.h" @@ -1129,6 +1130,12 @@ void Session::initializeNativeSession() m_nativeSession->add_extension(<::create_ut_metadata_plugin); if (isPeXEnabled()) m_nativeSession->add_extension(<::create_ut_pex_plugin); + +#if (LIBTORRENT_VERSION_NUM < 10200) + m_nativeSession->add_extension(boost::shared_ptr {new NativeSessionExtension}); +#else + m_nativeSession->add_extension(std::make_shared()); +#endif } void Session::processBannedIPs(lt::ip_filter &filter) @@ -2014,14 +2021,28 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne // Reuse existing torrent_handle lt::torrent_handle handle = m_nativeSession->find_torrent(hash); - // We need to pause it first to create TorrentHandle within the same - // underlying state as in other cases. - handle.auto_managed(false); - handle.pause(); - // createTorrentHandle() for this is called in the torrent_paused_alert handler + + // Preloaded torrent is in "Upload mode" so we need to disable it + // otherwise the torrent never be downloaded (until application restart) + handle.set_upload_mode(false); + + if (params.paused) { + // Preloaded torrent isn't auto managed already + handle.pause(); + } + else if (!params.forced) { + handle.auto_managed(true); + handle.pause(); + } m_loadedMetadata.remove(hash); m_addingTorrents.insert(hash, params); + + --m_extraLimit; + adjustLimits(); + + // use common 2nd step of torrent addition + createTorrentHandle(handle); return true; } @@ -2110,11 +2131,14 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne // Common p.flags &= ~lt::add_torrent_params::flag_duplicate_is_error; // Already checked - // Make sure the torrent will be initially checked and then paused - // to perform some service jobs on it. We will start it if needed. - p.flags |= lt::add_torrent_params::flag_paused; - p.flags |= lt::add_torrent_params::flag_auto_managed; - p.flags |= lt::add_torrent_params::flag_stop_when_ready; + if (params.paused || !params.forced) + p.flags |= lt::add_torrent_params::flag_paused; + else + p.flags &= ~lt::add_torrent_params::flag_paused; + if (params.paused || params.forced) + p.flags &= ~lt::add_torrent_params::flag_auto_managed; + else + p.flags |= lt::add_torrent_params::flag_auto_managed; // Limits p.max_connections = maxConnectionsPerTorrent(); p.max_uploads = maxUploadsPerTorrent(); @@ -2164,14 +2188,29 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne // Reuse existing torrent_handle lt::torrent_handle handle = m_nativeSession->find_torrent(hash); - // We need to pause it first to create TorrentHandle within the same - // underlying state as in other cases. - handle.unset_flags(lt::torrent_flags::auto_managed); - handle.pause(); - // createTorrentHandle() for this is called in the torrent_paused_alert handler + + // Preloaded torrent is in "Upload mode" so we need to disable it + // otherwise the torrent never be downloaded (until application restart) + handle.unset_flags(lt::torrent_flags::upload_mode); + + if (params.paused) { + // Preloaded torrent isn't auto managed already + handle.pause(); + } + else if (!params.forced) { + handle.set_flags(lt::torrent_flags::auto_managed); + handle.pause(); + } + m_loadedMetadata.remove(hash); m_addingTorrents.insert(hash, params); + + --m_extraLimit; + adjustLimits(); + + // use common 2nd step of torrent addition + createTorrentHandle(handle); return true; } @@ -2272,11 +2311,15 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne // Common p.flags &= ~lt::torrent_flags::duplicate_is_error; // Already checked - // Make sure the torrent will be initially checked and then paused - // to perform some service jobs on it. We will start it if needed. - p.flags |= lt::torrent_flags::paused; - p.flags |= lt::torrent_flags::auto_managed; - p.flags |= lt::torrent_flags::stop_when_ready; + if (params.paused || !params.forced) + p.flags |= lt::torrent_flags::paused; + else + p.flags &= ~lt::torrent_flags::paused; + if (params.paused || params.forced) + p.flags &= ~lt::torrent_flags::auto_managed; + else + p.flags |= lt::torrent_flags::auto_managed; + // Limits p.max_connections = maxConnectionsPerTorrent(); p.max_uploads = maxUploadsPerTorrent(); @@ -4267,9 +4310,6 @@ void Session::dispatchTorrentAlert(const lt::alert *a) } switch (a->type()) { - case lt::torrent_paused_alert::alert_type: - handleTorrentPausedAlert(static_cast(a)); - break; case lt::metadata_received_alert::alert_type: handleMetadataReceivedAlert(static_cast(a)); break; @@ -4414,29 +4454,6 @@ void Session::handleMetadataReceivedAlert(const lt::metadata_received_alert *p) } } -void Session::handleTorrentPausedAlert(const libtorrent::torrent_paused_alert *p) -{ - const InfoHash hash {p->handle.info_hash()}; - - if (m_addingTorrents.contains(hash)) { - // Adding preloaded torrent - lt::torrent_handle handle = p->handle; - --m_extraLimit; - - // Preloaded torrent is in "Upload mode" so we need to disable it - // otherwise the torrent never be downloaded (until application restart) -#if (LIBTORRENT_VERSION_NUM < 10200) - handle.set_upload_mode(false); -#else - handle.unset_flags(lt::torrent_flags::upload_mode); -#endif - - adjustLimits(); - // use common 2nd step of torrent addition - createTorrentHandle(handle); - } -} - void Session::handleFileErrorAlert(const lt::file_error_alert *p) { TorrentHandle *const torrent = m_torrents.value(p->handle.info_hash()); diff --git a/src/base/bittorrent/session.h b/src/base/bittorrent/session.h index c7b8ce03d..a139e9d95 100644 --- a/src/base/bittorrent/session.h +++ b/src/base/bittorrent/session.h @@ -566,7 +566,6 @@ namespace BitTorrent void handleAddTorrentAlert(const lt::add_torrent_alert *p); void handleStateUpdateAlert(const lt::state_update_alert *p); void handleMetadataReceivedAlert(const lt::metadata_received_alert *p); - void handleTorrentPausedAlert(const lt::torrent_paused_alert *p); void handleFileErrorAlert(const lt::file_error_alert *p); void handleTorrentRemovedAlert(const lt::torrent_removed_alert *p); void handleTorrentDeletedAlert(const lt::torrent_deleted_alert *p); diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 247a55220..683e1fd64 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -213,8 +213,6 @@ TorrentHandle::TorrentHandle(Session *session, const lt::torrent_handle &nativeH , m_hasMissingFiles(false) , m_hasRootFolder(params.hasRootFolder) , m_needsToSetFirstLastPiecePriority(false) - , m_needsToStartForced(params.forced) - , m_pauseWhenReady(params.paused) { if (m_useAutoTMM) m_savePath = Utils::Fs::toNativePath(m_session->categorySavePath(m_category)); @@ -239,20 +237,6 @@ TorrentHandle::TorrentHandle(Session *session, const lt::torrent_handle &nativeH if (filesCount() == 1) m_hasRootFolder = false; } - - if (!hasMetadata()) { - // There is nothing to prepare - if (!m_pauseWhenReady) { - // Resume torrent because it was added in "resumed" state - // but it's actually paused during initialization. - m_startupState = Starting; - resume_impl(m_needsToStartForced); - } - else { - m_startupState = Started; - m_pauseWhenReady = false; - } - } } TorrentHandle::~TorrentHandle() {} @@ -1360,8 +1344,6 @@ bool TorrentHandle::setCategory(const QString &category) void TorrentHandle::move(QString path) { - if (m_startupState != Started) return; - m_useAutoTMM = false; m_session->handleTorrentSavingModeChanged(this); @@ -1404,18 +1386,6 @@ void TorrentHandle::forceRecheck() m_nativeHandle.force_recheck(); m_unchecked = false; - - if ((m_startupState != Started) || isPaused()) { -#if (LIBTORRENT_VERSION_NUM < 10200) - m_nativeHandle.stop_when_ready(true); -#else - m_nativeHandle.set_flags(lt::torrent_flags::stop_when_ready); -#endif - setAutoManaged(true); - } - - if ((m_startupState == Started) && isPaused()) - m_pauseWhenReady = true; } void TorrentHandle::setSequentialDownload(const bool enable) @@ -1504,22 +1474,11 @@ void TorrentHandle::pause() setAutoManaged(false); m_nativeHandle.pause(); - if (m_startupState == Started) { - if (m_pauseWhenReady) { -#if (LIBTORRENT_VERSION_NUM < 10200) - m_nativeHandle.stop_when_ready(false); -#else - m_nativeHandle.unset_flags(lt::torrent_flags::stop_when_ready); -#endif - m_pauseWhenReady = false; - } - - // Libtorrent doesn't emit a torrent_paused_alert when the - // torrent is queued (no I/O) - // We test on the cached m_nativeStatus - if (isQueued()) - m_session->handleTorrentPaused(this); - } + // Libtorrent doesn't emit a torrent_paused_alert when the + // torrent is queued (no I/O) + // We test on the cached m_nativeStatus + if (isQueued()) + m_session->handleTorrentPaused(this); } void TorrentHandle::resume(bool forced) @@ -1711,25 +1670,9 @@ void TorrentHandle::handleTorrentCheckedAlert(const lt::torrent_checked_alert *p Q_UNUSED(p); qDebug("\"%s\" have just finished checking", qUtf8Printable(name())); - if (m_startupState == Preparing) { - if (!m_pauseWhenReady) { - if (!m_hasMissingFiles) { - // Resume torrent because it was added in "resumed" state - // but it's actually paused during initialization. - m_startupState = Starting; - resume_impl(m_needsToStartForced); - } - else { - // Torrent that has missing files is paused. - m_startupState = Started; - } - } - else { - m_startupState = Started; - m_pauseWhenReady = false; - if (m_fastresumeDataRejected && !m_hasMissingFiles) - saveResumeData(); - } + if (m_fastresumeDataRejected && !m_hasMissingFiles) { + saveResumeData(); + m_fastresumeDataRejected = false; } updateStatus(); @@ -1778,27 +1721,17 @@ void TorrentHandle::handleTorrentPausedAlert(const lt::torrent_paused_alert *p) { Q_UNUSED(p); - if (m_startupState == Started) { - if (!m_pauseWhenReady) { - updateStatus(); - m_speedMonitor.reset(); - } - else { - m_pauseWhenReady = false; - } + updateStatus(); + m_speedMonitor.reset(); - m_session->handleTorrentPaused(this); - } + m_session->handleTorrentPaused(this); } void TorrentHandle::handleTorrentResumedAlert(const lt::torrent_resumed_alert *p) { Q_UNUSED(p); - if (m_startupState == Started) - m_session->handleTorrentResumed(this); - else if (m_startupState == Starting) - m_startupState = Started; + m_session->handleTorrentResumed(this); } void TorrentHandle::handleSaveResumeDataAlert(const lt::save_resume_data_alert *p) @@ -1814,6 +1747,8 @@ void TorrentHandle::handleSaveResumeDataAlert(const lt::save_resume_data_alert * lt::entry resumeData = useDummyResumeData ? lt::entry() : lt::write_resume_data(p->params); #endif + updateStatus(); + if (useDummyResumeData) { resumeData["qBt-magnetUri"] = toMagnetUri().toStdString(); resumeData["paused"] = isPaused(); @@ -1841,7 +1776,11 @@ void TorrentHandle::handleSaveResumeDataAlert(const lt::save_resume_data_alert * resumeData["qBt-queuePosition"] = (static_cast(nativeHandle().queue_position()) + 1); // qBt starts queue at 1 resumeData["qBt-hasRootFolder"] = m_hasRootFolder; - if (m_pauseWhenReady) { +#if (LIBTORRENT_VERSION_NUM < 10200) + if (m_nativeStatus.stop_when_ready) { +#else + if (m_nativeStatus.flags & lt::torrent_flags::stop_when_ready) { +#endif // We need to redefine these values when torrent starting/rechecking // in "paused" state since native values can be logically wrong // (torrent can be not paused and auto_managed when it is checking). diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index 348dd540b..4a4def445 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -443,21 +443,9 @@ namespace BitTorrent bool m_hasMissingFiles; bool m_hasRootFolder; bool m_needsToSetFirstLastPiecePriority; - bool m_needsToStartForced; QHash m_trackerInfos; - enum StartupState - { - Preparing, // torrent is preparing to start regular processing - Starting, // torrent is prepared and starting to perform regular processing - Started // torrent is performing regular processing - }; - StartupState m_startupState = Preparing; - // Handle torrent state when it starts performing some service job - // being in Paused state so it might be unpaused internally and then paused again - bool m_pauseWhenReady; - bool m_unchecked = false; }; }