pineapple-src/src/yuzu/game_list_worker.h

95 lines
2.6 KiB
C
Raw Normal View History

2022-11-05 13:58:44 +01:00
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
// SPDX-License-Identifier: GPL-2.0-or-later
#pragma once
#include <atomic>
2023-10-26 01:19:00 +02:00
#include <deque>
2022-11-05 13:58:44 +01:00
#include <memory>
#include <string>
#include <QList>
#include <QObject>
#include <QRunnable>
#include <QString>
2023-10-13 17:25:20 +02:00
#include "common/thread.h"
2022-11-05 13:58:44 +01:00
#include "yuzu/compatibility_list.h"
2023-08-28 03:24:22 +02:00
#include "yuzu/play_time_manager.h"
2022-11-05 13:58:44 +01:00
namespace Core {
class System;
}
2023-10-26 01:19:00 +02:00
class GameList;
2022-11-05 13:58:44 +01:00
class QStandardItem;
namespace FileSys {
class NCA;
class VfsFilesystem;
} // namespace FileSys
/**
* Asynchronous worker object for populating the game list.
* Communicates with other threads through Qt's signal/slot system.
*/
class GameListWorker : public QObject, public QRunnable {
Q_OBJECT
public:
explicit GameListWorker(std::shared_ptr<FileSys::VfsFilesystem> vfs_,
FileSys::ManualContentProvider* provider_,
QVector<UISettings::GameDir>& game_dirs_,
2023-08-28 03:24:22 +02:00
const CompatibilityList& compatibility_list_,
const PlayTime::PlayTimeManager& play_time_manager_,
Core::System& system_);
2022-11-05 13:58:44 +01:00
~GameListWorker() override;
/// Starts the processing of directory tree information.
void run() override;
2023-10-26 01:19:00 +02:00
public:
2022-11-05 13:58:44 +01:00
/**
2023-10-26 01:19:00 +02:00
* Synchronously processes any events queued by the worker.
*
* AddDirEntry is called on the game list for every discovered directory.
* AddEntry is called on the game list for every discovered program.
* DonePopulating is called on the game list when processing completes.
2022-11-05 13:58:44 +01:00
*/
2023-10-26 01:19:00 +02:00
void ProcessEvents(GameList* game_list);
2022-11-05 13:58:44 +01:00
2023-10-26 01:19:00 +02:00
signals:
void DataAvailable();
private:
template <typename F>
void RecordEvent(F&& func);
2022-11-05 13:58:44 +01:00
private:
void AddTitlesToGameList(GameListDir* parent_dir);
enum class ScanTarget {
FillManualContentProvider,
PopulateGameList,
};
void ScanFileSystem(ScanTarget target, const std::string& dir_path, bool deep_scan,
GameListDir* parent_dir);
std::shared_ptr<FileSys::VfsFilesystem> vfs;
FileSys::ManualContentProvider* provider;
QVector<UISettings::GameDir>& game_dirs;
const CompatibilityList& compatibility_list;
2023-08-28 03:24:22 +02:00
const PlayTime::PlayTimeManager& play_time_manager;
2022-11-05 13:58:44 +01:00
QStringList watch_list;
2023-10-13 17:25:20 +02:00
2023-10-26 01:19:00 +02:00
std::mutex lock;
std::condition_variable cv;
std::deque<std::function<void(GameList*)>> queued_events;
2023-10-13 17:25:20 +02:00
std::atomic_bool stop_requested = false;
2023-10-26 01:19:00 +02:00
Common::Event processing_completed;
2022-11-05 13:58:44 +01:00
Core::System& system;
};