feat: use mod metadata for getting mod information

For now this doesn't mean much, but it will help when we need data
exclusive from the metadata, such as addon id and mod provider.

Also removes the metadata when the mod is deleted, and make the Mod.h
file a little more pleasing to look at :)
This commit is contained in:
flow 2022-04-15 00:24:57 -03:00 committed by flow
parent e93b9560b5
commit fcfb2cfc3d
No known key found for this signature in database
GPG key ID: 8D0F221F0A59F469
5 changed files with 90 additions and 60 deletions

View file

@ -1,18 +1,35 @@
#include "ModFolderLoadTask.h"
#include <QDebug>
ModFolderLoadTask::ModFolderLoadTask(QDir dir) :
m_dir(dir), m_result(new Result())
#include "modplatform/packwiz/Packwiz.h"
ModFolderLoadTask::ModFolderLoadTask(QDir& mods_dir, QDir& index_dir) :
m_mods_dir(mods_dir), m_index_dir(index_dir), m_result(new Result())
{
}
void ModFolderLoadTask::run()
{
m_dir.refresh();
for (auto entry : m_dir.entryInfoList())
{
Mod m(entry);
m_result->mods[m.mmc_id()] = m;
// 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, Packwiz::getIndexForMod(m_index_dir, entry));
m_result->mods[mod.mmc_id()] = mod;
}
// Read JAR files that don't have metadata
m_mods_dir.refresh();
for (auto entry : m_mods_dir.entryInfoList())
{
Mod mod(entry);
if(!m_result->mods.contains(mod.mmc_id()))
m_result->mods[mod.mmc_id()] = mod;
}
emit succeeded();
}