GameTracker: use WorkQueueThread
This commit is contained in:
parent
de9378bf63
commit
8c13e0230c
|
@ -35,7 +35,7 @@ public:
|
||||||
{
|
{
|
||||||
{
|
{
|
||||||
std::unique_lock<std::mutex> lg(m_lock);
|
std::unique_lock<std::mutex> lg(m_lock);
|
||||||
m_items.emplace(std::move(args)...);
|
m_items.emplace(std::forward<Args>(args)...);
|
||||||
}
|
}
|
||||||
m_wakeup.Set();
|
m_wakeup.Set();
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,23 +17,11 @@ static const QStringList game_filters{
|
||||||
|
|
||||||
GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent)
|
GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent)
|
||||||
{
|
{
|
||||||
m_loader = new GameLoader;
|
|
||||||
m_loader->moveToThread(&m_loader_thread);
|
|
||||||
|
|
||||||
qRegisterMetaType<QSharedPointer<GameFile>>();
|
qRegisterMetaType<QSharedPointer<GameFile>>();
|
||||||
connect(&m_loader_thread, &QThread::finished, m_loader, &QObject::deleteLater);
|
|
||||||
connect(this, &QFileSystemWatcher::directoryChanged, this, &GameTracker::UpdateDirectory);
|
connect(this, &QFileSystemWatcher::directoryChanged, this, &GameTracker::UpdateDirectory);
|
||||||
connect(this, &QFileSystemWatcher::fileChanged, this, &GameTracker::UpdateFile);
|
connect(this, &QFileSystemWatcher::fileChanged, this, &GameTracker::UpdateFile);
|
||||||
connect(this, &GameTracker::PathChanged, m_loader, &GameLoader::LoadGame);
|
|
||||||
connect(m_loader, &GameLoader::GameLoaded, this, &GameTracker::GameLoaded);
|
|
||||||
|
|
||||||
m_loader_thread.start();
|
m_load_thread.Reset([this](const QString& path) { LoadGame(path); });
|
||||||
}
|
|
||||||
|
|
||||||
GameTracker::~GameTracker()
|
|
||||||
{
|
|
||||||
m_loader_thread.quit();
|
|
||||||
m_loader_thread.wait();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameTracker::AddDirectory(const QString& dir)
|
void GameTracker::AddDirectory(const QString& dir)
|
||||||
|
@ -81,7 +69,7 @@ void GameTracker::UpdateDirectory(const QString& dir)
|
||||||
{
|
{
|
||||||
addPath(path);
|
addPath(path);
|
||||||
m_tracked_files[path] = QSet<QString>{dir};
|
m_tracked_files[path] = QSet<QString>{dir};
|
||||||
emit PathChanged(path);
|
m_load_thread.EmplaceItem(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -127,7 +115,7 @@ void GameTracker::UpdateFile(const QString& file)
|
||||||
GameRemoved(file);
|
GameRemoved(file);
|
||||||
addPath(file);
|
addPath(file);
|
||||||
|
|
||||||
emit PathChanged(file);
|
m_load_thread.EmplaceItem(file);
|
||||||
}
|
}
|
||||||
else if (removePath(file))
|
else if (removePath(file))
|
||||||
{
|
{
|
||||||
|
@ -136,7 +124,7 @@ void GameTracker::UpdateFile(const QString& file)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameLoader::LoadGame(const QString& path)
|
void GameTracker::LoadGame(const QString& path)
|
||||||
{
|
{
|
||||||
if (!DiscIO::ShouldHideFromGameList(path.toStdString()))
|
if (!DiscIO::ShouldHideFromGameList(path.toStdString()))
|
||||||
{
|
{
|
||||||
|
|
|
@ -9,25 +9,19 @@
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
|
||||||
#include <QThread>
|
|
||||||
|
|
||||||
|
#include "Common/WorkQueueThread.h"
|
||||||
#include "DolphinQt2/GameList/GameFile.h"
|
#include "DolphinQt2/GameList/GameFile.h"
|
||||||
|
|
||||||
class GameLoader;
|
|
||||||
|
|
||||||
// Watches directories and loads GameFiles in a separate thread.
|
// Watches directories and loads GameFiles in a separate thread.
|
||||||
// To use this, just add directories using AddDirectory, and listen for the
|
// To use this, just add directories using AddDirectory, and listen for the
|
||||||
// GameLoaded and GameRemoved signals. Ignore the PathChanged signal, it's
|
// GameLoaded and GameRemoved signals.
|
||||||
// only there because the Qt people made fileChanged and directoryChanged
|
|
||||||
// private.
|
|
||||||
class GameTracker final : public QFileSystemWatcher
|
class GameTracker final : public QFileSystemWatcher
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit GameTracker(QObject* parent = nullptr);
|
explicit GameTracker(QObject* parent = nullptr);
|
||||||
~GameTracker();
|
|
||||||
|
|
||||||
void AddDirectory(const QString& dir);
|
void AddDirectory(const QString& dir);
|
||||||
void RemoveDirectory(const QString& dir);
|
void RemoveDirectory(const QString& dir);
|
||||||
|
@ -36,28 +30,15 @@ signals:
|
||||||
void GameLoaded(QSharedPointer<GameFile> game);
|
void GameLoaded(QSharedPointer<GameFile> game);
|
||||||
void GameRemoved(const QString& path);
|
void GameRemoved(const QString& path);
|
||||||
|
|
||||||
void PathChanged(const QString& path);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
void LoadGame(const QString& path);
|
||||||
void UpdateDirectory(const QString& dir);
|
void UpdateDirectory(const QString& dir);
|
||||||
void UpdateFile(const QString& path);
|
void UpdateFile(const QString& path);
|
||||||
QSet<QString> FindMissingFiles(const QString& dir);
|
QSet<QString> FindMissingFiles(const QString& dir);
|
||||||
|
|
||||||
// game path -> directories that track it
|
// game path -> directories that track it
|
||||||
QMap<QString, QSet<QString>> m_tracked_files;
|
QMap<QString, QSet<QString>> m_tracked_files;
|
||||||
QThread m_loader_thread;
|
Common::WorkQueueThread<QString> m_load_thread;
|
||||||
GameLoader* m_loader;
|
|
||||||
};
|
|
||||||
|
|
||||||
class GameLoader final : public QObject
|
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
public:
|
|
||||||
void LoadGame(const QString& path);
|
|
||||||
|
|
||||||
signals:
|
|
||||||
void GameLoaded(QSharedPointer<GameFile> game);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Q_DECLARE_METATYPE(QSharedPointer<GameFile>)
|
Q_DECLARE_METATYPE(QSharedPointer<GameFile>)
|
||||||
|
|
Loading…
Reference in New Issue