Showing the changes to libraries/script-engine/src/FileScriptingInterface.cpp (1 of 13 files). Show all
Unified · Split
| @@ -28,94 +28,97 @@ · 27 unmodified lines | |||
| 28 | 28 | ||
| 29 | 29 | ||
| 30 | FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent) { | 30 | FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent) { |
| 31 | // nothing for now | 31 | // nothing for now |
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | void FileScriptingInterface::runUnzip(QString path, QUrl url) { | 34 | void FileScriptingInterface::runUnzip(QString path, QUrl url) { |
| 35 | qDebug() << "Url that was downloaded: " + url.toString(); | 35 | qDebug() << "Url that was downloaded: " + url.toString(); |
| 36 | qDebug() << "Path where download is saved: " + path; | 36 | qDebug() << "Path where download is saved: " + path; |
| 37 | QString file = unzipFile(path); | 37 | QString file = unzipFile(path); |
| 38 | if (file != "") { | 38 | if (file != "") { |
| 39 | qDebug() << "file to upload: " + file; | 39 | qDebug() << "file to upload: " + file; |
| 40 | QUrl url = QUrl::fromLocalFile(file); | 40 | QUrl url = QUrl::fromLocalFile(file); |
| 41 | qDebug() << "url from local file: " + url.toString(); | 41 | qDebug() << "url from local file: " + url.toString(); |
| 42 | emit unzipSuccess(url.toString()); | 42 | emit unzipSuccess(url.toString()); |
| 43 | //Application::toggleAssetServerWidget(file); | 43 | } else { |
| 44 | } else { | 44 | qDebug() << "unzip failed"; |
| 45 | qDebug() << "unzip failed"; | 45 | } |
| 46 | } | ||
| 47 | } | 46 | } |
| 48 | 47 | ||
| 49 | bool FileScriptingInterface::testUrl(QUrl url) { | 48 | bool FileScriptingInterface::testUrl(QUrl url) { |
| 50 | if (url.toString().contains(".zip") && url.toString().contains("fbx")) return true; | 49 | if (url.toString().contains(".zip") && url.toString().contains("fbx")) return true; |
| 51 | qDebug() << "This model is not a .fbx packaged in a .zip. Please try with another model."; | 50 | qDebug() << "This model is not a .fbx packaged in a .zip. Please try with another model."; |
| 52 | return false; | 51 | return false; |
| 53 | } | 52 | } |
| 54 | 53 | ||
| 54 | // this function is not in use | ||
| 55 | QString FileScriptingInterface::getTempDir() { | 55 | QString FileScriptingInterface::getTempDir() { |
| 56 | QTemporaryDir dir; | 56 | QTemporaryDir dir; |
| 57 | dir.setAutoRemove(false); | 57 | dir.setAutoRemove(false); |
| 58 | return dir.path(); | 58 | return dir.path(); |
| 59 | // remember I must do something to delete this temp dir later | 59 | // do something to delete this temp dir later |
| 60 | } | 60 | } |
| 61 | 61 | ||
| 62 | QString FileScriptingInterface::convertUrlToPath(QUrl url) { | 62 | QString FileScriptingInterface::convertUrlToPath(QUrl url) { |
| 63 | QString newUrl; | 63 | QString newUrl; |
| 64 | QString oldUrl = url.toString(); | 64 | QString oldUrl = url.toString(); |
| 65 | newUrl = oldUrl.section("filename=", 1, 1); | 65 | newUrl = oldUrl.section("filename=", 1, 1); |
| 66 | qDebug() << "Filename should be: " + newUrl; | 66 | qDebug() << "Filename should be: " + newUrl; |
| 67 | return newUrl; | 67 | return newUrl; |
| 68 | } | 68 | } |
| 69 | 69 | ||
| 70 | // this function is not in use | ||
| 70 | void FileScriptingInterface::downloadZip(QString path, const QString link) { | 71 | void FileScriptingInterface::downloadZip(QString path, const QString link) { |
| 71 | QUrl url = QUrl(link); | 72 | QUrl url = QUrl(link); |
| 72 | auto request = ResourceManager::createResourceRequest(nullptr, url); | 73 | auto request = ResourceManager::createResourceRequest(nullptr, url); |
| 73 | connect(request, &ResourceRequest::finished, this, [this, path]{ | 74 | connect(request, &ResourceRequest::finished, this, [this, path]{ |
| 74 | unzipFile(path); | 75 | unzipFile(path); |
| 75 | }); | 76 | }); |
| 76 | request->send(); | 77 | request->send(); |
| 77 | } | 78 | } |
| 78 | 79 | ||
| 79 | // clement's help :D | 80 | |
| 80 | QString FileScriptingInterface::unzipFile(QString path) { | 81 | QString FileScriptingInterface::unzipFile(QString path) { |
| 81 | 82 | ||
| 82 | qDebug() << "Zip file was downloaded"; | 83 | QDir dir(path); |
| 83 | QDir dir(path); | ||
| 84 | QString dirName = dir.path(); | 84 | QString dirName = dir.path(); |
| 85 | qDebug() << "Zip directory is stored at: " + dirName; | 85 | qDebug() << "Zip directory is stored at: " + dirName; |
| 86 | QString target = path.section("/", -1) + "/model_repo"; | ||
| 87 | qDebug() << "Target path: " + target; | ||
| 86 | QStringList list = JlCompress::extractDir(dirName, "C:/Users/elisa/Downloads/test"); | 88 | QStringList list = JlCompress::extractDir(dirName, "C:/Users/elisa/Downloads/test"); |
| 87 | 89 | ||
| 88 | qDebug() << list; | 90 | qDebug() << list; |
| 89 | 91 | ||
| 90 | if (!list.isEmpty()) { | 92 | if (!list.isEmpty()) { |
| 91 | return list.front(); | 93 | return list.front(); |
| 92 | } else { | 94 | } else { |
| 93 | qDebug() << "Extraction failed"; | 95 | qDebug() << "Extraction failed"; |
| 94 | return ""; | 96 | return ""; |
| 95 | } | 97 | } |
| 96 | 98 | ||
| 97 | } | 99 | } |
| 98 | 100 | ||
| 101 | // this function is not in use | ||
| 99 | void FileScriptingInterface::recursiveFileScan(QFileInfo file, QString* dirName) { | 102 | void FileScriptingInterface::recursiveFileScan(QFileInfo file, QString* dirName) { |
| 100 | /*if (!file.isDir()) { | 103 | /*if (!file.isDir()) { |
| 101 | qDebug() << "Regular file logged: " + file.fileName(); | 104 | qDebug() << "Regular file logged: " + file.fileName(); |
| 102 | return; | 105 | return; |
| 103 | }*/ | 106 | }*/ |
| 104 | QFileInfoList files; | 107 | QFileInfoList files; |
| 105 | 108 | ||
| 106 | if (file.fileName().contains(".zip")) { | 109 | if (file.fileName().contains(".zip")) { |
| 107 | qDebug() << "Extracting archive: " + file.fileName(); | 110 | qDebug() << "Extracting archive: " + file.fileName(); |
| 108 | JlCompress::extractDir(file.fileName()); | 111 | JlCompress::extractDir(file.fileName()); |
| 109 | } | 112 | } |
| 110 | files = file.dir().entryInfoList(); | 113 | files = file.dir().entryInfoList(); |
| 111 | 114 | ||
| 112 | /*if (files.empty()) { | 115 | /*if (files.empty()) { |
| 113 | files = JlCompress::getFileList(file.fileName()); | 116 | files = JlCompress::getFileList(file.fileName()); |
| 114 | }*/ | 117 | }*/ |
| 115 | 118 | ||
| 116 | foreach (QFileInfo file, files) { | 119 | foreach (QFileInfo file, files) { |
| 117 | qDebug() << "Looking into file: " + file.fileName(); | 120 | qDebug() << "Looking into file: " + file.fileName(); |
| 118 | recursiveFileScan(file, dirName); | 121 | recursiveFileScan(file, dirName); |
| 119 | } | 122 | } |
| 120 | return; | 123 | return; |
| 121 | } | 124 | } |