game_list_worker.h 2.4 KB

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