Browse Source

Proactively append extension to incomplete files

PR #17631.
adaptive-webui-19844
Vladimir Golovnev 2 years ago committed by GitHub
parent
commit
fe34749cfe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 20
      src/base/bittorrent/filesearcher.cpp
  2. 2
      src/base/bittorrent/filesearcher.h
  3. 5
      src/base/bittorrent/sessionimpl.cpp

20
src/base/bittorrent/filesearcher.cpp

@ -31,9 +31,9 @@
#include "base/bittorrent/infohash.h" #include "base/bittorrent/infohash.h"
void FileSearcher::search(const BitTorrent::TorrentID &id, const PathList &originalFileNames void FileSearcher::search(const BitTorrent::TorrentID &id, const PathList &originalFileNames
, const Path &savePath, const Path &downloadPath) , const Path &savePath, const Path &downloadPath, const bool forceAppendExt)
{ {
const auto findInDir = [](const Path &dirPath, PathList &fileNames) -> bool const auto findInDir = [](const Path &dirPath, PathList &fileNames, const bool forceAppendExt) -> bool
{ {
bool found = false; bool found = false;
for (Path &fileName : fileNames) for (Path &fileName : fileNames)
@ -42,10 +42,18 @@ void FileSearcher::search(const BitTorrent::TorrentID &id, const PathList &origi
{ {
found = true; found = true;
} }
else if ((dirPath / fileName + QB_EXT).exists()) else
{
const Path incompleteFilename = fileName + QB_EXT;
if ((dirPath / incompleteFilename).exists())
{ {
found = true; found = true;
fileName = fileName + QB_EXT; fileName = incompleteFilename;
}
else if (forceAppendExt)
{
fileName = incompleteFilename;
}
} }
} }
@ -54,11 +62,11 @@ void FileSearcher::search(const BitTorrent::TorrentID &id, const PathList &origi
Path usedPath = savePath; Path usedPath = savePath;
PathList adjustedFileNames = originalFileNames; PathList adjustedFileNames = originalFileNames;
const bool found = findInDir(usedPath, adjustedFileNames); const bool found = findInDir(usedPath, adjustedFileNames, (forceAppendExt && downloadPath.isEmpty()));
if (!found && !downloadPath.isEmpty()) if (!found && !downloadPath.isEmpty())
{ {
usedPath = downloadPath; usedPath = downloadPath;
findInDir(usedPath, adjustedFileNames); findInDir(usedPath, adjustedFileNames, forceAppendExt);
} }
emit searchFinished(id, usedPath, adjustedFileNames); emit searchFinished(id, usedPath, adjustedFileNames);

2
src/base/bittorrent/filesearcher.h

@ -47,7 +47,7 @@ public:
public slots: public slots:
void search(const BitTorrent::TorrentID &id, const PathList &originalFileNames void search(const BitTorrent::TorrentID &id, const PathList &originalFileNames
, const Path &savePath, const Path &downloadPath); , const Path &savePath, const Path &downloadPath, bool forceAppendExt);
signals: signals:
void searchFinished(const BitTorrent::TorrentID &id, const Path &savePath, const PathList &fileNames); void searchFinished(const BitTorrent::TorrentID &id, const Path &savePath, const PathList &fileNames);

5
src/base/bittorrent/sessionimpl.cpp

@ -2606,8 +2606,11 @@ bool SessionImpl::addTorrent_impl(const std::variant<MagnetUri, TorrentInfo> &so
} }
const auto nativeIndexes = torrentInfo.nativeIndexes(); const auto nativeIndexes = torrentInfo.nativeIndexes();
if (!isFindingIncompleteFiles)
{
for (int index = 0; index < filePaths.size(); ++index) for (int index = 0; index < filePaths.size(); ++index)
p.renamed_files[nativeIndexes[index]] = filePaths.at(index).toString().toStdString(); p.renamed_files[nativeIndexes[index]] = filePaths.at(index).toString().toStdString();
}
Q_ASSERT(p.file_priorities.empty()); Q_ASSERT(p.file_priorities.empty());
Q_ASSERT(addTorrentParams.filePriorities.isEmpty() || (addTorrentParams.filePriorities.size() == nativeIndexes.size())); Q_ASSERT(addTorrentParams.filePriorities.isEmpty() || (addTorrentParams.filePriorities.size() == nativeIndexes.size()));
@ -2715,7 +2718,7 @@ void SessionImpl::findIncompleteFiles(const TorrentInfo &torrentInfo, const Path
const PathList originalFileNames = (filePaths.isEmpty() ? torrentInfo.filePaths() : filePaths); const PathList originalFileNames = (filePaths.isEmpty() ? torrentInfo.filePaths() : filePaths);
QMetaObject::invokeMethod(m_fileSearcher, [=]() QMetaObject::invokeMethod(m_fileSearcher, [=]()
{ {
m_fileSearcher->search(searchId, originalFileNames, savePath, downloadPath); m_fileSearcher->search(searchId, originalFileNames, savePath, downloadPath, isAppendExtensionEnabled());
}); });
} }

Loading…
Cancel
Save