@@ -0,0 +1,30 @@
// Copyright 2017 Dolphin Emulator Project
// Licensed under GPLv2+
// Refer to the license.txt file included.

#pragma once

#include <QFile>

#include <mutex>

#include "DolphinQt2/GameList/GameFile.h"

class GameFileCache
{
public:
explicit GameFileCache();

void Update(const GameFile& gamefile);
void Save();
void Load();
bool IsCached(const QString& path);
GameFile GetFile(const QString& path);
QList<QString> GetCached();

private:
QString m_path;

QMap<QString, GameFile> m_gamefiles;
std::mutex m_mutex;
};
@@ -7,7 +7,9 @@
#include <QFile>

#include "DiscIO/DirectoryBlob.h"
#include "DolphinQt2/GameList/GameFileCache.h"
#include "DolphinQt2/GameList/GameTracker.h"
#include "DolphinQt2/QtUtils/QueueOnObject.h"
#include "DolphinQt2/Settings.h"

static const QStringList game_filters{
@@ -21,6 +23,8 @@ GameTracker::GameTracker(QObject* parent) : QFileSystemWatcher(parent)
connect(this, &QFileSystemWatcher::directoryChanged, this, &GameTracker::UpdateDirectory);
connect(this, &QFileSystemWatcher::fileChanged, this, &GameTracker::UpdateFile);

cache.Load();

m_load_thread.Reset([this](const QString& path) { LoadGame(path); });
}

@@ -128,8 +132,23 @@ void GameTracker::LoadGame(const QString& path)
{
if (!DiscIO::ShouldHideFromGameList(path.toStdString()))
{
if (cache.IsCached(path))
{
const QDateTime last_modified = QFileInfo(path).lastModified();
auto cached_file = cache.GetFile(path);
if (cached_file.GetLastModified() >= last_modified)
{
emit GameLoaded(QSharedPointer<GameFile>::create(cached_file));
return;
}
}

auto game = QSharedPointer<GameFile>::create(path);
if (game->IsValid())
{
emit GameLoaded(game);
cache.Update(*game);
cache.Save();
}
}
}
@@ -12,6 +12,7 @@

#include "Common/WorkQueueThread.h"
#include "DolphinQt2/GameList/GameFile.h"
#include "DolphinQt2/GameList/GameFileCache.h"

// Watches directories and loads GameFiles in a separate thread.
// To use this, just add directories using AddDirectory, and listen for the
@@ -39,6 +40,7 @@ class GameTracker final : public QFileSystemWatcher
// game path -> directories that track it
QMap<QString, QSet<QString>> m_tracked_files;
Common::WorkQueueThread<QString> m_load_thread;
GameFileCache cache;
};

Q_DECLARE_METATYPE(QSharedPointer<GameFile>)