Skip to content

Commit

Permalink
Changes for code style.
Browse files Browse the repository at this point in the history
  • Loading branch information
Lymia committed Jan 29, 2025
1 parent ab28873 commit b953ecb
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 24 deletions.
9 changes: 6 additions & 3 deletions ai/coreai.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,9 +166,12 @@ void CoreAI::loadIni(QString file)
{
AI_CONSOLE_PRINT("CoreAI::loadIni " + file, GameConsole::eDEBUG);
m_iniFiles.append(file);
QStringList searchFiles;
if (file.isEmpty()) return;
for (auto & file : Vfs::findAll("resources/aidata/" + file))
if (file.isEmpty())
{
return;
}
QStringList searchFiles = Vfs::findAll("resources/aidata/" + file);
for (auto & file : searchFiles)
{
if (QFile::exists(file))
{
Expand Down
8 changes: 6 additions & 2 deletions coreengine/audiomanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,8 @@ void AudioManager::createSoundCache()
{
if (Mainapp::getInstance()->isAudioThread())
{
for (auto & folder : Vfs::createSearchPathRev("resources/sounds/"))
auto searchPath = Vfs::createSearchPathRev("resources/sounds/");
for (auto & folder : searchPath)
{
if (QFile::exists(folder + "res.xml"))
{
Expand Down Expand Up @@ -633,7 +634,10 @@ void AudioManager::SlotLoadFolder(QString folder)
#ifdef AUDIOSUPPORT
QStringList loadedSounds;
QStringList searchPath = Vfs::createSearchPathRev(folder);
for (QString folder : searchPath) loadMusicFolder(folder, loadedSounds);
for (QString folder : searchPath)
{
loadMusicFolder(folder, loadedSounds);
}
#endif
}

Expand Down
3 changes: 2 additions & 1 deletion coreengine/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2060,7 +2060,8 @@ void Settings::getModInfos(QString mod, QString & name, QString & description, Q
QStringList Settings::getAvailableMods()
{
QFileInfoList infoList;
for (const auto & entry : Vfs::findAllRev("mods", false))
auto searchPath = Vfs::findAllRev("mods", false);
for (const auto & entry : searchPath)
{
if (QFile::exists(entry))
{
Expand Down
49 changes: 39 additions & 10 deletions coreengine/vfs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ void Vfs::init()
// USEAPPCONFIGPATH is primarily set on Linux, where the "current directory" of programs launched from the start
// menu is normally the user's home directory. This is very unexpected behavior, and this should not be checked.
if (QFileInfo(".") != QFileInfo(Settings::userPath()))
{
searchPath.append({ "." });
}
#endif

QStringList mods = Settings::getInstance()->getMods();
Expand Down Expand Up @@ -95,15 +97,24 @@ QString Vfs::find(const QString& pName, bool checkMods) {
QString newPath;
for (auto & path : searchPath)
{
if (!checkMods && path.isModPath) continue;
if (!checkMods && path.isModPath)
{
continue;
}

newPath = path.root + name.path;
if (QFileInfo(newPath).exists()) return newPath;
if (QFileInfo(newPath).exists())
{
return newPath;
}

if (name.isResources && path.isModPath)
{
newPath = path.root + name.resourcesPath;
if (QFileInfo(newPath).exists()) return newPath;
if (QFileInfo(newPath).exists())
{
return newPath;
}
}
}

Expand All @@ -118,7 +129,10 @@ QStringList Vfs::createSearchPathInternal(const QString& pName, bool checkMods,
QString newPath;
for (auto & path : searchPath)
{
if (!checkMods && path.isModPath) continue;
if (!checkMods && path.isModPath)
{
continue;
}

newPath = path.root + name.path;
list.append(newPath);
Expand All @@ -130,7 +144,10 @@ QStringList Vfs::createSearchPathInternal(const QString& pName, bool checkMods,
}
}

if (!firstPriority) std::reverse(list.begin(), list.end());
if (!firstPriority)
{
std::reverse(list.begin(), list.end());
}
return list;
}

Expand All @@ -142,19 +159,31 @@ QStringList Vfs::findAllInternal(const QString& pName, bool checkMods, bool firs
QString newPath;
for (auto & path : searchPath)
{
if (!checkMods && path.isModPath) continue;
if (!checkMods && path.isModPath)
{
continue;
}

newPath = path.root + name.path;
if (QFileInfo(newPath).exists()) list.append(newPath);
if (QFileInfo(newPath).exists())
{
list.append(newPath);
}

if (name.isResources && path.isModPath)
{
newPath = path.root + name.resourcesPath;
if (QFileInfo(newPath).exists()) list.append(newPath);
}
if (QFileInfo(newPath).exists())
{
list.append(newPath);
}
}s
}

if (!firstPriority) std::reverse(list.begin(), list.end());
if (!firstPriority)
{
std::reverse(list.begin(), list.end());
}
return list;
}

Expand Down
18 changes: 10 additions & 8 deletions coreengine/vfs.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,6 @@

class Vfs final
{
Vfs() = delete;
~Vfs() = delete;

static QStringList createSearchPathInternal(const QString& name, bool checkMods = true, bool firstPriority = false);
static QStringList findAllInternal(const QString& name, bool checkMods = true, bool firstPriority = false);

static const QStringList emptyList;

public:

static void init();
Expand Down Expand Up @@ -56,6 +48,16 @@ class Vfs final
* Lists all files in a particular directory.
*/
static QFileInfoList list(const QString& name, const QStringList& filters = emptyList, bool checkMods = true);

private:

Vfs() = delete;
~Vfs() = delete;

static QStringList createSearchPathInternal(const QString& name, bool checkMods = true, bool firstPriority = false);
static QStringList findAllInternal(const QString& name, bool checkMods = true, bool firstPriority = false);

static const QStringList emptyList;
};

#endif // COREENGINE_VFS_H

0 comments on commit b953ecb

Please sign in to comment.