summaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorGravatar Martin Szulecki2013-01-16 13:16:58 +0100
committerGravatar Martin Szulecki2013-01-16 13:16:58 +0100
commitd61d30ab8edafb8cbac3eaa1935abdd2257eeaee (patch)
treeff815de5d0e8bde1b1fae79b14ede37e68f1ffd9 /tools
parentfae8c7cfc85525c782d5f0c20afd0270a93e656c (diff)
downloadlibimobiledevice-d61d30ab8edafb8cbac3eaa1935abdd2257eeaee.tar.gz
libimobiledevice-d61d30ab8edafb8cbac3eaa1935abdd2257eeaee.tar.bz2
idevicebackup2: Refactor output of overall progress for more frequent reporting
Diffstat (limited to 'tools')
-rw-r--r--tools/idevicebackup2.c46
1 files changed, 36 insertions, 10 deletions
diff --git a/tools/idevicebackup2.c b/tools/idevicebackup2.c
index b7e33f6..bcaad5c 100644
--- a/tools/idevicebackup2.c
+++ b/tools/idevicebackup2.c
@@ -549,6 +549,35 @@ static void print_progress(uint64_t current, uint64_t total)
549 PRINT_VERBOSE(1, "\n"); 549 PRINT_VERBOSE(1, "\n");
550} 550}
551 551
552static double overall_progress = 0;
553
554static void mb2_set_overall_progress(double progress)
555{
556 if (progress > 0.0)
557 overall_progress = progress;
558}
559
560static void mb2_set_overall_progress_from_message(plist_t message, char* identifier)
561{
562 plist_t node = NULL;
563 double progress = 0.0;
564
565 if (!strcmp(identifier, "DLMessageDownloadFiles")) {
566 node = plist_array_get_item(message, 3);
567 } else if (!strcmp(identifier, "DLMessageUploadFiles")) {
568 node = plist_array_get_item(message, 2);
569 } else if (!strcmp(identifier, "DLMessageMoveFiles") || !strcmp(identifier, "DLMessageMoveItems")) {
570 node = plist_array_get_item(message, 3);
571 } else if (!strcmp(identifier, "DLMessageRemoveFiles") || !strcmp(identifier, "DLMessageRemoveItems")) {
572 node = plist_array_get_item(message, 3);
573 }
574
575 if (node != NULL) {
576 plist_get_real_val(node, &progress);
577 mb2_set_overall_progress(progress);
578 }
579}
580
552static void mb2_multi_status_add_file_error(plist_t status_dict, const char *path, int error_code, const char *error_message) 581static void mb2_multi_status_add_file_error(plist_t status_dict, const char *path, int error_code, const char *error_message)
553{ 582{
554 if (!status_dict) return; 583 if (!status_dict) return;
@@ -1859,9 +1888,11 @@ checkpoint:
1859 1888
1860 if (!strcmp(dlmsg, "DLMessageDownloadFiles")) { 1889 if (!strcmp(dlmsg, "DLMessageDownloadFiles")) {
1861 /* device wants to download files from the computer */ 1890 /* device wants to download files from the computer */
1891 mb2_set_overall_progress_from_message(message, dlmsg);
1862 mb2_handle_send_files(message, backup_directory); 1892 mb2_handle_send_files(message, backup_directory);
1863 } else if (!strcmp(dlmsg, "DLMessageUploadFiles")) { 1893 } else if (!strcmp(dlmsg, "DLMessageUploadFiles")) {
1864 /* device wants to send files to the computer */ 1894 /* device wants to send files to the computer */
1895 mb2_set_overall_progress_from_message(message, dlmsg);
1865 file_count += mb2_handle_receive_files(message, backup_directory); 1896 file_count += mb2_handle_receive_files(message, backup_directory);
1866 } else if (!strcmp(dlmsg, "DLMessageGetFreeDiskSpace")) { 1897 } else if (!strcmp(dlmsg, "DLMessageGetFreeDiskSpace")) {
1867 /* device wants to know how much disk space is available on the computer */ 1898 /* device wants to know how much disk space is available on the computer */
@@ -1888,6 +1919,7 @@ checkpoint:
1888 mb2_handle_make_directory(message, backup_directory); 1919 mb2_handle_make_directory(message, backup_directory);
1889 } else if (!strcmp(dlmsg, "DLMessageMoveFiles") || !strcmp(dlmsg, "DLMessageMoveItems")) { 1920 } else if (!strcmp(dlmsg, "DLMessageMoveFiles") || !strcmp(dlmsg, "DLMessageMoveItems")) {
1890 /* perform a series of rename operations */ 1921 /* perform a series of rename operations */
1922 mb2_set_overall_progress_from_message(message, dlmsg);
1891 plist_t moves = plist_array_get_item(message, 1); 1923 plist_t moves = plist_array_get_item(message, 1);
1892 uint32_t cnt = plist_dict_get_size(moves); 1924 uint32_t cnt = plist_dict_get_size(moves);
1893 PRINT_VERBOSE(1, "Moving %d file%s\n", cnt, (cnt == 1) ? "" : "s"); 1925 PRINT_VERBOSE(1, "Moving %d file%s\n", cnt, (cnt == 1) ? "" : "s");
@@ -1941,6 +1973,7 @@ checkpoint:
1941 printf("Could not send status response, error %d\n", err); 1973 printf("Could not send status response, error %d\n", err);
1942 } 1974 }
1943 } else if (!strcmp(dlmsg, "DLMessageRemoveFiles") || !strcmp(dlmsg, "DLMessageRemoveItems")) { 1975 } else if (!strcmp(dlmsg, "DLMessageRemoveFiles") || !strcmp(dlmsg, "DLMessageRemoveItems")) {
1976 mb2_set_overall_progress_from_message(message, dlmsg);
1944 plist_t removes = plist_array_get_item(message, 1); 1977 plist_t removes = plist_array_get_item(message, 1);
1945 uint32_t cnt = plist_array_get_size(removes); 1978 uint32_t cnt = plist_array_get_size(removes);
1946 PRINT_VERBOSE(1, "Removing %d file%s\n", cnt, (cnt == 1) ? "" : "s"); 1979 PRINT_VERBOSE(1, "Removing %d file%s\n", cnt, (cnt == 1) ? "" : "s");
@@ -2072,16 +2105,9 @@ checkpoint:
2072 } 2105 }
2073 2106
2074 /* print status */ 2107 /* print status */
2075 if (plist_array_get_size(message) >= 3) { 2108 if (overall_progress > 0) {
2076 plist_t pnode = plist_array_get_item(message, 3); 2109 print_progress_real(overall_progress, 0);
2077 if (pnode && (plist_get_node_type(pnode) == PLIST_REAL)) { 2110 PRINT_VERBOSE(1, " Finished\n");
2078 double progress = 0.0;
2079 plist_get_real_val(pnode, &progress);
2080 if (progress > 0) {
2081 print_progress_real(progress, 0);
2082 PRINT_VERBOSE(1, " Finished\n");
2083 }
2084 }
2085 } 2111 }
2086 2112
2087 if (message) 2113 if (message)