diff options
Diffstat (limited to 'src/curl.cpp')
-rw-r--r-- | src/curl.cpp | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/src/curl.cpp b/src/curl.cpp index 56c19ec..a3c5e28 100644 --- a/src/curl.cpp +++ b/src/curl.cpp @@ -5,6 +5,12 @@ using namespace std; +#if OS_FAMILY == OS_FAMILY_WINDOWS +#pragma comment(lib, "Ws2_32.lib") +#pragma comment(lib, "Wldap32.lib") +#pragma comment(lib, "Crypt32.lib") +#endif + #ifdef DEBUG #define CURL_DEBUG #endif @@ -44,7 +50,7 @@ namespace sibs return size * nmemb; } - Result<bool> curl::downloadFile(const char *url, const char *filepath) + Result<bool> curl::downloadFile(const char *url, const _tinydir_char_t *filepath) { CURL *curl_handle = curl_easy_init(); curl_easy_setopt(curl_handle, CURLOPT_URL, url); @@ -60,15 +66,19 @@ namespace sibs curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writeToFile); curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, true); curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "SIBS"); - + curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE); +#if OS_FAMILY == OS_FAMILY_POSIX FILE *file = fopen(filepath, "wb"); +#else + FILE *file = _wfopen(filepath, L"wb"); +#endif if(!file) { int error = errno; curl_easy_cleanup(curl_handle); string errMsg = "Failed to open file for writing: "; - errMsg += filepath; + errMsg += toUtf8(filepath); if(error != 0) { errMsg += "; Reason: "; @@ -131,8 +141,9 @@ namespace sibs curl_easy_setopt(curl_handle, CURLOPT_NOPROGRESS, noProgressMeter); curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, writeToString); curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, true); - curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "Hacker"); - + curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "SIBS"); + curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, FALSE); + curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, &result.str); printf("Downloading from url: %s\n", url); CURLcode curlResponse = curl_easy_perform(curl_handle); |