History

Can drag blocks zip folder into hifi and upload the .obj

Elisa Lupin-Jimenez committed 9 years ago

Commit 9cfc4dc1 parent e11cf1c6 files · +95 −38Browse files

Showing the changes to libraries/script-engine/src/FileScriptingInterface.cpp (1 of 6 files). Show all

Unified · Split

libraries/script-engine/src/FileScriptingInterface.cpp+30−20
@@ -32,12 +32,19 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent · 31 unmodified lines
3232 // nothing for now
3333 }
3434
35−void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) {
35+void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd, bool isBlocks) {
3636 qCDebug(scriptengine) << "Url that was downloaded: " + url.toString();
3737 qCDebug(scriptengine) << "Path where download is saved: " + path;
3838 QString fileName = "/" + path.section("/", -1);
3939 QString tempDir = path;
40− tempDir.remove(fileName);
40+ if (!isBlocks) {
41+ tempDir.remove(fileName);
42+ } else {
43+ QTemporaryDir blocks;
44+ tempDir = blocks.path();
45+ path.remove("file:///");
46+ }
47+
4148 qCDebug(scriptengine) << "Temporary directory at: " + tempDir;
4249 if (!isTempDir(tempDir)) {
4350 qCDebug(scriptengine) << "Temporary directory mismatch; risk of losing files";
@@ -45,6 +52,7 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) { · 1 unmodified line
4552 }
4653
4754 QString file = unzipFile(path, tempDir);
55+ qCDebug(scriptengine) << "Unzipped file: " << file;
4856 QString filename = QUrl::fromLocalFile(file).toString();
4957 if (file != "") {
5058 qCDebug(scriptengine) << "File to upload: " + filename;
@@ -54,6 +62,26 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) { · 3 unmodified lines
5462 emit unzipResult(path, filename, autoAdd);
5563 }
5664
65+QString FileScriptingInterface::unzipFile(QString path, QString tempDir) {
66+
67+ QDir dir(path);
68+ QString dirName = dir.path();
69+ qCDebug(scriptengine) << "Directory to unzip: " << dirName;
70+ QString target = tempDir + "/model_repo";
71+ QStringList list = JlCompress::extractDir(dirName, target);
72+
73+ qCDebug(scriptengine) << list;
74+
75+ if (!list.isEmpty()) {
76+ return list.front();
77+ }
78+ else {
79+ qCDebug(scriptengine) << "Extraction failed";
80+ return "";
81+ }
82+
83+}
84+
5785 // fix to check that we are only referring to a temporary directory
5886 bool FileScriptingInterface::isTempDir(QString tempDir) {
5987 QString folderName = "/" + tempDir.section("/", -1);
@@ -92,24 +120,6 @@ void FileScriptingInterface::downloadZip(QString path, const QString link) { · 32 unmodified lines
92120 request->send();
93121 }
94122
95−QString FileScriptingInterface::unzipFile(QString path, QString tempDir) {
96−
97− QDir dir(path);
98− QString dirName = dir.path();
99− QString target = tempDir + "/model_repo";
100− QStringList list = JlCompress::extractDir(dirName, target);
101−
102− qCDebug(scriptengine) << list;
103−
104− if (!list.isEmpty()) {
105− return list.front();
106− } else {
107− qCDebug(scriptengine) << "Extraction failed";
108− return "";
109− }
110−
111−}
112−
113123 // this function is not in use
114124 void FileScriptingInterface::recursiveFileScan(QFileInfo file, QString* dirName) {
115125 /*if (!file.isDir()) {