diff options
author | Trial97 <alexandru.tripon97@gmail.com> | 2023-06-24 14:37:02 +0300 |
---|---|---|
committer | Trial97 <alexandru.tripon97@gmail.com> | 2023-06-24 14:37:02 +0300 |
commit | 9804996db652eb719a0eb40c41157d0813372eb2 (patch) | |
tree | 4908cbc55765b04b2c30dbb05bd8f83009901ee7 /launcher/modplatform/flame | |
parent | b774817ada44d0dcb5d1fabbf5b45f52fc3bc6a1 (diff) | |
download | PrismLauncher-9804996db652eb719a0eb40c41157d0813372eb2.tar.gz PrismLauncher-9804996db652eb719a0eb40c41157d0813372eb2.tar.bz2 PrismLauncher-9804996db652eb719a0eb40c41157d0813372eb2.zip |
Added resource packs to export
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
Diffstat (limited to 'launcher/modplatform/flame')
-rw-r--r-- | launcher/modplatform/flame/FlamePackExportTask.cpp | 36 | ||||
-rw-r--r-- | launcher/modplatform/flame/FlamePackExportTask.h | 7 |
2 files changed, 32 insertions, 11 deletions
diff --git a/launcher/modplatform/flame/FlamePackExportTask.cpp b/launcher/modplatform/flame/FlamePackExportTask.cpp index 0d7abc9f..45fc2e63 100644 --- a/launcher/modplatform/flame/FlamePackExportTask.cpp +++ b/launcher/modplatform/flame/FlamePackExportTask.cpp @@ -109,25 +109,42 @@ void FlamePackExportTask::collectHashes() auto mods = mcInstance->loaderModList()->allMods(); ConcurrentTask::Ptr hashing_task(new ConcurrentTask(this, "MakeHashesTask", 10)); task.reset(hashing_task); - setProgress(0, mods.count()); + int totalProgres = mods.count(); + setProgress(0, totalProgres); for (auto* mod : mods) { if (!mod || mod->type() == ResourceType::FOLDER) { - setProgress(m_progress + 1, mods.count()); + setProgress(m_progress + 1, totalProgres); continue; } if (mod->metadata() && mod->metadata()->provider == ModPlatform::ResourceProvider::FLAME) { resolvedFiles.insert(mod->fileinfo().absoluteFilePath(), { mod->metadata()->project_id.toInt(), mod->metadata()->file_id.toInt(), mod->enabled(), mod->metadata()->name, mod->metadata()->slug, mod->authors().join(", ") }); - setProgress(m_progress + 1, mods.count()); + setProgress(m_progress + 1, totalProgres); continue; } auto hash_task = Hashing::createFlameHasher(mod->fileinfo().absoluteFilePath()); - connect(hash_task.get(), &Hashing::Hasher::resultsReady, [this, mod, mods](QString hash) { + connect(hash_task.get(), &Hashing::Hasher::resultsReady, [this, mod, totalProgres](QString hash) { if (m_state == Task::State::Running) { - setProgress(m_progress + 1, mods.count()); - pendingHashes.insert(hash, mod); + setProgress(m_progress + 1, totalProgres); + pendingHashes.insert(hash, { mod->name(), mod->fileinfo().absoluteFilePath(), mod->enabled() }); + } + }); + connect(hash_task.get(), &Task::failed, this, &FlamePackExportTask::emitFailed); + hashing_task->addTask(hash_task); + } + + for (const QFileInfo& file : files) { + const QString relative = gameRoot.relativeFilePath(file.absoluteFilePath()); + if (!relative.endsWith(".zip") || !relative.startsWith("resourcepacks/")) + continue; + totalProgres++; + auto hash_task = Hashing::createFlameHasher(file.absoluteFilePath()); + connect(hash_task.get(), &Hashing::Hasher::resultsReady, [this, relative, file, totalProgres](QString hash) { + if (m_state == Task::State::Running) { + setProgress(m_progress + 1, totalProgres); + pendingHashes.insert(hash, { relative, file.absoluteFilePath(), true }); } }); connect(hash_task.get(), &Task::failed, this, &FlamePackExportTask::emitFailed); @@ -196,11 +213,10 @@ void FlamePackExportTask::makeApiRequest() continue; } - setStatus(tr("Parsing API response from CurseForge for '%1'...").arg((*mod)->name())); + setStatus(tr("Parsing API response from CurseForge for '%1'...").arg(mod->name)); if (Json::ensureBoolean(file_obj, "isAvailable", false, "isAvailable")) - resolvedFiles.insert( - mod.value()->fileinfo().absoluteFilePath(), - { Json::requireInteger(file_obj, "modId"), Json::requireInteger(file_obj, "id"), mod.value()->enabled() }); + resolvedFiles.insert(mod->path, + { Json::requireInteger(file_obj, "modId"), Json::requireInteger(file_obj, "id"), mod->enabled }); } } catch (Json::JsonException& e) { diff --git a/launcher/modplatform/flame/FlamePackExportTask.h b/launcher/modplatform/flame/FlamePackExportTask.h index 9ec9a230..629493d8 100644 --- a/launcher/modplatform/flame/FlamePackExportTask.h +++ b/launcher/modplatform/flame/FlamePackExportTask.h @@ -62,11 +62,16 @@ class FlamePackExportTask : public Task { QString slug; QString authors; }; + struct HashInfo { + QString name; + QString path; + bool enabled; + }; FlameAPI api; QFileInfoList files; - QMap<QString, Mod*> pendingHashes{}; + QMap<QString, HashInfo> pendingHashes{}; QMap<QString, ResolvedFile> resolvedFiles{}; Task::Ptr task; QFuture<BuildZipResult> buildZipFuture; |