diff --git a/src/app/effectsloader.cpp b/src/app/effectsloader.cpp index 4992d8bb0..223384da9 100755 --- a/src/app/effectsloader.cpp +++ b/src/app/effectsloader.cpp @@ -258,14 +258,8 @@ void EffectsLoader::iniShaderEffects() { makeCurrent(); - const QString presetPath = AppSupport::getAppShaderPresetsPath(); - QDirIterator presetIt(presetPath, QDirIterator::NoIteratorFlags); - - while (presetIt.hasNext()) { - const QString path = presetIt.next(); - const QFileInfo fileInfo(path); - if (!fileInfo.isFile() || - fileInfo.suffix() != "gre") { continue; } + for (const auto &path : AppSupport::getFilesFromPath(AppSupport::getAppShaderPresetsPath(), + QStringList() << "*.gre")) { try { iniShaderEffectProgramExec(path, false); } catch(const std::exception& e) { @@ -274,13 +268,8 @@ void EffectsLoader::iniShaderEffects() } const QString dirPath = AppSupport::getAppShaderEffectsPath(); - QDirIterator dirIt(dirPath, QDirIterator::NoIteratorFlags); - - while (dirIt.hasNext()) { - const QString path = dirIt.next(); - const QFileInfo fileInfo(path); - if (!fileInfo.isFile() || - fileInfo.suffix() != "gre") { continue; } + for (const auto &path : AppSupport::getFilesFromPath(dirPath, + QStringList() << "*.gre")) { try { iniShaderEffectProgramExec(path); } catch(const std::exception& e) { diff --git a/src/core/appsupport.cpp b/src/core/appsupport.cpp index c13ea4bfd..85350d436 100644 --- a/src/core/appsupport.cpp +++ b/src/core/appsupport.cpp @@ -34,6 +34,7 @@ #include #include #include +#include AppSupport::AppSupport(QObject *parent) : QObject{parent} @@ -317,3 +318,13 @@ const QPair AppSupport::getShaderID(const QString &path) return result; } + +const QStringList AppSupport::getFilesFromPath(const QString &path, + const QStringList &suffix) +{ + QStringList result; + if (path.isEmpty() || !QFile::exists(path)) { return result; } + QDirIterator it(path, suffix, QDir::Files, QDirIterator::Subdirectories); + while (it.hasNext()) { result << it.next(); } + return result; +} diff --git a/src/core/appsupport.h b/src/core/appsupport.h index c54a356bb..08262aa7d 100644 --- a/src/core/appsupport.h +++ b/src/core/appsupport.h @@ -30,6 +30,7 @@ #include #include #include +#include #if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)) #define QT_ENDL Qt::endl @@ -78,6 +79,8 @@ class CORE_EXPORT AppSupport : public QObject static const QString getFileMimeType(const QString &path); static const QString getFileIcon(const QString &path); static const QPair getShaderID(const QString &path); + static const QStringList getFilesFromPath(const QString &path, + const QStringList &suffix = QStringList()); }; #endif // APPSUPPORT_H