mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-02-22 04:49:12 -06:00
Making request-based downloading work
This commit is contained in:
@@ -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"; }
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
#include <ghoul/filesystem/filesystem.h>
|
||||
#include <ghoul/logging/logmanager.h>
|
||||
|
||||
#include <fstream>
|
||||
|
||||
#ifdef OPENSPACE_CURL_ENABLED
|
||||
#include <curl/curl.h>
|
||||
#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; }
|
||||
);
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user