Implement class for handling filesystem paths

PR #15915.
This commit is contained in:
Vladimir Golovnev 2022-02-08 06:03:48 +03:00 committed by GitHub
parent facfa26eed
commit dd1bd8ad10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
131 changed files with 2252 additions and 1868 deletions

View file

@ -27,37 +27,33 @@
*/
#include "filesearcher.h"
#include <QDir>
#include "base/bittorrent/common.h"
#include "base/bittorrent/infohash.h"
void FileSearcher::search(const BitTorrent::TorrentID &id, const QStringList &originalFileNames
, const QString &savePath, const QString &downloadPath)
void FileSearcher::search(const BitTorrent::TorrentID &id, const PathList &originalFileNames
, const Path &savePath, const Path &downloadPath)
{
const auto findInDir = [](const QString &dirPath, QStringList &fileNames) -> bool
const auto findInDir = [](const Path &dirPath, PathList &fileNames) -> bool
{
const QDir dir {dirPath};
bool found = false;
for (QString &fileName : fileNames)
for (Path &fileName : fileNames)
{
if (dir.exists(fileName))
if ((dirPath / fileName).exists())
{
found = true;
}
else if (dir.exists(fileName + QB_EXT))
else if ((dirPath / fileName + QB_EXT).exists())
{
found = true;
fileName += QB_EXT;
fileName = fileName + QB_EXT;
}
}
return found;
};
QString usedPath = savePath;
QStringList adjustedFileNames = originalFileNames;
Path usedPath = savePath;
PathList adjustedFileNames = originalFileNames;
const bool found = findInDir(usedPath, adjustedFileNames);
if (!found && !downloadPath.isEmpty())
{