From 405cea177877234981019c6916f6f97d818dfd51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 1 Jun 2015 01:19:12 +0200 Subject: GH-1031 include icon in exported instance if it is custom --- application/MainWindow.cpp | 23 +++++++++++-- application/dialogs/ExportInstanceDialog.cpp | 49 ++++++++++++++++++++++++++++ application/dialogs/NewInstanceDialog.cpp | 2 +- application/dialogs/NewInstanceDialog.ui | 4 --- 4 files changed, 71 insertions(+), 7 deletions(-) (limited to 'application') diff --git a/application/MainWindow.cpp b/application/MainWindow.cpp index 6c5aa3af..9ff120bd 100644 --- a/application/MainWindow.cpp +++ b/application/MainWindow.cpp @@ -1137,7 +1137,27 @@ void MainWindow::instanceFromZipPack(QString instName, QString instGroup, QStrin } newInstance->setName(instName); - newInstance->setIconKey(instIcon); + if(instIcon != "default") + { + newInstance->setIconKey(instIcon); + } + else + { + instIcon = newInstance->iconKey(); + auto importIconPath = PathCombine(newInstance->instanceRoot(), instIcon + ".png"); + if (QFile::exists(importIconPath)) + { + // import icon + auto iconList = ENV.icons(); + // FIXME: check if the file is OK before removing the existing one... + if(iconList->iconFileExists(instIcon)) + { + //FIXME: ask if icon should be overwritten. Show difference in the question dialog. + iconList->deleteIcon(instIcon); + } + iconList->installIcons({importIconPath}); + } + } newInstance->setGroupInitial(instGroup); MMC->instances()->add(InstancePtr(newInstance)); MMC->instances()->saveGroupList(); @@ -1225,7 +1245,6 @@ void MainWindow::on_actionAddInstance_triggered() const QUrl modpackUrl = newInstDlg.modpackUrl(); - if (modpackUrl.isValid()) { instanceFromZipPack(newInstDlg.instName(), newInstDlg.instGroup(), newInstDlg.iconKey(), modpackUrl); diff --git a/application/dialogs/ExportInstanceDialog.cpp b/application/dialogs/ExportInstanceDialog.cpp index 5d24c54b..ec376b1d 100644 --- a/application/dialogs/ExportInstanceDialog.cpp +++ b/application/dialogs/ExportInstanceDialog.cpp @@ -28,6 +28,8 @@ #include #include "MMCStrings.h" #include "SeparatorPrefixTree.h" +#include "Env.h" +#include class PackIgnoreProxy : public QSortFilterProxyModel { @@ -333,6 +335,51 @@ ExportInstanceDialog::~ExportInstanceDialog() delete ui; } +/// Save icon to instance's folder is needed +void SaveIcon(InstancePtr m_instance) +{ + auto iconKey = m_instance->iconKey(); + auto iconList = ENV.icons(); + auto mmcIcon = iconList->icon(iconKey); + if(mmcIcon) + { + bool saveIcon = false; + switch(mmcIcon->type()) + { + case MMCIcon::FileBased: + case MMCIcon::Transient: + saveIcon = true; + default: + break; + } + if(saveIcon) + { + auto & image = mmcIcon->m_images[mmcIcon->type()]; + auto & icon = image.icon; + auto sizes = icon.availableSizes(); + if(sizes.size() == 0) + { + return; + } + auto areaOf = [](QSize size) + { + return size.width() * size.height(); + }; + QSize largest = sizes[0]; + // find variant with largest area + for(auto size: sizes) + { + if(areaOf(largest) < areaOf(size)) + { + largest = size; + } + } + auto pixmap = icon.pixmap(largest); + pixmap.save(PathCombine(m_instance->instanceRoot(), iconKey + ".png")); + } + } +} + bool ExportInstanceDialog::doExport() { auto name = RemoveInvalidFilenameChars(m_instance->name()); @@ -356,6 +403,8 @@ bool ExportInstanceDialog::doExport() } } + SaveIcon(m_instance); + if (!MMCZip::compressDir(output, m_instance->instanceRoot(), name, &proxyModel->blockedPaths())) { QMessageBox::warning(this, tr("Error"), tr("Unable to export instance")); diff --git a/application/dialogs/NewInstanceDialog.cpp b/application/dialogs/NewInstanceDialog.cpp index d67d3ada..6cd651e4 100644 --- a/application/dialogs/NewInstanceDialog.cpp +++ b/application/dialogs/NewInstanceDialog.cpp @@ -65,7 +65,7 @@ NewInstanceDialog::NewInstanceDialog(QWidget *parent) layout()->setSizeConstraint(QLayout::SetFixedSize); setSelectedVersion(MMC->minecraftlist()->getRecommended(), true); - InstIconKey = "infinity"; + InstIconKey = "default"; ui->iconButton->setIcon(ENV.icons()->getIcon(InstIconKey)); ui->modpackEdit->setValidator(new UrlValidator(ui->modpackEdit)); diff --git a/application/dialogs/NewInstanceDialog.ui b/application/dialogs/NewInstanceDialog.ui index 6cb0c97c..58a87354 100644 --- a/application/dialogs/NewInstanceDialog.ui +++ b/application/dialogs/NewInstanceDialog.ui @@ -41,10 +41,6 @@ - - - :/icons/instances/infinity:/icons/instances/infinity - 80 -- cgit v1.2.3