From 1ac9536f9572f93568ab7161df83a4c463d76348 Mon Sep 17 00:00:00 2001 From: Elisa Lupin-Jimenez Date: Wed, 9 Aug 2017 15:56:07 -0700 Subject: [PATCH] Downloading blocks from marketplace in own asset folder --- interface/src/Application.cpp | 29 +++++++++++-------- interface/src/Application.h | 4 +-- .../src/FileScriptingInterface.cpp | 28 +++++------------- .../src/FileScriptingInterface.h | 5 ++-- 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/interface/src/Application.cpp b/interface/src/Application.cpp index 60b7477ac5..efd6bd9f48 100644 --- a/interface/src/Application.cpp +++ b/interface/src/Application.cpp @@ -2780,9 +2780,8 @@ bool Application::importFromZIP(const QString& filePath) { // handle Blocks download from Marketplace if (filePath.contains("vr.google.com/downloads")) { addAssetToWorldFromURL(filePath); - //qApp->getFileDownloadInterface()->runUnzip("", filePath, true, true); } else { - qApp->getFileDownloadInterface()->runUnzip(filePath, empty, true, true); + qApp->getFileDownloadInterface()->runUnzip(filePath, empty, true, true, false); } return true; } @@ -6227,9 +6226,8 @@ void Application::addAssetToWorldFromURL(QString url) { filename = url.section("filename=", 1, 1); // Filename is in "?filename=" parameter at end of URL. } if (url.contains("vr.google.com/downloads")) { - QRegExp blocksName("\/.*\.zip"); - //filename = url.section(blocksName); - filename = "blocks"; + filename = url.section('/', -1); + filename.remove(".zip?noDownload=false"); } if (!DependencyManager::get()->getThisNodeCanWriteAssets()) { @@ -6252,13 +6250,15 @@ void Application::addAssetToWorldFromURLRequestFinished() { auto result = request->getResult(); QString filename; + bool isBlocks = false; + if (url.contains("filename")) { filename = url.section("filename=", 1, 1); // Filename is in "?filename=" parameter at end of URL. } if (url.contains("vr.google.com/downloads")) { - QRegExp blocksName("\/.*\.zip"); - //filename = url.section(blocksName); - filename = "blocks"; + filename = url.section('/', -1); + filename.remove(".zip?noDownload=false"); + isBlocks = true; } if (result == ResourceRequest::Success) { @@ -6274,7 +6274,7 @@ void Application::addAssetToWorldFromURLRequestFinished() { if (tempFile.open(QIODevice::WriteOnly)) { tempFile.write(request->getData()); addAssetToWorldInfoClear(filename); // Remove message from list; next one added will have a different key. - qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true, false); + qApp->getFileDownloadInterface()->runUnzip(downloadPath, url, true, false, isBlocks); } else { QString errorInfo = "Couldn't open temporary file for download"; qWarning(interfaceapp) << errorInfo; @@ -6304,7 +6304,7 @@ void Application::addAssetToWorldUnzipFailure(QString filePath) { addAssetToWorldError(filename, "Couldn't unzip file " + filename + "."); } -void Application::addAssetToWorld(QString filePath, QString zipFile, bool isZip) { +void Application::addAssetToWorld(QString filePath, QString zipFile, bool isZip, bool isBlocks) { // Automatically upload and add asset to world as an alternative manual process initiated by showAssetServerWidget(). QString mapping; QString path = filePath; @@ -6313,6 +6313,11 @@ void Application::addAssetToWorld(QString filePath, QString zipFile, bool isZip) QString assetFolder = zipFile.section("/", -1); assetFolder.remove(".zip"); mapping = "/" + assetFolder + "/" + filename; + } else if (isBlocks) { + qCDebug(interfaceapp) << "Path to asset folder: " << zipFile; + QString assetFolder = zipFile.section('/', -1); + assetFolder.remove(".zip?noDownload=false"); + mapping = "/" + assetFolder + "/" + filename; } else { mapping = "/" + filename; } @@ -6692,12 +6697,12 @@ void Application::onAssetToWorldMessageBoxClosed() { } -void Application::handleUnzip(QString zipFile, QStringList unzipFile, bool autoAdd, bool isZip) { +void Application::handleUnzip(QString zipFile, QStringList unzipFile, bool autoAdd, bool isZip, bool isBlocks) { if (autoAdd) { if (!unzipFile.isEmpty()) { for (int i = 0; i < unzipFile.length(); i++) { qCDebug(interfaceapp) << "Preparing file for asset server: " << unzipFile.at(i); - addAssetToWorld(unzipFile.at(i), zipFile, isZip); + addAssetToWorld(unzipFile.at(i), zipFile, isZip, isBlocks); } } else { addAssetToWorldUnzipFailure(zipFile); diff --git a/interface/src/Application.h b/interface/src/Application.h index f8eb393f9e..516ea6ed3a 100644 --- a/interface/src/Application.h +++ b/interface/src/Application.h @@ -331,14 +331,14 @@ public slots: // FIXME: Move addAssetToWorld* methods to own class? void addAssetToWorldFromURL(QString url); void addAssetToWorldFromURLRequestFinished(); - void addAssetToWorld(QString filePath, QString zipFile, bool isZip); + void addAssetToWorld(QString filePath, QString zipFile, bool isZip, bool isBlocks); void addAssetToWorldUnzipFailure(QString filePath); void addAssetToWorldWithNewMapping(QString filePath, QString mapping, int copy); void addAssetToWorldUpload(QString filePath, QString mapping); void addAssetToWorldSetMapping(QString filePath, QString mapping, QString hash); void addAssetToWorldAddEntity(QString filePath, QString mapping); - void handleUnzip(QString sourceFile, QStringList destinationFile, bool autoAdd, bool isZip); + void handleUnzip(QString sourceFile, QStringList destinationFile, bool autoAdd, bool isZip, bool isBlocks); FileScriptingInterface* getFileDownloadInterface() { return _fileDownload; } diff --git a/libraries/script-engine/src/FileScriptingInterface.cpp b/libraries/script-engine/src/FileScriptingInterface.cpp index 1a121f3059..681156973b 100644 --- a/libraries/script-engine/src/FileScriptingInterface.cpp +++ b/libraries/script-engine/src/FileScriptingInterface.cpp @@ -32,14 +32,11 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent // nothing for now } -void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd, bool isZip) { +void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd, bool isZip, bool isBlocks) { qCDebug(scriptengine) << "Url that was downloaded: " + url.toString(); - /*if ((url.toString()).contains("vr.google.com/downloads")) { - - path = downloadBlocksZip(url); - }*/ qCDebug(scriptengine) << "Path where download is saved: " + path; QString fileName = "/" + path.section("/", -1); + qCDebug(scriptengine) << "Filename: " << fileName; QString tempDir = path; if (!isZip) { tempDir.remove(fileName); @@ -60,11 +57,14 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd, bool if (!fileList.isEmpty()) { qCDebug(scriptengine) << "File to upload: " + fileList.first(); - } - else { + } else { qCDebug(scriptengine) << "Unzip failed"; } - emit unzipResult(path, fileList, autoAdd, isZip); + + if (path.contains("vr.google.com/downloads")) { + isZip = true; + } + emit unzipResult(path, fileList, autoAdd, isZip, isBlocks); } @@ -115,18 +115,6 @@ QString FileScriptingInterface::convertUrlToPath(QUrl url) { return newUrl; } -// handles a download from Blocks in the marketplace -QString FileScriptingInterface::downloadBlocksZip(QUrl url) { - qCDebug(scriptengine) << "Made it to the download blocks! " << url.toString(); - - /*auto request = DependencyManager::get()->createResourceRequest(nullptr, url); - connect(request, &ResourceRequest::finished, this, [this, url] { - unzipFile(url, ""); // so intellisense isn't mad - }); - request->send();*/ - return url.toString(); -} - // this function is not in use void FileScriptingInterface::downloadZip(QString path, const QString link) { QUrl url = QUrl(link); diff --git a/libraries/script-engine/src/FileScriptingInterface.h b/libraries/script-engine/src/FileScriptingInterface.h index c2b309ce43..e4c27dbf7f 100644 --- a/libraries/script-engine/src/FileScriptingInterface.h +++ b/libraries/script-engine/src/FileScriptingInterface.h @@ -24,17 +24,16 @@ public: public slots: QString convertUrlToPath(QUrl url); - void runUnzip(QString path, QUrl url, bool autoAdd, bool isZip); + void runUnzip(QString path, QUrl url, bool autoAdd, bool isZip, bool isBlocks); QString getTempDir(); signals: - void unzipResult(QString zipFile, QStringList unzipFile, bool autoAdd, bool isZip); + void unzipResult(QString zipFile, QStringList unzipFile, bool autoAdd, bool isZip, bool isBlocks); private: bool isTempDir(QString tempDir); QStringList unzipFile(QString path, QString tempDir); void recursiveFileScan(QFileInfo file, QString* dirName); - QString downloadBlocksZip(QUrl url); void downloadZip(QString path, const QString link); };