From 4353741c543bdda2ed438fae753b02bdcec7aaca Mon Sep 17 00:00:00 2001 From: Micah Date: Mon, 26 Apr 2021 10:07:31 -0400 Subject: [PATCH] fix downloadFile function with waiting for complete --- src/engine/openspaceengine_lua.inl | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/engine/openspaceengine_lua.inl b/src/engine/openspaceengine_lua.inl index d5881b8ada..aa16a79db2 100644 --- a/src/engine/openspaceengine_lua.inl +++ b/src/engine/openspaceengine_lua.inl @@ -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(L, 1); const std::string& savePath = ghoul::lua::value(L, 2); + bool waitForComplete = false; + if (n == 3) { + waitForComplete = ghoul::lua::value(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,