MCPcopy Create free account
hub / github.com/MultiMC/Launcher / reconstructAssets

Function reconstructAssets

launcher/minecraft/AssetsUtils.cpp:202–283  ·  view source on GitHub ↗

FIXME: ugly code duplication

Source from the content-addressed store, hash-verified

200
201// FIXME: ugly code duplication
202bool reconstructAssets(QString assetsId, QString resourcesFolder)
203{
204 QDir assetsDir = QDir("assets/");
205 QDir indexDir = QDir(FS::PathCombine(assetsDir.path(), "indexes"));
206 QDir objectDir = QDir(FS::PathCombine(assetsDir.path(), "objects"));
207 QDir virtualDir = QDir(FS::PathCombine(assetsDir.path(), "virtual"));
208
209 QString indexPath = FS::PathCombine(indexDir.path(), assetsId + ".json");
210 QFile indexFile(indexPath);
211 QDir virtualRoot(FS::PathCombine(virtualDir.path(), assetsId));
212
213 if (!indexFile.exists())
214 {
215 qCritical() << "No assets index file" << indexPath << "; can't reconstruct assets!";
216 return false;
217 }
218
219 qDebug() << "reconstructAssets" << assetsDir.path() << indexDir.path() << objectDir.path() << virtualDir.path() << virtualRoot.path();
220
221 AssetsIndex index;
222 if(!AssetsUtils::loadAssetsIndexJson(assetsId, indexPath, index))
223 {
224 qCritical() << "Failed to load asset index file" << indexPath << "; can't reconstruct assets!";
225 return false;
226 }
227
228 QString targetPath;
229 bool removeLeftovers = false;
230 if(index.isVirtual)
231 {
232 targetPath = virtualRoot.path();
233 removeLeftovers = true;
234 qDebug() << "Reconstructing virtual assets folder at" << targetPath;
235 }
236 else if(index.mapToResources)
237 {
238 targetPath = resourcesFolder;
239 qDebug() << "Reconstructing resources folder at" << targetPath;
240 }
241
242 if (!targetPath.isNull())
243 {
244 auto presentFiles = collectPathsFromDir(targetPath);
245 for (QString map : index.objects.keys())
246 {
247 AssetObject asset_object = index.objects.value(map);
248 QString target_path = FS::PathCombine(targetPath, map);
249 QFile target(target_path);
250
251 QString tlk = asset_object.hash.left(2);
252
253 QString original_path = FS::PathCombine(objectDir.path(), tlk, asset_object.hash);
254 QFile original(original_path);
255 if (!original.exists())
256 continue;
257
258 presentFiles.remove(target_path);
259

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
copyMethod · 0.80
QDirClass · 0.50
removeMethod · 0.45
dirMethod · 0.45

Tested by

no test coverage detected