Handle unzip failure

This commit is contained in:
David Rowe 2016-12-15 11:52:34 +13:00 committed by Seth Alves
parent 77676436a2
commit e9dbb32277
4 changed files with 22 additions and 11 deletions

View file

@ -1891,7 +1891,7 @@ void Application::initializeUi() {
rootContext->setContextProperty("Entities", DependencyManager::get<EntityScriptingInterface>().data()); rootContext->setContextProperty("Entities", DependencyManager::get<EntityScriptingInterface>().data());
_fileDownload = new FileScriptingInterface(engine); _fileDownload = new FileScriptingInterface(engine);
rootContext->setContextProperty("File", _fileDownload); 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("MyAvatar", getMyAvatar().get());
rootContext->setContextProperty("Messages", DependencyManager::get<MessagesClient>().data()); rootContext->setContextProperty("Messages", DependencyManager::get<MessagesClient>().data());
rootContext->setContextProperty("Recording", DependencyManager::get<RecordingScriptingInterface>().data()); rootContext->setContextProperty("Recording", DependencyManager::get<RecordingScriptingInterface>().data());
@ -5649,6 +5649,12 @@ void Application::addAssetToWorldFromURLRequestFinished() {
request->deleteLater(); 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) { void Application::addAssetToWorld(QString filePath) {
// Automatically upload and add asset to world as an alternative manual process initiated by showAssetServerWidget(). // 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) { void Application::handleUnzip(QString zipFile, QString unzipFile, bool autoAdd) {
if (autoAdd && !filePath.isEmpty()) { if (autoAdd) {
addAssetToWorld(filePath); if (!unzipFile.isEmpty()) {
addAssetToWorld(unzipFile);
} else {
addAssetToWorldUnzipFailure(zipFile);
}
} else { } else {
showAssetServerWidget(filePath); showAssetServerWidget(unzipFile);
} }
} }

View file

@ -316,12 +316,13 @@ public slots:
void addAssetToWorldFromURL(QString url); void addAssetToWorldFromURL(QString url);
void addAssetToWorldFromURLRequestFinished(); void addAssetToWorldFromURLRequestFinished();
void addAssetToWorld(QString filePath); void addAssetToWorld(QString filePath);
void addAssetToWorldUnzipFailure(QString filePath);
void addAssetToWorldWithNewMapping(QString path, QString mapping, int copy); void addAssetToWorldWithNewMapping(QString path, QString mapping, int copy);
void addAssetToWorldUpload(QString path, QString mapping); void addAssetToWorldUpload(QString path, QString mapping);
void addAssetToWorldSetMapping(QString mapping, QString hash); void addAssetToWorldSetMapping(QString mapping, QString hash);
void addAssetToWorldAddEntity(QString mapping); void addAssetToWorldAddEntity(QString mapping);
void handleUnzip(QString filePath = "", bool autoAdd = false); void handleUnzip(QString sourceFile, QString destinationFile, bool autoAdd);
FileScriptingInterface* getFileDownloadInterface() { return _fileDownload; } FileScriptingInterface* getFileDownloadInterface() { return _fileDownload; }

View file

@ -44,13 +44,13 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) {
} }
QString file = unzipFile(path, tempDir); QString file = unzipFile(path, tempDir);
QString filename = QUrl::fromLocalFile(file).toString();
if (file != "") { if (file != "") {
qDebug() << "Object file to upload: " + file; qDebug() << "File to upload: " + filename;
QUrl url = QUrl::fromLocalFile(file);
emit unzipSuccess(url.toString(), autoAdd);
} else { } else {
qDebug() << "unzip failed"; qDebug() << "Unzip failed";
} }
emit unzipResult(path, filename, autoAdd);
} }
// fix to check that we are only referring to a temporary directory // fix to check that we are only referring to a temporary directory

View file

@ -28,7 +28,7 @@ public slots:
QString getTempDir(); QString getTempDir();
signals: signals:
void unzipSuccess(QString url, bool autoAdd); void unzipResult(QString zipFile, QString unzipFile, bool autoAdd);
private: private:
bool isTempDir(QString tempDir); bool isTempDir(QString tempDir);