Showing the changes to interface/src/Application.cpp (1 of 2 files). Show all
Unified · Split
| @@ -5344,7 +5344,32 @@ void Application::addAssetToWorld(QString filePath) { · 5343 unmodified lines | ||
| 5344 | 5344 | QString path = QUrl(filePath).toLocalFile(); |
| 5345 | 5345 | QString mapping = path.right(path.length() - path.lastIndexOf("/")); |
| 5346 | 5346 | |
| 5347 | − addAssetToWorldUpload(path, mapping); | |
| 5347 | + addAssetToWorldWithNewMapping(path, mapping, 0); | |
| 5348 | +} | |
| 5349 | + | |
| 5350 | +void Application::addAssetToWorldWithNewMapping(QString path, QString mapping, int copy) { | |
| 5351 | + auto request = DependencyManager::get<AssetClient>()->createGetMappingRequest(mapping); | |
| 5352 | + QObject::connect(request, &GetMappingRequest::finished, this, [=](GetMappingRequest* request) mutable { | |
| 5353 | + const int MAX_COPY_COUNT = 100; // Limit number of duplicate assets; recursion guard. | |
| 5354 | + if (request->getError() == GetMappingRequest::NotFound) { | |
| 5355 | + addAssetToWorldUpload(path, mapping); | |
| 5356 | + } else if (copy < MAX_COPY_COUNT - 1) { | |
| 5357 | + if (copy > 0) { | |
| 5358 | + mapping = mapping.remove(mapping.lastIndexOf("-"), QString::number(copy).length() + 1); | |
| 5359 | + } | |
| 5360 | + copy++; | |
| 5361 | + mapping = mapping.insert(mapping.lastIndexOf("."), "-" + QString::number(copy)); | |
| 5362 | + addAssetToWorldWithNewMapping(path, mapping, copy); | |
| 5363 | + } else { | |
| 5364 | + QString errorInfo = "Too many copies of asset name: " | |
| 5365 | + + mapping.left(mapping.length() - QString::number(copy).length() - 1); | |
| 5366 | + qCDebug(interfaceapp) << "Error downloading asset: " + errorInfo; | |
| 5367 | + OffscreenUi::warning("Error Downloading Asset", errorInfo); | |
| 5368 | + } | |
| 5369 | + request->deleteLater(); | |
| 5370 | + }); | |
| 5371 | + | |
| 5372 | + request->start(); | |
| 5348 | 5373 | } |
| 5349 | 5374 | |
| 5350 | 5375 | void Application::addAssetToWorldUpload(QString path, QString mapping) { |