X-Git-Url: https://git.street.me.uk/andy/viking.git/blobdiff_plain/6a2692bef555267902a0cac00ad38a1af1594d22..5ff75d1ed34298a223c651d46fe2aa000db3e459:/src/curl_download.c diff --git a/src/curl_download.c b/src/curl_download.c index 4b078aaa..f230dca0 100644 --- a/src/curl_download.c +++ b/src/curl_download.c @@ -33,6 +33,7 @@ #include +#include "background.h" #include "file.h" #include "globals.h" #include "curl_download.h" @@ -50,6 +51,11 @@ static size_t curl_write_func(void *ptr, size_t size, size_t nmemb, FILE *stream return fwrite(ptr, size, nmemb, stream); } +static int curl_progress_func(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) +{ + return a_background_testcancel(NULL); +} + static gchar *get_cookie_file(gboolean init) { static gchar *cookie_file = NULL; @@ -80,7 +86,7 @@ static gchar *get_cookie_file(gboolean init) if (vik_verbose) curl_easy_setopt ( curl, CURLOPT_VERBOSE, 1 ); curl_easy_setopt(curl, CURLOPT_URL, "http://maps.google.com/"); /* google.com sets "PREF" cookie */ - curl_easy_setopt ( curl, CURLOPT_FILE, out_file ); + curl_easy_setopt ( curl, CURLOPT_WRITEDATA, out_file ); curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, curl_write_func); curl_easy_setopt(curl, CURLOPT_COOKIEJAR, cookie_file); res = curl_easy_perform(curl); @@ -125,8 +131,11 @@ int curl_download_uri ( const char *uri, FILE *f, DownloadOptions *options ) if (vik_verbose) curl_easy_setopt ( curl, CURLOPT_VERBOSE, 1 ); curl_easy_setopt ( curl, CURLOPT_URL, uri ); - curl_easy_setopt ( curl, CURLOPT_FILE, f ); + curl_easy_setopt ( curl, CURLOPT_WRITEDATA, f ); curl_easy_setopt ( curl, CURLOPT_WRITEFUNCTION, curl_write_func); + curl_easy_setopt ( curl, CURLOPT_NOPROGRESS, 0 ); + curl_easy_setopt ( curl, CURLOPT_PROGRESSDATA, NULL ); + curl_easy_setopt ( curl, CURLOPT_PROGRESSFUNCTION, curl_progress_func); if (options != NULL) { if(options->referer != NULL) curl_easy_setopt ( curl, CURLOPT_REFERER, options->referer);