23 #include "pathfinder.h" 25 #include "configuration/doomseekerconfig.h" 26 #include "datapaths.h" 27 #include "fileseeker.h" 29 #include "pathfinder/filesearchpath.h" 30 #include "strings.hpp" 35 #include <QScopedPointer> 36 #include <QSharedPointer> 38 DClass<PathFinderResult>
41 QStringList foundFiles;
42 QStringList missingFiles;
53 PathFinderResult::~PathFinderResult()
69 return d->missingFiles;
74 return d->missingFiles;
82 QSharedPointer <QList<FileSearchPath> > searchPaths;
84 QString resolveDir(
const QString &dir)
86 QFileInfo fileInfo(dir);
87 if (fileInfo.isSymLink())
88 fileInfo = QFileInfo(fileInfo.symLinkTarget());
90 if (fileInfo.isBundle())
91 return fileInfo.absoluteFilePath() +
"/Contents/MacOS";
94 if (fileInfo.isFile())
95 return fileInfo.absoluteDir().absolutePath();
97 return fileInfo.absoluteFilePath();
108 d->searchPaths.reset(
new QList<FileSearchPath>());
109 d->searchPaths->append(gConfig.combinedWadseekPaths());
110 removeUnneededPaths();
115 d->searchPaths.reset(
new QList<FileSearchPath>());
116 for (
const QString &path : paths)
117 d->searchPaths->append(path);
118 removeUnneededPaths();
121 PathFinder::~PathFinder()
128 #if defined(Q_OS_WIN32) 130 << gDefaultDataPaths->workingDirectory()
131 << gDefaultDataPaths->workingDirectory() +
"/.." 135 paths <<
"/usr/bin" <<
"/usr/local/bin" <<
"/usr/share/bin" 136 <<
"/usr/games/" <<
"/usr/local/games/" 137 <<
"/usr/share/games/" << gDefaultDataPaths->workingDirectory() <<
".";
139 QStringList pathsCopy(paths);
140 for (
const QString &path : pathsCopy)
142 for (
const QString &suffix : suffixes)
152 d->searchPaths->prepend(d->resolveDir(dir));
153 removeUnneededPaths();
158 d->searchPaths->append(d->resolveDir(dir));
159 removeUnneededPaths();
164 if (d->searchPaths->count() == 0)
166 QScopedPointer<FileSeeker> seeker(FileSeeker::createSeeker(d->searchPaths));
167 QString result = seeker->findFile(fileName);
174 for (
const QString file : files)
176 QString filePath = findFile(file);
177 if (filePath.isNull())
190 void PathFinder::removeUnneededPaths()
const 192 Qt::CaseSensitivity caseSensitivity;
194 caseSensitivity = Qt::CaseInsensitive;
196 caseSensitivity = Qt::CaseSensitive;
199 for (
int mainIterator = 0; mainIterator < d->searchPaths->length(); ++mainIterator)
201 for (
int subIterator = mainIterator + 1; subIterator < d->searchPaths->length(); ++subIterator)
203 const FileSearchPath &mainPath = d->searchPaths->at(mainIterator);
207 if (QDir(mainPath.path()).absolutePath().compare(QDir(subPath.path()).absolutePath(), caseSensitivity) == 0)
209 (*d->searchPaths.data())[mainIterator]
210 .setRecursive(mainPath.isRecursive() || subPath.isRecursive());
211 d->searchPaths->removeAt(subIterator);
217 if (mainPath.isRecursive() &&
218 QDir(subPath.path()).absolutePath().startsWith(QDir(mainPath.path()).absolutePath(), caseSensitivity))
220 d->searchPaths->removeAt(subIterator);
221 subIterator = mainIterator;
226 if (subPath.isRecursive() &&
227 QDir(mainPath.path()).absolutePath().startsWith(QDir(subPath.path()).absolutePath(), caseSensitivity))
229 d->searchPaths->removeAt(mainIterator);
static QString combinePaths(QString pathFront, QString pathEnd)
Result of multiple file search operation done by PathFinder.
Performs a case-insensitive (OS independent) file searches.
QStringList & missingFiles()
Names of not found files.
void addSearchDir(const QString &dir)
Adds directory where search will be performed.
QStringList & foundFiles()
Paths to found files.
PathFinderResult findFiles(const QStringList &files) const
Performs a search for multiple files, marking them as found or missing.
PathFinder()
Constructs PathFinder where paths are read from program configuration from file (WAD) path list setti...
static QString programFilesDirectory(MachineType machineType)
QString findFile(const QString &fileName) const
Performs a search for a single file.
static PathFinder genericPathFinder(const QStringList &suffixes)
Generic PathFinder that looks in PATH and other common dirs.
void addPrioritySearchDir(const QString &dir)