game_list_worker.h 2.0 KB

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