| 76 | } |
| 77 | |
| 78 | void RetrieveToFile(const std::string &url, const std::string &path, RetrieveOnProgressCallback on_progress_cb) { |
| 79 | const auto rc = socketInitializeDefault(); |
| 80 | if(R_FAILED(rc)) { |
| 81 | return; |
| 82 | } |
| 83 | |
| 84 | auto f = fopen(path.c_str(), "wb"); |
| 85 | if(f) { |
| 86 | g_CurrentOnProgressCallback = on_progress_cb; |
| 87 | auto curl = curl_easy_init(); |
| 88 | curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); |
| 89 | curl_easy_setopt(curl, CURLOPT_USERAGENT, "Goldleaf"); |
| 90 | curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0l); |
| 91 | curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0l); |
| 92 | curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1l); |
| 93 | curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, FileWriteImpl); |
| 94 | curl_easy_setopt(curl, CURLOPT_WRITEDATA, f); |
| 95 | curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0l); |
| 96 | curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, ProgressImpl); |
| 97 | |
| 98 | curl_easy_perform(curl); |
| 99 | curl_easy_cleanup(curl); |
| 100 | fclose(f); |
| 101 | } |
| 102 | socketExit(); |
| 103 | } |
| 104 | |
| 105 | bool HasConnection() { |
| 106 | return gethostid() == INADDR_LOOPBACK; |