From e273ac3a0da33d3a26c018a92c1dc85890abdcca Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Sat, 6 Feb 2021 14:30:33 +0300 Subject: [PATCH 1/2] Allow "missing files" torrents to save more resume data --- src/base/bittorrent/torrentimpl.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index f1f9aa2e3..7235cc022 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1565,7 +1565,19 @@ void TorrentImpl::handleTorrentResumedAlert(const lt::torrent_resumed_alert *p) void TorrentImpl::handleSaveResumeDataAlert(const lt::save_resume_data_alert *p) { - if (!m_hasMissingFiles) + if (m_hasMissingFiles) + { + const auto havePieces = m_ltAddTorrentParams.have_pieces; + const auto unfinishedPieces = m_ltAddTorrentParams.unfinished_pieces; + const auto verifiedPieces = m_ltAddTorrentParams.verified_pieces; + + // Update recent resume data but preserve existing progress + m_ltAddTorrentParams = p->params; + m_ltAddTorrentParams.have_pieces = havePieces; + m_ltAddTorrentParams.unfinished_pieces = unfinishedPieces; + m_ltAddTorrentParams.verified_pieces = verifiedPieces; + } + else { // Update recent resume data m_ltAddTorrentParams = p->params; From c3f02d833ceddebe5c0fea4075e4086529731b66 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Sat, 6 Feb 2021 14:59:51 +0300 Subject: [PATCH 2/2] Restart "missing files" torrents after changing location --- src/base/bittorrent/torrentimpl.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/base/bittorrent/torrentimpl.cpp b/src/base/bittorrent/torrentimpl.cpp index 7235cc022..483742336 100644 --- a/src/base/bittorrent/torrentimpl.cpp +++ b/src/base/bittorrent/torrentimpl.cpp @@ -1387,6 +1387,7 @@ void TorrentImpl::resume(const TorrentOperatingMode mode) { m_hasMissingFiles = false; m_isStopped = false; + m_ltAddTorrentParams.ti = std::const_pointer_cast(m_nativeHandle.torrent_file()); reload(); updateStatus(); return; @@ -1446,8 +1447,21 @@ void TorrentImpl::handleMoveStorageJobFinished(const bool hasOutstandingJob) saveResumeData(); - while ((m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty()) - m_moveFinishedTriggers.takeFirst()(); + if (!m_storageIsMoving) + { + if (m_hasMissingFiles) + { + // it can be moved to the proper location + m_hasMissingFiles = false; + m_ltAddTorrentParams.save_path = m_nativeStatus.save_path; + m_ltAddTorrentParams.ti = std::const_pointer_cast(m_nativeHandle.torrent_file()); + reload(); + updateStatus(); + } + + while ((m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty()) + m_moveFinishedTriggers.takeFirst()(); + } } void TorrentImpl::handleTrackerReplyAlert(const lt::tracker_reply_alert *p)