game_list_worker.h 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // SPDX-FileCopyrightText: Copyright 2018 yuzu Emulator Project
  2. // SPDX-License-Identifier: GPL-2.0-or-later
  3. #pragma once
  4. #include <atomic>
  5. #include <memory>
  6. #include <string>
  7. #include <QList>
  8. #include <QObject>
  9. #include <QRunnable>
  10. #include <QString>
  11. #include "yuzu/compatibility_list.h"
  12. namespace Core {
  13. class System;
  14. }
  15. class QStandardItem;
  16. namespace FileSys {
  17. class NCA;
  18. class VfsFilesystem;
  19. } // namespace FileSys
  20. /**
  21. * Asynchronous worker object for populating the game list.
  22. * Communicates with other threads through Qt's signal/slot system.
  23. */
  24. class GameListWorker : public QObject, public QRunnable {
  25. Q_OBJECT
  26. public:
  27. explicit GameListWorker(std::shared_ptr<FileSys::VfsFilesystem> vfs_,
  28. FileSys::ManualContentProvider* provider_,
  29. QVector<UISettings::GameDir>& game_dirs_,
  30. const CompatibilityList& compatibility_list_, Core::System& system_);
  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
  41. * entry.
  42. */
  43. void DirEntryReady(GameListDir* entry_items);
  44. void EntryReady(QList<QStandardItem*> entry_items, GameListDir* parent_dir);
  45. /**
  46. * After the worker has traversed the game directory looking for entries, this signal is
  47. * emitted with a list of folders that should be watched for changes as well.
  48. */
  49. void Finished(QStringList watch_list);
  50. private:
  51. void AddTitlesToGameList(GameListDir* parent_dir);
  52. enum class ScanTarget {
  53. FillManualContentProvider,
  54. PopulateGameList,
  55. };
  56. void ScanFileSystem(ScanTarget target, const std::string& dir_path, bool deep_scan,
  57. GameListDir* parent_dir);
  58. std::shared_ptr<FileSys::VfsFilesystem> vfs;
  59. FileSys::ManualContentProvider* provider;
  60. QVector<UISettings::GameDir>& game_dirs;
  61. const CompatibilityList& compatibility_list;
  62. QStringList watch_list;
  63. std::atomic_bool stop_processing;
  64. Core::System& system;
  65. };