From 98ad7dd049a366e21d60a34548736a3c8ef72877 Mon Sep 17 00:00:00 2001 From: dec05eba Date: Sat, 30 Dec 2017 04:32:49 +0100 Subject: Add support for windows (ugly fast solution) --- src/curl.cpp | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) (limited to 'src/curl.cpp') 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 curl::downloadFile(const char *url, const char *filepath) + Result 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); -- cgit v1.2.3