diff --git a/apps/Launcher/syncwidget.cpp b/apps/Launcher/syncwidget.cpp index c984031480..a444f4c058 100644 --- a/apps/Launcher/syncwidget.cpp +++ b/apps/Launcher/syncwidget.cpp @@ -128,6 +128,12 @@ void SyncWidget::handleFileRequest(QString module, FileRequests files) { qDebug() << "File Requests"; for (const FileRequest& f : files) { qDebug() << f.identifier << " (" << f.version << ")" << " -> " << f.destination; + DlManager.downloadRequestFiles( + f.identifier.toStdString(), + fullPath(module, f.destination).toStdString(), + f.version, + [](const ghoul::filesystem::File& f) { qDebug() << "finished"; } + ); } diff --git a/src/engine/downloadmanager.cpp b/src/engine/downloadmanager.cpp index f6be8283d5..b40afb8851 100644 --- a/src/engine/downloadmanager.cpp +++ b/src/engine/downloadmanager.cpp @@ -27,6 +27,8 @@ #include #include +#include + #ifdef OPENSPACE_CURL_ENABLED #include #endif @@ -69,7 +71,7 @@ bool DownloadManager::downloadFile( curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, writeData); curl_easy_setopt(curl, CURLOPT_WRITEDATA, fp); LDEBUG("Starting download for file: '" << url << - "' into file '" << file.filename() << "'"); + "' into file '" << file.path() << "'"); CURLcode res = curl_easy_perform(curl); curl_easy_cleanup(curl); fclose(fp); @@ -95,12 +97,40 @@ bool DownloadManager::downloadRequestFiles( DownloadFinishedCallback finishedCallback, DownloadProgressCallback progressCallback) { - // Escaping is necessary ---abock + bool s = FileSys.createDirectory(destination, true); + // TODO: Check s ---abock + // TODO: Escaping is necessary ---abock const std::string fullRequest =_requestURL + "?" + RequestIdentifier + "=" + identifier + "&" + RequestFileVersion + "=" + std::to_string(version) + "&" + - RequestApplicationVersion = "=" + std::to_string(_applicationVersion); + RequestApplicationVersion + "=" + std::to_string(_applicationVersion); + LDEBUG("Request: " << fullRequest); + std::string requestFile = absPath("${TEMPORARY}/" + identifier); + LDEBUG("Request File: " << requestFile); + + bool success = downloadFile( + fullRequest, + requestFile, + [destination](const ghoul::filesystem::File& f) { + LDEBUG("Finished: " << f.path()); + std::ifstream temporary(f.path()); + std::string line; + int nFiles = 0; + int nFinished = 0; + while (std::getline(temporary, line)) { + ++nFiles; + std::string file = ghoul::filesystem::File(line).filename(); + + LDEBUG("\tLine: " << line << " ; Dest: " << destination.path() + "/" + file); + bool success = DlManager.downloadFile( + line, + destination.path() + "/" + file, + [&nFinished](const ghoul::filesystem::File& f) { ++nFinished; } + ); + } + } + );