Add more null protection for skin management
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
bee59c904a
commit
d38e7fa142
@ -336,7 +336,11 @@ void SkinList::save()
|
|||||||
arr << s.toJSON();
|
arr << s.toJSON();
|
||||||
}
|
}
|
||||||
doc["skins"] = arr;
|
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()
|
int SkinList::getSelectedAccountSkin()
|
||||||
|
@ -41,7 +41,7 @@ SkinModel::SkinModel(QDir skinDir, QJsonObject obj)
|
|||||||
|
|
||||||
QString SkinModel::name() const
|
QString SkinModel::name() const
|
||||||
{
|
{
|
||||||
return QFileInfo(m_path).baseName();
|
return QFileInfo(m_path).completeBaseName();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SkinModel::rename(QString newName)
|
bool SkinModel::rename(QString newName)
|
||||||
|
@ -116,7 +116,7 @@ void SkinManageDialog::selectionChanged(QItemSelection selected, QItemSelection
|
|||||||
return;
|
return;
|
||||||
m_selected_skin = key;
|
m_selected_skin = key;
|
||||||
auto skin = m_list.skin(key);
|
auto skin = m_list.skin(key);
|
||||||
if (!skin)
|
if (!skin || !skin->isValid())
|
||||||
return;
|
return;
|
||||||
ui->selectedModel->setPixmap(skin->getTexture().scaled(size() * (1. / 3), Qt::KeepAspectRatio, Qt::FastTransformation));
|
ui->selectedModel->setPixmap(skin->getTexture().scaled(size() * (1. / 3), Qt::KeepAspectRatio, Qt::FastTransformation));
|
||||||
ui->capeCombo->setCurrentIndex(m_capes_idx.value(skin->getCapeId()));
|
ui->capeCombo->setCurrentIndex(m_capes_idx.value(skin->getCapeId()));
|
||||||
@ -212,7 +212,10 @@ void SkinManageDialog::setupCapes()
|
|||||||
void SkinManageDialog::on_capeCombo_currentIndexChanged(int index)
|
void SkinManageDialog::on_capeCombo_currentIndexChanged(int index)
|
||||||
{
|
{
|
||||||
auto id = ui->capeCombo->currentData();
|
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) {
|
if (auto skin = m_list.skin(m_selected_skin); skin) {
|
||||||
skin->setCapeId(id.toString());
|
skin->setCapeId(id.toString());
|
||||||
}
|
}
|
||||||
@ -505,8 +508,13 @@ void SkinManageDialog::resizeEvent(QResizeEvent* event)
|
|||||||
QSize s = size() * (1. / 3);
|
QSize s = size() * (1. / 3);
|
||||||
|
|
||||||
if (auto skin = m_list.skin(m_selected_skin); skin) {
|
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();
|
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));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user