summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorGravatar Nikias Bassen2012-02-13 02:50:43 +0100
committerGravatar Nikias Bassen2012-02-13 02:50:43 +0100
commitf8ddc75b339351d9536b2df6868d5f92702742f4 (patch)
treef4f22647198f13159ea65065f3911949c7ab5c95 /src
parent9dd1484f561edf6f86f5e6cb128ddee93fbc9652 (diff)
downloadidevicerestore-f8ddc75b339351d9536b2df6868d5f92702742f4.tar.gz
idevicerestore-f8ddc75b339351d9536b2df6868d5f92702742f4.tar.bz2
download: add progress bar for download_to_file function
Diffstat (limited to 'src')
-rw-r--r--src/download.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/download.c b/src/download.c
index ebf5da4..cbde282 100644
--- a/src/download.c
+++ b/src/download.c
@@ -82,6 +82,17 @@ int download_to_buffer(const char* url, char** buf, uint32_t* length)
return res;
}
+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);
+ }
+
+ return 0;
+}
+
int download_to_file(const char* url, const char* filename)
{
int res = 0;
@@ -100,6 +111,8 @@ int download_to_file(const char* url, const char* filename)
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);
+ curl_easy_setopt(handle, CURLOPT_NOPROGRESS, 0);
curl_easy_setopt(handle, CURLOPT_USERAGENT, "InetURL/1.0");
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);
curl_easy_setopt(handle, CURLOPT_URL, url);