Browse Source

Store libtorrent native file index in QHash

adaptive-webui-19844
Vladimir Golovnev (Glassez) 5 years ago
parent
commit
4021a0c7ce
No known key found for this signature in database
GPG Key ID: 52A2C7DEE2DFA6F7
  1. 30
      src/base/bittorrent/torrenthandle.cpp
  2. 8
      src/base/bittorrent/torrenthandle.h

30
src/base/bittorrent/torrenthandle.cpp

@ -74,16 +74,28 @@ const QString QB_EXT {QStringLiteral(".!qB")};
using namespace BitTorrent; using namespace BitTorrent;
#if (LIBTORRENT_VERSION_NUM >= 10200)
namespace libtorrent
{
namespace aux
{
template <typename T, typename Tag>
uint qHash(const strong_typedef<T, Tag> &key, const uint seed)
{
return static_cast<uint>((std::hash<strong_typedef<T, Tag>> {})(key) ^ seed);
}
}
}
#endif
namespace namespace
{ {
#if (LIBTORRENT_VERSION_NUM < 10200) #if (LIBTORRENT_VERSION_NUM < 10200)
using LTDownloadPriority = int; using LTDownloadPriority = int;
using LTFileIndex = int;
using LTPieceIndex = int; using LTPieceIndex = int;
using LTQueuePosition = int; using LTQueuePosition = int;
#else #else
using LTDownloadPriority = lt::download_priority_t; using LTDownloadPriority = lt::download_priority_t;
using LTFileIndex = lt::file_index_t;
using LTPieceIndex = lt::piece_index_t; using LTPieceIndex = lt::piece_index_t;
using LTQueuePosition = lt::queue_position_t; using LTQueuePosition = lt::queue_position_t;
#endif #endif
@ -1513,7 +1525,7 @@ void TorrentHandle::renameFile(const int index, const QString &name)
{ {
if (m_startupState != Started) return; if (m_startupState != Started) return;
m_oldPath[index].push_back(filePath(index)); m_oldPath[LTFileIndex {index}].push_back(filePath(index));
++m_renameCount; ++m_renameCount;
m_nativeHandle.rename_file(LTFileIndex {index}, Utils::Fs::toNativePath(name).toStdString()); m_nativeHandle.rename_file(LTFileIndex {index}, Utils::Fs::toNativePath(name).toStdString());
} }
@ -1813,11 +1825,11 @@ void TorrentHandle::handleFileRenamedAlert(const lt::file_renamed_alert *p)
// remove empty leftover folders // remove empty leftover folders
// for example renaming "a/b/c" to "d/b/c", then folders "a/b" and "a" will // for example renaming "a/b/c" to "d/b/c", then folders "a/b" and "a" will
// be removed if they are empty // be removed if they are empty
const QString oldFilePath = m_oldPath[LTUnderlyingType<LTFileIndex> {p->index}].takeFirst(); const QString oldFilePath = m_oldPath[p->index].takeFirst();
const QString newFilePath = Utils::Fs::toUniformPath(p->new_name()); const QString newFilePath = Utils::Fs::toUniformPath(p->new_name());
if (m_oldPath[LTUnderlyingType<LTFileIndex> {p->index}].isEmpty()) if (m_oldPath[p->index].isEmpty())
m_oldPath.remove(LTUnderlyingType<LTFileIndex> {p->index}); m_oldPath.remove(p->index);
QVector<QStringRef> oldPathParts = oldFilePath.splitRef('/', QString::SkipEmptyParts); QVector<QStringRef> oldPathParts = oldFilePath.splitRef('/', QString::SkipEmptyParts);
oldPathParts.removeLast(); // drop file name part oldPathParts.removeLast(); // drop file name part
@ -1856,9 +1868,9 @@ void TorrentHandle::handleFileRenameFailedAlert(const lt::file_rename_failed_ale
.arg(name(), filePath(LTUnderlyingType<LTFileIndex> {p->index}) .arg(name(), filePath(LTUnderlyingType<LTFileIndex> {p->index})
, QString::fromStdString(p->error.message())), Log::WARNING); , QString::fromStdString(p->error.message())), Log::WARNING);
m_oldPath[LTUnderlyingType<LTFileIndex> {p->index}].removeFirst(); m_oldPath[p->index].removeFirst();
if (m_oldPath[LTUnderlyingType<LTFileIndex> {p->index}].isEmpty()) if (m_oldPath[p->index].isEmpty())
m_oldPath.remove(LTUnderlyingType<LTFileIndex> {p->index}); m_oldPath.remove(p->index);
--m_renameCount; --m_renameCount;
while (!isMoveInProgress() && (m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty()) while (!isMoveInProgress() && (m_renameCount == 0) && !m_moveFinishedTriggers.isEmpty())

8
src/base/bittorrent/torrenthandle.h

@ -355,6 +355,12 @@ namespace BitTorrent
private: private:
typedef std::function<void ()> EventTrigger; typedef std::function<void ()> EventTrigger;
#if (LIBTORRENT_VERSION_NUM < 10200)
using LTFileIndex = int;
#else
using LTFileIndex = lt::file_index_t;
#endif
void updateStatus(); void updateStatus();
void updateStatus(const lt::torrent_status &nativeStatus); void updateStatus(const lt::torrent_status &nativeStatus);
void updateState(); void updateState();
@ -419,7 +425,7 @@ namespace BitTorrent
// Until libtorrent provide an "old_name" field in `file_renamed_alert` // Until libtorrent provide an "old_name" field in `file_renamed_alert`
// we will rely on this workaround to remove empty leftover folders // we will rely on this workaround to remove empty leftover folders
QHash<int, QVector<QString>> m_oldPath; QHash<LTFileIndex, QVector<QString>> m_oldPath;
bool m_useAutoTMM; bool m_useAutoTMM;

Loading…
Cancel
Save