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-21 03:15:39 +05:30
|
|
|
if(m_result->mods.contains(mod.internal_id())){
|
|
|
|
m_result->mods[mod.internal_id()].setStatus(ModStatus::Installed);
|
|
|
|
}
|
|
|
|
else {
|
2022-04-16 06:37:35 +05:30
|
|
|
m_result->mods[mod.internal_id()] = mod;
|
2022-04-21 03:15:39 +05:30
|
|
|
m_result->mods[mod.internal_id()].setStatus(ModStatus::NoMetadata);
|
|
|
|
}
|
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;
|
|
|
|
|
2022-04-17 20:10:41 +05:30
|
|
|
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-21 03:15:39 +05:30
|
|
|
mod.setStatus(ModStatus::NotInstalled);
|
2022-04-17 18:49:23 +05:30
|
|
|
m_result->mods[mod.internal_id()] = mod;
|
|
|
|
}
|
|
|
|
}
|