mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-02-10 03:39:55 +00:00
Simplify converting file names into absolute file paths
This commit is contained in:
parent
d18d860ea2
commit
de112a2950
@ -98,6 +98,27 @@ namespace Launcher
|
||||
{
|
||||
return Settings::Manager::getUInt64("max navmeshdb file size", "Navigator") / (1024 * 1024);
|
||||
}
|
||||
|
||||
std::optional<QString> findFirstPath(const QStringList& directories, const QString& fileName)
|
||||
{
|
||||
for (const QString& directoryPath : directories)
|
||||
{
|
||||
const QString filePath = QDir(directoryPath).absoluteFilePath(fileName);
|
||||
if (QFile::exists(filePath))
|
||||
return filePath;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
QStringList findAllFilePaths(const QStringList& directories, const QStringList& fileNames)
|
||||
{
|
||||
QStringList result;
|
||||
result.reserve(fileNames.size());
|
||||
for (const QString& fileName : fileNames)
|
||||
if (const auto filepath = findFirstPath(directories, fileName))
|
||||
result.append(*filepath);
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -305,25 +326,8 @@ void Launcher::DataFilesPage::populateFileViews(const QString& contentModelName)
|
||||
row++;
|
||||
}
|
||||
|
||||
PathIterator pathIterator(directories);
|
||||
|
||||
mSelector->setProfileContent(filesInProfile(contentModelName, pathIterator));
|
||||
}
|
||||
|
||||
QStringList Launcher::DataFilesPage::filesInProfile(const QString& profileName, PathIterator& pathIterator)
|
||||
{
|
||||
QStringList files = mLauncherSettings.getContentListFiles(profileName);
|
||||
QStringList filepaths;
|
||||
|
||||
for (const QString& file : files)
|
||||
{
|
||||
QString filepath = pathIterator.findFirstPath(file);
|
||||
|
||||
if (!filepath.isEmpty())
|
||||
filepaths << filepath;
|
||||
}
|
||||
|
||||
return filepaths;
|
||||
mSelector->setProfileContent(
|
||||
findAllFilePaths(directories, mLauncherSettings.getContentListFiles(contentModelName)));
|
||||
}
|
||||
|
||||
void Launcher::DataFilesPage::saveSettings(const QString& profile)
|
||||
|
@ -140,58 +140,6 @@ namespace Launcher
|
||||
QStringList selectedFilePaths() const;
|
||||
QStringList selectedArchivePaths() const;
|
||||
QStringList selectedDirectoriesPaths() const;
|
||||
|
||||
class PathIterator
|
||||
{
|
||||
QStringList::ConstIterator mCitEnd;
|
||||
QStringList::ConstIterator mCitCurrent;
|
||||
QStringList::ConstIterator mCitBegin;
|
||||
QString mFile;
|
||||
QString mFilePath;
|
||||
|
||||
public:
|
||||
PathIterator(const QStringList& list)
|
||||
{
|
||||
mCitBegin = list.constBegin();
|
||||
mCitCurrent = mCitBegin;
|
||||
mCitEnd = list.constEnd();
|
||||
}
|
||||
|
||||
QString findFirstPath(const QString& file)
|
||||
{
|
||||
mCitCurrent = mCitBegin;
|
||||
mFile = file;
|
||||
return path();
|
||||
}
|
||||
|
||||
QString findNextPath() { return path(); }
|
||||
|
||||
private:
|
||||
QString path()
|
||||
{
|
||||
bool success = false;
|
||||
QDir dir;
|
||||
QFileInfo file;
|
||||
|
||||
while (!success)
|
||||
{
|
||||
if (mCitCurrent == mCitEnd)
|
||||
break;
|
||||
|
||||
dir.setPath(*(mCitCurrent++));
|
||||
file.setFile(dir.absoluteFilePath(mFile));
|
||||
|
||||
success = file.exists();
|
||||
}
|
||||
|
||||
if (success)
|
||||
return file.absoluteFilePath();
|
||||
|
||||
return "";
|
||||
}
|
||||
};
|
||||
|
||||
QStringList filesInProfile(const QString& profileName, PathIterator& pathIterator);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user