2019-08-04 06:57:53 +05:30
|
|
|
#include "ModFolderLoadTask.h"
|
|
|
|
#include <QDebug>
|
|
|
|
|
2022-04-17 18:49:23 +05:30
|
|
|
#include "Application.h"
|
2022-04-16 21:57:29 +05:30
|
|
|
#include "minecraft/mod/MetadataHandler.h"
|
2022-04-15 08:54:57 +05:30
|
|
|
|
2022-04-16 06:37:35 +05:30
|
|
|
ModFolderLoadTask::ModFolderLoadTask(QDir& mods_dir, QDir& index_dir)
|
|
|
|
: m_mods_dir(mods_dir), m_index_dir(index_dir), m_result(new Result())
|
|
|
|
{}
|
2019-08-04 06:57:53 +05:30
|
|
|
|
|
|
|
void ModFolderLoadTask::run()
|
|
|
|
{
|
2022-04-17 18:49:23 +05:30
|
|
|
if (!APPLICATION->settings()->get("DontUseModMetadata").toBool()) {
|
|
|
|
// Read metadata first
|
|
|
|
getFromMetadata();
|
2022-04-15 08:54:57 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
// Read JAR files that don't have metadata
|
|
|
|
m_mods_dir.refresh();
|
2022-04-16 06:37:35 +05:30
|
|
|
for (auto entry : m_mods_dir.entryInfoList()) {
|
2022-04-15 08:54:57 +05:30
|
|
|
Mod mod(entry);
|
2022-04-16 06:37:35 +05:30
|
|
|
if (!m_result->mods.contains(mod.internal_id()))
|
|
|
|
m_result->mods[mod.internal_id()] = mod;
|
2019-08-04 06:57:53 +05:30
|
|
|
}
|
2022-04-15 08:54:57 +05:30
|
|
|
|
2019-08-04 06:57:53 +05:30
|
|
|
emit succeeded();
|
|
|
|
}
|
2022-04-17 18:49:23 +05:30
|
|
|
|
|
|
|
void ModFolderLoadTask::getFromMetadata()
|
|
|
|
{
|
|
|
|
m_index_dir.refresh();
|
|
|
|
for (auto entry : m_index_dir.entryList()) {
|
|
|
|
// QDir::Filter::NoDotAndDotDot seems to exclude all files for some reason...
|
|
|
|
if (entry == "." || entry == "..")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
entry.chop(5); // Remove .toml at the end
|
|
|
|
Mod mod(m_mods_dir, Metadata::get(m_index_dir, entry));
|
|
|
|
m_result->mods[mod.internal_id()] = mod;
|
|
|
|
}
|
|
|
|
}
|