Skip to content

Commit

Permalink
Recursively scan for shader plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
rodlie committed Aug 17, 2023
1 parent e5dfdd4 commit 39995c8
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/app/effectsloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down
11 changes: 11 additions & 0 deletions src/core/appsupport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
#include <QMimeType>
#include <QDomDocument>
#include <QDomElement>
#include <QDirIterator>

AppSupport::AppSupport(QObject *parent)
: QObject{parent}
Expand Down Expand Up @@ -317,3 +318,13 @@ const QPair<QString, QString> 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;
}
3 changes: 3 additions & 0 deletions src/core/appsupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include <QVariant>
#include <QPalette>
#include <QPair>
#include <QStringList>

#if (QT_VERSION >= QT_VERSION_CHECK(5, 14, 0))
#define QT_ENDL Qt::endl
Expand Down Expand Up @@ -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<QString,QString> getShaderID(const QString &path);
static const QStringList getFilesFromPath(const QString &path,
const QStringList &suffix = QStringList());
};

#endif // APPSUPPORT_H

0 comments on commit 39995c8

Please sign in to comment.