diff --git a/src/addons/network.cpp b/src/addons/network.cpp index dca557bc8..59c9c9f6b 100644 --- a/src/addons/network.cpp +++ b/src/addons/network.cpp @@ -27,29 +27,16 @@ #include "io/file_manager.hpp" // ------------------------------------------------------------------------------------------------------ -void download(std::string file) +void 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; curl_easy_setopt(session, CURLOPT_URL, std::string(UserConfigParams::m_server_addons.toString() + "/" + file).c_str()); - - FILE * 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); - fclose(fp); - curl_easy_cleanup(session); - std::cout << UserConfigParams::m_server_addons.toString() << std::endl; -} - -// ------------------------------------------------------------------------------------------------------ -void 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; - curl_easy_setopt(session, CURLOPT_URL, std::string(UserConfigParams::m_server_addons.toString() + "/" + file).c_str()); - - FILE * fp = fopen(std::string(file_manager->getConfigDir() + std::string("/") + save).c_str(), "w"); + FILE * fp; + if(save != "") + fp = fopen(std::string(file_manager->getConfigDir() + std::string("/") + save).c_str(), "w"); + else + 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); diff --git a/src/addons/network.hpp b/src/addons/network.hpp index 0f7e52eb3..27ffc7be4 100644 --- a/src/addons/network.hpp +++ b/src/addons/network.hpp @@ -21,11 +21,7 @@ #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); - -/** Download a file with a specific destination. */ - -void download(std::string file, std::string out); +void download(std::string file, std::string save = ""); #endif #endif diff --git a/src/io/file_manager.cpp b/src/io/file_manager.cpp index 6a54fa724..5381bdfbe 100644 --- a/src/io/file_manager.cpp +++ b/src/io/file_manager.cpp @@ -583,3 +583,10 @@ void FileManager::listFiles(std::set& result, const std::string& di } // listFiles //----------------------------------------------------------------------------- + +#ifdef ADDONS_MANAGER +void FileManager::checkAndCreateDirForAddons(std::string addons_path) +{ + checkAndCreateDirectory(getAddonsDir() + "/data/" + addons_path); +} +#endif diff --git a/src/io/file_manager.hpp b/src/io/file_manager.hpp index 3aaf4a28b..f968ed40e 100644 --- a/src/io/file_manager.hpp +++ b/src/io/file_manager.hpp @@ -80,6 +80,7 @@ public: std::string getConfigDir () const; #ifdef ADDONS_MANAGER std::string getAddonsDir () const; + void checkAndCreateDirForAddons(std::string addons_path); #endif std::string getKartDir () const; std::string getDataDir () const;