From e9dbb32277cfca94d8fb56b1887c2c7cee1dc23f Mon Sep 17 00:00:00 2001 From: David Rowe Date: Thu, 15 Dec 2016 11:52:34 +1300 Subject: [PATCH] Handle unzip failure --- interface/src/Application.cpp | 20 ++++++++++++++----- interface/src/Application.h | 3 ++- .../src/FileScriptingInterface.cpp | 8 ++++---- .../src/FileScriptingInterface.h | 2 +- 4 files changed, 22 insertions(+), 11 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index a0fc8e31db..6fc51968f1 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -1891,7 +1891,7 @@ void Application::initializeUi() { rootContext->setContextProperty("Entities", DependencyManager::get().data()); _fileDownload = new FileScriptingInterface(engine); rootContext->setContextProperty("File", _fileDownload); - connect(_fileDownload, &FileScriptingInterface::unzipSuccess, this, &Application::handleUnzip); + connect(_fileDownload, &FileScriptingInterface::unzipResult, this, &Application::handleUnzip); rootContext->setContextProperty("MyAvatar", getMyAvatar().get()); rootContext->setContextProperty("Messages", DependencyManager::get().data()); rootContext->setContextProperty("Recording", DependencyManager::get().data()); @@ -5649,6 +5649,12 @@ void Application::addAssetToWorldFromURLRequestFinished() { request->deleteLater(); } +void Application::addAssetToWorldUnzipFailure(QString filePath) { + QString filename = filePath.right(filePath.length() - filePath.lastIndexOf("/") - 1); + qWarning(interfaceapp) << "Couldn't unzip file" << filePath; + addAssetToWorldError(filename, "Couldn't unzip file " + filename + "."); +} + void Application::addAssetToWorld(QString filePath) { // Automatically upload and add asset to world as an alternative manual process initiated by showAssetServerWidget(). @@ -6020,11 +6026,15 @@ void Application::addAssetToWorldMessageClose() { } -void Application::handleUnzip(QString filePath, bool autoAdd) { - if (autoAdd && !filePath.isEmpty()) { - addAssetToWorld(filePath); +void Application::handleUnzip(QString zipFile, QString unzipFile, bool autoAdd) { + if (autoAdd) { + if (!unzipFile.isEmpty()) { + addAssetToWorld(unzipFile); + } else { + addAssetToWorldUnzipFailure(zipFile); + } } else { - showAssetServerWidget(filePath); + showAssetServerWidget(unzipFile); } } diff --git a/interface/src/Application.h b/interface/src/Application.h index 0972371755..a1473e9cb4 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -316,12 +316,13 @@ public slots: void addAssetToWorldFromURL(QString url); void addAssetToWorldFromURLRequestFinished(); void addAssetToWorld(QString filePath); + void addAssetToWorldUnzipFailure(QString filePath); void addAssetToWorldWithNewMapping(QString path, QString mapping, int copy); void addAssetToWorldUpload(QString path, QString mapping); void addAssetToWorldSetMapping(QString mapping, QString hash); void addAssetToWorldAddEntity(QString mapping); - void handleUnzip(QString filePath = "", bool autoAdd = false); + void handleUnzip(QString sourceFile, QString destinationFile, bool autoAdd); FileScriptingInterface* getFileDownloadInterface() { return _fileDownload; } diff --git a/libraries/script-engine/src/FileScriptingInterface.cpp b/libraries/script-engine/src/FileScriptingInterface.cpp index 3c2222da6f..32a76f2fd3 100644 --- a/libraries/script-engine/src/FileScriptingInterface.cpp +++ b/libraries/script-engine/src/FileScriptingInterface.cpp @@ -44,13 +44,13 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) { } QString file = unzipFile(path, tempDir); + QString filename = QUrl::fromLocalFile(file).toString(); if (file != "") { - qDebug() << "Object file to upload: " + file; - QUrl url = QUrl::fromLocalFile(file); - emit unzipSuccess(url.toString(), autoAdd); + qDebug() << "File to upload: " + filename; } else { - qDebug() << "unzip failed"; + qDebug() << "Unzip failed"; } + emit unzipResult(path, filename, autoAdd); } // fix to check that we are only referring to a temporary directory diff --git a/libraries/script-engine/src/FileScriptingInterface.h b/libraries/script-engine/src/FileScriptingInterface.h index 6a793d79f8..5e9a6029e8 100644 --- a/libraries/script-engine/src/FileScriptingInterface.h +++ b/libraries/script-engine/src/FileScriptingInterface.h @@ -28,7 +28,7 @@ public slots: QString getTempDir(); signals: - void unzipSuccess(QString url, bool autoAdd); + void unzipResult(QString zipFile, QString unzipFile, bool autoAdd); private: bool isTempDir(QString tempDir);