feat: allow disabling mod metadata usage

This commit is contained in:
flow
2022-04-17 10:19:23 -03:00
committed by flow
parent 23febc6d94
commit 4439666e67
8 changed files with 107 additions and 40 deletions

View File

@ -124,7 +124,11 @@ bool Mod::enable(bool value)
bool Mod::destroy(QDir& index_dir)
{
Metadata::remove(index_dir, m_name);
auto n = name();
// FIXME: This can fail to remove the metadata if the
// "DontUseModMetadata" setting is on, since there could
// be a name mismatch!
Metadata::remove(index_dir, n);
m_type = MOD_UNKNOWN;
return FS::deletePath(m_file.filePath());

View File

@ -2,6 +2,7 @@
#include <toml.h>
#include "Application.h"
#include "FileSystem.h"
#include "minecraft/mod/MetadataHandler.h"
@ -18,6 +19,11 @@ void LocalModUpdateTask::executeTask()
{
setStatus(tr("Updating index for mod:\n%1").arg(m_mod.name));
if(APPLICATION->settings()->get("DontUseModMetadata").toBool()){
emitSucceeded();
return;
}
auto pw_mod = Metadata::create(m_index_dir, m_mod, m_mod_version);
Metadata::update(m_index_dir, pw_mod);

View File

@ -1,6 +1,7 @@
#include "ModFolderLoadTask.h"
#include <QDebug>
#include "Application.h"
#include "minecraft/mod/MetadataHandler.h"
ModFolderLoadTask::ModFolderLoadTask(QDir& mods_dir, QDir& index_dir)
@ -9,16 +10,9 @@ ModFolderLoadTask::ModFolderLoadTask(QDir& mods_dir, QDir& index_dir)
void ModFolderLoadTask::run()
{
// Read metadata first
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;
if (!APPLICATION->settings()->get("DontUseModMetadata").toBool()) {
// Read metadata first
getFromMetadata();
}
// Read JAR files that don't have metadata
@ -31,3 +25,17 @@ void ModFolderLoadTask::run()
emit succeeded();
}
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;
}
}

View File

@ -24,6 +24,10 @@ public:
void run();
signals:
void succeeded();
private:
void getFromMetadata();
private:
QDir& m_mods_dir, m_index_dir;
ResultPtr m_result;