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
3434 void FileScriptingInterface::runUnzip(QString path, QUrl url) {
3535 qDebug() << "Url that was downloaded: " + url.toString();
3636 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+ }
3847 }
3948
4049 bool FileScriptingInterface::testUrl(QUrl url) {
@@ -68,67 +77,22 @@ void FileScriptingInterface::downloadZip(QString path, const QString link) { · 27 unmodified lines
6877 }
6978
7079 // 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+ }
13296
13397 }
13498