2019-08-04 02:27:53 +01:00
|
|
|
#include "ModFolderLoadTask.h"
|
|
|
|
#include <QDebug>
|
|
|
|
|
2022-04-17 14:19:23 +01:00
|
|
|
#include "Application.h"
|
2022-04-16 17:27:29 +01:00
|
|
|
#include "minecraft/mod/MetadataHandler.h"
|
2022-04-15 04:24:57 +01:00
|
|
|
|
2022-04-16 02:07:35 +01:00
|
|
|
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 02:27:53 +01:00
|
|
|
|
|
|
|
void ModFolderLoadTask::run()
|
|
|
|
{
|
2022-04-17 14:19:23 +01:00
|
|
|
if (!APPLICATION->settings()->get("DontUseModMetadata").toBool()) {
|
|
|
|
// Read metadata first
|
|
|
|
getFromMetadata();
|
2022-04-15 04:24:57 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Read JAR files that don't have metadata
|
|
|
|
m_mods_dir.refresh();
|
2022-04-16 02:07:35 +01:00
|
|
|
for (auto entry : m_mods_dir.entryInfoList()) {
|
2022-04-15 04:24:57 +01:00
|
|
|
Mod mod(entry);
|
2022-04-16 02:07:35 +01:00
|
|
|
if (!m_result->mods.contains(mod.internal_id()))
|
|
|
|
m_result->mods[mod.internal_id()] = mod;
|
2019-08-04 02:27:53 +01:00
|
|
|
}
|
2022-04-15 04:24:57 +01:00
|
|
|
|
2019-08-04 02:27:53 +01:00
|
|
|
emit succeeded();
|
|
|
|
}
|
2022-04-17 14:19:23 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-04-17 15:40:41 +01:00
|
|
|
auto metadata = Metadata::get(m_index_dir, entry);
|
|
|
|
// TODO: Don't simply return. Instead, show to the user that the metadata is there, but
|
|
|
|
// it's not currently 'installed' (i.e. there's no JAR file yet).
|
|
|
|
if(!metadata.isValid()){
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
Mod mod(m_mods_dir, metadata);
|
2022-04-17 14:19:23 +01:00
|
|
|
m_result->mods[mod.internal_id()] = mod;
|
|
|
|
}
|
|
|
|
}
|