summaryrefslogtreecommitdiff
path: root/Source/Core/DolphinQt2/GameList/GameFileCache.cpp
diff options
context:
space:
mode:
authorspycrab <spycrab@users.noreply.github.com>2017-08-14 16:05:46 +0200
committerspycrab <spycrab@users.noreply.github.com>2017-08-24 07:17:31 +0200
commitb9c5a2af052425ecf0ec41db86c2b01c2f0bafbd (patch)
treec90c983cd6539d53b90b82ec294d28ab1d09cd9f /Source/Core/DolphinQt2/GameList/GameFileCache.cpp
parent935c1da35769348d4053eca29c8531e97c510139 (diff)
Qt: Implement gamelist caching
Diffstat (limited to 'Source/Core/DolphinQt2/GameList/GameFileCache.cpp')
-rw-r--r--Source/Core/DolphinQt2/GameList/GameFileCache.cpp87
1 files changed, 87 insertions, 0 deletions
diff --git a/Source/Core/DolphinQt2/GameList/GameFileCache.cpp b/Source/Core/DolphinQt2/GameList/GameFileCache.cpp
new file mode 100644
index 0000000000..40e1928649
--- /dev/null
+++ b/Source/Core/DolphinQt2/GameList/GameFileCache.cpp
@@ -0,0 +1,87 @@
+// Copyright 2017 Dolphin Emulator Project
+// Licensed under GPLv2+
+// Refer to the license.txt file included.
+
+#include "GameFileCache.h"
+
+#include <QDataStream>
+#include <QDir>
+#include <QFileInfo>
+
+#include "Common/FileUtil.h"
+#include "Core/ConfigManager.h"
+#include "DolphinQt2/Settings.h"
+
+static const int CACHE_VERSION = 1; // Last changed in PR #5927
+static const int DATASTREAM_VERSION = QDataStream::Qt_5_0;
+
+GameFileCache::GameFileCache()
+ : m_path(QString::fromStdString(File::GetUserPath(D_CACHE_IDX) + "qt_gamefile.cache"))
+{
+}
+
+bool GameFileCache::IsCached(const QString& path)
+{
+ std::lock_guard<std::mutex> guard(m_mutex);
+
+ return m_gamefiles.contains(path);
+}
+
+GameFile GameFileCache::GetFile(const QString& path)
+{
+ std::lock_guard<std::mutex> guard(m_mutex);
+
+ return m_gamefiles[path];
+}
+
+void GameFileCache::Load()
+{
+ std::lock_guard<std::mutex> guard(m_mutex);
+
+ QFile file(m_path);
+
+ if (!file.open(QIODevice::ReadOnly))
+ return;
+
+ QDataStream stream(&file);
+ stream.setVersion(DATASTREAM_VERSION);
+
+ qint32 cache_version;
+ stream >> cache_version;
+
+ // If the cache file is using an older version, ignore it and create it from scratch
+ if (cache_version != CACHE_VERSION)
+ return;
+
+ stream >> m_gamefiles;
+}
+
+void GameFileCache::Save()
+{
+ std::lock_guard<std::mutex> guard(m_mutex);
+
+ QFile file(m_path);
+
+ if (!file.open(QIODevice::WriteOnly))
+ return;
+
+ QDataStream stream(&file);
+ stream.setVersion(DATASTREAM_VERSION);
+
+ stream << static_cast<qint32>(CACHE_VERSION);
+ stream << m_gamefiles;
+}
+
+void GameFileCache::Update(const GameFile& gamefile)
+{
+ std::lock_guard<std::mutex> guard(m_mutex);
+
+ m_gamefiles[gamefile.GetFilePath()] = gamefile;
+}
+
+QList<QString> GameFileCache::GetCached()
+{
+ std::lock_guard<std::mutex> guard(m_mutex);
+
+ return m_gamefiles.keys();
+}