fix: improve handling of unrecognized pack formats

Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
flow 2022-09-03 15:05:23 -03:00
parent 43a7af3f44
commit bedd3c50b6
No known key found for this signature in database
GPG Key ID: 8D0F221F0A59F469
2 changed files with 9 additions and 9 deletions

View File

@ -23,8 +23,7 @@ void ResourcePack::setPackFormat(int new_format_id)
QMutexLocker locker(&m_data_lock);
if (!s_pack_format_versions.contains(new_format_id)) {
qCritical() << "Error: Pack format '%1' is not a recognized resource pack id.";
return;
qWarning() << "Pack format '%1' is not a recognized resource pack id!";
}
m_pack_format = new_format_id;
@ -71,10 +70,6 @@ QPixmap ResourcePack::image(QSize size)
std::pair<Version, Version> ResourcePack::compatibleVersions() const
{
if (!s_pack_format_versions.contains(m_pack_format)) {
// Not having a valid pack format is fine if we didn't yet parse the .mcmeta file,
// but if we did and we still don't have a valid pack format, that's a bit concerning.
Q_ASSERT(!isResolved());
return { {}, {} };
}

View File

@ -60,12 +60,17 @@ QVariant ResourcePackFolderModel::data(const QModelIndex& index, int role) const
case NameColumn:
return m_resources[row]->name();
case PackFormatColumn: {
auto version_bounds = at(row)->compatibleVersions();
auto resource = at(row);
auto pack_format = resource->packFormat();
if (pack_format == 0)
return tr("Unrecognized");
auto version_bounds = resource->compatibleVersions();
if (version_bounds.first.toString().isEmpty())
return QString::number(at(row)->packFormat());
return QString::number(pack_format);
return QString("%1 (%2 - %3)")
.arg(QString::number(at(row)->packFormat()), version_bounds.first.toString(), version_bounds.second.toString());
.arg(QString::number(pack_format), version_bounds.first.toString(), version_bounds.second.toString());
}
case DateColumn:
return m_resources[row]->dateTimeChanged();