mirror of
https://github.com/OpenSpace/OpenSpace.git
synced 2026-01-25 21:48:41 -06:00
fix downloadFile function with waiting for complete
This commit is contained in:
@@ -266,10 +266,14 @@ int removeTag(lua_State* L) {
|
||||
* Downloads a file from Lua interpreter
|
||||
*/
|
||||
int downloadFile(lua_State* L) {
|
||||
ghoul::lua::checkArgumentsAndThrow(L, 2, "lua::addTag");
|
||||
int n = ghoul::lua::checkArgumentsAndThrow(L, {2, 3}, "lua::addTag");
|
||||
|
||||
const std::string& uri = ghoul::lua::value<std::string>(L, 1);
|
||||
const std::string& savePath = ghoul::lua::value<std::string>(L, 2);
|
||||
bool waitForComplete = false;
|
||||
if (n == 3) {
|
||||
waitForComplete = ghoul::lua::value<bool>(L, 3);
|
||||
}
|
||||
lua_settop(L, 0);
|
||||
|
||||
LINFOC("OpenSpaceEngine", fmt::format("Downloading file from {}", uri));
|
||||
@@ -281,6 +285,14 @@ int downloadFile(lua_State* L) {
|
||||
DownloadManager::FailOnError::Yes,
|
||||
5
|
||||
);
|
||||
|
||||
if (waitForComplete) {
|
||||
while (!future->isFinished && future->errorMessage.empty() ) {
|
||||
//just wait
|
||||
LTRACEC("OpenSpaceEngine", fmt::format("waiting {}", future->errorMessage));
|
||||
}
|
||||
}
|
||||
|
||||
if (!future || !future->isFinished) {
|
||||
return ghoul::lua::luaError(
|
||||
L,
|
||||
|
||||
Reference in New Issue
Block a user