diff options
author | ticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2008-12-14 23:15:38 (EST) |
---|---|---|
committer | ticktock35 <ticktock35@e8e0d7a0-c8d9-11dd-a880-a1081c7ac358> | 2008-12-14 23:15:38 (EST) |
commit | 7fc0de8e48b598a188237a13424be3f86189b3d9 (patch) | |
tree | 1d9e20bef91e6170ef9f52ecac2427b6c88c80a8 | |
parent | 33f7f7dd7817690b4248b164bdb149a35a7a6b95 (diff) |
ipkg: add a simple progress bar while downloading
git-svn-id: http://opkg.googlecode.com/svn/trunk@7 e8e0d7a0-c8d9-11dd-a880-a1081c7ac358
-rw-r--r-- | ipkg_download.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/ipkg_download.c b/ipkg_download.c index 192c8b3..621ff03 100644 --- a/ipkg_download.c +++ b/ipkg_download.c @@ -4,6 +4,7 @@ Carl D. Worth Copyright (C) 2001 University of Southern California + Copyright (C) 2008 OpenMoko Inc This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as @@ -27,6 +28,29 @@ #include "file_util.h" #include "str_util.h" + +int +curl_progress_func (void* data, + double t, /* dltotal */ + double d, /* dlnow */ + double ultotal, + double ulnow) +{ + int i; + int p = d*100/t; + printf ("\r%3d%% |", p); + for (i = 1; i < 73; i++) + { + if (i <= p) + printf ("="); + else + printf ("-"); + } + printf ("|"); + fflush(stdout); + return 0; +} + int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name) { int err = 0; @@ -99,12 +123,14 @@ int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name CURL *curl; CURLcode res; FILE * file = fopen (tmp_file_location, "w"); - + curl = curl_easy_init (); if (curl) { curl_easy_setopt (curl, CURLOPT_URL, src); curl_easy_setopt (curl, CURLOPT_WRITEDATA, file); + curl_easy_setopt(curl, CURLOPT_NOPROGRESS, 0); + curl_easy_setopt (curl, CURLOPT_PROGRESSFUNCTION, curl_progress_func); res = curl_easy_perform (curl); curl_easy_cleanup (curl); fclose (file); @@ -113,6 +139,8 @@ int ipkg_download(ipkg_conf_t *conf, const char *src, const char *dest_file_name else return -1; + printf ("\n"); + err = file_move(tmp_file_location, dest_file_name); free(tmp_file_location); |