diff --git a/src/server/slavefuncs.c b/src/server/slavefuncs.c --- a/src/server/slavefuncs.c +++ b/src/server/slavefuncs.c @@ -78,8 +78,17 @@ size_t curl_writetodisk(void *ptr, size_ return fwrite(ptr, size, nmemb, stream); } +/** Helper function for cURL's progressbar */ +int curl_progress( char *Bar,double t,double d,double ultotal,double ulnow) +{ +fprintf(stderr,"Downloading... %f%% complete\r",d/t*100); +return 0; +} + /** Retrieves a URL with cURL and saves it to disk */ int curlget(char *url, char *out){ + + double *Bar; // Stores cURL progressbar info CURL *curl; CURLcode res; FILE *outfile; @@ -91,9 +100,13 @@ int curlget(char *url, char *out){ curl_easy_setopt(curl, CURLOPT_URL, url); curl_easy_setopt(curl, CURLOPT_WRITEDATA, outfile); curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, curl_writetodisk); // this MUST be set for win32 compat. + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); + curl_easy_setopt(curl, CURLOPT_PROGRESSFUNCTION, curl_progress); + curl_easy_setopt(curl, CURLOPT_PROGRESSDATA, &Bar); res = curl_easy_perform(curl); curl_easy_cleanup(curl); } + fprintf(stderr,"\n"); // Clears out he progressbar's carriage return return res; // 0 means OK, nonzero means AAAH badness }