game_list_worker.h 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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 "common/common_types.h"
  15. #include "yuzu/compatibility_list.h"
  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. GameListWorker(std::shared_ptr<FileSys::VfsFilesystem> vfs,
  29. FileSys::ManualContentProvider* provider, QString dir_path, bool deep_scan,
  30. const CompatibilityList& compatibility_list);
  31. ~GameListWorker() override;
  32. /// Starts the processing of directory tree information.
  33. void run() override;
  34. /// Tells the worker that it should no longer continue processing. Thread-safe.
  35. void Cancel();
  36. signals:
  37. /**
  38. * The `EntryReady` signal is emitted once an entry has been prepared and is ready
  39. * to be added to the game list.
  40. * @param entry_items a list with `QStandardItem`s that make up the columns of the new entry.
  41. */
  42. void EntryReady(QList<QStandardItem*> entry_items);
  43. /**
  44. * After the worker has traversed the game directory looking for entries, this signal is emitted
  45. * with a list of folders that should be watched for changes as well.
  46. */
  47. void Finished(QStringList watch_list);
  48. private:
  49. void AddTitlesToGameList();
  50. enum class ScanTarget {
  51. FillManualContentProvider,
  52. PopulateGameList,
  53. };
  54. void ScanFileSystem(ScanTarget target, const std::string& dir_path, unsigned int recursion = 0);
  55. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  56. FileSys::ManualContentProvider* provider;
  57. QStringList watch_list;
  58. QString dir_path;
  59. bool deep_scan;
  60. const CompatibilityList& compatibility_list;
  61. std::atomic_bool stop_processing;
  62. };