game_list_worker.h 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <atomic>
  5. #include <deque>
  6. #include <memory>
  7. #include <string>
  8. #include <QList>
  9. #include <QObject>
  10. #include <QRunnable>
  11. #include <QString>
  12. #include "common/thread.h"
  13. #include "yuzu/compatibility_list.h"
  14. #include "yuzu/play_time_manager.h"
  15. namespace Core {
  16. class System;
  17. }
  18. class GameList;
  19. class QStandardItem;
  20. namespace FileSys {
  21. class NCA;
  22. class VfsFilesystem;
  23. } // namespace FileSys
  24. /**
  25. * Asynchronous worker object for populating the game list.
  26. * Communicates with other threads through Qt's signal/slot system.
  27. */
  28. class GameListWorker : public QObject, public QRunnable {
  29. Q_OBJECT
  30. public:
  31. explicit GameListWorker(std::shared_ptr<FileSys::VfsFilesystem> vfs_,
  32. FileSys::ManualContentProvider* provider_,
  33. QVector<UISettings::GameDir>& game_dirs_,
  34. const CompatibilityList& compatibility_list_,
  35. const PlayTime::PlayTimeManager& play_time_manager_,
  36. Core::System& system_);
  37. ~GameListWorker() override;
  38. /// Starts the processing of directory tree information.
  39. void run() override;
  40. public:
  41. /**
  42. * Synchronously processes any events queued by the worker.
  43. *
  44. * AddDirEntry is called on the game list for every discovered directory.
  45. * AddEntry is called on the game list for every discovered program.
  46. * DonePopulating is called on the game list when processing completes.
  47. */
  48. void ProcessEvents(GameList* game_list);
  49. signals:
  50. void DataAvailable();
  51. private:
  52. template <typename F>
  53. void RecordEvent(F&& func);
  54. private:
  55. void AddTitlesToGameList(GameListDir* parent_dir);
  56. enum class ScanTarget {
  57. FillManualContentProvider,
  58. PopulateGameList,
  59. };
  60. void ScanFileSystem(ScanTarget target, const std::string& dir_path, bool deep_scan,
  61. GameListDir* parent_dir);
  62. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  63. FileSys::ManualContentProvider* provider;
  64. QVector<UISettings::GameDir>& game_dirs;
  65. const CompatibilityList& compatibility_list;
  66. const PlayTime::PlayTimeManager& play_time_manager;
  67. QStringList watch_list;
  68. std::mutex lock;
  69. std::condition_variable cv;
  70. std::deque<std::function<void(GameList*)>> queued_events;
  71. std::atomic_bool stop_requested = false;
  72. Common::Event processing_completed;
  73. Core::System& system;
  74. };