2022-04-23 10:59:50 +02:00
|
|
|
// SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-09-07 22:08:08 +02:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <atomic>
|
2023-10-24 04:09:29 +02:00
|
|
|
#include <deque>
|
2018-09-07 22:08:08 +02:00
|
|
|
#include <memory>
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
#include <QList>
|
|
|
|
#include <QObject>
|
|
|
|
#include <QRunnable>
|
|
|
|
#include <QString>
|
|
|
|
|
2023-10-13 03:07:49 +02:00
|
|
|
#include "common/thread.h"
|
2018-09-10 01:09:37 +02:00
|
|
|
#include "yuzu/compatibility_list.h"
|
2023-08-28 00:41:42 +02:00
|
|
|
#include "yuzu/play_time_manager.h"
|
2018-09-07 22:08:08 +02:00
|
|
|
|
2021-07-30 15:32:26 +02:00
|
|
|
namespace Core {
|
|
|
|
class System;
|
|
|
|
}
|
|
|
|
|
2023-10-24 04:09:29 +02:00
|
|
|
class GameList;
|
2018-09-07 22:08:08 +02: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:
|
2022-06-13 22:52:19 +02:00
|
|
|
explicit GameListWorker(std::shared_ptr<FileSys::VfsFilesystem> vfs_,
|
|
|
|
FileSys::ManualContentProvider* provider_,
|
|
|
|
QVector<UISettings::GameDir>& game_dirs_,
|
2023-08-28 00:41:42 +02:00
|
|
|
const CompatibilityList& compatibility_list_,
|
|
|
|
const PlayTime::PlayTimeManager& play_time_manager_,
|
|
|
|
Core::System& system_);
|
2018-09-07 22:08:08 +02:00
|
|
|
~GameListWorker() override;
|
|
|
|
|
|
|
|
/// Starts the processing of directory tree information.
|
|
|
|
void run() override;
|
|
|
|
|
2023-10-24 04:09:29 +02:00
|
|
|
public:
|
2018-09-07 22:08:08 +02:00
|
|
|
/**
|
2023-10-24 04:09:29 +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.
|
2018-09-07 22:08:08 +02:00
|
|
|
*/
|
2023-10-24 04:09:29 +02:00
|
|
|
void ProcessEvents(GameList* game_list);
|
2018-09-07 22:08:08 +02:00
|
|
|
|
2023-10-24 04:09:29 +02:00
|
|
|
signals:
|
|
|
|
void DataAvailable();
|
|
|
|
|
|
|
|
private:
|
|
|
|
template <typename F>
|
|
|
|
void RecordEvent(F&& func);
|
2018-09-07 22:08:08 +02:00
|
|
|
|
|
|
|
private:
|
2019-05-01 23:21:04 +02:00
|
|
|
void AddTitlesToGameList(GameListDir* parent_dir);
|
2019-03-04 18:40:53 +01:00
|
|
|
|
|
|
|
enum class ScanTarget {
|
|
|
|
FillManualContentProvider,
|
|
|
|
PopulateGameList,
|
|
|
|
};
|
|
|
|
|
2021-05-26 01:32:56 +02:00
|
|
|
void ScanFileSystem(ScanTarget target, const std::string& dir_path, bool deep_scan,
|
2019-05-01 23:21:04 +02:00
|
|
|
GameListDir* parent_dir);
|
2018-09-07 22:08:08 +02:00
|
|
|
|
|
|
|
std::shared_ptr<FileSys::VfsFilesystem> vfs;
|
2019-03-04 18:40:53 +01:00
|
|
|
FileSys::ManualContentProvider* provider;
|
2019-06-08 00:51:58 +02:00
|
|
|
QVector<UISettings::GameDir>& game_dirs;
|
2019-10-05 01:41:02 +02:00
|
|
|
const CompatibilityList& compatibility_list;
|
2023-08-28 00:41:42 +02:00
|
|
|
const PlayTime::PlayTimeManager& play_time_manager;
|
2019-10-05 01:41:02 +02:00
|
|
|
|
|
|
|
QStringList watch_list;
|
2023-10-13 03:07:49 +02:00
|
|
|
|
2023-10-24 04:09:29 +02:00
|
|
|
std::mutex lock;
|
|
|
|
std::condition_variable cv;
|
|
|
|
std::deque<std::function<void(GameList*)>> queued_events;
|
2023-10-13 03:07:49 +02:00
|
|
|
std::atomic_bool stop_requested = false;
|
2023-10-24 04:09:29 +02:00
|
|
|
Common::Event processing_completed;
|
2021-07-30 15:32:26 +02:00
|
|
|
|
|
|
|
Core::System& system;
|
2018-09-07 22:08:08 +02:00
|
|
|
};
|