Showing the changes to libraries/script-engine/src/FileScriptingInterface.cpp (1 of 5 files). Show all
Unified · Split
| @@ -3,7 +3,7 @@ · 2 unmodified lines | |||
| 3 | // interface/src/scripting | 3 | // interface/src/scripting |
| 4 | // | 4 | // |
| 5 | // Created by Elisa Lupin-Jimenez on 6/28/16. | 5 | // Created by Elisa Lupin-Jimenez on 6/28/16. |
| 6 | // Copyright 2014 High Fidelity, Inc. | 6 | // Copyright 2016 High Fidelity, Inc. |
| 7 | // | 7 | // |
| 8 | // Distributed under the Apache License, Version 2.0. | 8 | // Distributed under the Apache License, Version 2.0. |
| 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html | 9 | // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html |
| @@ -12,6 +12,10 @@ · 2 unmodified lines | |||
| 12 | #include <QTemporaryDir> | 12 | #include <QTemporaryDir> |
| 13 | #include <QFile> | 13 | #include <QFile> |
| 14 | #include <QUrl> | 14 | #include <QUrl> |
| 15 | #include <QByteArray> | ||
| 16 | #include <QString> | ||
| 17 | #include <quazip/quazip.h> | ||
| 18 | #include <JICompress.h> | ||
| 15 | #include "ResourceManager.h" | 19 | #include "ResourceManager.h" |
| 16 | 20 | ||
| 17 | #include "FileScriptingInterface.h" | 21 | #include "FileScriptingInterface.h" |
| @@ -29,23 +33,78 @@ void FileScriptingInterface::downloadZip() { · 11 unmodified lines | |||
| 29 | } | 33 | } |
| 30 | 34 | ||
| 31 | // clement's help :D | 35 | // clement's help :D |
| 32 | bool FileScriptingInterface::unzipFile() { | 36 | void FileScriptingInterface::unzipFile() { |
| 33 | ResourceRequest* request = qobject_cast<ResourceRequest*>(sender()); | 37 | ResourceRequest* request = qobject_cast<ResourceRequest*>(sender()); |
| 38 | QUrl url = request->getUrl(); | ||
| 34 | 39 | ||
| 35 | // Get the file URL | 40 | if (request->getResult() == ResourceRequest::Success) { |
| 36 | QUrl url = request->getUrl(); | 41 | qDebug() << "Zip file was downloaded"; |
| 42 | QTemporaryDir dir; | ||
| 43 | QByteArray compressedFileContent = request->getData(); // <-- Downloaded file is in here | ||
| 44 | QBuffer buffer(&compressedFileContent); | ||
| 45 | buffer.open(QIODevice::ReadOnly); | ||
| 37 | 46 | ||
| 38 | if (request->getResult() == ResourceRequest::Success) { | 47 | QString dirName = dir.path(); |
| 39 | qDebug() << "Success =)"; | 48 | JICompress::extractDir(buffer, dirName); |
| 40 | 49 | ||
| 41 | QByteArray fileContent = request->getData(); // <-- Downloaded file is in here | 50 | QFileInfoList files = dir.entryInfoList(); |
| 42 | // Do stuff | 51 | foreach (QFileInfo file, files) { |
| 43 | // | 52 | recursiveFileScan(file); |
| 44 | // unzipFile(fileContent); | 53 | } |
| 54 | |||
| 55 | |||
| 56 | /*foreach (QFileInfo file, files) { | ||
| 57 | if (file.isDir()) { | ||
| 58 | if (file.fileName().contains(".zip")) { | ||
| 59 | qDebug() << "Zip file expanded: " + file.fileName(); | ||
| 60 | } | ||
| 61 | |||
| 62 | qDebug() << "Regular file logged: " + file.fileName(); | ||
| 63 | } | ||
| 64 | }*/ | ||
| 65 | |||
| 66 | |||
| 67 | //QString zipFileName = QFile::decodeName(&compressedFileContent); | ||
| 45 | 68 | ||
| 46 | } else { | 69 | //QFile file = |
| 47 | qDebug() << "Could not download the file =("; | 70 | //need to convert this byte array to a file |
| 71 | /*QuaZip zip(zipFileName); | ||
| 72 | |||
| 73 | if (zip.open(QuaZip::mdUnzip)) { | ||
| 74 | qDebug() << "Opened"; | ||
| 75 | |||
| 76 | for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) { | ||
| 77 | // do something | ||
| 78 | qDebug() << zip.getCurrentFileName(); | ||
| 48 | } | 79 | } |
| 80 | if (zip.getZipError() == UNZ_OK) { | ||
| 81 | // ok, there was no error | ||
| 82 | }*/ | ||
| 83 | |||
| 84 | |||
| 85 | buffer.close(); | ||
| 86 | } else { | ||
| 87 | qDebug() << "Could not download the zip file"; | ||
| 88 | } | ||
| 49 | 89 | ||
| 50 | } | 90 | } |
| 51 | 91 | ||
| 92 | void FileScriptingInterface::recursiveFileScan(QFileInfo file) { | ||
| 93 | if (!file.isDir()) { | ||
| 94 | qDebug() << "Regular file logged:" + file.fileName(); | ||
| 95 | return; | ||
| 96 | } | ||
| 97 | if (file.fileName().contains(".zip")) { | ||
| 98 | |||
| 99 | } | ||
| 100 | |||
| 101 | QFileInfoList files = file.entryInfoList(); | ||
| 102 | if (files.empty()) { | ||
| 103 | files = JlCompress::getFileList(file.fileName()); | ||
| 104 | } | ||
| 105 | foreach (QFileInfo file, files) { | ||
| 106 | if (file.fileName().contains(".zip")) { | ||
| 107 | |||
| 108 | } | ||
| 109 | } | ||
| 110 | } | ||