summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2011-04-26 22:51:31 +0200
committerGravatar Martin Szulecki2011-04-26 22:51:31 +0200
commitceb09353a8524917de1a9d3b65518c631a300de1 (patch)
tree8167cc8cb7e41efb03b2927b3e7d1d90fd24f2a8
parent7569c579433b8bcf6acf15c7e769c3fd79a9e460 (diff)
downloadlibimobiledevice-ceb09353a8524917de1a9d3b65518c631a300de1.tar.gz
libimobiledevice-ceb09353a8524917de1a9d3b65518c631a300de1.tar.bz2
idevicebackup4: Split print_progress() to be able to pass percentages
-rw-r--r--tools/idevicebackup4.c41
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)
453 } 453 }
454} 454}
455 455
456static void print_progress(uint64_t current, uint64_t total) 456static void print_progress_real(double progress, int flush)
457{ 457{
458 gchar *format_size = NULL;
459 int i = 0; 458 int i = 0;
460 double progress = ((double)current/(double)total)*100;
461 if (progress < 0)
462 return;
463
464 if (progress > 100)
465 progress = 100;
466
467 PRINT_VERBOSE(1, "\r["); 459 PRINT_VERBOSE(1, "\r[");
468 for(i = 0; i < 50; i++) { 460 for(i = 0; i < 50; i++) {
469 if(i < progress / 2) { 461 if(i < progress / 2) {
@@ -474,6 +466,25 @@ static void print_progress(uint64_t current, uint64_t total)
474 } 466 }
475 PRINT_VERBOSE(1, "] %3.0f%%", progress); 467 PRINT_VERBOSE(1, "] %3.0f%%", progress);
476 468
469 if (flush > 0) {
470 fflush(stdout);
471 if (progress == 100)
472 PRINT_VERBOSE(1, "\n");
473 }
474}
475
476static void print_progress(uint64_t current, uint64_t total)
477{
478 gchar *format_size = NULL;
479 double progress = ((double)current/(double)total)*100;
480 if (progress < 0)
481 return;
482
483 if (progress > 100)
484 progress = 100;
485
486 print_progress_real((double)progress, 0);
487
477 format_size = g_format_size_for_display(current); 488 format_size = g_format_size_for_display(current);
478 PRINT_VERBOSE(1, " (%s", format_size); 489 PRINT_VERBOSE(1, " (%s", format_size);
479 g_free(format_size); 490 g_free(format_size);
@@ -652,6 +663,7 @@ static void mb2_handle_send_files(plist_t message, const char *backup_dir)
652 uint32_t i = 0; 663 uint32_t i = 0;
653 uint32_t sent; 664 uint32_t sent;
654 plist_t errplist = NULL; 665 plist_t errplist = NULL;
666 double progress = 0;
655 667
656 if (!message || (plist_get_node_type(message) != PLIST_ARRAY) || (plist_array_get_size(message) < 2) || !backup_dir) return; 668 if (!message || (plist_get_node_type(message) != PLIST_ARRAY) || (plist_array_get_size(message) < 2) || !backup_dir) return;
657 669
@@ -659,8 +671,12 @@ static void mb2_handle_send_files(plist_t message, const char *backup_dir)
659 cnt = plist_array_get_size(files); 671 cnt = plist_array_get_size(files);
660 if (cnt == 0) return; 672 if (cnt == 0) return;
661 673
674 plist_t val = plist_array_get_item(message, 3);
675 plist_get_real_val(val, &progress);
676 val = NULL;
677
662 for (i = 0; i < cnt; i++) { 678 for (i = 0; i < cnt; i++) {
663 plist_t val = plist_array_get_item(files, i); 679 val = plist_array_get_item(files, i);
664 if (plist_get_node_type(val) != PLIST_STRING) { 680 if (plist_get_node_type(val) != PLIST_STRING) {
665 continue; 681 continue;
666 } 682 }
@@ -686,6 +702,11 @@ static void mb2_handle_send_files(plist_t message, const char *backup_dir)
686 mobilebackup2_send_status_response(mobilebackup2, -13, "Multi status", errplist); 702 mobilebackup2_send_status_response(mobilebackup2, -13, "Multi status", errplist);
687 plist_free(errplist); 703 plist_free(errplist);
688 } 704 }
705
706 if (progress > 0) {
707 print_progress_real(progress, 1);
708 PRINT_VERBOSE(1, "\n");
709 }
689} 710}
690 711
691static int mb2_handle_receive_files(plist_t message, const char *backup_dir) 712static int mb2_handle_receive_files(plist_t message, const char *backup_dir)