From cd6959b712872407376b1cbd5bcc41daa4650d76 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Mon, 29 Mar 2021 11:26:44 +0300 Subject: [PATCH] Save "resume data" once file priority is changed --- src/base/bittorrent/session.cpp | 3 +++ src/base/bittorrent/torrentimpl.cpp | 13 +++++++++++++ src/base/bittorrent/torrentimpl.h | 14 ++++++++++++++ 3 files changed, 30 insertions(+) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 77b76dd9f..7229695c6 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -4257,6 +4257,9 @@ void Session::handleAlert(const lt::alert *a) { switch (a->type()) { +#if (LIBTORRENT_VERSION_NUM >= 20003) + case lt::file_prio_alert::alert_type: +#endif case lt::file_renamed_alert::alert_type: case lt::file_completed_alert::alert_type: case lt::torrent_finished_alert::alert_type: diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index ce2c16f12..fd26985f5 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1876,6 +1876,14 @@ void TorrentImpl::handleFileCompletedAlert(const lt::file_completed_alert *p) } } +#if (LIBTORRENT_VERSION_NUM >= 20003) +void TorrentImpl::handleFilePrioAlert(const lt::file_prio_alert *p) +{ + if (m_nativeHandle.need_save_resume_data()) + m_session->handleTorrentNeedSaveResumeData(this); +} +#endif + void TorrentImpl::handleMetadataReceivedAlert(const lt::metadata_received_alert *p) { Q_UNUSED(p); @@ -1913,6 +1921,11 @@ void TorrentImpl::handleAlert(const lt::alert *a) { switch (a->type()) { +#if (LIBTORRENT_VERSION_NUM >= 20003) + case lt::file_prio_alert::alert_type: + handleFilePrioAlert(static_cast(a)); + break; +#endif case lt::file_renamed_alert::alert_type: handleFileRenamedAlert(static_cast(a)); break; diff --git a/src/base/bittorrent/torrentimpl.h b/src/base/bittorrent/torrentimpl.h index 5b49b7d7b..bc4232677 100644 --- a/src/base/bittorrent/torrentimpl.h +++ b/src/base/bittorrent/torrentimpl.h @@ -49,6 +49,17 @@ #include "torrent.h" #include "torrentinfo.h" +#if (LIBTORRENT_VERSION_NUM == 20003) +// file_prio_alert is missing to be forward declared in "libtorrent/fwd.hpp" +namespace libtorrent +{ + inline namespace v2 + { + struct file_prio_alert; + } +} +#endif + namespace BitTorrent { class Session; @@ -244,6 +255,9 @@ namespace BitTorrent void handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p); void handleFileCompletedAlert(const lt::file_completed_alert *p); +#if (LIBTORRENT_VERSION_NUM >= 20003) + void handleFilePrioAlert(const lt::file_prio_alert *p); +#endif void handleFileRenamedAlert(const lt::file_renamed_alert *p); void handleFileRenameFailedAlert(const lt::file_rename_failed_alert *p); void handleMetadataReceivedAlert(const lt::metadata_received_alert *p);