67 bool download([[maybe_unused]]
const std::string& url, [[maybe_unused]]
const std::string& local_path)
69#if defined(__APPLE__) && TARGET_OS_IPHONE
70 ERR_NW <<
"Standalone file downloads are currently disabled for iOS builds.";
73 std::unique_ptr<CURL,
decltype(&curl_easy_cleanup)> curl(curl_easy_init(), curl_easy_cleanup);
76 char error[CURL_ERROR_SIZE];
77 std::fill_n(error, CURL_ERROR_SIZE-1,
' ');
78 error[CURL_ERROR_SIZE-1] =
'\0';
81 ERR_NW <<
"curl_easy_init failed initialization, unable to download file.";
89 (res = curl_easy_setopt(curl.get(), CURLOPT_CAINFO, (
game_config::path +
"/certificates/cacert.pem").c_str()) ) != CURLE_OK ||
91 (res = curl_easy_setopt(curl.get(), CURLOPT_URL, url.c_str())) != CURLE_OK ||
92 (res = curl_easy_setopt(curl.get(), CURLOPT_WRITEFUNCTION,
write_callback)) != CURLE_OK ||
93 (res = curl_easy_setopt(curl.get(), CURLOPT_WRITEDATA, &buffer)) != CURLE_OK ||
94 (res = curl_easy_setopt(curl.get(), CURLOPT_ERRORBUFFER, error)) != CURLE_OK ||
95 (res = curl_easy_setopt(curl.get(), CURLOPT_FORBID_REUSE, 1L)) != CURLE_OK ||
96 (res = curl_easy_setopt(curl.get(), CURLOPT_FRESH_CONNECT, 1L)) != CURLE_OK ||
97 (res = curl_easy_setopt(curl.get(), CURLOPT_FAILONERROR, 1L)) != CURLE_OK ||
98 (res = curl_easy_setopt(curl.get(), CURLOPT_TIMEOUT_MS, 5000L)) != CURLE_OK ||
99#
if LIBCURL_VERSION_NUM >= 0x075500
100 (res = curl_easy_setopt(curl.get(), CURLOPT_PROTOCOLS_STR,
"https")) != CURLE_OK
102 (res = curl_easy_setopt(curl.get(), CURLOPT_PROTOCOLS, CURLPROTO_HTTPS)) != CURLE_OK
105 ERR_NW <<
"Error setting curl option: " << curl_easy_strerror(res);
109 res = curl_easy_perform(curl.get());
110 if(res != CURLE_OK) {
111 ERR_NW <<
"Error downloading file from url `" << url <<
"`.\n"
112 <<
"Short error: " << curl_easy_strerror(res) <<
"\n"
113 <<
"Long error: " << std::string(error);
119 DBG_NW <<
"Wrote downloaded file to: " << local_path;
121 ERR_NW <<
"io_exception writing downloaded data to file at: " << local_path <<
"\n" <<
e.what() <<
" : " <<
e.message;