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