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

Function SaveIcon

launcher/ui/dialogs/ExportInstanceDialog.cpp:341–377  ·  view source on GitHub ↗

Save icon to instance's folder is needed

Source from the content-addressed store, hash-verified

339
340/// Save icon to instance's folder is needed
341void SaveIcon(InstancePtr m_instance)
342{
343 auto iconKey = m_instance->iconKey();
344 auto iconList = APPLICATION->icons();
345 auto mmcIcon = iconList->icon(iconKey);
346 if(!mmcIcon || mmcIcon->isBuiltIn()) {
347 return;
348 }
349 auto path = mmcIcon->getFilePath();
350 if(!path.isNull()) {
351 QFileInfo inInfo (path);
352 FS::copy(path, FS::PathCombine(m_instance->instanceRoot(), inInfo.fileName())) ();
353 return;
354 }
355 auto & image = mmcIcon->m_images[mmcIcon->type()];
356 auto & icon = image.icon;
357 auto sizes = icon.availableSizes();
358 if(sizes.size() == 0)
359 {
360 return;
361 }
362 auto areaOf = [](QSize size)
363 {
364 return size.width() * size.height();
365 };
366 QSize largest = sizes[0];
367 // find variant with largest area
368 for(auto size: sizes)
369 {
370 if(areaOf(largest) < areaOf(size))
371 {
372 largest = size;
373 }
374 }
375 auto pixmap = icon.pixmap(largest);
376 pixmap.save(FS::PathCombine(m_instance->instanceRoot(), iconKey + ".png"));
377}
378
379bool ExportInstanceDialog::doExport()
380{

Callers 1

doExportMethod · 0.85

Calls 12

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

Tested by

no test coverage detected