Merge pull request #2825 from Trial97/skin_fix

This commit is contained in:
timoreo 2024-09-17 08:50:19 +02:00 committed by GitHub
commit dc67807894
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 29 additions and 8 deletions

View File

@ -173,7 +173,11 @@ void InstanceCopyTask::copyFinished()
allowed_symlinks_file
.filePath()); // we dont want to modify the original. also make sure the resulting file is not itself a link.
FS::write(allowed_symlinks_file.filePath(), allowed_symlinks);
try {
FS::write(allowed_symlinks_file.filePath(), allowed_symlinks);
} catch (const FS::FileSystemException& e) {
qCritical() << "Failed to write symlink :" << e.cause();
}
}
emitSucceeded();

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

@ -164,7 +164,12 @@ void ExportToModListDialog::done(int result)
if (output.isEmpty())
return;
FS::write(output, ui->finalText->toPlainText().toUtf8());
try {
FS::write(output, ui->finalText->toPlainText().toUtf8());
} catch (const FS::FileSystemException& e) {
qCritical() << "Failed to save mod list file :" << e.cause();
}
}
QDialog::done(result);

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));
}
}