mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2024-11-28 05:27:15 +03:00
Merge pull request #11126 from Chocobo1/addedTime
Fix wrong "added on" date
This commit is contained in:
commit
7ce26435bd
3 changed files with 49 additions and 56 deletions
|
@ -156,31 +156,6 @@ namespace
|
|||
return QString::fromUtf8(str.data(), static_cast<int>(str.size()));
|
||||
}
|
||||
|
||||
template <typename Entry>
|
||||
QSet<QString> entryListToSetImpl(const Entry &entry)
|
||||
{
|
||||
Q_ASSERT(entry.type() == Entry::list_t);
|
||||
QSet<QString> output;
|
||||
for (int i = 0; i < entry.list_size(); ++i) {
|
||||
const QString tag = fromLTString(entry.list_string_value_at(i));
|
||||
if (Session::isValidTag(tag))
|
||||
output.insert(tag);
|
||||
else
|
||||
qWarning() << QString("Dropping invalid stored tag: %1").arg(tag);
|
||||
}
|
||||
return output;
|
||||
}
|
||||
|
||||
bool isList(const lt::bdecode_node &entry)
|
||||
{
|
||||
return entry.type() == lt::bdecode_node::list_t;
|
||||
}
|
||||
|
||||
QSet<QString> entryListToSet(const lt::bdecode_node &entry)
|
||||
{
|
||||
return entryListToSetImpl(entry);
|
||||
}
|
||||
|
||||
QString normalizePath(const QString &path)
|
||||
{
|
||||
QString tmp = Utils::Fs::toUniformPath(path.trimmed());
|
||||
|
@ -2028,6 +2003,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;
|
||||
|
@ -3662,13 +3642,13 @@ void Session::startUpTorrents()
|
|||
QStringList fastresumes = resumeDataDir.entryList(
|
||||
QStringList(QLatin1String("*.fastresume")), QDir::Files, QDir::Unsorted);
|
||||
|
||||
typedef struct
|
||||
struct TorrentResumeData
|
||||
{
|
||||
QString hash;
|
||||
MagnetUri magnetUri;
|
||||
CreateTorrentParams addTorrentData;
|
||||
QByteArray data;
|
||||
} TorrentResumeData;
|
||||
};
|
||||
|
||||
int resumedTorrentsCount = 0;
|
||||
const auto startupTorrent = [this, &resumeDataDir, &resumedTorrentsCount](const TorrentResumeData ¶ms)
|
||||
|
@ -4422,49 +4402,59 @@ namespace
|
|||
|
||||
bool loadTorrentResumeData(const QByteArray &data, CreateTorrentParams &torrentParams, int &queuePos, MagnetUri &magnetUri)
|
||||
{
|
||||
lt::error_code ec;
|
||||
lt::bdecode_node root;
|
||||
lt::bdecode(data.constData(), (data.constData() + data.size()), root, ec);
|
||||
if (ec || (root.type() != lt::bdecode_node::dict_t)) return false;
|
||||
|
||||
torrentParams = CreateTorrentParams();
|
||||
|
||||
torrentParams.restored = true;
|
||||
torrentParams.skipChecking = false;
|
||||
|
||||
lt::error_code ec;
|
||||
lt::bdecode_node fast;
|
||||
lt::bdecode(data.constData(), data.constData() + data.size(), fast, ec);
|
||||
if (ec || (fast.type() != lt::bdecode_node::dict_t)) return false;
|
||||
|
||||
torrentParams.name = fromLTString(root.dict_find_string_value("qBt-name"));
|
||||
torrentParams.savePath = Profile::instance().fromPortablePath(
|
||||
Utils::Fs::toUniformPath(fromLTString(fast.dict_find_string_value("qBt-savePath"))));
|
||||
Utils::Fs::toUniformPath(fromLTString(root.dict_find_string_value("qBt-savePath"))));
|
||||
torrentParams.disableTempPath = root.dict_find_int_value("qBt-tempPathDisabled");
|
||||
torrentParams.sequential = root.dict_find_int_value("qBt-sequential");
|
||||
torrentParams.hasSeedStatus = root.dict_find_int_value("qBt-seedStatus");
|
||||
torrentParams.firstLastPiecePriority = root.dict_find_int_value("qBt-firstLastPiecePriority");
|
||||
torrentParams.hasRootFolder = root.dict_find_int_value("qBt-hasRootFolder");
|
||||
torrentParams.seedingTimeLimit = root.dict_find_int_value("qBt-seedingTimeLimit", TorrentHandle::USE_GLOBAL_SEEDING_TIME);
|
||||
|
||||
LTString ratioLimitString = fast.dict_find_string_value("qBt-ratioLimit");
|
||||
const bool isAutoManaged = root.dict_find_int_value("auto_managed");
|
||||
const bool isPaused = root.dict_find_int_value("paused");
|
||||
torrentParams.paused = root.dict_find_int_value("qBt-paused", (isPaused && !isAutoManaged));
|
||||
torrentParams.forced = root.dict_find_int_value("qBt-forced", (!isPaused && !isAutoManaged));
|
||||
|
||||
const LTString ratioLimitString = root.dict_find_string_value("qBt-ratioLimit");
|
||||
if (ratioLimitString.empty())
|
||||
torrentParams.ratioLimit = fast.dict_find_int_value("qBt-ratioLimit", TorrentHandle::USE_GLOBAL_RATIO * 1000) / 1000.0;
|
||||
torrentParams.ratioLimit = root.dict_find_int_value("qBt-ratioLimit", TorrentHandle::USE_GLOBAL_RATIO * 1000) / 1000.0;
|
||||
else
|
||||
torrentParams.ratioLimit = fromLTString(ratioLimitString).toDouble();
|
||||
torrentParams.seedingTimeLimit = fast.dict_find_int_value("qBt-seedingTimeLimit", TorrentHandle::USE_GLOBAL_SEEDING_TIME);
|
||||
|
||||
// **************************************************************************************
|
||||
// Workaround to convert legacy label to category
|
||||
// TODO: Should be removed in future
|
||||
torrentParams.category = fromLTString(fast.dict_find_string_value("qBt-label"));
|
||||
torrentParams.category = fromLTString(root.dict_find_string_value("qBt-label"));
|
||||
if (torrentParams.category.isEmpty())
|
||||
// **************************************************************************************
|
||||
torrentParams.category = fromLTString(fast.dict_find_string_value("qBt-category"));
|
||||
// auto because the return type depends on the #if above.
|
||||
const auto tagsEntry = fast.dict_find_list("qBt-tags");
|
||||
if (isList(tagsEntry))
|
||||
torrentParams.tags = entryListToSet(tagsEntry);
|
||||
torrentParams.name = fromLTString(fast.dict_find_string_value("qBt-name"));
|
||||
torrentParams.hasSeedStatus = fast.dict_find_int_value("qBt-seedStatus");
|
||||
torrentParams.disableTempPath = fast.dict_find_int_value("qBt-tempPathDisabled");
|
||||
torrentParams.hasRootFolder = fast.dict_find_int_value("qBt-hasRootFolder");
|
||||
torrentParams.category = fromLTString(root.dict_find_string_value("qBt-category"));
|
||||
|
||||
magnetUri = MagnetUri(fromLTString(fast.dict_find_string_value("qBt-magnetUri")));
|
||||
const bool isAutoManaged = fast.dict_find_int_value("auto_managed");
|
||||
const bool isPaused = fast.dict_find_int_value("paused");
|
||||
torrentParams.paused = fast.dict_find_int_value("qBt-paused", (isPaused && !isAutoManaged));
|
||||
torrentParams.forced = fast.dict_find_int_value("qBt-forced", (!isPaused && !isAutoManaged));
|
||||
torrentParams.firstLastPiecePriority = fast.dict_find_int_value("qBt-firstLastPiecePriority");
|
||||
torrentParams.sequential = fast.dict_find_int_value("qBt-sequential");
|
||||
const lt::bdecode_node tagsNode = root.dict_find("qBt-tags");
|
||||
if (tagsNode.type() == lt::bdecode_node::list_t) {
|
||||
for (int i = 0; i < tagsNode.list_size(); ++i) {
|
||||
const QString tag = fromLTString(tagsNode.list_string_value_at(i));
|
||||
if (Session::isValidTag(tag))
|
||||
torrentParams.tags << tag;
|
||||
}
|
||||
}
|
||||
|
||||
queuePos = fast.dict_find_int_value("qBt-queuePosition");
|
||||
const lt::bdecode_node addedTimeNode = root.dict_find("qBt-addedTime");
|
||||
if (addedTimeNode.type() == lt::bdecode_node::int_t)
|
||||
torrentParams.addedTime = QDateTime::fromSecsSinceEpoch(addedTimeNode.int_value());
|
||||
|
||||
queuePos = root.dict_find_int_value("qBt-queuePosition");
|
||||
magnetUri = MagnetUri(fromLTString(root.dict_find_string_value("qBt-magnetUri")));
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -50,7 +50,6 @@
|
|||
#endif
|
||||
|
||||
#include <QBitArray>
|
||||
#include <QDateTime>
|
||||
#include <QDebug>
|
||||
#include <QDir>
|
||||
#include <QFile>
|
||||
|
@ -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();
|
||||
|
|
|
@ -36,6 +36,7 @@
|
|||
#include <libtorrent/torrent_handle.hpp>
|
||||
#include <libtorrent/torrent_status.hpp>
|
||||
|
||||
#include <QDateTime>
|
||||
#include <QHash>
|
||||
#include <QObject>
|
||||
#include <QQueue>
|
||||
|
@ -83,6 +84,7 @@ namespace BitTorrent
|
|||
int downloadLimit;
|
||||
// for new torrents
|
||||
QVector<DownloadPriority> filePriorities;
|
||||
QDateTime addedTime;
|
||||
// for restored torrents
|
||||
qreal ratioLimit;
|
||||
int seedingTimeLimit;
|
||||
|
|
Loading…
Reference in a new issue