do not update the metadata if mod is invalid

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2023-08-26 23:36:46 +03:00
parent d25e89a4c1
commit a2d44744fe
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318

View File

@ -156,29 +156,38 @@ void V1::updateModIndex(QDir& index_dir, Mod& mod)
FS::ensureFilePathExists(index_file.fileName()); FS::ensureFilePathExists(index_file.fileName());
} }
toml::table update;
switch (mod.provider) {
case (ModPlatform::ResourceProvider::FLAME):
if (mod.file_id.toInt() == 0 || mod.project_id.toInt() == 0) {
qCritical() << QString("Did not write file %1 because missing information!").arg(normalized_fname);
return;
}
update = toml::table{
{ "file-id", mod.file_id.toInt() },
{ "project-id", mod.project_id.toInt() },
};
break;
case (ModPlatform::ResourceProvider::MODRINTH):
if (mod.mod_id().toString().isEmpty() || mod.version().toString().isEmpty()) {
qCritical() << QString("Did not write file %1 because missing information!").arg(normalized_fname);
return;
}
update = toml::table{
{ "mod-id", mod.mod_id().toString().toStdString() },
{ "version", mod.version().toString().toStdString() },
};
break;
}
if (!index_file.open(QIODevice::ReadWrite)) { if (!index_file.open(QIODevice::ReadWrite)) {
qCritical() << QString("Could not open file %1!").arg(indexFileName(mod.name)); qCritical() << QString("Could not open file %1!").arg(normalized_fname);
return; return;
} }
// Put TOML data into the file // Put TOML data into the file
QTextStream in_stream(&index_file); QTextStream in_stream(&index_file);
{ {
toml::table update;
switch (mod.provider) {
case (ModPlatform::ResourceProvider::FLAME):
update = toml::table{
{ "file-id", mod.file_id.toInt() },
{ "project-id", mod.project_id.toInt() },
};
break;
case (ModPlatform::ResourceProvider::MODRINTH):
update = toml::table{
{ "mod-id", mod.mod_id().toString().toStdString() },
{ "version", mod.version().toString().toStdString() },
};
break;
}
auto tbl = toml::table{ { "name", mod.name.toStdString() }, auto tbl = toml::table{ { "name", mod.name.toStdString() },
{ "filename", mod.filename.toStdString() }, { "filename", mod.filename.toStdString() },
{ "side", mod.side.toStdString() }, { "side", mod.side.toStdString() },