Showing the changes to libraries/script-engine/src/FileScriptingInterface.cpp (1 of 6 files). Show all
Unified · Split
| @@ -32,12 +32,19 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent · 31 unmodified lines | |||
| 32 | // nothing for now | 32 | // nothing for now |
| 33 | } | 33 | } |
| 34 | 34 | ||
| 35 | void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) { | 35 | void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd, bool isBlocks) { |
| 36 | qCDebug(scriptengine) << "Url that was downloaded: " + url.toString(); | 36 | qCDebug(scriptengine) << "Url that was downloaded: " + url.toString(); |
| 37 | qCDebug(scriptengine) << "Path where download is saved: " + path; | 37 | qCDebug(scriptengine) << "Path where download is saved: " + path; |
| 38 | QString fileName = "/" + path.section("/", -1); | 38 | QString fileName = "/" + path.section("/", -1); |
| 39 | QString tempDir = path; | 39 | 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 | |||
| 41 | qCDebug(scriptengine) << "Temporary directory at: " + tempDir; | 48 | qCDebug(scriptengine) << "Temporary directory at: " + tempDir; |
| 42 | if (!isTempDir(tempDir)) { | 49 | if (!isTempDir(tempDir)) { |
| 43 | qCDebug(scriptengine) << "Temporary directory mismatch; risk of losing files"; | 50 | 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 | |||
| 45 | } | 52 | } |
| 46 | 53 | ||
| 47 | QString file = unzipFile(path, tempDir); | 54 | QString file = unzipFile(path, tempDir); |
| 55 | qCDebug(scriptengine) << "Unzipped file: " << file; | ||
| 48 | QString filename = QUrl::fromLocalFile(file).toString(); | 56 | QString filename = QUrl::fromLocalFile(file).toString(); |
| 49 | if (file != "") { | 57 | if (file != "") { |
| 50 | qCDebug(scriptengine) << "File to upload: " + filename; | 58 | qCDebug(scriptengine) << "File to upload: " + filename; |
| @@ -54,6 +62,26 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url, bool autoAdd) { · 3 unmodified lines | |||
| 54 | emit unzipResult(path, filename, autoAdd); | 62 | emit unzipResult(path, filename, autoAdd); |
| 55 | } | 63 | } |
| 56 | 64 | ||
| 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 | |||
| 57 | // fix to check that we are only referring to a temporary directory | 85 | // fix to check that we are only referring to a temporary directory |
| 58 | bool FileScriptingInterface::isTempDir(QString tempDir) { | 86 | bool FileScriptingInterface::isTempDir(QString tempDir) { |
| 59 | QString folderName = "/" + tempDir.section("/", -1); | 87 | QString folderName = "/" + tempDir.section("/", -1); |
| @@ -92,24 +120,6 @@ void FileScriptingInterface::downloadZip(QString path, const QString link) { · 32 unmodified lines | |||
| 92 | request->send(); | 120 | request->send(); |
| 93 | } | 121 | } |
| 94 | 122 | ||
| 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 | |||
| 113 | // this function is not in use | 123 | // this function is not in use |
| 114 | void FileScriptingInterface::recursiveFileScan(QFileInfo file, QString* dirName) { | 124 | void FileScriptingInterface::recursiveFileScan(QFileInfo file, QString* dirName) { |
| 115 | /*if (!file.isDir()) { | 125 | /*if (!file.isDir()) { |