Qt: Fix gamelist updating
This commit is contained in:
parent
54dcd3a89b
commit
7455c9bf51
|
@ -90,6 +90,8 @@ void GameListModel::UpdateGame(QSharedPointer<GameFile> game)
|
||||||
int entry = FindGame(path);
|
int entry = FindGame(path);
|
||||||
if (entry < 0)
|
if (entry < 0)
|
||||||
entry = m_games.size();
|
entry = m_games.size();
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
|
||||||
beginInsertRows(QModelIndex(), entry, entry);
|
beginInsertRows(QModelIndex(), entry, entry);
|
||||||
m_games.insert(entry, game);
|
m_games.insert(entry, game);
|
||||||
|
|
|
@ -55,8 +55,8 @@ void GameTracker::RemoveDirectory(const QString& dir)
|
||||||
QString path = QFileInfo(it.next()).canonicalFilePath();
|
QString path = QFileInfo(it.next()).canonicalFilePath();
|
||||||
if (m_tracked_files.contains(path))
|
if (m_tracked_files.contains(path))
|
||||||
{
|
{
|
||||||
m_tracked_files[path]--;
|
m_tracked_files[path].remove(dir);
|
||||||
if (m_tracked_files[path] == 0)
|
if (m_tracked_files[path].empty())
|
||||||
{
|
{
|
||||||
removePath(path);
|
removePath(path);
|
||||||
m_tracked_files.remove(path);
|
m_tracked_files.remove(path);
|
||||||
|
@ -72,23 +72,63 @@ void GameTracker::UpdateDirectory(const QString& dir)
|
||||||
while (it.hasNext())
|
while (it.hasNext())
|
||||||
{
|
{
|
||||||
QString path = QFileInfo(it.next()).canonicalFilePath();
|
QString path = QFileInfo(it.next()).canonicalFilePath();
|
||||||
|
auto& tracked_file = m_tracked_files[path];
|
||||||
|
|
||||||
if (m_tracked_files.contains(path))
|
if (m_tracked_files.contains(path))
|
||||||
{
|
{
|
||||||
m_tracked_files[path]++;
|
if (!tracked_file.contains(dir))
|
||||||
|
tracked_file.insert(dir);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
addPath(path);
|
addPath(path);
|
||||||
m_tracked_files[path] = 1;
|
m_tracked_files[path] = QSet<QString>{dir};
|
||||||
emit PathChanged(path);
|
emit PathChanged(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto& missing : FindMissingFiles(dir))
|
||||||
|
{
|
||||||
|
auto& tracked_file = m_tracked_files[missing];
|
||||||
|
|
||||||
|
tracked_file.remove(dir);
|
||||||
|
if (tracked_file.empty())
|
||||||
|
{
|
||||||
|
m_tracked_files.remove(missing);
|
||||||
|
GameRemoved(missing);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
QSet<QString> GameTracker::FindMissingFiles(const QString& dir)
|
||||||
|
{
|
||||||
|
QDirIterator it(dir, game_filters, QDir::NoFilter, QDirIterator::Subdirectories);
|
||||||
|
|
||||||
|
QSet<QString> missing_files;
|
||||||
|
|
||||||
|
for (const auto& key : m_tracked_files.keys())
|
||||||
|
{
|
||||||
|
if (m_tracked_files[key].contains(dir))
|
||||||
|
missing_files.insert(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (it.hasNext())
|
||||||
|
{
|
||||||
|
QString path = QFileInfo(it.next()).canonicalFilePath();
|
||||||
|
if (m_tracked_files.contains(path))
|
||||||
|
missing_files.remove(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
return missing_files;
|
||||||
}
|
}
|
||||||
|
|
||||||
void GameTracker::UpdateFile(const QString& file)
|
void GameTracker::UpdateFile(const QString& file)
|
||||||
{
|
{
|
||||||
if (QFileInfo(file).exists())
|
if (QFileInfo(file).exists())
|
||||||
{
|
{
|
||||||
|
GameRemoved(file);
|
||||||
|
addPath(file);
|
||||||
|
|
||||||
emit PathChanged(file);
|
emit PathChanged(file);
|
||||||
}
|
}
|
||||||
else if (removePath(file))
|
else if (removePath(file))
|
||||||
|
|
|
@ -6,13 +6,13 @@
|
||||||
|
|
||||||
#include <QFileSystemWatcher>
|
#include <QFileSystemWatcher>
|
||||||
#include <QMap>
|
#include <QMap>
|
||||||
|
#include <QSet>
|
||||||
#include <QSharedPointer>
|
#include <QSharedPointer>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
|
|
||||||
#include "DolphinQt2/GameList/GameFile.h"
|
#include "DolphinQt2/GameList/GameFile.h"
|
||||||
#include "DolphinQt2/GameList/GameTracker.h"
|
|
||||||
|
|
||||||
class GameLoader;
|
class GameLoader;
|
||||||
|
|
||||||
|
@ -42,9 +42,10 @@ signals:
|
||||||
private:
|
private:
|
||||||
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);
|
||||||
|
|
||||||
// game path -> number of directories that track it
|
// game path -> directories that track it
|
||||||
QMap<QString, int> m_tracked_files;
|
QMap<QString, QSet<QString>> m_tracked_files;
|
||||||
QThread m_loader_thread;
|
QThread m_loader_thread;
|
||||||
GameLoader* m_loader;
|
GameLoader* m_loader;
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue