summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/idevicebackup.c57
1 files changed, 49 insertions, 8 deletions
diff --git a/tools/idevicebackup.c b/tools/idevicebackup.c
index b8e39bb..76ae1a0 100644
--- a/tools/idevicebackup.c
+++ b/tools/idevicebackup.c
@@ -630,6 +630,29 @@ static void do_post_notification(const char *notification)
630 } 630 }
631} 631}
632 632
633static void print_progress(double progress)
634{
635 int i = 0;
636 if (progress < 0)
637 return;
638
639 if (progress > 100)
640 progress = 100;
641
642 printf("\r[");
643 for(i = 0; i < 50; i++) {
644 if(i < progress / 2) {
645 printf("=");
646 } else {
647 printf(" ");
648 }
649 }
650 printf("] %3.0f%%", progress);
651 fflush(stdout);
652 if (progress == 100)
653 printf("\n");
654}
655
633/** 656/**
634 * signal handler function for cleaning up properly 657 * signal handler function for cleaning up properly
635 */ 658 */
@@ -933,6 +956,8 @@ int main(int argc, char *argv[])
933 plist_t message = NULL; 956 plist_t message = NULL;
934 957
935 /* receive and save DLSendFile files and metadata, ACK each */ 958 /* receive and save DLSendFile files and metadata, ACK each */
959 uint64_t file_size = 0;
960 uint64_t file_size_current = 0;
936 int file_index = 0; 961 int file_index = 0;
937 int hunk_index = 0; 962 int hunk_index = 0;
938 uint64_t backup_real_size = 0; 963 uint64_t backup_real_size = 0;
@@ -985,8 +1010,7 @@ int main(int argc, char *argv[])
985 } 1010 }
986 is_manifest = (b == 1) ? TRUE: FALSE; 1011 is_manifest = (b == 1) ? TRUE: FALSE;
987 1012
988 /* check if we completed a file */ 1013 if ((hunk_index == 0) && (!is_manifest)) {
989 if ((file_status == DEVICE_LINK_FILE_STATUS_LAST_HUNK) && (!is_manifest)) {
990 /* get source filename */ 1014 /* get source filename */
991 node = plist_dict_get_item(node_tmp, "DLFileSource"); 1015 node = plist_dict_get_item(node_tmp, "DLFileSource");
992 plist_get_string_val(node, &filename_source); 1016 plist_get_string_val(node, &filename_source);
@@ -994,8 +1018,8 @@ int main(int argc, char *argv[])
994 /* increase received size */ 1018 /* increase received size */
995 node = plist_dict_get_item(node_tmp, "DLFileAttributesKey"); 1019 node = plist_dict_get_item(node_tmp, "DLFileAttributesKey");
996 node = plist_dict_get_item(node, "FileSize"); 1020 node = plist_dict_get_item(node, "FileSize");
997 plist_get_uint_val(node, &length); 1021 plist_get_uint_val(node, &file_size);
998 backup_real_size += length; 1022 backup_real_size += file_size;
999 1023
1000 format_size = g_format_size_for_display(backup_real_size); 1024 format_size = g_format_size_for_display(backup_real_size);
1001 printf("(%s", format_size); 1025 printf("(%s", format_size);
@@ -1005,11 +1029,16 @@ int main(int argc, char *argv[])
1005 printf("/%s): ", format_size); 1029 printf("/%s): ", format_size);
1006 g_free(format_size); 1030 g_free(format_size);
1007 1031
1008 printf("Received file %s... ", filename_source); 1032 format_size = g_format_size_for_display(file_size);
1033 printf("Receiving file %s (%s)... \n", filename_source, format_size);
1034 g_free(format_size);
1009 1035
1010 if (filename_source) 1036 if (filename_source)
1011 free(filename_source); 1037 free(filename_source);
1038 }
1012 1039
1040 /* check if we completed a file */
1041 if ((file_status == DEVICE_LINK_FILE_STATUS_LAST_HUNK) && (!is_manifest)) {
1013 /* save <hash>.mdinfo */ 1042 /* save <hash>.mdinfo */
1014 node = plist_dict_get_item(node_tmp, "BackupFileInfo"); 1043 node = plist_dict_get_item(node_tmp, "BackupFileInfo");
1015 if (node) { 1044 if (node) {
@@ -1048,6 +1077,8 @@ int main(int argc, char *argv[])
1048 plist_get_data_val(node_tmp, &buffer, &length); 1077 plist_get_data_val(node_tmp, &buffer, &length);
1049 1078
1050 buffer_write_to_filename(filename_mddata, buffer, length); 1079 buffer_write_to_filename(filename_mddata, buffer, length);
1080 if (!is_manifest)
1081 file_size_current += length;
1051 1082
1052 /* activate currently sent manifest */ 1083 /* activate currently sent manifest */
1053 if ((file_status == DEVICE_LINK_FILE_STATUS_LAST_HUNK) && (is_manifest)) { 1084 if ((file_status == DEVICE_LINK_FILE_STATUS_LAST_HUNK) && (is_manifest)) {
@@ -1060,6 +1091,15 @@ int main(int argc, char *argv[])
1060 g_free(filename_mddata); 1091 g_free(filename_mddata);
1061 } 1092 }
1062 1093
1094 if ((!is_manifest)) {
1095 if (hunk_index == 0 && file_status == DEVICE_LINK_FILE_STATUS_LAST_HUNK) {
1096 print_progress(100);
1097 } else {
1098 if (file_size > 0)
1099 print_progress((double)((file_size_current*100)/file_size));
1100 }
1101 }
1102
1063 hunk_index++; 1103 hunk_index++;
1064 1104
1065 if (file_ext) 1105 if (file_ext)
@@ -1070,13 +1110,14 @@ int main(int argc, char *argv[])
1070 message = NULL; 1110 message = NULL;
1071 1111
1072 if (file_status == DEVICE_LINK_FILE_STATUS_LAST_HUNK) { 1112 if (file_status == DEVICE_LINK_FILE_STATUS_LAST_HUNK) {
1073 if (!is_manifest)
1074 printf("DONE\n");
1075
1076 /* acknowlegdge that we received the file */ 1113 /* acknowlegdge that we received the file */
1077 mobilebackup_send_backup_file_received(mobilebackup); 1114 mobilebackup_send_backup_file_received(mobilebackup);
1078 /* reset hunk_index */ 1115 /* reset hunk_index */
1079 hunk_index = 0; 1116 hunk_index = 0;
1117 if (!is_manifest) {
1118 file_size_current = 0;
1119 file_size = 0;
1120 }
1080 } 1121 }
1081files_out: 1122files_out:
1082 if (quit_flag > 0) { 1123 if (quit_flag > 0) {