Add more null protection for skin management

Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
Trial97 2024-09-16 12:41:33 +03:00
parent bee59c904a
commit d38e7fa142
No known key found for this signature in database
GPG Key ID: 55EF5DA53DB36318
3 changed files with 18 additions and 6 deletions

View File

@ -336,7 +336,11 @@ void SkinList::save()
arr << s.toJSON();
}
doc["skins"] = arr;
Json::write(doc, m_dir.absoluteFilePath("index.json"));
try {
Json::write(doc, m_dir.absoluteFilePath("index.json"));
} catch (const FS::FileSystemException& e) {
qCritical() << "Failed to write skin index file :" << e.cause();
}
}
int SkinList::getSelectedAccountSkin()

View File

@ -41,7 +41,7 @@ SkinModel::SkinModel(QDir skinDir, QJsonObject obj)
QString SkinModel::name() const
{
return QFileInfo(m_path).baseName();
return QFileInfo(m_path).completeBaseName();
}
bool SkinModel::rename(QString newName)

View File

@ -116,7 +116,7 @@ void SkinManageDialog::selectionChanged(QItemSelection selected, QItemSelection
return;
m_selected_skin = key;
auto skin = m_list.skin(key);
if (!skin)
if (!skin || !skin->isValid())
return;
ui->selectedModel->setPixmap(skin->getTexture().scaled(size() * (1. / 3), Qt::KeepAspectRatio, Qt::FastTransformation));
ui->capeCombo->setCurrentIndex(m_capes_idx.value(skin->getCapeId()));
@ -212,7 +212,10 @@ void SkinManageDialog::setupCapes()
void SkinManageDialog::on_capeCombo_currentIndexChanged(int index)
{
auto id = ui->capeCombo->currentData();
ui->capeImage->setPixmap(m_capes.value(id.toString(), {}).scaled(size() * (1. / 3), Qt::KeepAspectRatio, Qt::FastTransformation));
auto cape = m_capes.value(id.toString(), {});
if (!cape.isNull()) {
ui->capeImage->setPixmap(cape.scaled(size() * (1. / 3), Qt::KeepAspectRatio, Qt::FastTransformation));
}
if (auto skin = m_list.skin(m_selected_skin); skin) {
skin->setCapeId(id.toString());
}
@ -505,8 +508,13 @@ void SkinManageDialog::resizeEvent(QResizeEvent* event)
QSize s = size() * (1. / 3);
if (auto skin = m_list.skin(m_selected_skin); skin) {
ui->selectedModel->setPixmap(skin->getTexture().scaled(s, Qt::KeepAspectRatio, Qt::FastTransformation));
if (skin->isValid()) {
ui->selectedModel->setPixmap(skin->getTexture().scaled(s, Qt::KeepAspectRatio, Qt::FastTransformation));
}
}
auto id = ui->capeCombo->currentData();
ui->capeImage->setPixmap(m_capes.value(id.toString(), {}).scaled(s, Qt::KeepAspectRatio, Qt::FastTransformation));
auto cape = m_capes.value(id.toString(), {});
if (!cape.isNull()) {
ui->capeImage->setPixmap(cape.scaled(s, Qt::KeepAspectRatio, Qt::FastTransformation));
}
}