History

Handle duplicate Clara download asset names

David Rowe committed 10 years ago

Commit cee8b661 parent 3ca2c192 files · +27 −1Browse files

Showing the changes to interface/src/Application.cpp (1 of 2 files). Show all

Unified · Split

interface/src/Application.cpp+26−1
@@ -5344,7 +5344,32 @@ void Application::addAssetToWorld(QString filePath) { · 5343 unmodified lines
5344 QString path = QUrl(filePath).toLocalFile();5344 QString path = QUrl(filePath).toLocalFile();
5345 QString mapping = path.right(path.length() - path.lastIndexOf("/"));5345 QString mapping = path.right(path.length() - path.lastIndexOf("/"));
5346 5346
5347 addAssetToWorldUpload(path, mapping);5347 addAssetToWorldWithNewMapping(path, mapping, 0);
5348}
5349
5350void 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
5350void Application::addAssetToWorldUpload(QString path, QString mapping) {5375void Application::addAssetToWorldUpload(QString path, QString mapping) {