History

Downloads from Clara.io and uploads to asset server

elisa-lj11 committed 10 years ago

Commit a94a3041 parent 615627e4 files · +34 −64Browse files

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

Unified · Split

libraries/script-engine/src/FileScriptingInterface.cpp+26−62
@@ -34,7 +34,16 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent · 33 unmodified lines
34void FileScriptingInterface::runUnzip(QString path, QUrl url) {34void 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 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
40bool FileScriptingInterface::testUrl(QUrl url) {49bool FileScriptingInterface::testUrl(QUrl url) {
@@ -68,67 +77,22 @@ void FileScriptingInterface::downloadZip(QString path, const QString link) { · 27 unmodified lines
68}77}
69 78
70// clement's help :D79// clement's help :D
71void FileScriptingInterface::unzipFile(QString path) {80QString FileScriptingInterface::unzipFile(QString path) {
72 //ResourceRequest* request = qobject_cast<ResourceRequest*>(sender());81
73 //QUrl url = request->getUrl();82 qDebug() << "Zip file was downloaded";
74 83 QDir dir(path);
75 //if (request->getResult() == ResourceRequest::Success) {84 QString dirName = dir.path();
76 qDebug() << "Zip file was downloaded";85 qDebug() << "Zip directory is stored at: " + dirName;
77 QDir dir(path);86 QStringList list = JlCompress::extractDir(dirName, "C:/Users/elisa/Downloads/test");
78 //QByteArray compressedFileContent = request->getData(); // <-- Downloaded file is in here87
79 //QBuffer buffer(&compressedFileContent);88 qDebug() << list;
80 //buffer.open(QIODevice::ReadOnly);89
81 90 if (!list.isEmpty()) {
82 //QString zipFileName = QFile::decodeName(compressedFileContent);91 return list.front();
83 QString dirName = dir.path();92 } else {
84 //QDir testPath("C:/Users/elisa/Downloads/banana.zip");93 qDebug() << "Extraction failed";
85 qDebug() << "Zip directory is stored at: " + dirName;94 return "";
86 QStringList list = JlCompress::extractDir(dirName, "C:/Users/elisa/Downloads/test");95 }
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 //}
132 96
133}97}
134 98