Downloading blocks from marketplace in own asset folder

This commit is contained in:
Elisa Lupin-Jimenez 2017-08-09 15:56:07 -07:00
parent 17acf0520d
commit 1ac9536f95
4 changed files with 29 additions and 37 deletions

View file

@ -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<NodeList>()->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);

View file

@ -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; }

View file

@ -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<ResourceManager>()->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);

View file

@ -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);
};