diff options
author | Martin Szulecki | 2011-04-26 22:51:31 +0200 |
---|---|---|
committer | Martin Szulecki | 2011-04-26 22:51:31 +0200 |
commit | ceb09353a8524917de1a9d3b65518c631a300de1 (patch) | |
tree | 8167cc8cb7e41efb03b2927b3e7d1d90fd24f2a8 | |
parent | 7569c579433b8bcf6acf15c7e769c3fd79a9e460 (diff) | |
download | libimobiledevice-ceb09353a8524917de1a9d3b65518c631a300de1.tar.gz libimobiledevice-ceb09353a8524917de1a9d3b65518c631a300de1.tar.bz2 |
idevicebackup4: Split print_progress() to be able to pass percentages
-rw-r--r-- | tools/idevicebackup4.c | 41 |
1 files changed, 31 insertions, 10 deletions
diff --git a/tools/idevicebackup4.c b/tools/idevicebackup4.c index 50451f3..d581633 100644 --- a/tools/idevicebackup4.c +++ b/tools/idevicebackup4.c @@ -453,17 +453,9 @@ static void do_post_notification(const char *notification) } } -static void print_progress(uint64_t current, uint64_t total) +static void print_progress_real(double progress, int flush) { - gchar *format_size = NULL; int i = 0; - double progress = ((double)current/(double)total)*100; - if (progress < 0) - return; - - if (progress > 100) - progress = 100; - PRINT_VERBOSE(1, "\r["); for(i = 0; i < 50; i++) { if(i < progress / 2) { @@ -474,6 +466,25 @@ static void print_progress(uint64_t current, uint64_t total) } PRINT_VERBOSE(1, "] %3.0f%%", progress); + if (flush > 0) { + fflush(stdout); + if (progress == 100) + PRINT_VERBOSE(1, "\n"); + } +} + +static void print_progress(uint64_t current, uint64_t total) +{ + gchar *format_size = NULL; + double progress = ((double)current/(double)total)*100; + if (progress < 0) + return; + + if (progress > 100) + progress = 100; + + print_progress_real((double)progress, 0); + format_size = g_format_size_for_display(current); PRINT_VERBOSE(1, " (%s", format_size); g_free(format_size); @@ -652,6 +663,7 @@ static void mb2_handle_send_files(plist_t message, const char *backup_dir) uint32_t i = 0; uint32_t sent; plist_t errplist = NULL; + double progress = 0; if (!message || (plist_get_node_type(message) != PLIST_ARRAY) || (plist_array_get_size(message) < 2) || !backup_dir) return; @@ -659,8 +671,12 @@ static void mb2_handle_send_files(plist_t message, const char *backup_dir) cnt = plist_array_get_size(files); if (cnt == 0) return; + plist_t val = plist_array_get_item(message, 3); + plist_get_real_val(val, &progress); + val = NULL; + for (i = 0; i < cnt; i++) { - plist_t val = plist_array_get_item(files, i); + val = plist_array_get_item(files, i); if (plist_get_node_type(val) != PLIST_STRING) { continue; } @@ -686,6 +702,11 @@ static void mb2_handle_send_files(plist_t message, const char *backup_dir) mobilebackup2_send_status_response(mobilebackup2, -13, "Multi status", errplist); plist_free(errplist); } + + if (progress > 0) { + print_progress_real(progress, 1); + PRINT_VERBOSE(1, "\n"); + } } static int mb2_handle_receive_files(plist_t message, const char *backup_dir) |