MCPcopy Create free account
hub / github.com/PolyMC/PolyMC / SaveIcon

Function SaveIcon

launcher/ui/dialogs/ExportInstanceDialog.cpp:361–397  ·  view source on GitHub ↗

Save icon to instance's folder is needed

Source from the content-addressed store, hash-verified

359
360/// Save icon to instance's folder is needed
361void SaveIcon(InstancePtr m_instance)
362{
363 auto iconKey = m_instance->iconKey();
364 auto iconList = APPLICATION->icons();
365 auto mmcIcon = iconList->icon(iconKey);
366 if(!mmcIcon || mmcIcon->isBuiltIn()) {
367 return;
368 }
369 auto path = mmcIcon->getFilePath();
370 if(!path.isNull()) {
371 QFileInfo inInfo (path);
372 FS::copy(path, FS::PathCombine(m_instance->instanceRoot(), inInfo.fileName())) ();
373 return;
374 }
375 auto & image = mmcIcon->m_images[mmcIcon->type()];
376 auto & icon = image.icon;
377 auto sizes = icon.availableSizes();
378 if(sizes.size() == 0)
379 {
380 return;
381 }
382 auto areaOf = [](QSize size)
383 {
384 return size.width() * size.height();
385 };
386 QSize largest = sizes[0];
387 // find variant with largest area
388 for(auto size: sizes)
389 {
390 if(areaOf(largest) < areaOf(size))
391 {
392 largest = size;
393 }
394 }
395 auto pixmap = icon.pixmap(largest);
396 pixmap.save(FS::PathCombine(m_instance->instanceRoot(), iconKey + ".png"));
397}
398
399bool ExportInstanceDialog::doExport()
400{

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