MCPcopy Create free account
hub / github.com/FreesmTeam/FreesmLauncher / SaveIcon

Function SaveIcon

launcher/ui/dialogs/ExportInstanceDialog.cpp:100–130  ·  view source on GitHub ↗

Save icon to instance's folder is needed

Source from the content-addressed store, hash-verified

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

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