mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-03-14 17:40:26 -05:00
Improve implementation and interface of http downloads
This commit is contained in:
@@ -112,14 +112,16 @@ void HttpSynchronization::start() {
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: Do this in a new thread!
|
||||
std::vector<std::string> listUrls = fileListUrls();
|
||||
for (const auto& url : listUrls) {
|
||||
if (trySyncFromUrl(url)) {
|
||||
resolve();
|
||||
return;
|
||||
_syncThread = std::thread([this, listUrls] {
|
||||
for (const auto& url : listUrls) {
|
||||
if (trySyncFromUrl(url)) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
//fail();
|
||||
});
|
||||
}
|
||||
|
||||
void HttpSynchronization::cancel() {
|
||||
@@ -150,9 +152,11 @@ bool HttpSynchronization::trySyncFromUrl(std::string listUrl) {
|
||||
HttpRequest::RequestOptions opt;
|
||||
opt.requestTimeoutSeconds = 0;
|
||||
|
||||
HttpMemoryDownload fileListDownload(listUrl);
|
||||
SyncHttpMemoryDownload fileListDownload(listUrl);
|
||||
fileListDownload.download(opt);
|
||||
|
||||
// ...
|
||||
|
||||
const std::vector<char>& buffer = fileListDownload.downloadedData();
|
||||
|
||||
std::istringstream fileList(std::string(buffer.begin(), buffer.end()));
|
||||
@@ -168,7 +172,7 @@ bool HttpSynchronization::trySyncFromUrl(std::string listUrl) {
|
||||
filename;
|
||||
|
||||
std::thread t([opt, line, fileDestination]() {
|
||||
HttpFileDownload fileDownload(line, fileDestination);
|
||||
SyncHttpFileDownload fileDownload(line, fileDestination);
|
||||
fileDownload.download(opt);
|
||||
});
|
||||
downloadThreads.push_back(std::move(t));
|
||||
@@ -176,6 +180,7 @@ bool HttpSynchronization::trySyncFromUrl(std::string listUrl) {
|
||||
for (auto& t : downloadThreads) {
|
||||
t.join();
|
||||
}
|
||||
|
||||
createSyncFile();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user