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

Function reconstructAssets

launcher/minecraft/AssetsUtils.cpp:205–276  ·  view source on GitHub ↗

FIXME: ugly code duplication

Source from the content-addressed store, hash-verified

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

Callers 1

executeTaskMethod · 0.85

Calls 10

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

Tested by

no test coverage detected