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

Method update

launcher/minecraft/skins/SkinList.cpp:68–150  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

66}
67
68bool SkinList::update()
69{
70 QVector<SkinModel> newSkins;
71 m_dir.refresh();
72
73 auto manifestInfo = QFileInfo(m_dir.absoluteFilePath("index.json"));
74 if (manifestInfo.exists()) {
75 try {
76 auto doc = Json::requireDocument(manifestInfo.absoluteFilePath(), "SkinList JSON file");
77 const auto root = doc.object();
78 auto skins = Json::ensureArray(root, "skins");
79 for (auto jSkin : skins) {
80 SkinModel s(m_dir, Json::ensureObject(jSkin));
81 if (s.isValid()) {
82 newSkins << s;
83 }
84 }
85 } catch (const Exception& e) {
86 qCritical() << "Couldn't load skins json:" << e.cause();
87 }
88 }
89
90 bool needsSave = false;
91 const auto& skin = m_acct->accountData()->minecraftProfile.skin;
92 if (!skin.url.isEmpty() && !skin.data.isEmpty()) {
93 QPixmap skinTexture;
94 SkinModel* nskin = nullptr;
95 for (auto i = 0; i < newSkins.size(); i++) {
96 if (newSkins[i].getURL() == skin.url) {
97 nskin = &newSkins[i];
98 break;
99 }
100 }
101 if (!nskin) {
102 auto name = m_acct->profileName() + ".png";
103 if (QFileInfo(m_dir.absoluteFilePath(name)).exists()) {
104 name = QUrl(skin.url).fileName() + ".png";
105 }
106 auto path = m_dir.absoluteFilePath(name);
107 if (skinTexture.loadFromData(skin.data, "PNG") && skinTexture.save(path)) {
108 SkinModel s(path);
109 s.setModel(skin.variant.toUpper() == "SLIM" ? SkinModel::SLIM : SkinModel::CLASSIC);
110 s.setCapeId(m_acct->accountData()->minecraftProfile.currentCape);
111 s.setURL(skin.url);
112 newSkins << s;
113 needsSave = true;
114 }
115 } else {
116 nskin->setCapeId(m_acct->accountData()->minecraftProfile.currentCape);
117 nskin->setModel(skin.variant.toUpper() == "SLIM" ? SkinModel::SLIM : SkinModel::CLASSIC);
118 }
119 }
120
121 auto folderContents = m_dir.entryInfoList();
122 // if there are any untracked files...
123 for (QFileInfo entry : folderContents) {
124 if (!entry.isFile() && entry.suffix() != "png")
125 continue;

Callers 1

executeTaskMethod · 0.45

Calls 15

QFileInfoClass · 0.85
requireDocumentFunction · 0.85
QUrlClass · 0.85
saveFunction · 0.85
existsMethod · 0.80
objectMethod · 0.80
causeMethod · 0.80
accountDataMethod · 0.80
getURLMethod · 0.80
setCapeIdMethod · 0.80
setURLMethod · 0.80
appendMethod · 0.80

Tested by

no test coverage detected