Save icon to instance's folder is needed
| 98 | |
| 99 | /// Save icon to instance's folder is needed |
| 100 | void SaveIcon(InstancePtr m_instance) |
| 101 | { |
| 102 | auto iconKey = m_instance->iconKey(); |
| 103 | auto iconList = APPLICATION->icons(); |
| 104 | auto mmcIcon = iconList->icon(iconKey); |
| 105 | if (!mmcIcon || mmcIcon->isBuiltIn()) { |
| 106 | return; |
| 107 | } |
| 108 | auto path = mmcIcon->getFilePath(); |
| 109 | if (!path.isNull()) { |
| 110 | QFileInfo inInfo(path); |
| 111 | FS::copy(path, FS::PathCombine(m_instance->instanceRoot(), inInfo.fileName()))(); |
| 112 | return; |
| 113 | } |
| 114 | auto& image = mmcIcon->m_images[mmcIcon->type()]; |
| 115 | auto& icon = image.icon; |
| 116 | auto sizes = icon.availableSizes(); |
| 117 | if (sizes.size() == 0) { |
| 118 | return; |
| 119 | } |
| 120 | auto areaOf = [](QSize size) { return size.width() * size.height(); }; |
| 121 | QSize largest = sizes[0]; |
| 122 | // find variant with largest area |
| 123 | for (auto size : sizes) { |
| 124 | if (areaOf(largest) < areaOf(size)) { |
| 125 | largest = size; |
| 126 | } |
| 127 | } |
| 128 | auto pixmap = icon.pixmap(largest); |
| 129 | pixmap.save(FS::PathCombine(m_instance->instanceRoot(), iconKey + ".png")); |
| 130 | } |
| 131 | |
| 132 | void ExportInstanceDialog::doExport() |
| 133 | { |
no test coverage detected