2022-04-13 23:16:36 +01:00
|
|
|
#include "LocalModUpdateTask.h"
|
|
|
|
|
|
|
|
#include <toml.h>
|
|
|
|
|
2022-04-17 14:19:23 +01:00
|
|
|
#include "Application.h"
|
2022-04-13 23:16:36 +01:00
|
|
|
#include "FileSystem.h"
|
2022-04-16 17:27:29 +01:00
|
|
|
#include "minecraft/mod/MetadataHandler.h"
|
2022-04-13 23:16:36 +01:00
|
|
|
|
2022-04-15 02:02:41 +01:00
|
|
|
LocalModUpdateTask::LocalModUpdateTask(QDir index_dir, ModPlatform::IndexedPack& mod, ModPlatform::IndexedVersion& mod_version)
|
|
|
|
: m_index_dir(index_dir), m_mod(mod), m_mod_version(mod_version)
|
2022-04-13 23:16:36 +01:00
|
|
|
{
|
|
|
|
// Ensure a '.index' folder exists in the mods folder, and create it if it does not
|
2022-04-15 02:02:41 +01:00
|
|
|
if (!FS::ensureFolderPathExists(index_dir.path())) {
|
2022-04-13 23:16:36 +01:00
|
|
|
emitFailed(QString("Unable to create index for mod %1!").arg(m_mod.name));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void LocalModUpdateTask::executeTask()
|
|
|
|
{
|
|
|
|
setStatus(tr("Updating index for mod:\n%1").arg(m_mod.name));
|
|
|
|
|
2022-04-17 14:19:23 +01:00
|
|
|
if(APPLICATION->settings()->get("DontUseModMetadata").toBool()){
|
|
|
|
emitSucceeded();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2022-04-16 17:27:29 +01:00
|
|
|
auto pw_mod = Metadata::create(m_index_dir, m_mod, m_mod_version);
|
|
|
|
Metadata::update(m_index_dir, pw_mod);
|
2022-04-13 23:16:36 +01:00
|
|
|
|
|
|
|
emitSucceeded();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool LocalModUpdateTask::abort()
|
|
|
|
{
|
|
|
|
emitAborted();
|
|
|
|
return true;
|
|
|
|
}
|