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

Function loadAssetsIndexJson

launcher/minecraft/AssetsUtils.cpp:89–184  ·  view source on GitHub ↗

* Returns true on success, with index populated * index is undefined otherwise */

Source from the content-addressed store, hash-verified

87 * index is undefined otherwise
88 */
89bool loadAssetsIndexJson(const QString &assetsId, const QString &path, AssetsIndex& index)
90{
91 /*
92 {
93 "objects": {
94 "icons/icon_16x16.png": {
95 "hash": "bdf48ef6b5d0d23bbb02e17d04865216179f510a",
96 "size": 3665
97 },
98 ...
99 }
100 }
101 }
102 */
103
104 QFile file(path);
105
106 // Try to open the file and fail if we can't.
107 // TODO: We should probably report this error to the user.
108 if (!file.open(QIODevice::ReadOnly))
109 {
110 qCritical() << "Failed to read assets index file" << path;
111 return false;
112 }
113 index.id = assetsId;
114
115 // Read the file and close it.
116 QByteArray jsonData = file.readAll();
117 file.close();
118
119 QJsonParseError parseError;
120 QJsonDocument jsonDoc = QJsonDocument::fromJson(jsonData, &parseError);
121
122 // Fail if the JSON is invalid.
123 if (parseError.error != QJsonParseError::NoError)
124 {
125 qCritical() << "Failed to parse assets index file:" << parseError.errorString()
126 << "at offset " << QString::number(parseError.offset);
127 return false;
128 }
129
130 // Make sure the root is an object.
131 if (!jsonDoc.isObject())
132 {
133 qCritical() << "Invalid assets index JSON: Root should be an array.";
134 return false;
135 }
136
137 QJsonObject root = jsonDoc.object();
138
139 QJsonValue isVirtual = root.value("virtual");
140 if (!isVirtual.isUndefined())
141 {
142 index.isVirtual = isVirtual.toBool(false);
143 }
144
145 QJsonValue mapToResources = root.value("map_to_resources");
146 if (!mapToResources.isUndefined())

Callers 3

getAssetsDirFunction · 0.85
reconstructAssetsFunction · 0.85
assetIndexFinishedMethod · 0.85

Calls 7

fromJsonFunction · 0.85
openMethod · 0.80
objectMethod · 0.80
beginMethod · 0.80
endMethod · 0.80
insertMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected