feat: add metadata get/delete via mod id

This is, in many cases, more reliable than name comparisons, so it's
useful specially in cases where a mod changes name between versions

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow
2022-06-11 17:19:34 -03:00
parent 9a07ede615
commit 91a5c4bdcb
6 changed files with 57 additions and 12 deletions

View File

@ -52,8 +52,18 @@ class Metadata {
Packwiz::V1::deleteModIndex(index_dir, mod_name);
}
static void remove(QDir& index_dir, QVariant& mod_id)
{
Packwiz::V1::deleteModIndex(index_dir, mod_id);
}
static auto get(QDir& index_dir, QString& mod_name) -> ModStruct
{
return Packwiz::V1::getIndexForMod(index_dir, mod_name);
}
static auto get(QDir& index_dir, QVariant& mod_id) -> ModStruct
{
return Packwiz::V1::getIndexForMod(index_dir, mod_id);
}
};

View File

@ -164,12 +164,8 @@ void Mod::setMetadata(Metadata::ModStruct* metadata)
auto Mod::destroy(QDir& index_dir, bool preserve_metadata) -> bool
{
auto n = name();
// FIXME: This can fail to remove the metadata if the
// "ModMetadataDisabled" setting is on, since there could
// be a name mismatch!
if(!preserve_metadata)
Metadata::remove(index_dir, n);
if (!preserve_metadata && status() != ModStatus::NoMetadata)
Metadata::remove(index_dir, metadata()->mod_id());
m_type = MOD_UNKNOWN;
return FS::deletePath(m_file.filePath());

View File

@ -44,7 +44,7 @@ void LocalModUpdateTask::executeTask()
{
setStatus(tr("Updating index for mod:\n%1").arg(m_mod.name));
auto old_metadata = Metadata::get(m_index_dir, m_mod.name);
auto old_metadata = Metadata::get(m_index_dir, m_mod.addonId);
if (old_metadata.isValid()) {
emit hasOldMod(old_metadata.name, old_metadata.filename);
}