game_list_worker.h 2.3 KB

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