From c72455263b9b0c66d8521e1017080cf3c8e40706 Mon Sep 17 00:00:00 2001 From: Nikias Bassen Date: Tue, 17 Jul 2012 15:38:51 +0200 Subject: download: only redraw progress bar on percentage change --- src/download.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'src/download.c') diff --git a/src/download.c b/src/download.c index cbde282..6222502 100644 --- a/src/download.c +++ b/src/download.c @@ -82,12 +82,17 @@ int download_to_buffer(const char* url, char** buf, uint32_t* length) return res; } +static int lastprogress = 0; + int download_progress(void *clientp, double dltotal, double dlnow, double ultotal, double ulnow) { double p = (dlnow / dltotal) * 100; if (p < 100.0f) { - print_progress_bar(p); + if ((int)p > lastprogress) { + print_progress_bar(p); + lastprogress = (int)p; + } } return 0; @@ -109,6 +114,7 @@ int download_to_file(const char* url, const char* filename) return -1; } + lastprogress = 0; curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, (curl_write_callback)&fwrite); curl_easy_setopt(handle, CURLOPT_WRITEDATA, f); curl_easy_setopt(handle, CURLOPT_PROGRESSFUNCTION, (curl_progress_callback)&download_progress); -- cgit v1.1-32-gdbae