mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 17:01:18 +02:00
Added quazip for unzipping functions
This commit is contained in:
parent
f277a019bf
commit
0e79aa9dbe
5 changed files with 89 additions and 15 deletions
1
BUILD.md
1
BUILD.md
|
@ -5,6 +5,7 @@
|
||||||
* [OpenSSL](https://www.openssl.org/community/binaries.html) ~> 1.0.1m
|
* [OpenSSL](https://www.openssl.org/community/binaries.html) ~> 1.0.1m
|
||||||
* IMPORTANT: Using the recommended version of OpenSSL is critical to avoid security vulnerabilities.
|
* IMPORTANT: Using the recommended version of OpenSSL is critical to avoid security vulnerabilities.
|
||||||
* [VHACD](https://github.com/virneo/v-hacd)(clone this repository)(Optional)
|
* [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
|
####CMake External Project Dependencies
|
||||||
|
|
||||||
|
|
|
@ -201,6 +201,7 @@ set_property(DIRECTORY PROPERTY EP_PREFIX ${EXTERNAL_PROJECT_PREFIX})
|
||||||
setup_externals_binary_dir()
|
setup_externals_binary_dir()
|
||||||
|
|
||||||
option(USE_NSIGHT "Attempt to find the nSight libraries" 1)
|
option(USE_NSIGHT "Attempt to find the nSight libraries" 1)
|
||||||
|
option(GET_QUAZIP "Get QuaZip library automatically as external project" 1)
|
||||||
|
|
||||||
|
|
||||||
if (WIN32)
|
if (WIN32)
|
||||||
|
|
|
@ -1,3 +1,9 @@
|
||||||
set(TARGET_NAME script-engine)
|
set(TARGET_NAME script-engine)
|
||||||
setup_hifi_library(Gui Network Script ScriptTools WebSockets Widgets)
|
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)
|
link_hifi_libraries(shared networking octree gpu ui procedural model model-networking recording avatars fbx entities controllers animation audio physics)
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// interface/src/scripting
|
// interface/src/scripting
|
||||||
//
|
//
|
||||||
// Created by Elisa Lupin-Jimenez on 6/28/16.
|
// 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.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
@ -12,6 +12,10 @@
|
||||||
#include <QTemporaryDir>
|
#include <QTemporaryDir>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QByteArray>
|
||||||
|
#include <QString>
|
||||||
|
#include <quazip/quazip.h>
|
||||||
|
#include <JICompress.h>
|
||||||
#include "ResourceManager.h"
|
#include "ResourceManager.h"
|
||||||
|
|
||||||
#include "FileScriptingInterface.h"
|
#include "FileScriptingInterface.h"
|
||||||
|
@ -29,23 +33,78 @@ void FileScriptingInterface::downloadZip() {
|
||||||
}
|
}
|
||||||
|
|
||||||
// clement's help :D
|
// clement's help :D
|
||||||
bool FileScriptingInterface::unzipFile() {
|
void FileScriptingInterface::unzipFile() {
|
||||||
ResourceRequest* request = qobject_cast<ResourceRequest*>(sender());
|
ResourceRequest* request = qobject_cast<ResourceRequest*>(sender());
|
||||||
|
QUrl url = request->getUrl();
|
||||||
|
|
||||||
// Get the file URL
|
if (request->getResult() == ResourceRequest::Success) {
|
||||||
QUrl url = request->getUrl();
|
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) {
|
QString dirName = dir.path();
|
||||||
qDebug() << "Success =)";
|
JICompress::extractDir(buffer, dirName);
|
||||||
|
|
||||||
QByteArray fileContent = request->getData(); // <-- Downloaded file is in here
|
QFileInfoList files = dir.entryInfoList();
|
||||||
// Do stuff
|
foreach (QFileInfo file, files) {
|
||||||
//
|
recursiveFileScan(file);
|
||||||
// unzipFile(fileContent);
|
|
||||||
|
|
||||||
} else {
|
|
||||||
qDebug() << "Could not download the 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")) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
// interface/src/scripting
|
// interface/src/scripting
|
||||||
//
|
//
|
||||||
// Created by Elisa Lupin-Jimenez on 6/28/16.
|
// 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.
|
// Distributed under the Apache License, Version 2.0.
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
||||||
|
@ -21,10 +21,17 @@ public:
|
||||||
FileScriptingInterface(QObject* parent);
|
FileScriptingInterface(QObject* parent);
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
QScriptValue hasFocus();
|
void unzipFile();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
void downloadZip();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
private:
|
||||||
|
void downloadZip();
|
||||||
|
void unzipFile();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif // hifi_FileScriptingInterface_h
|
#endif // hifi_FileScriptingInterface_h
|
Loading…
Reference in a new issue