mirror of
https://github.com/JulianGro/overte.git
synced 2025-04-09 07:22:19 +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
|
||||
running: false
|
||||
repeat: false
|
||||
interval: 1000
|
||||
interval: 1500
|
||||
property var handler;
|
||||
onTriggered: handler();
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue