FIXME: ugly code duplication
| 222 | |
| 223 | // FIXME: ugly code duplication |
| 224 | bool 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 |
no test coverage detected