mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 09:48:44 +02:00
Switched saving download/upload to temporary directory
This commit is contained in:
parent
b1b2ea48b2
commit
a9a8710689
4 changed files with 16 additions and 17 deletions
|
@ -66,7 +66,7 @@ WebEngineView {
|
||||||
id: zipTimer
|
id: zipTimer
|
||||||
running: false
|
running: false
|
||||||
repeat: false
|
repeat: false
|
||||||
interval: 1000
|
interval: 1500
|
||||||
property var handler;
|
property var handler;
|
||||||
onTriggered: handler();
|
onTriggered: handler();
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,6 +77,7 @@ OriginalDesktop.Desktop {
|
||||||
property bool webViewProfileSetup: false
|
property bool webViewProfileSetup: false
|
||||||
property string currentUrl: ""
|
property string currentUrl: ""
|
||||||
property string adaptedPath: ""
|
property string adaptedPath: ""
|
||||||
|
property string tempDir: ""
|
||||||
|
|
||||||
function initWebviewProfileHandlers(profile) {
|
function initWebviewProfileHandlers(profile) {
|
||||||
console.log("the webview url in desktop is: " + currentUrl);
|
console.log("the webview url in desktop is: " + currentUrl);
|
||||||
|
@ -86,12 +87,12 @@ OriginalDesktop.Desktop {
|
||||||
profile.downloadRequested.connect(function(download){
|
profile.downloadRequested.connect(function(download){
|
||||||
console.log("Download start: " + download.state);
|
console.log("Download start: " + download.state);
|
||||||
adaptedPath = File.convertUrlToPath(currentUrl);
|
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);
|
console.log("Path where it should download: " + download.path);
|
||||||
download.accept();
|
download.accept();
|
||||||
console.log("Download accept: " + download.state);
|
console.log("Download accept: " + download.state);
|
||||||
if (download.state === WebEngineDownloadItem.DownloadInterrupted) {
|
if (download.state === WebEngineDownloadItem.DownloadInterrupted) {
|
||||||
console.log("Download? " + download.state);
|
|
||||||
console.log("download failed to complete");
|
console.log("download failed to complete");
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -100,7 +101,7 @@ OriginalDesktop.Desktop {
|
||||||
if (download.state === WebEngineDownloadItem.DownloadCompleted) {
|
if (download.state === WebEngineDownloadItem.DownloadCompleted) {
|
||||||
console.log("Download Finished: " + download.state);
|
console.log("Download Finished: " + download.state);
|
||||||
console.log("File object is: " + File);
|
console.log("File object is: " + File);
|
||||||
File.runUnzip(download.path, currentUrl);
|
File.runUnzip(download.path, tempDir, currentUrl);
|
||||||
} else {
|
} else {
|
||||||
console.log("The download was corrupted, state: " + download.state);
|
console.log("The download was corrupted, state: " + download.state);
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,10 +31,10 @@ FileScriptingInterface::FileScriptingInterface(QObject* parent) : QObject(parent
|
||||||
// nothing for now
|
// 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() << "Url that was downloaded: " + url.toString();
|
||||||
qDebug() << "Path where download is saved: " + path;
|
qDebug() << "Path where download is saved: " + path;
|
||||||
QString file = unzipFile(path);
|
QString file = unzipFile(path, tempDir);
|
||||||
if (file != "") {
|
if (file != "") {
|
||||||
qDebug() << "file to upload: " + file;
|
qDebug() << "file to upload: " + file;
|
||||||
QUrl url = QUrl::fromLocalFile(file);
|
QUrl url = QUrl::fromLocalFile(file);
|
||||||
|
@ -43,6 +43,8 @@ void FileScriptingInterface::runUnzip(QString path, QUrl url) {
|
||||||
} else {
|
} else {
|
||||||
qDebug() << "unzip failed";
|
qDebug() << "unzip failed";
|
||||||
}
|
}
|
||||||
|
qDebug() << "Removing temporary directory at: " + tempDir;
|
||||||
|
QDir(tempDir).removeRecursively();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool FileScriptingInterface::testUrl(QUrl url) {
|
bool FileScriptingInterface::testUrl(QUrl url) {
|
||||||
|
@ -72,20 +74,20 @@ void FileScriptingInterface::downloadZip(QString path, const QString link) {
|
||||||
QUrl url = QUrl(link);
|
QUrl url = QUrl(link);
|
||||||
auto request = ResourceManager::createResourceRequest(nullptr, url);
|
auto request = ResourceManager::createResourceRequest(nullptr, url);
|
||||||
connect(request, &ResourceRequest::finished, this, [this, path]{
|
connect(request, &ResourceRequest::finished, this, [this, path]{
|
||||||
unzipFile(path);
|
unzipFile(path, ""); // so intellisense isn't mad
|
||||||
});
|
});
|
||||||
request->send();
|
request->send();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
QString FileScriptingInterface::unzipFile(QString path) {
|
QString FileScriptingInterface::unzipFile(QString path, QString tempDir) {
|
||||||
|
|
||||||
QDir dir(path);
|
QDir dir(path);
|
||||||
QString dirName = dir.path();
|
QString dirName = dir.path();
|
||||||
qDebug() << "Zip directory is stored at: " + dirName;
|
qDebug() << "Zip directory is stored at: " + dirName;
|
||||||
QString target = path.section("/", -1) + "/model_repo";
|
QString target = tempDir + "/model_repo";
|
||||||
qDebug() << "Target path: " + target;
|
qDebug() << "Target path: " + target;
|
||||||
QStringList list = JlCompress::extractDir(dirName, "C:/Users/elisa/Downloads/test");
|
QStringList list = JlCompress::extractDir(dirName, target);
|
||||||
|
|
||||||
qDebug() << list;
|
qDebug() << list;
|
||||||
|
|
||||||
|
|
|
@ -22,22 +22,18 @@ class FileScriptingInterface : public QObject {
|
||||||
public:
|
public:
|
||||||
FileScriptingInterface(QObject* parent);
|
FileScriptingInterface(QObject* parent);
|
||||||
|
|
||||||
//void runUnzip(QString path, QString importURL);
|
|
||||||
QString getTempDir();
|
|
||||||
|
|
||||||
|
|
||||||
public slots:
|
public slots:
|
||||||
//void unzipFile(QString path);
|
|
||||||
bool testUrl(QUrl url);
|
bool testUrl(QUrl url);
|
||||||
QString convertUrlToPath(QUrl url);
|
QString convertUrlToPath(QUrl url);
|
||||||
void runUnzip(QString path, QUrl url);
|
void runUnzip(QString path, QString tempDir, QUrl url);
|
||||||
|
QString getTempDir();
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void unzipSuccess(QString url);
|
void unzipSuccess(QString url);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
//void downloadZip();
|
QString unzipFile(QString path, QString tempDir);
|
||||||
QString unzipFile(QString path);
|
|
||||||
void recursiveFileScan(QFileInfo file, QString* dirName);
|
void recursiveFileScan(QFileInfo file, QString* dirName);
|
||||||
void downloadZip(QString path, const QString link);
|
void downloadZip(QString path, const QString link);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue