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

Function reconstructAssets

launcher/minecraft/AssetsUtils.cpp:224–305  ·  view source on GitHub ↗

FIXME: ugly code duplication

Source from the content-addressed store, hash-verified

222
223// FIXME: ugly code duplication
224bool reconstructAssets(QString assetsId, QString resourcesFolder)
225{
226 QDir assetsDir = QDir("assets/");
227 QDir indexDir = QDir(FS::PathCombine(assetsDir.path(), "indexes"));
228 QDir objectDir = QDir(FS::PathCombine(assetsDir.path(), "objects"));
229 QDir virtualDir = QDir(FS::PathCombine(assetsDir.path(), "virtual"));
230
231 QString indexPath = FS::PathCombine(indexDir.path(), assetsId + ".json");
232 QFile indexFile(indexPath);
233 QDir virtualRoot(FS::PathCombine(virtualDir.path(), assetsId));
234
235 if (!indexFile.exists())
236 {
237 qCritical() << "No assets index file" << indexPath << "; can't reconstruct assets!";
238 return false;
239 }
240
241 qDebug() << "reconstructAssets" << assetsDir.path() << indexDir.path() << objectDir.path() << virtualDir.path() << virtualRoot.path();
242
243 AssetsIndex index;
244 if(!AssetsUtils::loadAssetsIndexJson(assetsId, indexPath, index))
245 {
246 qCritical() << "Failed to load asset index file" << indexPath << "; can't reconstruct assets!";
247 return false;
248 }
249
250 QString targetPath;
251 bool removeLeftovers = false;
252 if(index.isVirtual)
253 {
254 targetPath = virtualRoot.path();
255 removeLeftovers = true;
256 qDebug() << "Reconstructing virtual assets folder at" << targetPath;
257 }
258 else if(index.mapToResources)
259 {
260 targetPath = resourcesFolder;
261 qDebug() << "Reconstructing resources folder at" << targetPath;
262 }
263
264 if (!targetPath.isNull())
265 {
266 auto presentFiles = collectPathsFromDir(targetPath);
267 for (QString map : index.objects.keys())
268 {
269 AssetObject asset_object = index.objects.value(map);
270 QString target_path = FS::PathCombine(targetPath, map);
271 QFile target(target_path);
272
273 QString tlk = asset_object.hash.left(2);
274
275 QString original_path = FS::PathCombine(objectDir.path(), tlk, asset_object.hash);
276 QFile original(original_path);
277 if (!original.exists())
278 continue;
279
280 presentFiles.remove(target_path);
281

Callers 1

executeTaskMethod · 0.85

Calls 10

PathCombineFunction · 0.85
loadAssetsIndexJsonFunction · 0.85
collectPathsFromDirFunction · 0.85
ensureFolderPathExistsFunction · 0.85
pathMethod · 0.80
existsMethod · 0.80
dirMethod · 0.80
copyMethod · 0.80
QDirClass · 0.50
removeMethod · 0.45

Tested by

no test coverage detected