fix: don't try to delete mods multiple times

Shows a more helpful message if there's a parsing error when reading the
index file.

Also fixes a clazy warning with using the `.data()` method in a
temporary QByteArray object.
This commit is contained in:
flow 2022-04-21 15:47:46 -03:00 committed by flow
parent e17b6804a7
commit 67e0214fa5
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
2 changed files with 7 additions and 2 deletions

View File

@ -339,6 +339,9 @@ bool ModFolderModel::deleteMods(const QModelIndexList& indexes)
for (auto i: indexes) for (auto i: indexes)
{ {
if(i.column() != 0) {
continue;
}
Mod &m = mods[i.row()]; Mod &m = mods[i.row()];
auto index_dir = indexDir(); auto index_dir = indexDir();
m.destroy(index_dir); m.destroy(index_dir);

View File

@ -162,12 +162,14 @@ auto V1::getIndexForMod(QDir& index_dir, QString& index_file_name) -> Mod
// NOLINTNEXTLINE(modernize-avoid-c-arrays) // NOLINTNEXTLINE(modernize-avoid-c-arrays)
char errbuf[200]; char errbuf[200];
table = toml_parse(index_file.readAll().data(), errbuf, sizeof(errbuf)); auto file_bytearray = index_file.readAll();
table = toml_parse(file_bytearray.data(), errbuf, sizeof(errbuf));
index_file.close(); index_file.close();
if (!table) { if (!table) {
qCritical() << QString("Could not open file %1!").arg(indexFileName(mod.name)); qWarning() << QString("Could not open file %1!").arg(indexFileName(index_file_name));
qWarning() << "Reason: " << QString(errbuf);
return {}; return {};
} }