From 0e79aa9dbe6b132cd57e26b6355a97975a2b2e82 Mon Sep 17 00:00:00 2001 From: elisa-lj11 Date: Wed, 29 Jun 2016 18:10:51 -0700 Subject: [PATCH] Added quazip for unzipping functions --- BUILD.md | 1 + CMakeLists.txt | 1 + libraries/script-engine/CMakeLists.txt | 6 ++ .../src/FileScriptingInterface.cpp | 85 ++++++++++++++++--- .../src/FileScriptingInterface.h | 11 ++- 5 files changed, 89 insertions(+), 15 deletions(-) diff --git a/BUILD.md b/BUILD.md index c1ccd3193e..4ff45a0b1e 100644 --- a/BUILD.md +++ b/BUILD.md @@ -5,6 +5,7 @@ * [OpenSSL](https://www.openssl.org/community/binaries.html) ~> 1.0.1m * IMPORTANT: Using the recommended version of OpenSSL is critical to avoid security vulnerabilities. * [VHACD](https://github.com/virneo/v-hacd)(clone this repository)(Optional) +* [QuaZip](http://sourceforge.net/projects/quazip/files/quazip/) ~> 0.7.1 ####CMake External Project Dependencies diff --git a/CMakeLists.txt b/CMakeLists.txt index 0d42be3d95..c0e11a72be 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -201,6 +201,7 @@ set_property(DIRECTORY PROPERTY EP_PREFIX ${EXTERNAL_PROJECT_PREFIX}) setup_externals_binary_dir() option(USE_NSIGHT "Attempt to find the nSight libraries" 1) +option(GET_QUAZIP "Get QuaZip library automatically as external project" 1) if (WIN32) diff --git a/libraries/script-engine/CMakeLists.txt b/libraries/script-engine/CMakeLists.txt index 48fda99b9d..79fa7a1504 100644 --- a/libraries/script-engine/CMakeLists.txt +++ b/libraries/script-engine/CMakeLists.txt @@ -1,3 +1,9 @@ set(TARGET_NAME script-engine) setup_hifi_library(Gui Network Script ScriptTools WebSockets Widgets) + +add_dependency_external_projects(quazip) +find_package(QuaZip REQUIRED) +target_include_directories(${TARGET_NAME} SYSTEM PUBLIC ${QUAZIP_INCLUDE_DIRS}) +target_link_libraries(${TARGET_NAME} ${QUAZIP_LIBRARIES}) + link_hifi_libraries(shared networking octree gpu ui procedural model model-networking recording avatars fbx entities controllers animation audio physics) diff --git a/libraries/script-engine/src/FileScriptingInterface.cpp b/libraries/script-engine/src/FileScriptingInterface.cpp index 3ecb1bfd22..6e9652e134 100644 --- a/libraries/script-engine/src/FileScriptingInterface.cpp +++ b/libraries/script-engine/src/FileScriptingInterface.cpp @@ -3,7 +3,7 @@ // interface/src/scripting // // Created by Elisa Lupin-Jimenez on 6/28/16. -// Copyright 2014 High Fidelity, Inc. +// Copyright 2016 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -12,6 +12,10 @@ #include #include #include +#include +#include +#include +#include #include "ResourceManager.h" #include "FileScriptingInterface.h" @@ -29,23 +33,78 @@ void FileScriptingInterface::downloadZip() { } // clement's help :D -bool FileScriptingInterface::unzipFile() { +void FileScriptingInterface::unzipFile() { ResourceRequest* request = qobject_cast(sender()); + QUrl url = request->getUrl(); - // Get the file URL - QUrl url = request->getUrl(); + if (request->getResult() == ResourceRequest::Success) { + qDebug() << "Zip file was downloaded"; + QTemporaryDir dir; + QByteArray compressedFileContent = request->getData(); // <-- Downloaded file is in here + QBuffer buffer(&compressedFileContent); + buffer.open(QIODevice::ReadOnly); - if (request->getResult() == ResourceRequest::Success) { - qDebug() << "Success =)"; + QString dirName = dir.path(); + JICompress::extractDir(buffer, dirName); - QByteArray fileContent = request->getData(); // <-- Downloaded file is in here - // Do stuff - // - // unzipFile(fileContent); - - } else { - qDebug() << "Could not download the file =("; + QFileInfoList files = dir.entryInfoList(); + foreach (QFileInfo file, files) { + recursiveFileScan(file); } + + /*foreach (QFileInfo file, files) { + if (file.isDir()) { + if (file.fileName().contains(".zip")) { + qDebug() << "Zip file expanded: " + file.fileName(); + } + + qDebug() << "Regular file logged: " + file.fileName(); + } + }*/ + + + //QString zipFileName = QFile::decodeName(&compressedFileContent); + + //QFile file = + //need to convert this byte array to a file + /*QuaZip zip(zipFileName); + + if (zip.open(QuaZip::mdUnzip)) { + qDebug() << "Opened"; + + for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) { + // do something + qDebug() << zip.getCurrentFileName(); + } + if (zip.getZipError() == UNZ_OK) { + // ok, there was no error + }*/ + + + buffer.close(); + } else { + qDebug() << "Could not download the zip file"; + } + } +void FileScriptingInterface::recursiveFileScan(QFileInfo file) { + if (!file.isDir()) { + qDebug() << "Regular file logged:" + file.fileName(); + return; + } + if (file.fileName().contains(".zip")) { + + } + + QFileInfoList files = file.entryInfoList(); + if (files.empty()) { + files = JlCompress::getFileList(file.fileName()); + } + foreach (QFileInfo file, files) { + if (file.fileName().contains(".zip")) { + + } + } +} diff --git a/libraries/script-engine/src/FileScriptingInterface.h b/libraries/script-engine/src/FileScriptingInterface.h index 67ea207aba..89e3434382 100644 --- a/libraries/script-engine/src/FileScriptingInterface.h +++ b/libraries/script-engine/src/FileScriptingInterface.h @@ -3,7 +3,7 @@ // interface/src/scripting // // Created by Elisa Lupin-Jimenez on 6/28/16. -// Copyright 2014 High Fidelity, Inc. +// Copyright 2016 High Fidelity, Inc. // // Distributed under the Apache License, Version 2.0. // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html @@ -21,10 +21,17 @@ public: FileScriptingInterface(QObject* parent); public slots: - QScriptValue hasFocus(); + void unzipFile(); + +signals: + void downloadZip(); }; +private: + void downloadZip(); + void unzipFile(); + #endif // hifi_FileScriptingInterface_h \ No newline at end of file