Showing the changes to libraries/script-engine/src/FileScriptingInterface.cpp (1 of 4 files). Show all
Unified · Split
| @@ -34,7 +34,16 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent · 33 unmodified lines | ||
| 34 | 34 | void FileScriptingInterface::runUnzip(QString path, QUrl url) { |
| 35 | 35 | qDebug() << "Url that was downloaded: " + url.toString(); |
| 36 | 36 | qDebug() << "Path where download is saved: " + path; |
| 37 | − unzipFile(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 | + } | |
| 38 | 47 | } |
| 39 | 48 | |
| 40 | 49 | bool FileScriptingInterface::testUrl(QUrl url) { |
| @@ -68,67 +77,22 @@ void FileScriptingInterface::downloadZip(QString path, const QString link) { · 27 unmodified lines | ||
| 68 | 77 | } |
| 69 | 78 | |
| 70 | 79 | // clement's help :D |
| 71 | −void FileScriptingInterface::unzipFile(QString path) { | |
| 72 | − //ResourceRequest* request = qobject_cast<ResourceRequest*>(sender()); | |
| 73 | − //QUrl url = request->getUrl(); | |
| 74 | − | |
| 75 | − //if (request->getResult() == ResourceRequest::Success) { | |
| 76 | − qDebug() << "Zip file was downloaded"; | |
| 77 | − QDir dir(path); | |
| 78 | − //QByteArray compressedFileContent = request->getData(); // <-- Downloaded file is in here | |
| 79 | − //QBuffer buffer(&compressedFileContent); | |
| 80 | − //buffer.open(QIODevice::ReadOnly); | |
| 81 | − | |
| 82 | − //QString zipFileName = QFile::decodeName(compressedFileContent); | |
| 83 | − QString dirName = dir.path(); | |
| 84 | − //QDir testPath("C:/Users/elisa/Downloads/banana.zip"); | |
| 85 | − qDebug() << "Zip directory is stored at: " + dirName; | |
| 86 | − QStringList list = JlCompress::extractDir(dirName, "C:/Users/elisa/Downloads/test"); | |
| 87 | − | |
| 88 | − qDebug() << list; | |
| 89 | − | |
| 90 | − //QFileInfoList files = dir.entryInfoList(); | |
| 91 | − QFileInfoList files = dir.entryInfoList(); | |
| 92 | − foreach(QFileInfo file, files) { | |
| 93 | − qDebug() << "My file: " + file.fileName(); | |
| 94 | − recursiveFileScan(file, &dirName); | |
| 95 | − | |
| 96 | − } | |
| 97 | − | |
| 98 | − | |
| 99 | − /*foreach (QFileInfo file, files) { | |
| 100 | − if (file.isDir()) { | |
| 101 | − if (file.fileName().contains(".zip")) { | |
| 102 | − qDebug() << "Zip file expanded: " + file.fileName(); | |
| 103 | − } | |
| 104 | − | |
| 105 | − qDebug() << "Regular file logged: " + file.fileName(); | |
| 106 | − } | |
| 107 | − }*/ | |
| 108 | − | |
| 109 | − | |
| 110 | − | |
| 111 | − | |
| 112 | − //QFile file = | |
| 113 | − //need to convert this byte array to a file | |
| 114 | − /*QuaZip zip(zipFileName); | |
| 115 | − | |
| 116 | − if (zip.open(QuaZip::mdUnzip)) { | |
| 117 | − qDebug() << "Opened"; | |
| 118 | − | |
| 119 | − for (bool more = zip.goToFirstFile(); more; more = zip.goToNextFile()) { | |
| 120 | − // do something | |
| 121 | − qDebug() << zip.getCurrentFileName(); | |
| 122 | − } | |
| 123 | − if (zip.getZipError() == UNZ_OK) { | |
| 124 | − // ok, there was no error | |
| 125 | − }*/ | |
| 126 | − | |
| 127 | − | |
| 128 | − //buffer.close(); | |
| 129 | − //} else { | |
| 130 | − // qDebug() << "Could not download the zip file"; | |
| 131 | − //} | |
| 80 | +QString FileScriptingInterface::unzipFile(QString path) { | |
| 81 | + | |
| 82 | + qDebug() << "Zip file was downloaded"; | |
| 83 | + QDir dir(path); | |
| 84 | + QString dirName = dir.path(); | |
| 85 | + qDebug() << "Zip directory is stored at: " + dirName; | |
| 86 | + QStringList list = JlCompress::extractDir(dirName, "C:/Users/elisa/Downloads/test"); | |
| 87 | + | |
| 88 | + qDebug() << list; | |
| 89 | + | |
| 90 | + if (!list.isEmpty()) { | |
| 91 | + return list.front(); | |
| 92 | + } else { | |
| 93 | + qDebug() << "Extraction failed"; | |
| 94 | + return ""; | |
| 95 | + } | |
| 132 | 96 | |
| 133 | 97 | } |
| 134 | 98 | |