History

Switched saving download/upload to temporary directory

elisa-lj11 committed 10 years ago

Commit a9a87101 parent b1b2ea44 files · +16 −17Browse 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+8−6
@@ -31,10 +31,10 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent · 30 unmodified lines
31 // nothing for now31 // nothing for now
32}32}
33 33
34void FileScriptingInterface::runUnzip(QString path, QUrl url) {34void FileScriptingInterface::runUnzip(QString path, QString tempDir, 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, tempDir);
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);
@@ -43,6 +43,8 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url) { · 2 unmodified lines
43 } else {43 } else {
44 qDebug() << "unzip failed";44 qDebug() << "unzip failed";
45 }45 }
46 qDebug() << "Removing temporary directory at: " + tempDir;
47 QDir(tempDir).removeRecursively();
46}48}
47 49
48bool FileScriptingInterface::testUrl(QUrl url) {50bool FileScriptingInterface::testUrl(QUrl url) {
@@ -72,20 +74,20 @@ void FileScriptingInterface::downloadZip(QString path, const QString link) { · 23 unmodified lines
72 QUrl url = QUrl(link);74 QUrl url = QUrl(link);
73 auto request = ResourceManager::createResourceRequest(nullptr, url);75 auto request = ResourceManager::createResourceRequest(nullptr, url);
74 connect(request, &ResourceRequest::finished, this, [this, path]{76 connect(request, &ResourceRequest::finished, this, [this, path]{
75 unzipFile(path);77 unzipFile(path, ""); // so intellisense isn't mad
76 });78 });
77 request->send();79 request->send();
78}80}
79 81
80 82
81QString FileScriptingInterface::unzipFile(QString path) {83QString FileScriptingInterface::unzipFile(QString path, QString tempDir) {
82 84
83 QDir dir(path);85 QDir dir(path);
84 QString dirName = dir.path();86 QString dirName = dir.path();
85 qDebug() << "Zip directory is stored at: " + dirName;87 qDebug() << "Zip directory is stored at: " + dirName;
86 QString target = path.section("/", -1) + "/model_repo";88 QString target = tempDir + "/model_repo";
87 qDebug() << "Target path: " + target;89 qDebug() << "Target path: " + target;
88 QStringList list = JlCompress::extractDir(dirName, "C:/Users/elisa/Downloads/test");90 QStringList list = JlCompress::extractDir(dirName, target);
89 91
90 qDebug() << list;92 qDebug() << list;
91 93