diff --git a/src/base/bittorrent/session.cpp b/src/base/bittorrent/session.cpp index 09e3bc22f..62a0bf31b 100644 --- a/src/base/bittorrent/session.cpp +++ b/src/base/bittorrent/session.cpp @@ -33,7 +33,6 @@ #include #include #include -#include #include #include #include @@ -156,16 +155,6 @@ namespace return expanded; } - QStringList findAllFiles(const QString &dirPath) - { - QStringList files; - QDirIterator it(dirPath, QDir::Files, QDirIterator::Subdirectories); - while (it.hasNext()) - files << it.next(); - - return files; - } - template struct LowerLimited { @@ -1729,35 +1718,19 @@ bool Session::findIncompleteFiles(TorrentInfo &torrentInfo, QString &savePath) c { auto findInDir = [](const QString &dirPath, TorrentInfo &torrentInfo) -> bool { + const QDir dir(dirPath); bool found = false; - if (torrentInfo.filesCount() == 1) { - const QString filePath = dirPath + torrentInfo.filePath(0); - if (QFile(filePath).exists()) { + for (int i = 0; i < torrentInfo.filesCount(); ++i) { + const QString filePath = torrentInfo.filePath(i); + if (dir.exists(filePath)) { found = true; } - else if (QFile(filePath + QB_EXT).exists()) { + else if (dir.exists(filePath + QB_EXT)) { found = true; - torrentInfo.renameFile(0, torrentInfo.filePath(0) + QB_EXT); - } - } - else { - QSet allFiles; - int dirPathSize = dirPath.size(); - foreach (const QString &file, findAllFiles(dirPath + torrentInfo.name())) - allFiles << file.mid(dirPathSize); - for (int i = 0; i < torrentInfo.filesCount(); ++i) { - QString filePath = torrentInfo.filePath(i); - if (allFiles.contains(filePath)) { - found = true; - } - else { - filePath += QB_EXT; - if (allFiles.contains(filePath)) { - found = true; - torrentInfo.renameFile(i, filePath); - } - } + torrentInfo.renameFile(i, filePath + QB_EXT); } + if ((i % 100) == 0) + qApp->processEvents(); } return found;