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