MCPcopy Create free account
hub / github.com/ElyPrismLauncher/Launcher / SaveIcon

Function SaveIcon

launcher/ui/dialogs/ExportInstanceDialog.cpp:101–131  ·  view source on GitHub ↗

Save icon to instance's folder is needed

Source from the content-addressed store, hash-verified

99
100/// Save icon to instance's folder is needed
101void 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
133void ExportInstanceDialog::doExport()
134{

Callers 1

doExportMethod · 0.85

Calls 11

copyClass · 0.85
PathCombineFunction · 0.85
iconsMethod · 0.80
isBuiltInMethod · 0.80
getFilePathMethod · 0.80
instanceRootMethod · 0.80
iconKeyMethod · 0.45
iconMethod · 0.45
typeMethod · 0.45
sizeMethod · 0.45
saveMethod · 0.45

Tested by

no test coverage detected