basefileseeker.cpp
1 #include "basefileseeker.h"
2 
3 #include "pathfinder/filesearchpath.h"
4 #include <QDir>
5 
6 QString BaseFileSeeker::findFile(const QString& fileName, const QList<FileSearchPath>& paths)
7 {
8  foreach (const FileSearchPath& candidate, paths)
9  {
10  QString result = findFileInPath(fileName, candidate);
11  if (!result.isNull())
12  {
13  return result;
14  }
15  }
16  return QString();
17 }
18 
19 QString BaseFileSeeker::findFileInPath(const QString& fileName, const FileSearchPath& path)
20 {
21  QString result = findFileInSpecifiedDirectory(fileName, path.path());
22  if (!result.isNull())
23  {
24  return result;
25  }
26 
27  if (path.isRecursive())
28  {
29  QDir dir(path.path());
30  QStringList subDirs = dir.entryList(QDir::Dirs | QDir::NoDotAndDotDot);
31  foreach (const QString& subDir, subDirs)
32  {
33  FileSearchPath subSearchPath(dir.filePath(subDir));
34  subSearchPath.setRecursive(true);
35  QString result = findFileInPath(fileName, subSearchPath);
36  if (!result.isNull())
37  {
38  return result;
39  }
40  }
41  }
42  return QString();
43 }