diff --git a/interface/resources/qml/controls-uit/WebView.qml b/interface/resources/qml/controls-uit/WebView.qml index fdc1452d9b..bb08e5e389 100644 --- a/interface/resources/qml/controls-uit/WebView.qml +++ b/interface/resources/qml/controls-uit/WebView.qml @@ -66,7 +66,7 @@ WebEngineView { id: zipTimer running: false repeat: false - interval: 1000 + interval: 1500 property var handler; onTriggered: handler(); } diff --git a/interface/resources/qml/hifi/Desktop.qml b/interface/resources/qml/hifi/Desktop.qml index 9ab9324b74..ab1fffdcf5 100644 --- a/interface/resources/qml/hifi/Desktop.qml +++ b/interface/resources/qml/hifi/Desktop.qml @@ -77,6 +77,7 @@ OriginalDesktop.Desktop { property bool webViewProfileSetup: false property string currentUrl: "" property string adaptedPath: "" + property string tempDir: "" function initWebviewProfileHandlers(profile) { console.log("the webview url in desktop is: " + currentUrl); @@ -86,12 +87,12 @@ OriginalDesktop.Desktop { profile.downloadRequested.connect(function(download){ console.log("Download start: " + download.state); adaptedPath = File.convertUrlToPath(currentUrl); - download.path = "C:/Users/elisa/Downloads/" + adaptedPath; + tempDir = File.getTempDir(); + download.path = tempDir + "/" + adaptedPath; console.log("Path where it should download: " + download.path); download.accept(); console.log("Download accept: " + download.state); if (download.state === WebEngineDownloadItem.DownloadInterrupted) { - console.log("Download? " + download.state); console.log("download failed to complete"); } }) @@ -100,7 +101,7 @@ OriginalDesktop.Desktop { if (download.state === WebEngineDownloadItem.DownloadCompleted) { console.log("Download Finished: " + download.state); console.log("File object is: " + File); - File.runUnzip(download.path, currentUrl); + File.runUnzip(download.path, tempDir, currentUrl); } else { console.log("The download was corrupted, state: " + download.state); } diff --git a/libraries/script-engine/src/FileScriptingInterface.cpp b/libraries/script-engine/src/FileScriptingInterface.cpp index 4126b5fdad..94d8d1b424 100644 --- a/libraries/script-engine/src/FileScriptingInterface.cpp +++ b/libraries/script-engine/src/FileScriptingInterface.cpp @@ -31,10 +31,10 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent // nothing for now } -void FileScriptingInterface::runUnzip(QString path, QUrl url) { +void FileScriptingInterface::runUnzip(QString path, QString tempDir, QUrl url) { qDebug() << "Url that was downloaded: " + url.toString(); qDebug() << "Path where download is saved: " + path; - QString file = unzipFile(path); + QString file = unzipFile(path, tempDir); if (file != "") { qDebug() << "file to upload: " + file; QUrl url = QUrl::fromLocalFile(file); @@ -43,6 +43,8 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url) { } else { qDebug() << "unzip failed"; } + qDebug() << "Removing temporary directory at: " + tempDir; + QDir(tempDir).removeRecursively(); } bool FileScriptingInterface::testUrl(QUrl url) { @@ -72,20 +74,20 @@ void FileScriptingInterface::downloadZip(QString path, const QString link) { QUrl url = QUrl(link); auto request = ResourceManager::createResourceRequest(nullptr, url); connect(request, &ResourceRequest::finished, this, [this, path]{ - unzipFile(path); + unzipFile(path, ""); // so intellisense isn't mad }); request->send(); } -QString FileScriptingInterface::unzipFile(QString path) { +QString FileScriptingInterface::unzipFile(QString path, QString tempDir) { QDir dir(path); QString dirName = dir.path(); qDebug() << "Zip directory is stored at: " + dirName; - QString target = path.section("/", -1) + "/model_repo"; + QString target = tempDir + "/model_repo"; qDebug() << "Target path: " + target; - QStringList list = JlCompress::extractDir(dirName, "C:/Users/elisa/Downloads/test"); + QStringList list = JlCompress::extractDir(dirName, target); qDebug() << list; diff --git a/libraries/script-engine/src/FileScriptingInterface.h b/libraries/script-engine/src/FileScriptingInterface.h index df6b91c678..2658622644 100644 --- a/libraries/script-engine/src/FileScriptingInterface.h +++ b/libraries/script-engine/src/FileScriptingInterface.h @@ -22,22 +22,18 @@ class FileScriptingInterface : public QObject { public: FileScriptingInterface(QObject* parent); - //void runUnzip(QString path, QString importURL); - QString getTempDir(); - public slots: - //void unzipFile(QString path); bool testUrl(QUrl url); QString convertUrlToPath(QUrl url); - void runUnzip(QString path, QUrl url); + void runUnzip(QString path, QString tempDir, QUrl url); + QString getTempDir(); signals: void unzipSuccess(QString url); private: - //void downloadZip(); - QString unzipFile(QString path); + QString unzipFile(QString path, QString tempDir); void recursiveFileScan(QFileInfo file, QString* dirName); void downloadZip(QString path, const QString link);