diff --git a/launcher/minecraft/mod/tasks/BasicFolderLoadTask.h b/launcher/minecraft/mod/tasks/BasicFolderLoadTask.h index cc02a9b9..7ea512b3 100644 --- a/launcher/minecraft/mod/tasks/BasicFolderLoadTask.h +++ b/launcher/minecraft/mod/tasks/BasicFolderLoadTask.h @@ -10,32 +10,41 @@ #include "tasks/Task.h" -/** Very simple task that just loads a folder's contents directly. +/** Very simple task that just loads a folder's contents directly. */ -class BasicFolderLoadTask : public Task -{ +class BasicFolderLoadTask : public Task { Q_OBJECT -public: + public: struct Result { QMap resources; }; using ResultPtr = std::shared_ptr; - [[nodiscard]] ResultPtr result() const { - return m_result; - } + [[nodiscard]] ResultPtr result() const { return m_result; } -public: - BasicFolderLoadTask(QDir dir) : Task(nullptr, false), m_dir(dir), m_result(new Result) {} + public: + BasicFolderLoadTask(QDir dir) : Task(nullptr, false), m_dir(dir), m_result(new Result) + { + m_create_func = [](QFileInfo const& entry) -> Resource* { + return new Resource(entry); + }; + } + BasicFolderLoadTask(QDir dir, std::function create_function) + : Task(nullptr, false), m_dir(dir), m_result(new Result), m_create_func(std::move(create_function)) + {} [[nodiscard]] bool canAbort() const override { return true; } - bool abort() override { m_aborted = true; return true; } + bool abort() override + { + m_aborted = true; + return true; + } void executeTask() override { m_dir.refresh(); for (auto entry : m_dir.entryInfoList()) { - auto resource = new Resource(entry); + auto resource = m_create_func(entry); m_result->resources.insert(resource->internal_id(), resource); } @@ -50,4 +59,6 @@ private: ResultPtr m_result; bool m_aborted = false; + + std::function m_create_func; };