mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-01-11 15:27:54 +00:00
Merge pull request #10961 from glassez/fastresume
Save updated resume data for completed torrents
This commit is contained in:
commit
02ab77053e
@ -1798,6 +1798,12 @@ void Session::bottomTorrentsQueuePos(const QStringList &hashes)
|
|||||||
saveTorrentsQueue();
|
saveTorrentsQueue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Session::handleTorrentSaveResumeDataRequested(const TorrentHandle *torrent)
|
||||||
|
{
|
||||||
|
qDebug("Saving resume data is requested for torrent '%s'...", qUtf8Printable(torrent->name()));
|
||||||
|
++m_numResumeData;
|
||||||
|
}
|
||||||
|
|
||||||
QHash<InfoHash, TorrentHandle *> Session::torrents() const
|
QHash<InfoHash, TorrentHandle *> Session::torrents() const
|
||||||
{
|
{
|
||||||
return m_torrents;
|
return m_torrents;
|
||||||
@ -2168,7 +2174,7 @@ void Session::generateResumeData(const bool final)
|
|||||||
|| torrent->hasMissingFiles())
|
|| torrent->hasMissingFiles())
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3334,55 +3340,48 @@ void Session::updateSeedingLimitTimer()
|
|||||||
|
|
||||||
void Session::handleTorrentShareLimitChanged(TorrentHandle *const torrent)
|
void Session::handleTorrentShareLimitChanged(TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
saveTorrentResumeData(torrent);
|
|
||||||
updateSeedingLimitTimer();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Session::saveTorrentResumeData(TorrentHandle *const torrent)
|
|
||||||
{
|
|
||||||
qDebug("Saving fastresume data for %s", qUtf8Printable(torrent->name()));
|
|
||||||
torrent->saveResumeData();
|
torrent->saveResumeData();
|
||||||
++m_numResumeData;
|
updateSeedingLimitTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handleTorrentNameChanged(TorrentHandle *const torrent)
|
void Session::handleTorrentNameChanged(TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handleTorrentSavePathChanged(TorrentHandle *const torrent)
|
void Session::handleTorrentSavePathChanged(TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
emit torrentSavePathChanged(torrent);
|
emit torrentSavePathChanged(torrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handleTorrentCategoryChanged(TorrentHandle *const torrent, const QString &oldCategory)
|
void Session::handleTorrentCategoryChanged(TorrentHandle *const torrent, const QString &oldCategory)
|
||||||
{
|
{
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
emit torrentCategoryChanged(torrent, oldCategory);
|
emit torrentCategoryChanged(torrent, oldCategory);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handleTorrentTagAdded(TorrentHandle *const torrent, const QString &tag)
|
void Session::handleTorrentTagAdded(TorrentHandle *const torrent, const QString &tag)
|
||||||
{
|
{
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
emit torrentTagAdded(torrent, tag);
|
emit torrentTagAdded(torrent, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handleTorrentTagRemoved(TorrentHandle *const torrent, const QString &tag)
|
void Session::handleTorrentTagRemoved(TorrentHandle *const torrent, const QString &tag)
|
||||||
{
|
{
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
emit torrentTagRemoved(torrent, tag);
|
emit torrentTagRemoved(torrent, tag);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handleTorrentSavingModeChanged(TorrentHandle *const torrent)
|
void Session::handleTorrentSavingModeChanged(TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
emit torrentSavingModeChanged(torrent);
|
emit torrentSavingModeChanged(torrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handleTorrentTrackersAdded(TorrentHandle *const torrent, const QVector<TrackerEntry> &newTrackers)
|
void Session::handleTorrentTrackersAdded(TorrentHandle *const torrent, const QVector<TrackerEntry> &newTrackers)
|
||||||
{
|
{
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
|
|
||||||
for (const TrackerEntry &newTracker : newTrackers)
|
for (const TrackerEntry &newTracker : newTrackers)
|
||||||
LogMsg(tr("Tracker '%1' was added to torrent '%2'").arg(newTracker.url(), torrent->name()));
|
LogMsg(tr("Tracker '%1' was added to torrent '%2'").arg(newTracker.url(), torrent->name()));
|
||||||
@ -3394,7 +3393,7 @@ void Session::handleTorrentTrackersAdded(TorrentHandle *const torrent, const QVe
|
|||||||
|
|
||||||
void Session::handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QVector<TrackerEntry> &deletedTrackers)
|
void Session::handleTorrentTrackersRemoved(TorrentHandle *const torrent, const QVector<TrackerEntry> &deletedTrackers)
|
||||||
{
|
{
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
|
|
||||||
for (const TrackerEntry &deletedTracker : deletedTrackers)
|
for (const TrackerEntry &deletedTracker : deletedTrackers)
|
||||||
LogMsg(tr("Tracker '%1' was deleted from torrent '%2'").arg(deletedTracker.url(), torrent->name()));
|
LogMsg(tr("Tracker '%1' was deleted from torrent '%2'").arg(deletedTracker.url(), torrent->name()));
|
||||||
@ -3406,27 +3405,27 @@ void Session::handleTorrentTrackersRemoved(TorrentHandle *const torrent, const Q
|
|||||||
|
|
||||||
void Session::handleTorrentTrackersChanged(TorrentHandle *const torrent)
|
void Session::handleTorrentTrackersChanged(TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
emit trackersChanged(torrent);
|
emit trackersChanged(torrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList<QUrl> &newUrlSeeds)
|
void Session::handleTorrentUrlSeedsAdded(TorrentHandle *const torrent, const QList<QUrl> &newUrlSeeds)
|
||||||
{
|
{
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
for (const QUrl &newUrlSeed : newUrlSeeds)
|
for (const QUrl &newUrlSeed : newUrlSeeds)
|
||||||
LogMsg(tr("URL seed '%1' was added to torrent '%2'").arg(newUrlSeed.toString(), torrent->name()));
|
LogMsg(tr("URL seed '%1' was added to torrent '%2'").arg(newUrlSeed.toString(), torrent->name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QList<QUrl> &urlSeeds)
|
void Session::handleTorrentUrlSeedsRemoved(TorrentHandle *const torrent, const QList<QUrl> &urlSeeds)
|
||||||
{
|
{
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
for (const QUrl &urlSeed : urlSeeds)
|
for (const QUrl &urlSeed : urlSeeds)
|
||||||
LogMsg(tr("URL seed '%1' was removed from torrent '%2'").arg(urlSeed.toString(), torrent->name()));
|
LogMsg(tr("URL seed '%1' was removed from torrent '%2'").arg(urlSeed.toString(), torrent->name()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handleTorrentMetadataReceived(TorrentHandle *const torrent)
|
void Session::handleTorrentMetadataReceived(TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
|
|
||||||
// Save metadata
|
// Save metadata
|
||||||
const QDir resumeDataDir(m_resumeFolderPath);
|
const QDir resumeDataDir(m_resumeFolderPath);
|
||||||
@ -3443,13 +3442,13 @@ void Session::handleTorrentMetadataReceived(TorrentHandle *const torrent)
|
|||||||
void Session::handleTorrentPaused(TorrentHandle *const torrent)
|
void Session::handleTorrentPaused(TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
if (!torrent->hasError() && !torrent->hasMissingFiles())
|
if (!torrent->hasError() && !torrent->hasMissingFiles())
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
emit torrentPaused(torrent);
|
emit torrentPaused(torrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Session::handleTorrentResumed(TorrentHandle *const torrent)
|
void Session::handleTorrentResumed(TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
emit torrentResumed(torrent);
|
emit torrentResumed(torrent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3461,7 +3460,7 @@ void Session::handleTorrentChecked(TorrentHandle *const torrent)
|
|||||||
void Session::handleTorrentFinished(TorrentHandle *const torrent)
|
void Session::handleTorrentFinished(TorrentHandle *const torrent)
|
||||||
{
|
{
|
||||||
if (!torrent->hasError() && !torrent->hasMissingFiles())
|
if (!torrent->hasError() && !torrent->hasMissingFiles())
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
emit torrentFinished(torrent);
|
emit torrentFinished(torrent);
|
||||||
|
|
||||||
qDebug("Checking if the torrent contains torrent files to download");
|
qDebug("Checking if the torrent contains torrent files to download");
|
||||||
@ -3965,7 +3964,7 @@ void Session::createTorrentHandle(const lt::torrent_handle &nativeHandle)
|
|||||||
|
|
||||||
// In case of crash before the scheduled generation
|
// In case of crash before the scheduled generation
|
||||||
// of the fastresumes.
|
// of the fastresumes.
|
||||||
saveTorrentResumeData(torrent);
|
torrent->saveResumeData();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (((torrent->ratioLimit() >= 0) || (torrent->seedingTimeLimit() >= 0))
|
if (((torrent->ratioLimit() >= 0) || (torrent->seedingTimeLimit() >= 0))
|
||||||
|
@ -423,6 +423,7 @@ namespace BitTorrent
|
|||||||
void bottomTorrentsQueuePos(const QStringList &hashes);
|
void bottomTorrentsQueuePos(const QStringList &hashes);
|
||||||
|
|
||||||
// TorrentHandle interface
|
// TorrentHandle interface
|
||||||
|
void handleTorrentSaveResumeDataRequested(const TorrentHandle *torrent);
|
||||||
void handleTorrentShareLimitChanged(TorrentHandle *const torrent);
|
void handleTorrentShareLimitChanged(TorrentHandle *const torrent);
|
||||||
void handleTorrentNameChanged(TorrentHandle *const torrent);
|
void handleTorrentNameChanged(TorrentHandle *const torrent);
|
||||||
void handleTorrentSavePathChanged(TorrentHandle *const torrent);
|
void handleTorrentSavePathChanged(TorrentHandle *const torrent);
|
||||||
@ -540,7 +541,6 @@ namespace BitTorrent
|
|||||||
|
|
||||||
void updateSeedingLimitTimer();
|
void updateSeedingLimitTimer();
|
||||||
void exportTorrentFile(TorrentHandle *const torrent, TorrentExportFolder folder = TorrentExportFolder::Regular);
|
void exportTorrentFile(TorrentHandle *const torrent, TorrentExportFolder folder = TorrentExportFolder::Regular);
|
||||||
void saveTorrentResumeData(TorrentHandle *const torrent);
|
|
||||||
|
|
||||||
void handleAlert(const lt::alert *a);
|
void handleAlert(const lt::alert *a);
|
||||||
void dispatchTorrentAlert(const lt::alert *a);
|
void dispatchTorrentAlert(const lt::alert *a);
|
||||||
|
@ -203,6 +203,7 @@ TorrentHandle::TorrentHandle(Session *session, const lt::torrent_handle &nativeH
|
|||||||
, m_ratioLimit(params.ratioLimit)
|
, m_ratioLimit(params.ratioLimit)
|
||||||
, m_seedingTimeLimit(params.seedingTimeLimit)
|
, m_seedingTimeLimit(params.seedingTimeLimit)
|
||||||
, m_tempPathDisabled(params.disableTempPath)
|
, m_tempPathDisabled(params.disableTempPath)
|
||||||
|
, m_fastresumeDataRejected(false)
|
||||||
, m_hasMissingFiles(false)
|
, m_hasMissingFiles(false)
|
||||||
, m_hasRootFolder(params.hasRootFolder)
|
, m_hasRootFolder(params.hasRootFolder)
|
||||||
, m_needsToSetFirstLastPiecePriority(false)
|
, m_needsToSetFirstLastPiecePriority(false)
|
||||||
@ -546,6 +547,7 @@ bool TorrentHandle::needSaveResumeData() const
|
|||||||
void TorrentHandle::saveResumeData()
|
void TorrentHandle::saveResumeData()
|
||||||
{
|
{
|
||||||
m_nativeHandle.save_resume_data();
|
m_nativeHandle.save_resume_data();
|
||||||
|
m_session->handleTorrentSaveResumeDataRequested(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
int TorrentHandle::filesCount() const
|
int TorrentHandle::filesCount() const
|
||||||
@ -1670,6 +1672,8 @@ void TorrentHandle::handleTorrentCheckedAlert(const lt::torrent_checked_alert *p
|
|||||||
else {
|
else {
|
||||||
m_startupState = Started;
|
m_startupState = Started;
|
||||||
m_pauseWhenReady = false;
|
m_pauseWhenReady = false;
|
||||||
|
if (m_fastresumeDataRejected && !m_hasMissingFiles)
|
||||||
|
saveResumeData();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1806,6 +1810,8 @@ void TorrentHandle::handleSaveResumeDataFailedAlert(const lt::save_resume_data_f
|
|||||||
|
|
||||||
void TorrentHandle::handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p)
|
void TorrentHandle::handleFastResumeRejectedAlert(const lt::fastresume_rejected_alert *p)
|
||||||
{
|
{
|
||||||
|
m_fastresumeDataRejected = true;
|
||||||
|
|
||||||
if (p->error.value() == lt::errors::mismatching_file_size) {
|
if (p->error.value() == lt::errors::mismatching_file_size) {
|
||||||
// Mismatching file size (files were probably moved)
|
// Mismatching file size (files were probably moved)
|
||||||
m_hasMissingFiles = true;
|
m_hasMissingFiles = true;
|
||||||
@ -1813,7 +1819,7 @@ void TorrentHandle::handleFastResumeRejectedAlert(const lt::fastresume_rejected_
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
LogMsg(tr("Fast resume data was rejected for torrent '%1'. Reason: %2. Checking again...")
|
LogMsg(tr("Fast resume data was rejected for torrent '%1'. Reason: %2. Checking again...")
|
||||||
.arg(name(), QString::fromStdString(p->message())), Log::CRITICAL);
|
.arg(name(), QString::fromStdString(p->message())), Log::WARNING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -438,6 +438,7 @@ namespace BitTorrent
|
|||||||
qreal m_ratioLimit;
|
qreal m_ratioLimit;
|
||||||
int m_seedingTimeLimit;
|
int m_seedingTimeLimit;
|
||||||
bool m_tempPathDisabled;
|
bool m_tempPathDisabled;
|
||||||
|
bool m_fastresumeDataRejected;
|
||||||
bool m_hasMissingFiles;
|
bool m_hasMissingFiles;
|
||||||
bool m_hasRootFolder;
|
bool m_hasRootFolder;
|
||||||
bool m_needsToSetFirstLastPiecePriority;
|
bool m_needsToSetFirstLastPiecePriority;
|
||||||
|
Loading…
Reference in New Issue
Block a user