diff options
| author | 2010-01-25 02:14:40 +0100 | |
|---|---|---|
| committer | 2010-01-25 02:14:40 +0100 | |
| commit | a6bb8a89e42b6b301214d5f6e52522e5be7870eb (patch) | |
| tree | 7bd9c7067c435b4a3146b8bcb2dcbc7b944dde2a | |
| parent | 9f1677222b06f41c4ab309918511f3c3918a822e (diff) | |
| download | libimobiledevice-a6bb8a89e42b6b301214d5f6e52522e5be7870eb.tar.gz libimobiledevice-a6bb8a89e42b6b301214d5f6e52522e5be7870eb.tar.bz2 | |
Print progress of backup
| -rw-r--r-- | tools/iphonebackup.c | 47 |
1 files changed, 39 insertions, 8 deletions
diff --git a/tools/iphonebackup.c b/tools/iphonebackup.c index 1ad4116..927d195 100644 --- a/tools/iphonebackup.c +++ b/tools/iphonebackup.c | |||
| @@ -242,6 +242,8 @@ int main(int argc, char *argv[]) | |||
| 242 | plist_t node_tmp = NULL; | 242 | plist_t node_tmp = NULL; |
| 243 | char *buffer = NULL; | 243 | char *buffer = NULL; |
| 244 | uint64_t length = 0; | 244 | uint64_t length = 0; |
| 245 | uint64_t backup_total_size = 0; | ||
| 246 | uint64_t c = 0; | ||
| 245 | 247 | ||
| 246 | /* we need to exit cleanly on running backups and restores or we cause havok */ | 248 | /* we need to exit cleanly on running backups and restores or we cause havok */ |
| 247 | signal(SIGINT, clean_exit); | 249 | signal(SIGINT, clean_exit); |
| @@ -352,8 +354,6 @@ int main(int argc, char *argv[]) | |||
| 352 | /* TODO: check domain com.apple.mobile.backup key RequiresEncrypt and WillEncrypt with lockdown */ | 354 | /* TODO: check domain com.apple.mobile.backup key RequiresEncrypt and WillEncrypt with lockdown */ |
| 353 | /* TODO: verify battery on AC enough battery remaining */ | 355 | /* TODO: verify battery on AC enough battery remaining */ |
| 354 | 356 | ||
| 355 | /* ????: create target directory: MobileSync/Backup/<uuid>-YYYYMMDD-HHMMSS/ */ | ||
| 356 | |||
| 357 | /* create Info.plist (Device infos, IC-Info.sidb, photos, app_ids, iTunesPrefs) */ | 357 | /* create Info.plist (Device infos, IC-Info.sidb, photos, app_ids, iTunesPrefs) */ |
| 358 | printf("Creating \"%s/Info.plist\".\n", backup_directory); | 358 | printf("Creating \"%s/Info.plist\".\n", backup_directory); |
| 359 | plist_t info_plist = mobilebackup_factory_info_plist(); | 359 | plist_t info_plist = mobilebackup_factory_info_plist(); |
| @@ -370,6 +370,7 @@ int main(int argc, char *argv[]) | |||
| 370 | /* create Manifest.plist (backup manifest (backup state)) */ | 370 | /* create Manifest.plist (backup manifest (backup state)) */ |
| 371 | printf("Creating \"%s/Manifest.plist\".\n", backup_directory); | 371 | printf("Creating \"%s/Manifest.plist\".\n", backup_directory); |
| 372 | char *manifest_path = g_build_path(G_DIR_SEPARATOR_S, backup_directory, "Manifest.plist", NULL); | 372 | char *manifest_path = g_build_path(G_DIR_SEPARATOR_S, backup_directory, "Manifest.plist", NULL); |
| 373 | /* FIXME: We should read the last Manifest.plist and send it to the device */ | ||
| 373 | plist_t manifest_plist = NULL; | 374 | plist_t manifest_plist = NULL; |
| 374 | if (stat(manifest_path, &st) == 0) | 375 | if (stat(manifest_path, &st) == 0) |
| 375 | remove(manifest_path); | 376 | remove(manifest_path); |
| @@ -406,6 +407,7 @@ int main(int argc, char *argv[]) | |||
| 406 | printf("Device accepts manifest and will send backup data now...\n"); | 407 | printf("Device accepts manifest and will send backup data now...\n"); |
| 407 | backup_ok = 1; | 408 | backup_ok = 1; |
| 408 | printf("Acknowledging...\n"); | 409 | printf("Acknowledging...\n"); |
| 410 | printf("Please wait. Device prepares backup data...\n"); | ||
| 409 | /* send it back for ACK */ | 411 | /* send it back for ACK */ |
| 410 | mobilebackup_send(mobilebackup, message); | 412 | mobilebackup_send(mobilebackup, message); |
| 411 | } | 413 | } |
| @@ -423,23 +425,51 @@ int main(int argc, char *argv[]) | |||
| 423 | 425 | ||
| 424 | /* receive and save DLSendFile files and metadata, ACK each */ | 426 | /* receive and save DLSendFile files and metadata, ACK each */ |
| 425 | int file_index = 0; | 427 | int file_index = 0; |
| 428 | uint64_t backup_real_size = 0; | ||
| 426 | char *file_path = NULL; | 429 | char *file_path = NULL; |
| 427 | char *file_ext = NULL; | 430 | char *file_ext = NULL; |
| 428 | char *filename_mdinfo = NULL; | 431 | char *filename_mdinfo = NULL; |
| 429 | char *filename_mddata = NULL; | 432 | char *filename_mddata = NULL; |
| 430 | char *filename_source = NULL; | 433 | char *filename_source = NULL; |
| 434 | char *format_size = NULL; | ||
| 431 | do { | 435 | do { |
| 432 | mobilebackup_receive(mobilebackup, &message); | 436 | mobilebackup_receive(mobilebackup, &message); |
| 433 | node = plist_array_get_item(message, 0); | 437 | node = plist_array_get_item(message, 0); |
| 434 | if (plist_strcmp(node, "DLSendFile")) | 438 | if (plist_strcmp(node, "DLSendFile")) |
| 435 | break; | 439 | break; |
| 436 | 440 | ||
| 437 | /* get source filename and print it */ | ||
| 438 | node_tmp = plist_array_get_item(message, 2); | 441 | node_tmp = plist_array_get_item(message, 2); |
| 439 | node = plist_dict_get_item(node_tmp, "DLFileSource"); | 442 | |
| 440 | plist_get_string_val(node, &filename_source); | 443 | /* first message contains total backup size */ |
| 441 | printf("Received file %s...", filename_source); | 444 | if (file_index == 0) { |
| 442 | free(filename_source); | 445 | node = plist_dict_get_item(node_tmp, "BackupTotalSizeKey"); |
| 446 | plist_get_uint_val(node, &backup_total_size); | ||
| 447 | format_size = g_format_size_for_display(backup_total_size); | ||
| 448 | printf("Backup will need %s on disk.\n", format_size); | ||
| 449 | g_free(format_size); | ||
| 450 | } | ||
| 451 | |||
| 452 | /* print out "received" if DLFileStatusKey is 2 (last file piece) */ | ||
| 453 | node = plist_dict_get_item(node_tmp, "DLFileStatusKey"); | ||
| 454 | plist_get_uint_val(node, &c); | ||
| 455 | if (c == 2) { | ||
| 456 | node = plist_dict_get_item(node_tmp, "DLFileAttributesKey"); | ||
| 457 | node = plist_dict_get_item(node, "FileSize"); | ||
| 458 | plist_get_uint_val(node, &length); | ||
| 459 | backup_real_size += length; | ||
| 460 | format_size = g_format_size_for_display(backup_real_size); | ||
| 461 | printf("(%s", format_size); | ||
| 462 | g_free(format_size); | ||
| 463 | format_size = g_format_size_for_display(backup_total_size); | ||
| 464 | printf("/%s): ", format_size); | ||
| 465 | g_free(format_size); | ||
| 466 | |||
| 467 | /* get source filename and print it */ | ||
| 468 | node = plist_dict_get_item(node_tmp, "DLFileSource"); | ||
| 469 | plist_get_string_val(node, &filename_source); | ||
| 470 | printf("Received file %s... ", filename_source); | ||
| 471 | free(filename_source); | ||
| 472 | } | ||
| 443 | 473 | ||
| 444 | /* save <hash>.mdinfo */ | 474 | /* save <hash>.mdinfo */ |
| 445 | node = plist_dict_get_item(node_tmp, "BackupFileInfo"); | 475 | node = plist_dict_get_item(node_tmp, "BackupFileInfo"); |
| @@ -469,7 +499,8 @@ int main(int argc, char *argv[]) | |||
| 469 | g_free(filename_mddata); | 499 | g_free(filename_mddata); |
| 470 | } | 500 | } |
| 471 | 501 | ||
| 472 | printf("DONE\n"); | 502 | if (c == 2) |
| 503 | printf("DONE\n"); | ||
| 473 | 504 | ||
| 474 | if (file_ext) | 505 | if (file_ext) |
| 475 | free(file_ext); | 506 | free(file_ext); |
