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

Function loadAssetsIndexJson

launcher/minecraft/AssetsUtils.cpp:86–170  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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

Callers 3

getAssetsDirFunction · 0.85
reconstructAssetsFunction · 0.85
assetIndexFinishedMethod · 0.85

Calls 7

openMethod · 0.80
closeMethod · 0.80
errorStringMethod · 0.80
objectMethod · 0.80
valueMethod · 0.80
insertMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected