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