Added resource packs to export
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
b774817ada
commit
9804996db6
@ -109,25 +109,42 @@ void FlamePackExportTask::collectHashes()
|
|||||||
auto mods = mcInstance->loaderModList()->allMods();
|
auto mods = mcInstance->loaderModList()->allMods();
|
||||||
ConcurrentTask::Ptr hashing_task(new ConcurrentTask(this, "MakeHashesTask", 10));
|
ConcurrentTask::Ptr hashing_task(new ConcurrentTask(this, "MakeHashesTask", 10));
|
||||||
task.reset(hashing_task);
|
task.reset(hashing_task);
|
||||||
setProgress(0, mods.count());
|
int totalProgres = mods.count();
|
||||||
|
setProgress(0, totalProgres);
|
||||||
for (auto* mod : mods) {
|
for (auto* mod : mods) {
|
||||||
if (!mod || mod->type() == ResourceType::FOLDER) {
|
if (!mod || mod->type() == ResourceType::FOLDER) {
|
||||||
setProgress(m_progress + 1, mods.count());
|
setProgress(m_progress + 1, totalProgres);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (mod->metadata() && mod->metadata()->provider == ModPlatform::ResourceProvider::FLAME) {
|
if (mod->metadata() && mod->metadata()->provider == ModPlatform::ResourceProvider::FLAME) {
|
||||||
resolvedFiles.insert(mod->fileinfo().absoluteFilePath(),
|
resolvedFiles.insert(mod->fileinfo().absoluteFilePath(),
|
||||||
{ mod->metadata()->project_id.toInt(), mod->metadata()->file_id.toInt(), mod->enabled(),
|
{ mod->metadata()->project_id.toInt(), mod->metadata()->file_id.toInt(), mod->enabled(),
|
||||||
mod->metadata()->name, mod->metadata()->slug, mod->authors().join(", ") });
|
mod->metadata()->name, mod->metadata()->slug, mod->authors().join(", ") });
|
||||||
setProgress(m_progress + 1, mods.count());
|
setProgress(m_progress + 1, totalProgres);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
auto hash_task = Hashing::createFlameHasher(mod->fileinfo().absoluteFilePath());
|
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) {
|
if (m_state == Task::State::Running) {
|
||||||
setProgress(m_progress + 1, mods.count());
|
setProgress(m_progress + 1, totalProgres);
|
||||||
pendingHashes.insert(hash, mod);
|
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);
|
connect(hash_task.get(), &Task::failed, this, &FlamePackExportTask::emitFailed);
|
||||||
@ -196,11 +213,10 @@ void FlamePackExportTask::makeApiRequest()
|
|||||||
continue;
|
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"))
|
if (Json::ensureBoolean(file_obj, "isAvailable", false, "isAvailable"))
|
||||||
resolvedFiles.insert(
|
resolvedFiles.insert(mod->path,
|
||||||
mod.value()->fileinfo().absoluteFilePath(),
|
{ Json::requireInteger(file_obj, "modId"), Json::requireInteger(file_obj, "id"), mod->enabled });
|
||||||
{ Json::requireInteger(file_obj, "modId"), Json::requireInteger(file_obj, "id"), mod.value()->enabled() });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (Json::JsonException& e) {
|
} catch (Json::JsonException& e) {
|
||||||
|
@ -62,11 +62,16 @@ class FlamePackExportTask : public Task {
|
|||||||
QString slug;
|
QString slug;
|
||||||
QString authors;
|
QString authors;
|
||||||
};
|
};
|
||||||
|
struct HashInfo {
|
||||||
|
QString name;
|
||||||
|
QString path;
|
||||||
|
bool enabled;
|
||||||
|
};
|
||||||
|
|
||||||
FlameAPI api;
|
FlameAPI api;
|
||||||
|
|
||||||
QFileInfoList files;
|
QFileInfoList files;
|
||||||
QMap<QString, Mod*> pendingHashes{};
|
QMap<QString, HashInfo> pendingHashes{};
|
||||||
QMap<QString, ResolvedFile> resolvedFiles{};
|
QMap<QString, ResolvedFile> resolvedFiles{};
|
||||||
Task::Ptr task;
|
Task::Ptr task;
|
||||||
QFuture<BuildZipResult> buildZipFuture;
|
QFuture<BuildZipResult> buildZipFuture;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user