game_list_worker.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. // Copyright 2018 yuzu emulator team
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <atomic>
  6. #include <map>
  7. #include <memory>
  8. #include <string>
  9. #include <unordered_map>
  10. #include <QList>
  11. #include <QObject>
  12. #include <QRunnable>
  13. #include <QString>
  14. #include <QVector>
  15. #include "common/common_types.h"
  16. #include "yuzu/compatibility_list.h"
  17. class QStandardItem;
  18. namespace FileSys {
  19. class NCA;
  20. class VfsFilesystem;
  21. } // namespace FileSys
  22. /**
  23. * Asynchronous worker object for populating the game list.
  24. * Communicates with other threads through Qt's signal/slot system.
  25. */
  26. class GameListWorker : public QObject, public QRunnable {
  27. Q_OBJECT
  28. public:
  29. explicit GameListWorker(std::shared_ptr<FileSys::VfsFilesystem> vfs,
  30. FileSys::ManualContentProvider* provider,
  31. QVector<UISettings::GameDir>& game_dirs,
  32. const CompatibilityList& compatibility_list);
  33. ~GameListWorker() override;
  34. /// Starts the processing of directory tree information.
  35. void run() override;
  36. /// Tells the worker that it should no longer continue processing. Thread-safe.
  37. void Cancel();
  38. signals:
  39. /**
  40. * The `EntryReady` signal is emitted once an entry has been prepared and is ready
  41. * to be added to the game list.
  42. * @param entry_items a list with `QStandardItem`s that make up the columns of the new
  43. * entry.
  44. */
  45. void DirEntryReady(GameListDir* entry_items);
  46. void EntryReady(QList<QStandardItem*> entry_items, GameListDir* parent_dir);
  47. /**
  48. * After the worker has traversed the game directory looking for entries, this signal is
  49. * emitted with a list of folders that should be watched for changes as well.
  50. */
  51. void Finished(QStringList watch_list);
  52. private:
  53. void AddTitlesToGameList(GameListDir* parent_dir);
  54. enum class ScanTarget {
  55. FillManualContentProvider,
  56. PopulateGameList,
  57. };
  58. void ScanFileSystem(ScanTarget target, const std::string& dir_path, unsigned int recursion,
  59. GameListDir* parent_dir);
  60. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  61. FileSys::ManualContentProvider* provider;
  62. QStringList watch_list;
  63. const CompatibilityList& compatibility_list;
  64. QVector<UISettings::GameDir>& game_dirs;
  65. std::atomic_bool stop_processing;
  66. };