From 3a11c23efd6c035cafe58a7710ba72db76205e90 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 26 Aug 2019 12:30:22 +0800 Subject: [PATCH] Fix wrong "added on" date This only happens for magnet links when its metadata has yet to be retrieved. Closes #11124. --- src/base/bittorrent/session.cpp | 9 +++++++++ src/base/bittorrent/torrenthandle.cpp | 3 ++- src/base/bittorrent/torrenthandle.h | 2 ++ 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 426ee20df..934eaf14f 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -2028,6 +2028,11 @@ bool Session::addTorrent_impl(CreateTorrentParams params, const MagnetUri &magne p.upload_limit = params.uploadLimit; p.download_limit = params.downloadLimit; +#if (LIBTORRENT_VERSION_NUM >= 10200) + if (params.addedTime.isValid()) + p.added_time = params.addedTime.toSecsSinceEpoch(); +#endif + // Preallocation mode p.storage_mode = isPreallocationEnabled() ? lt::storage_mode_allocate : lt::storage_mode_sparse; @@ -4464,6 +4469,10 @@ namespace torrentParams.firstLastPiecePriority = fast.dict_find_int_value("qBt-firstLastPiecePriority"); torrentParams.sequential = fast.dict_find_int_value("qBt-sequential"); + const lt::bdecode_node addedTimeNode = fast.dict_find("qBt-addedTime"); + if (addedTimeNode.type() == lt::bdecode_node::int_t) + torrentParams.addedTime = QDateTime::fromSecsSinceEpoch(addedTimeNode.int_value()); + queuePos = fast.dict_find_int_value("qBt-queuePosition"); return true; diff --git a/src/base/bittorrent/torrenthandle.cpp b/src/base/bittorrent/torrenthandle.cpp index 97b355c32..455ae6435 100644 --- a/src/base/bittorrent/torrenthandle.cpp +++ b/src/base/bittorrent/torrenthandle.cpp @@ -50,7 +50,6 @@ #endif #include -#include #include #include #include @@ -1775,6 +1774,8 @@ void TorrentHandle::handleSaveResumeDataAlert(const lt::save_resume_data_alert * // restored if qBittorrent quits before the metadata are retrieved: resumeData["qBt-firstLastPiecePriority"] = hasFirstLastPiecePriority(); resumeData["qBt-sequential"] = isSequentialDownload(); + + resumeData["qBt-addedTime"] = addedTime().toSecsSinceEpoch(); } else { const auto savePath = resumeData.find_key("save_path")->string(); diff --git a/src/base/bittorrent/torrenthandle.h b/src/base/bittorrent/torrenthandle.h index 7443024be..4a52a9b89 100644 --- a/src/base/bittorrent/torrenthandle.h +++ b/src/base/bittorrent/torrenthandle.h @@ -36,6 +36,7 @@ #include #include +#include #include #include #include @@ -83,6 +84,7 @@ namespace BitTorrent int downloadLimit; // for new torrents QVector filePriorities; + QDateTime addedTime; // for restored torrents qreal ratioLimit; int seedingTimeLimit;