diff --git a/src/addons/network.cpp b/src/addons/network.cpp index 76f748acb..a59b26022 100644 --- a/src/addons/network.cpp +++ b/src/addons/network.cpp @@ -27,7 +27,7 @@ #include "io/file_manager.hpp" // ------------------------------------------------------------------------------------------------------ -void download(std::string file, std::string save) +bool download(std::string file, std::string save) { CURL *session = curl_easy_init(); std::cout << "Downloading: " << std::string(UserConfigParams::m_server_addons.toString() + "/" + file) << std::endl; @@ -39,10 +39,22 @@ void download(std::string file, std::string save) fp = fopen(std::string(file_manager->getConfigDir() + std::string("/") + file).c_str(), "w"); curl_easy_setopt(session, CURLOPT_WRITEDATA, fp); curl_easy_setopt(session, CURLOPT_WRITEFUNCTION, fwrite); - curl_easy_perform(session); + curl_easy_setopt(session, CURLOPT_PROGRESSFUNCTION, &progressDownload); + curl_easy_setopt(session, CURLOPT_NOPROGRESS, 0); + int succes = curl_easy_perform(session); fclose(fp); curl_easy_cleanup(session); - std::cout << UserConfigParams::m_server_addons.toString() << std::endl; + if(succes == 0) + std::cout << "Download successfull" << std::endl; + else + std::cout << "Download failed... check your network connexion" << std::endl; +} +int progressDownload (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) +{ + int progress = dlnow/dltotal*100; + if(isnan(dlnow/dltotal*100)) + progress = 0; + std::cout << "Download progress: " << progress << "%" << std::endl; + return 0; } - #endif diff --git a/src/addons/network.hpp b/src/addons/network.hpp index 27ffc7be4..2456e8fc2 100644 --- a/src/addons/network.hpp +++ b/src/addons/network.hpp @@ -21,7 +21,8 @@ #define HEADER_NETWORK_HPP /** Download a file. The file name isn't absolute, the server in the config will be added to file. */ -void download(std::string file, std::string save = ""); +bool download(std::string file, std::string save = ""); +int progressDownload (void *clientp, double dltotal, double dlnow, double ultotal, double ulnow); #endif #endif